Skip to content

Commit

Permalink
Async constructor error message should follow V8
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Dec 3, 2016
1 parent d6ce054 commit 7219731
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/messages.ts
Expand Up @@ -49,5 +49,6 @@ export const Messages = {
DuplicateBinding: 'Duplicate binding %0',
DeclarationMissingInitializer: 'Missing initializer in %0 declaration',
LetInLexicalBinding: 'let is disallowed as a lexically bound name',
ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer'
ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer',
ConstructorIsAsync: 'Class constructor may not be an async method'
};
8 changes: 6 additions & 2 deletions src/parser.ts
Expand Up @@ -3130,8 +3130,12 @@ export class Parser {
isAsync = true;
token = this.lookahead;
key = this.parseObjectPropertyKey();
if (token.type === Token.Identifier && ['get', 'set', 'constructor'].indexOf(token.value) >= 0) {
this.tolerateUnexpectedToken(token);
if (token.type === Token.Identifier) {
if (token.value === 'get' || token.value === 'set') {
this.tolerateUnexpectedToken(token);
} else if (token.value === 'constructor') {
this.tolerateUnexpectedToken(token, Messages.ConstructorIsAsync);
}
}
}
}
Expand Down
@@ -1 +1 @@
{"index":16,"lineNumber":1,"column":17,"message":"Error: Line 1: Unexpected identifier","description":"Unexpected identifier"}
{"index":16,"lineNumber":1,"column":17,"message":"Error: Line 1: Class constructor may not be an async method","description":"Class constructor may not be an async method"}

0 comments on commit 7219731

Please sign in to comment.