Enable top-level await parsing by default (#13387)
This commit is contained in:
parent
b707842dd0
commit
ddaf0d4296
10
Makefile
10
Makefile
@ -1,6 +1,6 @@
|
|||||||
FLOW_COMMIT = a1f9a4c709dcebb27a5084acf47755fbae699c25
|
FLOW_COMMIT = 92bbb5e9dacb8185aa73ea343954d0434b42c40b
|
||||||
TEST262_COMMIT = f9efc461420e3729a8fe24ac2472fad9d6357a70
|
TEST262_COMMIT = f9efc461420e3729a8fe24ac2472fad9d6357a70
|
||||||
TYPESCRIPT_COMMIT = 3de706a8525c2ded782fc032fa4afe2e485100d3
|
TYPESCRIPT_COMMIT = e34b2adcaed2ff12761f7cbf87a299f5082c4e63
|
||||||
|
|
||||||
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
||||||
export FORCE_COLOR = true
|
export FORCE_COLOR = true
|
||||||
@ -134,7 +134,7 @@ test-ci-coverage:
|
|||||||
bootstrap-flow:
|
bootstrap-flow:
|
||||||
rm -rf build/flow
|
rm -rf build/flow
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
git clone --single-branch --shallow-since=2018-11-01 https://github.com/facebook/flow.git build/flow
|
git clone --single-branch --shallow-since=2021-05-01 https://github.com/facebook/flow.git build/flow
|
||||||
cd build/flow && git checkout -q $(FLOW_COMMIT)
|
cd build/flow && git checkout -q $(FLOW_COMMIT)
|
||||||
|
|
||||||
test-flow:
|
test-flow:
|
||||||
@ -146,7 +146,7 @@ test-flow-update-allowlist:
|
|||||||
bootstrap-typescript:
|
bootstrap-typescript:
|
||||||
rm -rf ./build/typescript
|
rm -rf ./build/typescript
|
||||||
mkdir -p ./build
|
mkdir -p ./build
|
||||||
git clone --single-branch --shallow-since=2019-09-01 https://github.com/microsoft/TypeScript.git ./build/typescript
|
git clone --single-branch --shallow-since=2021-05-01 https://github.com/microsoft/TypeScript.git ./build/typescript
|
||||||
cd build/typescript && git checkout -q $(TYPESCRIPT_COMMIT)
|
cd build/typescript && git checkout -q $(TYPESCRIPT_COMMIT)
|
||||||
|
|
||||||
test-typescript:
|
test-typescript:
|
||||||
@ -158,7 +158,7 @@ test-typescript-update-allowlist:
|
|||||||
bootstrap-test262:
|
bootstrap-test262:
|
||||||
rm -rf build/test262
|
rm -rf build/test262
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
git clone --single-branch --shallow-since=2019-12-01 https://github.com/tc39/test262.git build/test262
|
git clone --single-branch --shallow-since=2021-05-01 https://github.com/tc39/test262.git build/test262
|
||||||
cd build/test262 && git checkout -q $(TEST262_COMMIT)
|
cd build/test262 && git checkout -q $(TEST262_COMMIT)
|
||||||
|
|
||||||
test-test262:
|
test-test262:
|
||||||
|
|||||||
@ -39,14 +39,12 @@ import {
|
|||||||
SCOPE_DIRECT_SUPER,
|
SCOPE_DIRECT_SUPER,
|
||||||
SCOPE_FUNCTION,
|
SCOPE_FUNCTION,
|
||||||
SCOPE_SUPER,
|
SCOPE_SUPER,
|
||||||
SCOPE_PROGRAM,
|
|
||||||
} from "../util/scopeflags";
|
} from "../util/scopeflags";
|
||||||
import { ExpressionErrors } from "./util";
|
import { ExpressionErrors } from "./util";
|
||||||
import {
|
import {
|
||||||
PARAM_AWAIT,
|
PARAM_AWAIT,
|
||||||
PARAM_IN,
|
PARAM_IN,
|
||||||
PARAM_RETURN,
|
PARAM_RETURN,
|
||||||
PARAM,
|
|
||||||
functionFlags,
|
functionFlags,
|
||||||
} from "../util/production-parameter";
|
} from "../util/production-parameter";
|
||||||
import {
|
import {
|
||||||
@ -152,12 +150,7 @@ export default class ExpressionParser extends LValParser {
|
|||||||
|
|
||||||
// Convenience method to parse an Expression only
|
// Convenience method to parse an Expression only
|
||||||
getExpression(): N.Expression & N.ParserOutput {
|
getExpression(): N.Expression & N.ParserOutput {
|
||||||
let paramFlags = PARAM;
|
this.enterInitialScopes();
|
||||||
if (this.hasPlugin("topLevelAwait") && this.inModule) {
|
|
||||||
paramFlags |= PARAM_AWAIT;
|
|
||||||
}
|
|
||||||
this.scope.enter(SCOPE_PROGRAM);
|
|
||||||
this.prodParam.enter(paramFlags);
|
|
||||||
this.nextToken();
|
this.nextToken();
|
||||||
const expr = this.parseExpression();
|
const expr = this.parseExpression();
|
||||||
if (!this.match(tt.eof)) {
|
if (!this.match(tt.eof)) {
|
||||||
@ -615,12 +608,7 @@ export default class ExpressionParser extends LValParser {
|
|||||||
? this.state.type.startsExpr
|
? this.state.type.startsExpr
|
||||||
: this.state.type.startsExpr && !this.match(tt.modulo);
|
: this.state.type.startsExpr && !this.match(tt.modulo);
|
||||||
if (startsExpr && !this.isAmbiguousAwait()) {
|
if (startsExpr && !this.isAmbiguousAwait()) {
|
||||||
this.raiseOverwrite(
|
this.raiseOverwrite(startPos, Errors.AwaitNotInAsyncContext);
|
||||||
startPos,
|
|
||||||
this.hasPlugin("topLevelAwait")
|
|
||||||
? Errors.AwaitNotInAsyncContext
|
|
||||||
: Errors.AwaitNotInAsyncFunction,
|
|
||||||
);
|
|
||||||
return this.parseAwait(startPos, startLoc);
|
return this.parseAwait(startPos, startLoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -395,7 +395,7 @@ export default class UtilParser extends Tokenizer {
|
|||||||
|
|
||||||
enterInitialScopes() {
|
enterInitialScopes() {
|
||||||
let paramFlags = PARAM;
|
let paramFlags = PARAM;
|
||||||
if (this.hasPlugin("topLevelAwait") && this.inModule) {
|
if (this.inModule) {
|
||||||
paramFlags |= PARAM_AWAIT;
|
paramFlags |= PARAM_AWAIT;
|
||||||
}
|
}
|
||||||
this.scope.enter(SCOPE_PROGRAM);
|
this.scope.enter(SCOPE_PROGRAM);
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"]
|
|
||||||
}
|
|
||||||
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"sourceType": "module"
|
"sourceType": "module",
|
||||||
|
"throws": "Unexpected token (1:6)"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "File",
|
|
||||||
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
|
||||||
"errors": [
|
|
||||||
"SyntaxError: Unexpected reserved word 'await'. (1:0)"
|
|
||||||
],
|
|
||||||
"program": {
|
|
||||||
"type": "Program",
|
|
||||||
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
|
||||||
"sourceType": "module",
|
|
||||||
"interpreter": null,
|
|
||||||
"body": [
|
|
||||||
{
|
|
||||||
"type": "ExpressionStatement",
|
|
||||||
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
|
||||||
"expression": {
|
|
||||||
"type": "AssignmentExpression",
|
|
||||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
|
||||||
"operator": "=",
|
|
||||||
"left": {
|
|
||||||
"type": "Identifier",
|
|
||||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"await"},
|
|
||||||
"name": "await"
|
|
||||||
},
|
|
||||||
"right": {
|
|
||||||
"type": "CallExpression",
|
|
||||||
"start":8,"end":13,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":13}},
|
|
||||||
"callee": {
|
|
||||||
"type": "Identifier",
|
|
||||||
"start":8,"end":11,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":11},"identifierName":"foo"},
|
|
||||||
"name": "foo"
|
|
||||||
},
|
|
||||||
"arguments": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"directives": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Unexpected reserved word 'await'. (1:6)"
|
"SyntaxError: Can not use 'await' as identifier inside an async function. (1:6)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
|
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Unexpected reserved word 'await'. (1:8)"
|
"SyntaxError: Can not use 'await' as identifier inside an async function. (1:8)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
|
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Unexpected reserved word 'await'. (1:9)"
|
"SyntaxError: Can not use 'await' as identifier inside an async function. (1:9)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Unexpected reserved word 'await'. (1:6)"
|
"SyntaxError: Can not use 'await' as identifier inside an async function. (1:6)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (1:24)"
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (1:24)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (2:9)"
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (2:9)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
|
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (1:8)"
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (1:8)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
|
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (1:11)",
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (1:11)",
|
||||||
"SyntaxError: 'await' is not allowed in async function parameters. (1:11)"
|
"SyntaxError: 'await' is not allowed in async function parameters. (1:11)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
"start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (2:19)",
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (2:19)",
|
||||||
"SyntaxError: 'await' is not allowed in async function parameters. (2:19)"
|
"SyntaxError: 'await' is not allowed in async function parameters. (2:19)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (2:2)"
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (2:2)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":50}},
|
"start":0,"end":50,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":50}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Missing semicolon. (1:25)",
|
"SyntaxError: Missing semicolon. (1:25)",
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (1:41)"
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (1:41)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
|
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Missing semicolon. (1:10)",
|
"SyntaxError: Missing semicolon. (1:10)",
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (1:18)"
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (1:18)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (2:6)"
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (2:6)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
3
packages/babel-parser/test/fixtures/es2022/top-level-await-module/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2022/top-level-await-module/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
3
packages/babel-parser/test/fixtures/es2022/top-level-await-script/for-await/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2022/top-level-await-script/for-await/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected token, expected \"(\" (1:4)"
|
||||||
|
}
|
||||||
3
packages/babel-parser/test/fixtures/es2022/top-level-await-script/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2022/top-level-await-script/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "script"
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"allowAwaitOutsideFunction": true
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["v8intrinsic"]
|
||||||
|
}
|
||||||
@ -1,4 +1,3 @@
|
|||||||
{
|
{
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "unambiguous"
|
"sourceType": "unambiguous"
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":95,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
"start":0,"end":95,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: 'await' is only allowed within async functions. (5:6)"
|
"SyntaxError: 'await' is only allowed within async functions and at the top levels of modules. (5:6)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"sourceType": "script",
|
"sourceType": "script",
|
||||||
"plugins": ["moduleBlocks"]
|
"plugins": ["moduleBlocks"],
|
||||||
|
"throws": "Unexpected token (1:14)"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,55 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "File",
|
|
||||||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
|
||||||
"errors": [
|
|
||||||
"SyntaxError: Unexpected reserved word 'await'. (1:9)"
|
|
||||||
],
|
|
||||||
"program": {
|
|
||||||
"type": "Program",
|
|
||||||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
|
||||||
"sourceType": "script",
|
|
||||||
"interpreter": null,
|
|
||||||
"body": [
|
|
||||||
{
|
|
||||||
"type": "ExpressionStatement",
|
|
||||||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
|
|
||||||
"expression": {
|
|
||||||
"type": "ModuleExpression",
|
|
||||||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
|
|
||||||
"body": {
|
|
||||||
"type": "Program",
|
|
||||||
"start":9,"end":19,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":19}},
|
|
||||||
"sourceType": "module",
|
|
||||||
"interpreter": null,
|
|
||||||
"body": [
|
|
||||||
{
|
|
||||||
"type": "LabeledStatement",
|
|
||||||
"start":9,"end":17,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":17}},
|
|
||||||
"body": {
|
|
||||||
"type": "ExpressionStatement",
|
|
||||||
"start":16,"end":17,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":17}},
|
|
||||||
"expression": {
|
|
||||||
"type": "NumericLiteral",
|
|
||||||
"start":16,"end":17,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":17}},
|
|
||||||
"extra": {
|
|
||||||
"rawValue": 3,
|
|
||||||
"raw": "3"
|
|
||||||
},
|
|
||||||
"value": 3
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"label": {
|
|
||||||
"type": "Identifier",
|
|
||||||
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14},"identifierName":"await"},
|
|
||||||
"name": "await"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"directives": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"directives": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"sourceType": "module",
|
|
||||||
"plugins": ["moduleBlocks", "topLevelAwait"]
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "script",
|
|
||||||
"throws": "Unexpected token, expected \"(\" (1:4)"
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": [
|
|
||||||
"topLevelAwait"
|
|
||||||
],
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwati"],
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": [
|
|
||||||
"topLevelAwait"
|
|
||||||
],
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "script"
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "unambiguous",
|
|
||||||
"allowAwaitOutsideFunction": true
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "unambiguous"
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait", "v8intrinsic"],
|
|
||||||
"sourceType": "unambiguous"
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": ["topLevelAwait"],
|
|
||||||
"sourceType": "unambiguous"
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
await 0;
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"caller": {
|
|
||||||
"name": "test-fixture",
|
|
||||||
"supportsStaticESM": true,
|
|
||||||
"supportsDynamicImport": true,
|
|
||||||
"supportsTopLevelAwait": true
|
|
||||||
},
|
|
||||||
"presets": ["env"]
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
await 0;
|
|
||||||
@ -1 +0,0 @@
|
|||||||
await 0;
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"caller": {
|
|
||||||
"name": "test-fixture",
|
|
||||||
"supportsStaticESM": true,
|
|
||||||
"supportsDynamicImport": true,
|
|
||||||
"supportsTopLevelAwait": false
|
|
||||||
},
|
|
||||||
"presets": ["env"],
|
|
||||||
"throws": "Unexpected reserved word 'await'. (1:0)"
|
|
||||||
}
|
|
||||||
42
packages/babel-preset-env/test/top-level-await.js
Normal file
42
packages/babel-preset-env/test/top-level-await.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import env from "..";
|
||||||
|
import * as babel from "@babel/core";
|
||||||
|
|
||||||
|
describe("supportsTopLevelAwait enables the parser plugin for old parser versions", () => {
|
||||||
|
function extractParserOptions(api, { ref }) {
|
||||||
|
return {
|
||||||
|
manipulateOptions(opts, parserOpts) {
|
||||||
|
ref.parserOpts = parserOpts;
|
||||||
|
},
|
||||||
|
visitor: {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
it("supported", () => {
|
||||||
|
const ref = {};
|
||||||
|
babel.transformSync("", {
|
||||||
|
configFile: false,
|
||||||
|
presets: [env],
|
||||||
|
plugins: [[extractParserOptions, { ref }]],
|
||||||
|
caller: {
|
||||||
|
name: "test",
|
||||||
|
supportsTopLevelAwait: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ref.parserOpts.plugins).toContain("topLevelAwait");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("unsupported", () => {
|
||||||
|
const ref = {};
|
||||||
|
babel.transformSync("", {
|
||||||
|
configFile: false,
|
||||||
|
presets: [env],
|
||||||
|
plugins: [[extractParserOptions, { ref }]],
|
||||||
|
caller: {
|
||||||
|
name: "test",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ref.parserOpts.plugins).not.toContain("topLevelAwait");
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -5,6 +5,7 @@ JSX/invalid_unpaired_rcurly.js
|
|||||||
JSX_invalid/migrated_0000.js
|
JSX_invalid/migrated_0000.js
|
||||||
arrow_function/object_return_type.js
|
arrow_function/object_return_type.js
|
||||||
arrow_function_invalid/migrated_0002.js
|
arrow_function_invalid/migrated_0002.js
|
||||||
|
async_arrow_functions/with_type_parameters_types_disabled.js
|
||||||
async_await/migrated_0020.js
|
async_await/migrated_0020.js
|
||||||
async_await/migrated_0024.js
|
async_await/migrated_0024.js
|
||||||
async_await/migrated_0027.js
|
async_await/migrated_0027.js
|
||||||
@ -14,9 +15,23 @@ class_properties/migrated_0003.js
|
|||||||
class_properties/migrated_0008.js
|
class_properties/migrated_0008.js
|
||||||
class_properties/migrated_0021.js
|
class_properties/migrated_0021.js
|
||||||
class_properties/migrated_0026.js
|
class_properties/migrated_0026.js
|
||||||
|
comment_interning/class_method.js
|
||||||
|
comment_interning/class_property.js
|
||||||
|
comment_interning/declare_export_declaration.js
|
||||||
|
comment_interning/declare_interface.js
|
||||||
|
comment_interning/declare_type_alias.js
|
||||||
|
comment_interning/decorator.js
|
||||||
|
comment_interning/function_declaration.js
|
||||||
|
comment_interning/import.js
|
||||||
|
comment_interning/interface.js
|
||||||
|
comment_interning/object_type.js
|
||||||
|
comment_interning/remove_type_trailing_comments.js
|
||||||
|
comment_interning/super.js
|
||||||
|
comment_interning/type_alias.js
|
||||||
decorators/migrated_0003.js
|
decorators/migrated_0003.js
|
||||||
export_import_reserved_words/migrated_0003.js
|
export_import_reserved_words/migrated_0003.js
|
||||||
export_statements/export_trailing_comma.js
|
export_statements/export_trailing_comma.js
|
||||||
|
for_await_loops/migrated_0000.js
|
||||||
nullish_coalescing/missing-plugin.js
|
nullish_coalescing/missing-plugin.js
|
||||||
optional_chaining/missing-plugin.js
|
optional_chaining/missing-plugin.js
|
||||||
types/member/reserved_words.js
|
types/member/reserved_words.js
|
||||||
|
|||||||
@ -135,6 +135,7 @@ const ignoredFeatures = [
|
|||||||
"Symbol.unscopables",
|
"Symbol.unscopables",
|
||||||
"tail-call-optimization",
|
"tail-call-optimization",
|
||||||
"template",
|
"template",
|
||||||
|
"top-level-await",
|
||||||
"TypedArray",
|
"TypedArray",
|
||||||
"TypedArray.prototype.at",
|
"TypedArray.prototype.at",
|
||||||
"TypedArray.prototype.item",
|
"TypedArray.prototype.item",
|
||||||
@ -153,7 +154,6 @@ const ignoredTests = ["built-ins/RegExp/", "language/literals/regexp/"];
|
|||||||
|
|
||||||
const featuresToPlugins = {
|
const featuresToPlugins = {
|
||||||
"class-static-block": "classStaticBlock",
|
"class-static-block": "classStaticBlock",
|
||||||
"top-level-await": "topLevelAwait",
|
|
||||||
"import-assertions": "importAssertions",
|
"import-assertions": "importAssertions",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -109,6 +109,7 @@ declarationEmitInterfaceWithNonEntityNameExpressionHeritage.ts
|
|||||||
declarationEmitMixinPrivateProtected.ts
|
declarationEmitMixinPrivateProtected.ts
|
||||||
declarationEmitPrefersPathKindBasedOnBundling.ts
|
declarationEmitPrefersPathKindBasedOnBundling.ts
|
||||||
declarationEmitPrefersPathKindBasedOnBundling2.ts
|
declarationEmitPrefersPathKindBasedOnBundling2.ts
|
||||||
|
declarationEmitPrivatePromiseLikeInterface.ts
|
||||||
declarationEmitPrivateSymbolCausesVarDeclarationEmit2.ts
|
declarationEmitPrivateSymbolCausesVarDeclarationEmit2.ts
|
||||||
declarationEmitReadonlyComputedProperty.ts
|
declarationEmitReadonlyComputedProperty.ts
|
||||||
declarationEmitStringEnumUsedInNonlocalSpread.ts
|
declarationEmitStringEnumUsedInNonlocalSpread.ts
|
||||||
@ -221,6 +222,7 @@ exportSpecifierAndLocalMemberDeclaration.ts
|
|||||||
exportStarFromEmptyModule.ts
|
exportStarFromEmptyModule.ts
|
||||||
exportStarNotElided.ts
|
exportStarNotElided.ts
|
||||||
expressionsForbiddenInParameterInitializers.ts
|
expressionsForbiddenInParameterInitializers.ts
|
||||||
|
extendedUnicodePlaneIdentifiers.ts
|
||||||
extendingClassFromAliasAndUsageInIndexer.ts
|
extendingClassFromAliasAndUsageInIndexer.ts
|
||||||
extendsClauseAlreadySeen.ts
|
extendsClauseAlreadySeen.ts
|
||||||
extendsClauseAlreadySeen2.ts
|
extendsClauseAlreadySeen2.ts
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user