Raise recoverable error for await expressions in sync functions (#12520)
This commit is contained in:
parent
d98418efbe
commit
8fcba6eb55
@ -492,9 +492,15 @@ export default class ExpressionParser extends LValParser {
|
||||
// Parse unary operators, both prefix and postfix.
|
||||
// https://tc39.es/ecma262/#prod-UnaryExpression
|
||||
parseMaybeUnary(refExpressionErrors: ?ExpressionErrors): N.Expression {
|
||||
if (this.isContextual("await") && this.isAwaitAllowed()) {
|
||||
return this.parseAwait();
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
const isAwait = this.isContextual("await");
|
||||
|
||||
if (isAwait && this.isAwaitAllowed()) {
|
||||
this.next();
|
||||
return this.parseAwait(startPos, startLoc);
|
||||
}
|
||||
|
||||
const update = this.match(tt.incDec);
|
||||
const node = this.startNode();
|
||||
if (this.state.type.prefix) {
|
||||
@ -526,7 +532,24 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
}
|
||||
|
||||
return this.parseUpdate(node, update, refExpressionErrors);
|
||||
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 && startsExpr && !this.isAmbiguousAwait()) {
|
||||
if (!this.state.invalidAwaitErrors.has(startPos)) {
|
||||
this.raise(
|
||||
startPos,
|
||||
this.hasPlugin("topLevelAwait")
|
||||
? Errors.AwaitNotInAsyncContext
|
||||
: Errors.AwaitNotInAsyncFunction,
|
||||
);
|
||||
}
|
||||
return this.parseAwait(startPos, startLoc);
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/#prod-UpdateExpression
|
||||
@ -2332,6 +2355,7 @@ export default class ExpressionParser extends LValParser {
|
||||
? Errors.AwaitNotInAsyncContext
|
||||
: Errors.AwaitNotInAsyncFunction,
|
||||
);
|
||||
this.state.invalidAwaitErrors.add(startLoc);
|
||||
} else {
|
||||
this.raise(startLoc, Errors.UnexpectedReservedWord, word);
|
||||
}
|
||||
@ -2348,10 +2372,8 @@ export default class ExpressionParser extends LValParser {
|
||||
|
||||
// Parses await expression inside async function.
|
||||
|
||||
parseAwait(): N.AwaitExpression {
|
||||
const node = this.startNode();
|
||||
|
||||
this.next();
|
||||
parseAwait(startPos: number, startLoc: Position): N.AwaitExpression {
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
|
||||
this.expressionScope.recordParameterInitializerError(
|
||||
node.start,
|
||||
@ -2363,22 +2385,7 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
|
||||
if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
|
||||
if (
|
||||
this.hasPrecedingLineBreak() ||
|
||||
// All the following expressions are ambiguous:
|
||||
// await + 0, await - 0, await ( 0 ), await [ 0 ], await / 0 /u, await ``
|
||||
this.match(tt.plusMin) ||
|
||||
this.match(tt.parenL) ||
|
||||
this.match(tt.bracketL) ||
|
||||
this.match(tt.backQuote) ||
|
||||
// Sometimes the tokenizer generates tt.slash for regexps, and this is
|
||||
// handler by parseExprAtom
|
||||
this.match(tt.regexp) ||
|
||||
this.match(tt.slash) ||
|
||||
// This code could be parsed both as a modulo operator or as an intrinsic:
|
||||
// await %x(0)
|
||||
(this.hasPlugin("v8intrinsic") && this.match(tt.modulo))
|
||||
) {
|
||||
if (this.isAmbiguousAwait()) {
|
||||
this.ambiguousScriptDifferentAst = true;
|
||||
} else {
|
||||
this.sawUnambiguousESM = true;
|
||||
@ -2392,6 +2399,25 @@ export default class ExpressionParser extends LValParser {
|
||||
return this.finishNode(node, "AwaitExpression");
|
||||
}
|
||||
|
||||
isAmbiguousAwait(): boolean {
|
||||
return (
|
||||
this.hasPrecedingLineBreak() ||
|
||||
// All the following expressions are ambiguous:
|
||||
// await + 0, await - 0, await ( 0 ), await [ 0 ], await / 0 /u, await ``
|
||||
this.match(tt.plusMin) ||
|
||||
this.match(tt.parenL) ||
|
||||
this.match(tt.bracketL) ||
|
||||
this.match(tt.backQuote) ||
|
||||
// Sometimes the tokenizer generates tt.slash for regexps, and this is
|
||||
// handler by parseExprAtom
|
||||
this.match(tt.regexp) ||
|
||||
this.match(tt.slash) ||
|
||||
// This code could be parsed both as a modulo operator or as an intrinsic:
|
||||
// await %x(0)
|
||||
(this.hasPlugin("v8intrinsic") && this.match(tt.modulo))
|
||||
);
|
||||
}
|
||||
|
||||
// Parses yield expression inside generator.
|
||||
|
||||
parseYield(): N.YieldExpression {
|
||||
|
||||
@ -154,6 +154,9 @@ export default class State {
|
||||
// Tokens length in token store
|
||||
tokensLength: number = 0;
|
||||
|
||||
// Positions of invalid await errors
|
||||
invalidAwaitErrors: Set<number> = new Set();
|
||||
|
||||
curPosition(): Position {
|
||||
return new Position(this.curLine, this.pos - this.lineStart);
|
||||
}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected \";\" (1:30)"
|
||||
}
|
||||
54
packages/babel-parser/test/fixtures/es2017/async-functions/9/output.json
vendored
Normal file
54
packages/babel-parser/test/fixtures/es2017/async-functions/9/output.json
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions (1:24)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start":13,"end":20,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":20},"identifierName":"promise"},
|
||||
"name": "promise"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":22,"end":40,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":40}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":24,"end":38,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":38}},
|
||||
"expression": {
|
||||
"type": "AwaitExpression",
|
||||
"start":24,"end":37,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":37}},
|
||||
"argument": {
|
||||
"type": "Identifier",
|
||||
"start":30,"end":37,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":37},"identifierName":"promise"},
|
||||
"name": "promise"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"allowAwaitOutsideFunction": true,
|
||||
"throws": "Unexpected token, expected \";\" (2:15)"
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions (2:9)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"a"},
|
||||
"name": "a"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":13,"end":33,"loc":{"start":{"line":1,"column":13},"end":{"line":3,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ReturnStatement",
|
||||
"start":17,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}},
|
||||
"argument": {
|
||||
"type": "AwaitExpression",
|
||||
"start":24,"end":31,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":16}},
|
||||
"argument": {
|
||||
"type": "NumericLiteral",
|
||||
"start":30,"end":31,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":16}},
|
||||
"extra": {
|
||||
"rawValue": 1,
|
||||
"raw": "1"
|
||||
},
|
||||
"value": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
function foo() {
|
||||
await
|
||||
foo;
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":15,"end":33,"loc":{"start":{"line":1,"column":15},"end":{"line":4,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":19,"end":24,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":7}},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":24,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":7},"identifierName":"await"},
|
||||
"name": "await"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":27,"end":31,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":6}},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start":27,"end":30,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected \";\" (1:14)"
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions (1:8)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":6,"end":17,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":17}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":8,"end":15,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":15}},
|
||||
"expression": {
|
||||
"type": "AwaitExpression",
|
||||
"start":8,"end":15,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":15}},
|
||||
"argument": {
|
||||
"type": "Identifier",
|
||||
"start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15},"identifierName":"x"},
|
||||
"name": "x"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected \",\" (1:17)"
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions (1:11)",
|
||||
"SyntaxError: await is not allowed in async function parameters (1:11)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [
|
||||
{
|
||||
"type": "AssignmentPattern",
|
||||
"start":7,"end":18,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":18}},
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"x"},
|
||||
"name": "x"
|
||||
},
|
||||
"right": {
|
||||
"type": "AwaitExpression",
|
||||
"start":11,"end":18,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":18}},
|
||||
"argument": {
|
||||
"type": "NumericLiteral",
|
||||
"start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18}},
|
||||
"extra": {
|
||||
"rawValue": 2,
|
||||
"raw": "2"
|
||||
},
|
||||
"value": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":23,"end":25,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":25}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected \",\" (2:25)"
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions (2:19)",
|
||||
"SyntaxError: await is not allowed in async function parameters (2:19)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":15,"end":18,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":18},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":21,"end":55,"loc":{"start":{"line":1,"column":21},"end":{"line":3,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":25,"end":53,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":30}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":34,"end":37,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14},"identifierName":"bar"},
|
||||
"name": "bar"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [
|
||||
{
|
||||
"type": "AssignmentPattern",
|
||||
"start":38,"end":49,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":26}},
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"start":38,"end":39,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":16},"identifierName":"x"},
|
||||
"name": "x"
|
||||
},
|
||||
"right": {
|
||||
"type": "AwaitExpression",
|
||||
"start":42,"end":49,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":26}},
|
||||
"argument": {
|
||||
"type": "NumericLiteral",
|
||||
"start":48,"end":49,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":26}},
|
||||
"extra": {
|
||||
"rawValue": 2,
|
||||
"raw": "2"
|
||||
},
|
||||
"value": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":51,"end":53,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":30}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
function foo() {
|
||||
await { foo };
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions (2:2)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":15,"end":35,"loc":{"start":{"line":1,"column":15},"end":{"line":3,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":19,"end":33,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}},
|
||||
"expression": {
|
||||
"type": "AwaitExpression",
|
||||
"start":19,"end":32,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":15}},
|
||||
"argument": {
|
||||
"type": "ObjectExpression",
|
||||
"start":25,"end":32,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":15}},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start":27,"end":30,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13}},
|
||||
"extra": {
|
||||
"shorthand": true
|
||||
},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":27,"end":30,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": true,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start":27,"end":30,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,3 @@
|
||||
{
|
||||
"plugins": [
|
||||
"classStaticBlock"
|
||||
],
|
||||
"throws": "Unexpected token, expected \";\" (5:12)"
|
||||
}
|
||||
"plugins": ["classStaticBlock"]
|
||||
}
|
||||
|
||||
96
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-await/output.json
vendored
Normal file
96
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-await/output.json
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":95,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions (5:6)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":95,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":0,"end":95,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":15,"end":18,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":18},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":21,"end":95,"loc":{"start":{"line":1,"column":21},"end":{"line":8,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":25,"end":93,"loc":{"start":{"line":2,"column":2},"end":{"line":7,"column":3}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":31,"end":32,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":33,"end":93,"loc":{"start":{"line":2,"column":10},"end":{"line":7,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":39,"end":54,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":19}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":46,"end":49,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":14},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":52,"end":54,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":19}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":59,"end":89,"loc":{"start":{"line":4,"column":4},"end":{"line":6,"column":5}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":74,"end":83,"loc":{"start":{"line":5,"column":6},"end":{"line":5,"column":15}},
|
||||
"expression": {
|
||||
"type": "AwaitExpression",
|
||||
"start":74,"end":82,"loc":{"start":{"line":5,"column":6},"end":{"line":5,"column":14}},
|
||||
"argument": {
|
||||
"type": "NumericLiteral",
|
||||
"start":80,"end":82,"loc":{"start":{"line":5,"column":12},"end":{"line":5,"column":14}},
|
||||
"extra": {
|
||||
"rawValue": 42,
|
||||
"raw": "42"
|
||||
},
|
||||
"value": 42
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,4 @@
|
||||
{
|
||||
"plugins": [
|
||||
"topLevelAwait",
|
||||
"classProperties"
|
||||
],
|
||||
"sourceType": "module",
|
||||
"throws": "Unexpected token, expected \";\" (2:12)"
|
||||
}
|
||||
"plugins": ["topLevelAwati", "classProperties"],
|
||||
"sourceType": "module"
|
||||
}
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions (2:6)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"start":7,"end":33,"loc":{"start":{"line":1,"column":7},"end":{"line":3,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":15,"end":33,"loc":{"start":{"line":1,"column":15},"end":{"line":3,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassProperty",
|
||||
"start":19,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}},
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":20,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":3},"identifierName":"p"},
|
||||
"name": "p"
|
||||
},
|
||||
"computed": false,
|
||||
"value": {
|
||||
"type": "AwaitExpression",
|
||||
"start":23,"end":30,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":13}},
|
||||
"argument": {
|
||||
"type": "NumericLiteral",
|
||||
"start":29,"end":30,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":13}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
{
|
||||
"plugins": ["topLevelAwait"],
|
||||
"sourceType": "script",
|
||||
"throws": "Unexpected token, expected \";\" (1:6)"
|
||||
"sourceType": "script"
|
||||
}
|
||||
|
||||
33
packages/babel-parser/test/fixtures/experimental/top-level-await/top-level-script/output.json
vendored
Normal file
33
packages/babel-parser/test/fixtures/experimental/top-level-await/top-level-script/output.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"typescript",
|
||||
"topLevelAwait"
|
||||
],
|
||||
"throws": "Unexpected token, expected \";\" (2:20)"
|
||||
}
|
||||
"plugins": ["typescript", "topLevelAwait"]
|
||||
}
|
||||
|
||||
60
packages/babel-parser/test/fixtures/typescript/module-namespace/top-level-await/output.json
vendored
Normal file
60
packages/babel-parser/test/fixtures/typescript/module-namespace/top-level-await/output.json
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules (2:14)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "TSModuleDeclaration",
|
||||
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"N"},
|
||||
"name": "N"
|
||||
},
|
||||
"body": {
|
||||
"type": "TSModuleBlock",
|
||||
"start":12,"end":39,"loc":{"start":{"line":1,"column":12},"end":{"line":3,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"start":18,"end":37,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":23}},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start":24,"end":36,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":22}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":24,"end":25,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"x"},
|
||||
"name": "x"
|
||||
},
|
||||
"init": {
|
||||
"type": "AwaitExpression",
|
||||
"start":28,"end":36,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":22}},
|
||||
"argument": {
|
||||
"type": "NumericLiteral",
|
||||
"start":34,"end":36,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":22}},
|
||||
"extra": {
|
||||
"rawValue": 42,
|
||||
"raw": "42"
|
||||
},
|
||||
"value": 42
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "const"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user