Skip to content

Commit

Permalink
fix(parser): fixed escape keyword edgy cases
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Aug 15, 2019
1 parent 0a425ba commit 6c48765
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meriyah",
"version": "1.6.9",
"version": "1.6.10",
"description": "A 100% compliant, self-hosted javascript parser with high focus on both performance and stability",
"main": "dist/meriyah.umd.js",
"module": "dist/meriyah.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion src/meriyah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ export function parse(source: string, options?: Options): ESTree.Program {
export { Options, ESTree };

// Export current version
export const version = '1.6.9';
export const version = '1.6.10';
4 changes: 3 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5753,7 +5753,7 @@ export function parseObjectLiteralOrPattern(
let state = PropertyKind.None;
let key: ESTree.Expression | null = null;
let value;

let t = parser.token;
if (parser.token & (Token.IsIdentifier | Token.Keyword) || parser.token === Token.EscapedReserved) {
key = parseIdentifier(parser, context, 0);

Expand Down Expand Up @@ -5808,6 +5808,8 @@ export function parseObjectLiteralOrPattern(
if (parser.token & Token.IsIdentifier) {
const tokenAfterColon = parser.token;
const valueAfterColon = parser.tokenValue;
// A reserved word is an IdentifierName that cannot be used as an Identifier
destructible |= t === Token.EscapedReserved ? DestructuringKind.CannotDestruct : 0;

value = parsePrimaryExpressionExtended(parser, context, kind, 0, 1, 0, inGroup, tokenPos, linePos, colPos);

Expand Down
21 changes: 16 additions & 5 deletions test/parser/miscellaneous/escaped-keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('Miscellaneous - Escaped keywords', () => {
'var prot\\u0065cted = 1;',
'var { prot\\u0065cted } = {};',
'(publ\\u0069c);',
'var C = class { get "def\\u{61}ult"() { return "get string"; } set "def\\u{61}ult"(param) { stringSet = param; } };',
'var publ\\u0069c = 1;',
'var { publ\\u0069c } = {};',
'(st\\u0061tic);',
Expand All @@ -73,11 +74,6 @@ describe('Miscellaneous - Escaped keywords', () => {
'class aw\\u0061it {}',
'aw\\u0061it: 1;',
'function *a(){({yi\\u0065ld: 0})}',
'var y = { bre\\u0061k: x } = { break: 42 };',
'var y = { c\\u0061se: x } = { case: 42 };',
'var y = { c\\u0061tch: x } = { catch: 42 };',
'var y = { \\u0063onst: x } = { const: 42 };',
'var y = { \\u0064ebugger: x } = { debugger: 42 };',
'\\u0061sync',
'l\\u0065t\na',
'l\\u0065t',
Expand Down Expand Up @@ -113,6 +109,12 @@ describe('Miscellaneous - Escaped keywords', () => {
['var x = tr\\u0075e;', Context.None],
['var tr\\u0075e = 1;', Context.None],
['({ def\\u0061ult })', Context.None],
['0, { def\\u{61}ult: x } = { default: 42 };', Context.None],
['var y = { bre\\u0061k: x } = { break: 42 };', Context.None],
['var y = { c\\u0061se: x } = { case: 42 };', Context.None],
['var y = { c\\u0061tch: x } = { catch: 42 };', Context.None],
['var y = { \\u0063onst: x } = { const: 42 };', Context.None],
['var y = { \\u0064ebugger: x } = { debugger: 42 };', Context.None],
['var { tr\\u0075e } = {};', Context.None],
['tr\\u0075e = 1;', Context.None],
['(x === f\\u0061lse);', Context.None],
Expand Down Expand Up @@ -220,6 +222,14 @@ describe('Miscellaneous - Escaped keywords', () => {
['if (this \\u0069nstanceof Array) {}', Context.None],
['(n\\u0065w function f() {})', Context.None],
['(typ\\u0065of 123)', Context.None],
['var y = { c\\u0061se: x } = { case: 42 };', Context.None],
['({ def\\u{61}ult }) => 42;', Context.None],
['0, { def\\u{61}ult } = { default: 42 };', Context.None],
['var x = ({ bre\\u0061k }) => {};', Context.None],
['var x = ({ tr\\u0079 }) => {};', Context.None],
['var x = ({ typ\\u0065of }) => {};', Context.None],
['def\\u0061ult', Context.None],
['var x = { \\u0069mport } = { import: 42 };', Context.Strict | Context.Module],
['(v\\u006fid 0)', Context.None],
['aw\\u0061it: 1;', Context.Module | Context.Strict],
['var \\u{65}\\u{6e}\\u{75}\\u{6d} = 123;', Context.None],
Expand All @@ -230,6 +240,7 @@ describe('Miscellaneous - Escaped keywords', () => {
['var \\u0062\\u0072\\u0065\\u0061\\u006b = 123;;', Context.None],
['var \\u{63}ase = 123;', Context.None],
['var \\u{63}atch = 123;', Context.None],
['var x = { \\u0066unction } = { function: 42 };', Context.None],
['var \\u{63}ontinue = 123;', Context.None],
['var fina\\u{6c}ly = 123;', Context.None],
['var \\u{64}\\u{6f} = 123;', Context.None],
Expand Down

0 comments on commit 6c48765

Please sign in to comment.