Skip to content

Commit

Permalink
Don't treat await as a keyword
Browse files Browse the repository at this point in the history
The standard doesn't imply it should be.
  • Loading branch information
marijnh committed Sep 5, 2016
1 parent 7304648 commit b12370f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pp.buildBinary = function(startPos, startLoc, left, right, op, logical) {

pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
let startPos = this.start, startLoc = this.startLoc, expr
if (this.inAsync && (this.type === tt._await || this.isContextual("await"))) {
if (this.inAsync && this.isContextual("await")) {
expr = this.parseAwait(refDestructuringErrors)
sawUnary = true
} else if (this.type.prefix) {
Expand Down
2 changes: 1 addition & 1 deletion src/loose/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ lp.parseExprOp = function(left, start, minPrec, noIn, indent, line) {

lp.parseMaybeUnary = function(sawUnary) {
let start = this.storeCurrentPos(), expr
if (this.options.ecmaVersion >= 8 && this.inAsync && (this.tok.type === tt._await || this.toks.isContextual("await"))) {
if (this.options.ecmaVersion >= 8 && this.inAsync && this.toks.isContextual("await")) {
expr = this.parseAwait()
sawUnary = true
} else if (this.tok.type.prefix) {
Expand Down
4 changes: 2 additions & 2 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export class Parser {
constructor(options, input, startPos) {
this.options = options = getOptions(options)
this.sourceFile = options.sourceFile
this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5] + (options.ecmaVersion >= 8 && options.sourceType == "module" ? " await" : ""))
this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5])
let reserved = options.allowReserved ? "" :
reservedWords[options.ecmaVersion] + (options.ecmaVersion < 8 && options.sourceType == "module" ? " await" : "")
reservedWords[options.ecmaVersion] + (options.sourceType == "module" ? " await" : "")
this.reservedWords = keywordRegexp(reserved)
let reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict
this.reservedWordsStrict = keywordRegexp(reservedStrict)
Expand Down
1 change: 0 additions & 1 deletion src/tokentype.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export const types = {
starstar: new TokenType("**", {beforeExpr: true}),

// Keyword token types.
_await: kw("await"),
_break: kw("break"),
_case: kw("case", beforeExpr),
_catch: kw("catch"),
Expand Down
4 changes: 2 additions & 2 deletions test/tests-asyncawait.js
Original file line number Diff line number Diff line change
Expand Up @@ -1669,11 +1669,11 @@ test("await", {
}, {ecmaVersion: 8})

// 'await' is a keyword in modules.
testFail("await", "Unexpected token (1:0)", {ecmaVersion: 8, sourceType: "module"})
testFail("await", "The keyword 'await' is reserved (1:0)", {ecmaVersion: 8, sourceType: "module"})

// Await expressions is invalid outside of async functions.
testFail("await a", "Unexpected token (1:6)", {ecmaVersion: 8})
testFail("await a", "Unexpected token (1:0)", {ecmaVersion: 8, sourceType: "module"})
testFail("await a", "The keyword 'await' is reserved (1:0)", {ecmaVersion: 8, sourceType: "module"})

// Await expressions in async functions.
test("async function foo(a, b) { await a }", {
Expand Down

0 comments on commit b12370f

Please sign in to comment.