Skip to content

Commit

Permalink
fix: dot property should allow escaped keyword in strict mode
Browse files Browse the repository at this point in the history
closes #224
  • Loading branch information
3cp committed Sep 10, 2022
1 parent 427233e commit efaa535
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/lexer/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,20 @@ export function scanIdentifierSlowCase(
}

if (context & Context.Strict) {
return token === Token.StaticKeyword
? Token.EscapedFutureReserved
: (token & Token.FutureReserved) === Token.FutureReserved
? Token.EscapedFutureReserved
: (token & Token.Reserved) === Token.Reserved
? Token.EscapedReserved
: Token.AnyIdentifier;
if (token === Token.StaticKeyword) {
return Token.EscapedFutureReserved;
}
if ((token & Token.FutureReserved) === Token.FutureReserved) {
return Token.EscapedFutureReserved;
}
if ((token & Token.Reserved) === Token.Reserved) {
if (context & Context.AllowEscapedKeyword && (context & Context.InGlobal) === 0) {
return token;
} else {
return Token.EscapedReserved;
}
}
return Token.AnyIdentifier;
}
if (
context & Context.AllowEscapedKeyword &&
Expand Down
12 changes: 11 additions & 1 deletion test/parser/miscellaneous/escaped-keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,24 @@ describe('Miscellaneous - Escaped keywords', () => {
`async function a() {
\\u0061sync
p => {}
}`
}`,
`obj.bre\\u0061k = 42;`,
`for (\\u0061sync of [7]);`
]) {
it(`${arg}`, () => {
t.doesNotThrow(() => {
parseSource(`${arg}`, undefined, Context.None);
});
});
}

for (const arg of [`obj.bre\\u0061k = 42;`, `for (\\u0061sync of [7]);`]) {
it(`${arg}`, () => {
t.doesNotThrow(() => {
parseSource(`${arg}`, undefined, Context.Strict | Context.Module);
});
});
}
//
fail('Miscellaneous - Escaped identifiers (failures)', [
['(x === n\\u0075ll);', Context.None],
Expand Down

0 comments on commit efaa535

Please sign in to comment.