fix(node-swc): Fix handling of tagged template expressions in Visitor (#1544)

This commit is contained in:
Arend van Beelen jr 2021-04-06 08:22:05 +02:00 committed by GitHub
parent beeb1f9067
commit 228429c7bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -83,6 +83,9 @@ const Visitor = require("../../../Visitor").default;
call(...foo);
call(foo);
// Verify that visitor can handle tagged template expressions.
css\`color: red\`;
let arr = [elem, , ...foo];
module.exports = {

View File

@ -1156,7 +1156,10 @@ export default class Visitor {
visitTaggedTemplateExpression(n: TaggedTemplateExpression): Expression {
n.tag = this.visitExpression(n.tag);
n.expressions = n.expressions.map(this.visitExpression.bind(this));
const template = this.visitTemplateLiteral(n.template);
if (template.type === "TemplateLiteral") {
n.template = template;
}
return n;
}

View File

@ -957,21 +957,21 @@ export interface AwaitExpression extends ExpressionBase {
argument: Expression;
}
export interface TplBase {
export interface TemplateLiteral extends ExpressionBase {
type: "TemplateLiteral";
expressions: Expression[];
quasis: TemplateElement[];
}
export interface TemplateLiteral extends ExpressionBase, TplBase {
type: "TemplateLiteral";
}
export interface TaggedTemplateExpression extends ExpressionBase, TplBase {
export interface TaggedTemplateExpression extends ExpressionBase {
type: "TaggedTemplateExpression";
tag: Expression;
template: TemplateLiteral;
typeParameters: TsTypeParameterInstantiation;
}
@ -1272,7 +1272,7 @@ export interface ImportNamespaceSpecifier extends Node, HasSpan {
export interface NamedImportSpecifier extends Node, HasSpan {
type: "ImportSpecifier";
local: Identifier;
imported: Identifier;
imported: Identifier | null;
}
export type ExportSpecifier =