Skip to content

Commit

Permalink
Support TLA error in script
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Dec 23, 2020
1 parent e16250c commit 1affea3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -534,11 +534,15 @@ export default class ExpressionParser extends LValParser {

const expr = this.parseUpdate(node, update, refExpressionErrors);

const startsExpr = this.hasPlugin("v8intrinsic")
? this.state.type.startsExpr
: this.state.type.startsExpr && !this.match(tt.modulo);
if (
isAwait &&
this.scope.inFunction &&
this.state.type.startsExpr &&
!this.isAmbiguousAwait()
startsExpr &&
!this.isAmbiguousAwait() &&
(this.scope.inFunction ||
(this.hasPlugin("topLevelAwait") && !this.inModule))
) {
this.raise(startPos, Errors.AwaitNotInAsyncContext);
return this.parseAwait(startPos, startLoc);
Expand Down
@@ -1,5 +1,4 @@
{
"plugins": ["topLevelAwait"],
"sourceType": "script",
"throws": "Unexpected token, expected \";\" (1:6)"
"sourceType": "script"
}
@@ -0,0 +1,33 @@
{
"type": "File",
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}},
"errors": [
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules (1:0)"
],
"program": {
"type": "Program",
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}},
"expression": {
"type": "AwaitExpression",
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
"argument": {
"type": "NumericLiteral",
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7}},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
}
],
"directives": []
}
}

0 comments on commit 1affea3

Please sign in to comment.