Skip to content

Commit

Permalink
fix(parser): fixed confusing error message
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Aug 8, 2019
1 parent 5165c2e commit a6e0e71
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ export function validateBindingIdentifier(
if (t === Token.EscapedFutureReserved) {
report(parser, Errors.InvalidEscapedKeyword);
}

if (t === Token.EscapedReserved) {
report(parser, Errors.InvalidEscapedKeyword);
}
}

if ((t & Token.Reserved) === Token.Reserved) {
Expand All @@ -383,10 +387,6 @@ export function validateBindingIdentifier(
if (context & (Context.InYieldContext | Context.Strict) && t === Token.YieldKeyword) {
report(parser, Errors.DisallowedInContext, 'yield');
}

if (t === Token.EscapedReserved) {
report(parser, Errors.InvalidEscapedKeyword);
}
}

/**
Expand Down Expand Up @@ -765,16 +765,12 @@ export function classifyIdentifier(
parser: ParserState,
context: Context,
t: Token,
isArrow: 0 | 1,
shouldBanEscaped: 0 | 1
isArrow: 0 | 1
): any {
if ((t & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
if (context & Context.Strict) report(parser, Errors.StrictEvalArguments);
if (isArrow) parser.flags |= Flags.StrictEvalArguments;
}

if (shouldBanEscaped && (t & Token.EscapedReserved) === Token.EscapedReserved) {
report(parser, Errors.InvalidEscapedKeyword);
}
if (!isValidIdentifier(context, t)) report(parser, Errors.Unexpected);
}
1 change: 1 addition & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +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.InvalidExponentationLHS]:
'Unary expressions as the left operand of an exponentation expression must be disambiguated with parentheses',
[Errors.AsyncFunctionInSingleStatementContext]:
Expand Down
6 changes: 3 additions & 3 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
);
} else {
if (parser.token === Token.Arrow) {
classifyIdentifier(parser, context, token, /* isArrow */ 1, /* shouldBanEscaped */ 1);
classifyIdentifier(parser, context, token, /* isArrow */ 1);
expr = parseArrowFromIdentifier(parser, context, parser.tokenValue, expr, 0, 1, 0, start, line, column);
}

Expand Down Expand Up @@ -3452,7 +3452,7 @@ export function parseAsyncExpression(
}

if (parser.token === Token.Arrow) {
classifyIdentifier(parser, context, token, /* isArrow */ 1, /* shouldBanEscaped */ 1);
classifyIdentifier(parser, context, token, /* isArrow */ 1);
if (inNewExpression) report(parser, Errors.InvalidAsyncArrow);
return parseArrowFromIdentifier(
parser,
Expand Down Expand Up @@ -4099,7 +4099,7 @@ export function parsePrimaryExpressionExtended(
const expr = parseIdentifier(parser, context | Context.TaggedTemplate, identifierPattern);

if (parser.token === Token.Arrow) {
classifyIdentifier(parser, context, token, /* isArrow */ 1, /* shouldBanEscaped */ 1);
classifyIdentifier(parser, context, token, /* isArrow */ 1);
return parseArrowFromIdentifier(
parser,
context,
Expand Down

0 comments on commit a6e0e71

Please sign in to comment.