Skip to content

Commit

Permalink
Merge pull request #29 from surfly/4815-invalid-hex-octal-string-temp…
Browse files Browse the repository at this point in the history
…late

Handle correctly octal or hex values located in template strings
  • Loading branch information
ypapouski authored Apr 5, 2024
2 parents 117e84c + b4617e2 commit 92456cc
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dist/meriyah.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
138 changes: 137 additions & 1 deletion test/parser/expressions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,15 @@ 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'`",
'String.raw`{\rtf1adeflang1025ansiansicpg1252\\uc1`;'
]) {
it(`${arg}`, () => {
t.doesNotThrow(() => {
Expand Down Expand Up @@ -4033,6 +4041,134 @@ 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'
}
],
[
'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'
}
]
]);
});

0 comments on commit 92456cc

Please sign in to comment.