From 5bd213ae912df5a88986a439ebbaf459720b5a28 Mon Sep 17 00:00:00 2001 From: Yuri Papouski Date: Wed, 3 Apr 2024 09:05:15 +0000 Subject: [PATCH 1/3] Extend context with 'TaggedTemplate' for 'parseParenthesizedExpression' and for 'parseArguments' --- dist/meriyah.umd.js | 4 ++-- src/parser.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/meriyah.umd.js b/dist/meriyah.umd.js index 97465845..dc766b9b 100644 --- a/dist/meriyah.umd.js +++ b/dist/meriyah.umd.js @@ -6534,7 +6534,7 @@ case 67174411: const leadingComment = collectLeadingComments(parser); parser.leadingComments && parser.leadingComments.pop(); - const exprNode = parseParenthesizedExpression(parser, context, canAssign, 1, 0, start, line, column); + const exprNode = parseParenthesizedExpression(parser, context | 65536, canAssign, 1, 0, start, line, column); if (exprNode.leadingComment && leadingComment) { exprNode.leadingComments.concat(leadingComment); } @@ -6711,7 +6711,7 @@ nextToken(parser, context | 32768); const args = []; if (parser.token === 16) { - nextToken(parser, context); + nextToken(parser, context | 65536); return args; } while (parser.token !== 16) { diff --git a/src/parser.ts b/src/parser.ts index 1b1a511d..4d292f52 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4407,7 +4407,7 @@ export function parsePrimaryExpression( parser.leadingComments && parser.leadingComments.pop(); const exprNode = parseParenthesizedExpression( parser, - context, + context | Context.TaggedTemplate, canAssign, BindingKind.ArgumentList, Origin.None, @@ -4802,7 +4802,7 @@ export function parseArguments( const args: (ESTree.Expression | ESTree.SpreadElement)[] = []; if (parser.token === Token.RightParen) { - nextToken(parser, context); + nextToken(parser, context | Context.TaggedTemplate); return args; } From 94c30663cc536711fcff999d3a6f0239078a2401 Mon Sep 17 00:00:00 2001 From: Yuri Papouski Date: Wed, 3 Apr 2024 15:53:40 +0000 Subject: [PATCH 2/3] Add octal string template tests --- test/parser/expressions/template.ts | 95 ++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/test/parser/expressions/template.ts b/test/parser/expressions/template.ts index a6311be8..fa7a9a96 100644 --- a/test/parser/expressions/template.ts +++ b/test/parser/expressions/template.ts @@ -338,7 +338,14 @@ describe('Expressions - Template', () => { 'test`\\18`;', '(`\n`)', '(`\r`)', - 'new nestedNewOperatorFunction`1``2``3``array`' + 'new nestedNewOperatorFunction`1``2``3``array`', + "tag()`'\\00a0'`;", + "(tag = () => {})`'\\00a0'`", + "(() => {})`'\\00a0'`", + "(function tag() { return () => {}; })()`'\\00a0'`", + "(function() { return () => {}; })()`'\\00a0'`", + "(function tag() {})`'\\00a0'`", + "(function() {})`'\\00a0'`" ]) { it(`${arg}`, () => { t.doesNotThrow(() => { @@ -4033,6 +4040,92 @@ describe('Expressions - Template', () => { } } } + ], + [ + "tag()`'\\00a0'`;", + Context.None, + { + body: [ + { + expression: { + quasi: { + expressions: [], + quasis: [ + { + tail: true, + type: 'TemplateElement', + value: { + cooked: undefined, + raw: "'\\00a0'" + } + } + ], + type: 'TemplateLiteral' + }, + tag: { + arguments: [], + callee: { + name: 'tag', + type: 'Identifier' + }, + type: 'CallExpression' + }, + type: 'TaggedTemplateExpression' + }, + type: 'ExpressionStatement' + } + ], + sourceType: 'script', + type: 'Program' + } + ], + [ + "(tag = () => {})`'\\00a0'`", + Context.None, + { + body: [ + { + expression: { + quasi: { + expressions: [], + quasis: [ + { + tail: true, + type: 'TemplateElement', + value: { + cooked: undefined, + raw: "'\\00a0'" + } + } + ], + type: 'TemplateLiteral' + }, + tag: { + left: { + name: 'tag', + type: 'Identifier' + }, + operator: '=', + right: { + async: false, + body: { + body: [], + type: 'BlockStatement' + }, + expression: false, + params: [], + type: 'ArrowFunctionExpression' + }, + type: 'AssignmentExpression' + }, + type: 'TaggedTemplateExpression' + }, + type: 'ExpressionStatement' + } + ], + sourceType: 'script', + type: 'Program' + } ] ]); }); From b4617e2c01335417ca421af23972c508d28626e3 Mon Sep 17 00:00:00 2001 From: Yuri Papouski Date: Wed, 3 Apr 2024 16:27:10 +0000 Subject: [PATCH 3/3] Extend context with tagged template for property access --- dist/meriyah.umd.js | 2 +- src/parser.ts | 2 +- test/parser/expressions/template.ts | 45 ++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/dist/meriyah.umd.js b/dist/meriyah.umd.js index dc766b9b..c47058e1 100644 --- a/dist/meriyah.umd.js +++ b/dist/meriyah.umd.js @@ -6314,7 +6314,7 @@ case 67108877: { nextToken(parser, (context | 1073741824 | 8192) ^ 8192); parser.assignable = 1; - const property = parsePropertyOrPrivatePropertyName(parser, context); + const property = parsePropertyOrPrivatePropertyName(parser, context | 65536); expr = finishNode(parser, context, start, line, column, { type: 'MemberExpression', object: expr, diff --git a/src/parser.ts b/src/parser.ts index 4d292f52..deb1efa2 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4043,7 +4043,7 @@ export function parseMemberOrUpdateExpression( parser.assignable = AssignmentKind.Assignable; - const property = parsePropertyOrPrivatePropertyName(parser, context); + const property = parsePropertyOrPrivatePropertyName(parser, context | Context.TaggedTemplate); expr = finishNode(parser, context, start, line, column, { type: 'MemberExpression', diff --git a/test/parser/expressions/template.ts b/test/parser/expressions/template.ts index fa7a9a96..ce60a7ba 100644 --- a/test/parser/expressions/template.ts +++ b/test/parser/expressions/template.ts @@ -345,7 +345,8 @@ describe('Expressions - Template', () => { "(function tag() { return () => {}; })()`'\\00a0'`", "(function() { return () => {}; })()`'\\00a0'`", "(function tag() {})`'\\00a0'`", - "(function() {})`'\\00a0'`" + "(function() {})`'\\00a0'`", + 'String.raw`{\rtf1adeflang1025ansiansicpg1252\\uc1`;' ]) { it(`${arg}`, () => { t.doesNotThrow(() => { @@ -4126,6 +4127,48 @@ describe('Expressions - Template', () => { sourceType: 'script', type: 'Program' } + ], + [ + 'String.raw`{\rtf1adeflang1025ansiansicpg1252\\uc1`;', + Context.None, + { + body: [ + { + expression: { + quasi: { + expressions: [], + quasis: [ + { + tail: true, + type: 'TemplateElement', + value: { + cooked: undefined, + raw: '{\rtf1adeflang1025ansiansicpg1252\\uc1' + } + } + ], + type: 'TemplateLiteral' + }, + tag: { + computed: false, + object: { + name: 'String', + type: 'Identifier' + }, + property: { + name: 'raw', + type: 'Identifier' + }, + type: 'MemberExpression' + }, + type: 'TaggedTemplateExpression' + }, + type: 'ExpressionStatement' + } + ], + sourceType: 'script', + type: 'Program' + } ] ]); });