Skip to content

Commit

Permalink
fix(parser): fix tagged template parsing when tag has param(s)
Browse files Browse the repository at this point in the history
closes #350
  • Loading branch information
ypapouski authored Oct 28, 2024
1 parent f056e3d commit b549ed3
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5674,7 +5674,7 @@ export function parseArguments(
if (parser.getToken() === Token.RightParen) break;
}

consume(parser, context, Token.RightParen);
consume(parser, context | Context.TaggedTemplate, Token.RightParen);

return args;
}
Expand Down
218 changes: 218 additions & 0 deletions test/parser/expressions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ describe('Expressions - Template', () => {
'(`\r`)',
'new nestedNewOperatorFunction`1``2``3``array`',
"tag()`'\\00a0'`;",
"tag('a')`'\\00a0'`",
"tag()('a')`'\\00a0'`",
"tag('a')('b')`'\\00a0'`",
"tag()(...a)`'\\00a0'`",
"tag('a')(b)(c, ...d)`'\\00a0'`;",
"(tag = () => {})`'\\00a0'`",
"(() => {})`'\\00a0'`",
"(function tag() { return () => {}; })()`'\\00a0'`",
Expand Down Expand Up @@ -4103,6 +4108,219 @@ describe('Expressions - Template', () => {
type: 'Program'
}
],
[
"tag('a')`'\\00a0'`;",
Context.None,
{
body: [
{
expression: {
quasi: {
expressions: [],
quasis: [
{
tail: true,
type: 'TemplateElement',
value: {
cooked: null,
raw: "'\\00a0'"
}
}
],
type: 'TemplateLiteral'
},
tag: {
arguments: [
{
type: 'Literal',
value: 'a'
}
],
callee: {
name: 'tag',
type: 'Identifier'
},
type: 'CallExpression'
},
type: 'TaggedTemplateExpression'
},
type: 'ExpressionStatement'
}
],
sourceType: 'script',
type: 'Program'
}
],
[
"tag('a')('b')`'\\00a0'`;",
Context.None,
{
body: [
{
expression: {
quasi: {
expressions: [],
quasis: [
{
tail: true,
type: 'TemplateElement',
value: {
cooked: null,
raw: "'\\00a0'"
}
}
],
type: 'TemplateLiteral'
},
tag: {
arguments: [
{
type: 'Literal',
value: 'b'
}
],
callee: {
arguments: [
{
type: 'Literal',
value: 'a'
}
],
callee: {
name: 'tag',
type: 'Identifier'
},
type: 'CallExpression'
},
type: 'CallExpression'
},
type: 'TaggedTemplateExpression'
},
type: 'ExpressionStatement'
}
],
sourceType: 'script',
type: 'Program'
}
],
[
"tag()(...a)`'\\00a0'`;",
Context.None,
{
body: [
{
expression: {
quasi: {
expressions: [],
quasis: [
{
tail: true,
type: 'TemplateElement',
value: {
cooked: null,
raw: "'\\00a0'"
}
}
],
type: 'TemplateLiteral'
},
tag: {
arguments: [
{
argument: {
name: 'a',
type: 'Identifier'
},
type: 'SpreadElement'
}
],
callee: {
arguments: [],
callee: {
name: 'tag',
type: 'Identifier'
},
type: 'CallExpression'
},
type: 'CallExpression'
},
type: 'TaggedTemplateExpression'
},
type: 'ExpressionStatement'
}
],
sourceType: 'script',
type: 'Program'
}
],
[
"tag('a')(b)(c, ...d)`'\\00a0'`;",
Context.None,
{
body: [
{
expression: {
quasi: {
expressions: [],
quasis: [
{
tail: true,
type: 'TemplateElement',
value: {
cooked: null,
raw: "'\\00a0'"
}
}
],
type: 'TemplateLiteral'
},
tag: {
arguments: [
{
name: 'c',
type: 'Identifier'
},
{
argument: {
name: 'd',
type: 'Identifier'
},
type: 'SpreadElement'
}
],
callee: {
arguments: [
{
name: 'b',
type: 'Identifier'
}
],
callee: {
arguments: [
{
type: 'Literal',
value: 'a'
}
],
callee: {
name: 'tag',
type: 'Identifier'
},
type: 'CallExpression'
},
type: 'CallExpression'
},
type: 'CallExpression'
},
type: 'TaggedTemplateExpression'
},
type: 'ExpressionStatement'
}
],
sourceType: 'script',
type: 'Program'
}
],
[
"(tag = () => {})`'\\00a0'`",
Context.None,
Expand Down

0 comments on commit b549ed3

Please sign in to comment.