Skip to content

Commit

Permalink
fix(parser): fixed a few edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Aug 14, 2019
1 parent a4434ef commit 0a425ba
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 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.8",
"version": "1.6.9",
"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.8';
export const version = '1.6.9';
10 changes: 6 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5754,7 +5754,7 @@ export function parseObjectLiteralOrPattern(
let key: ESTree.Expression | null = null;
let value;

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

if (parser.token === Token.Comma || parser.token === Token.RightBrace || parser.token === Token.Assign) {
Expand Down Expand Up @@ -5795,8 +5795,9 @@ export function parseObjectLiteralOrPattern(
right
});
} else {
destructible |= token === Token.AwaitKeyword ? DestructuringKind.Await : 0;

destructible |=
(token === Token.AwaitKeyword ? DestructuringKind.Await : 0) |
(token === Token.EscapedReserved ? DestructuringKind.CannotDestruct : 0);
value = key;
}
} else if (consumeOpt(parser, context | Context.AllowRegExp, Token.Colon)) {
Expand Down Expand Up @@ -5947,6 +5948,7 @@ export function parseObjectLiteralOrPattern(
} else if (parser.token === Token.LeftBracket) {
destructible |= DestructuringKind.CannotDestruct;
if (token === Token.AsyncKeyword) state |= PropertyKind.Async;

state |=
(token === Token.GetKeyword
? PropertyKind.Getter
Expand All @@ -5968,7 +5970,7 @@ export function parseObjectLiteralOrPattern(
);
} else if (parser.token & (Token.IsIdentifier | Token.Keyword)) {
destructible |= DestructuringKind.CannotDestruct;

if (token === Token.EscapedReserved) report(parser, Errors.InvalidEscapedKeyword);
if (token === Token.AsyncKeyword) {
if (parser.flags & Flags.NewLine) report(parser, Errors.AsyncRestrictedProd);
state |= PropertyKind.Async;
Expand Down
12 changes: 12 additions & 0 deletions test/parser/miscellaneous/escaped-keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ 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 All @@ -99,6 +104,8 @@ describe('Miscellaneous - Escaped keywords', () => {
fail('Miscellaneous - Escaped identifiers (failures)', [
['(x === n\\u0075ll);', Context.None],
['var x = n\\u0075ll;', Context.None],
['var x = { interf\\u0061ce } = { interface: 42 };', Context.Strict | Context.Module],
['var x = ({ w\\u0069th }) => {};', Context.None],
['var n\\u0075ll = 1;', Context.None],
['var { n\\u0075ll } = { 1 };', Context.None],
['n\\u0075ll = 1;', Context.None],
Expand Down Expand Up @@ -193,6 +200,11 @@ describe('Miscellaneous - Escaped keywords', () => {
['cl\\u0061ss Foo {}', Context.None],
['var f = f\\u0075nction() {}', Context.None],
["thr\\u006fw 'boo';", Context.None],
['var x = { n\\u0065w } = { new: 42 };', Context.None],
['var x = { privat\\u0065 } = { private: 42 };', Context.Strict | Context.Module],
['var x = { sup\\u0065r } = { super: 42 };', Context.Strict | Context.Module],
['var x = { v\\u0061r } = { var: 42 };', Context.Strict | Context.Module],
['var x = { privat\\u0065 } = { private: 42 };', Context.Strict | Context.Module],
['w\\u0069th (this.scope) { }', Context.None],
['n\\u0075ll = 1;', Context.None],
['(x === tr\\u0075e);', Context.None],
Expand Down

0 comments on commit 0a425ba

Please sign in to comment.