Skip to content

Commit

Permalink
fix(parser): invalid generator setter should have correct error message
Browse files Browse the repository at this point in the history
closes #228
  • Loading branch information
3cp committed Nov 12, 2022
1 parent c67587c commit 193b3ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const enum Errors {
StrictFunctionName,
RestMissingArg,
InvalidGeneratorGetter,
InvalidGeneratorSetter,
InvalidComputedPropName,
InvalidGetSetGenerator,
InvalidAsyncGetter,
Expand Down Expand Up @@ -219,6 +220,7 @@ export const errorMessages: {
'Function name may not contain any reserved words or be eval or arguments in strict mode',
[Errors.RestMissingArg]: 'The rest operator is missing an argument',
[Errors.InvalidGeneratorGetter]: 'A getter cannot be a generator',
[Errors.InvalidGeneratorSetter]: 'A setter cannot be a generator',
[Errors.InvalidComputedPropName]: 'A computed property name must be followed by a colon or paren',
[Errors.InvalidObjLitKey]: 'Object literal keys that are strings or numbers must be a method or have a colon',
[Errors.InvalidAsyncGetter]: 'Found `* async x(){}` but this should be `async * x(){}`',
Expand Down
4 changes: 3 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6093,8 +6093,10 @@ export function parseObjectLiteralOrPattern(
} else if (parser.token === Token.Multiply) {
destructible |= DestructuringKind.CannotDestruct;

if (token === Token.GetKeyword || token === Token.SetKeyword) {
if (token === Token.GetKeyword) {
report(parser, Errors.InvalidGeneratorGetter);
} else if (token === Token.SetKeyword) {
report(parser, Errors.InvalidGeneratorSetter);
} else if (token === Token.AnyIdentifier) {
report(parser, Errors.InvalidEscapedKeyword);
}
Expand Down

0 comments on commit 193b3ef

Please sign in to comment.