Skip to content

Commit

Permalink
polish: improve await as id error in module
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Feb 2, 2023
1 parent 024f97c commit 037e8c6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
42 changes: 20 additions & 22 deletions packages/babel-parser/src/parser/expression.ts
Expand Up @@ -2793,7 +2793,26 @@ export default abstract class ExpressionParser extends LValParser {
return;
}

if (word === "yield") {
if (checkKeywords && isKeyword(word)) {
this.raise(Errors.UnexpectedKeyword, {
at: startLoc,
keyword: word,
});
return;
}

const reservedTest = !this.state.strict
? isReservedWord
: isBinding
? isStrictBindReservedWord
: isStrictReservedWord;

if (reservedTest(word, this.inModule)) {
this.raise(Errors.UnexpectedReservedWord, {
at: startLoc,
reservedWord: word,
});
} else if (word === "yield") {
if (this.prodParam.hasYield) {
this.raise(Errors.YieldBindingIdentifier, { at: startLoc });
return;
Expand All @@ -2818,27 +2837,6 @@ export default abstract class ExpressionParser extends LValParser {
return;
}
}

if (checkKeywords && isKeyword(word)) {
this.raise(Errors.UnexpectedKeyword, {
at: startLoc,
keyword: word,
});
return;
}

const reservedTest = !this.state.strict
? isReservedWord
: isBinding
? isStrictBindReservedWord
: isStrictReservedWord;

if (reservedTest(word, this.inModule)) {
this.raise(Errors.UnexpectedReservedWord, {
at: startLoc,
reservedWord: word,
});
}
}

isAwaitAllowed(): boolean {
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}},
"errors": [
"SyntaxError: Can not use 'await' as identifier inside an async function. (1:6)"
"SyntaxError: Unexpected reserved word 'await'. (1:6)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":24,"index":24}},
"errors": [
"SyntaxError: Can not use 'await' as identifier inside an async function. (1:8)"
"SyntaxError: Unexpected reserved word 'await'. (1:8)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":19,"index":19}},
"errors": [
"SyntaxError: Can not use 'await' as identifier inside an async function. (1:9)"
"SyntaxError: Unexpected reserved word 'await'. (1:9)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":14,"index":14}},
"errors": [
"SyntaxError: Can not use 'await' as identifier inside an async function. (1:6)"
"SyntaxError: Unexpected reserved word 'await'. (1:6)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,10 +2,10 @@
"type": "File",
"start":0,"end":113,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":12,"column":1,"index":113}},
"errors": [
"SyntaxError: Can not use 'await' as identifier inside an async function. (2:8)",
"SyntaxError: Can not use 'await' as identifier inside an async function. (5:8)",
"SyntaxError: Can not use 'await' as identifier inside an async function. (8:11)",
"SyntaxError: Can not use 'await' as identifier inside an async function. (11:13)"
"SyntaxError: Unexpected reserved word 'await'. (2:8)",
"SyntaxError: Unexpected reserved word 'await'. (5:8)",
"SyntaxError: Unexpected reserved word 'await'. (8:11)",
"SyntaxError: Unexpected reserved word 'await'. (11:13)"
],
"program": {
"type": "Program",
Expand Down

0 comments on commit 037e8c6

Please sign in to comment.