Skip to content

Commit

Permalink
fix(parser): fixed escape keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Aug 8, 2019
1 parent a6e0e71 commit de9c43b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const errorMessages: {
[Errors.InvalidSuperProperty]: 'Member access on super must be in a method',
[Errors.AwaitInParameter]: 'Await expression not allowed in formal parameter',
[Errors.YieldInParameter]: 'Yield expression not allowed in formal parameter',
[Errors.InvalidEscapedKeyword]: 'Keywords must be written literally, without embedded escapes',
[Errors.InvalidEscapedKeyword]: "Unexpected token: 'escaped keyword'",
[Errors.InvalidExponentationLHS]:
'Unary expressions as the left operand of an exponentation expression must be disambiguated with parentheses',
[Errors.AsyncFunctionInSingleStatementContext]:
Expand Down
4 changes: 2 additions & 2 deletions src/lexer/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ export function scanIdentifierSlowCase(

if (token === Token.YieldKeyword) {
return context & Context.AllowEscapedKeyword
? Token.ReservedIfStrict
? Token.AnyIdentifier
: context & Context.InYieldContext
? Token.EscapedReserved
: token;
}

return token === Token.AsyncKeyword && context & Context.AllowEscapedKeyword
? Token.Identifier
? Token.AnyIdentifier
: (token & Token.FutureReserved) === Token.FutureReserved
? token
: token === Token.AwaitKeyword && (context & Context.InAwaitContext) === 0
Expand Down
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5887,7 +5887,7 @@ export function parseObjectLiteralOrPattern(
} else if (parser.token === Token.Multiply) {
destructible |= DestructuringKind.CannotDestruct;

if (token === Token.GetKeyword || token === Token.SetKeyword) {
if (token === Token.GetKeyword || token === Token.SetKeyword || token === Token.AnyIdentifier) {
report(parser, Errors.InvalidGeneratorGetter);
}
nextToken(parser, context);
Expand Down
2 changes: 1 addition & 1 deletion src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const enum Token {

EscapedReserved = 118,
EscapedFutureReserved = 119,
ReservedIfStrict = 120 | IsIdentifier,
AnyIdentifier = 120 | IsIdentifier,

// Stage #3 proposals
PrivateName = 121,
Expand Down
12 changes: 6 additions & 6 deletions test/parser/miscellaneous/escaped-keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe('Miscellaneous - Escaped keywords', () => {
'aw\\u0061it: 1;',
'function *a(){({yi\\u0065ld: 0})}',
'\\u0061sync',
// '({i\\u0066: 0})',
'l\\u0065t\na',
'l\\u0065t',
`function a() {
Expand All @@ -73,15 +72,16 @@ describe('Miscellaneous - Escaped keywords', () => {
});
});
}

//
fail('Miscellaneous - Escaped identifiers (failures)', [
//['({ \\u0061sync* m(){}});', Context.None],
['const [l\\u0065t] = 1', Context.None],
['(function() {for (let l\\u0065t in {}) {}})()', Context.None],
['cl\\u0061ss Foo {}', Context.None],
['export function br\\u0065ak() {}', Context.Strict | Context.Module],
['class aw\\u0061it {}', Context.Strict | Context.Module],
['class l\\u0065t {}', Context.Strict],
['class st\\u0061tic {}', Context.Strict],
['class st\\u0061tic {}', Context.None],
// ['le\\u0074 x = 5', Context.None],
['class yi\\u0065ld {}', Context.Strict],
['aw\\u0061it: 1;', Context.Strict | Context.Module],
['a(1,2\\u0063onst foo = 1;', Context.None],
Expand Down Expand Up @@ -117,7 +117,6 @@ describe('Miscellaneous - Escaped keywords', () => {
['({\\u0073et set(){}})', Context.None],
['var v\\u0061r = 2000000;', Context.None],
['var v\\u{0061}r = 2000000', Context.None],
// ['String.raw`var {v\\u0061r} = obj`', Context.None],
['try { } catch(v\\u{0061}r) { }', Context.None],
['var obj = { async method() { void \\u0061wait; } };', Context.Strict],
['class C { async *gen() { void \\u0061wait; }}', Context.None],
Expand Down Expand Up @@ -233,6 +232,7 @@ describe('Miscellaneous - Escaped keywords', () => {
['class aw\\u0061it {}', Context.Strict | Context.Module],
['var gen = async function *() { var yi\\u0065ld; };', Context.None],
['var obj = { *method() { void yi\\u0065ld; } };', Context.None],
['var gen = function *g() { yi\\u0065ld: ; };', Context.None]
['var gen = function *g() { yi\\u0065ld: ; };', Context.None],
['({ \\u0061sync* m(){}});', Context.None]
]);
});

0 comments on commit de9c43b

Please sign in to comment.