Treat "await" as an invalid identifier (#4954)

It is valid (outside `async` functions) in the "script" parse goal, but always invalid in the "module" parse goal.

Fixes #4952.
This commit is contained in:
Diogo Franco 2017-03-19 11:28:52 +09:00 committed by GitHub
parent 8859715893
commit 256fcbc58f
4 changed files with 13 additions and 0 deletions

View File

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

View File

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

View File

@ -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);
}

View File

@ -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);
});
});
});