Skip to content

Commit

Permalink
Merge pull request #152 from jrvidal/await-keyword-151
Browse files Browse the repository at this point in the history
Fix: "await" is a future reserved word (fixes #151)
  • Loading branch information
nzakas committed Jun 26, 2015
2 parents 4772c86 + 95d388d commit 1b1967e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
10 changes: 5 additions & 5 deletions espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ function throwUnexpected(token) {
if (token.type === Token.Keyword) {
if (syntax.isFutureReservedWord(token.value)) {
throwError(token, Messages.UnexpectedReserved);
} else if (strict && syntax.isStrictModeReservedWord(token.value)) {
} else if (strict && syntax.isStrictModeReservedWord(token.value, extra.ecmaFeatures)) {
throwErrorTolerant(token, Messages.StrictReservedWord);
return;
}
Expand Down Expand Up @@ -3594,7 +3594,7 @@ function parseVariableIdentifier() {
token = lex();

if (token.type !== Token.Identifier) {
if (strict && token.type === Token.Keyword && syntax.isStrictModeReservedWord(token.value)) {
if (strict && token.type === Token.Keyword && syntax.isStrictModeReservedWord(token.value, extra.ecmaFeatures)) {
throwErrorTolerant(token, Messages.StrictReservedWord);
} else {
throwUnexpected(token);
Expand Down Expand Up @@ -4402,7 +4402,7 @@ function validateParam(options, param, name) {
if (syntax.isRestrictedWord(name)) {
options.firstRestricted = param;
options.message = Messages.StrictParamName;
} else if (syntax.isStrictModeReservedWord(name)) {
} else if (syntax.isStrictModeReservedWord(name, extra.ecmaFeatures)) {
options.firstRestricted = param;
options.message = Messages.StrictReservedWord;
} else if (options.paramSet.has(name)) {
Expand Down Expand Up @@ -4532,7 +4532,7 @@ function parseFunctionDeclaration(identifierIsOptional) {
if (syntax.isRestrictedWord(token.value)) {
firstRestricted = token;
message = Messages.StrictFunctionName;
} else if (syntax.isStrictModeReservedWord(token.value)) {
} else if (syntax.isStrictModeReservedWord(token.value, extra.ecmaFeatures)) {
firstRestricted = token;
message = Messages.StrictReservedWord;
}
Expand Down Expand Up @@ -4597,7 +4597,7 @@ function parseFunctionExpression() {
if (syntax.isRestrictedWord(token.value)) {
firstRestricted = token;
message = Messages.StrictFunctionName;
} else if (syntax.isStrictModeReservedWord(token.value)) {
} else if (syntax.isStrictModeReservedWord(token.value, extra.ecmaFeatures)) {
firstRestricted = token;
message = Messages.StrictReservedWord;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = {
}
},

isStrictModeReservedWord: function(id) {
isStrictModeReservedWord: function(id, ecmaFeatures) {
switch (id) {
case "implements":
case "interface":
Expand All @@ -125,6 +125,8 @@ module.exports = {
case "yield":
case "let":
return true;
case "await":
return ecmaFeatures.modules;
default:
return false;
}
Expand All @@ -138,7 +140,7 @@ module.exports = {

isKeyword: function(id, strict, ecmaFeatures) {

if (strict && this.isStrictModeReservedWord(id)) {
if (strict && this.isStrictModeReservedWord(id, ecmaFeatures)) {
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/ecma-features/modules/invalid-await.result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
"index": 11,
"lineNumber": 1,
"column": 12,
"description": "Use of future reserved word in strict mode"
};
1 change: 1 addition & 0 deletions tests/fixtures/ecma-features/modules/invalid-await.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var await;

0 comments on commit 1b1967e

Please sign in to comment.