Skip to content

Commit

Permalink
Treat "await" as an invalid identifier (#4954)
Browse files Browse the repository at this point in the history
It is valid (outside `async` functions) in the "script" parse goal, but always invalid in the "module" parse goal.

Fixes #4952.
  • Loading branch information
Diogo Franco committed Mar 19, 2017
1 parent 8859715 commit 256fcbc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
@@ -0,0 +1,3 @@
export {};

var obj = { await: function () {} };
@@ -0,0 +1,3 @@
export {};

var obj = { await: function _await() {} };
3 changes: 3 additions & 0 deletions packages/babel-types/src/validators.js
Expand Up @@ -167,6 +167,9 @@ export function isReferenced(node: Object, parent: Object): boolean {
export function isValidIdentifier(name: string): boolean {
if (typeof name !== "string" || esutils.keyword.isReservedWordES6(name, true)) {
return false;
} else if (name === "await") {
// invalid in module, valid in script; better be safe (see #4952)
return false;
} else {
return esutils.keyword.isIdentifierNameES6(name);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-types/test/validators.js
Expand Up @@ -26,5 +26,9 @@ suite("validators", function () {

assert(t.isNodesEquivalent(parse(program), parse(program2)) === false);
});

it("rejects 'await' as an identifier", function () {
assert(t.isValidIdentifier("await") === false);
});
});
});

0 comments on commit 256fcbc

Please sign in to comment.