enable experiments.importAsync by default

remove experiments.importAwait
This commit is contained in:
Tobias Koppers 2020-08-04 00:47:08 +02:00
parent 91173c8b5a
commit dfc8e35f2d
47 changed files with 49 additions and 264 deletions

View File

@ -882,14 +882,6 @@ export interface Experiments {
* Support WebAssembly as asynchronous EcmaScript Module.
*/
asyncWebAssembly?: boolean;
/**
* Allow 'import/export' syntax to import async modules.
*/
importAsync?: boolean;
/**
* Allow 'import/export await' syntax to import async modules.
*/
importAwait?: boolean;
/**
* Support .mjs files as way to define strict ESM file (node.js).
*/

View File

@ -305,13 +305,7 @@ class WebpackOptionsApply extends OptionsApply {
new RuntimePlugin().apply(compiler);
new InferAsyncModulesPlugin({
errorOnImport: options.experiments.importAsync
? false
: options.experiments.importAwait
? "await"
: true
}).apply(compiler);
new InferAsyncModulesPlugin().apply(compiler);
new DataUriPlugin().apply(compiler);
new FileUriPlugin().apply(compiler);
@ -319,8 +313,7 @@ class WebpackOptionsApply extends OptionsApply {
new CompatibilityPlugin().apply(compiler);
new HarmonyModulesPlugin({
module: options.module,
topLevelAwait: options.experiments.topLevelAwait,
importAwait: options.experiments.importAwait
topLevelAwait: options.experiments.topLevelAwait
}).apply(compiler);
if (options.amd !== false) {
const AMDPlugin = require("./dependencies/AMDPlugin");

View File

@ -5,21 +5,12 @@
"use strict";
const WebpackError = require("../WebpackError");
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
class InferAsyncModulesPlugin {
/**
* @param {Object} options options object
* @param {boolean | "await"=} options.errorOnImport false: no error, true: error when importing async module, "await": error when import async module without import await
*/
constructor({ errorOnImport = false } = {}) {
this.errorOnImport = errorOnImport;
}
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
@ -47,20 +38,6 @@ class InferAsyncModulesPlugin {
dep instanceof HarmonyImportDependency &&
connection.isActive(undefined)
) {
if (
this.errorOnImport &&
dep instanceof HarmonyImportSideEffectDependency &&
(this.errorOnImport === true || !dep.await)
) {
const error = new WebpackError(
this.errorOnImport === true
? "Tried to import async module with import/export (must enable experiments.importAsync to allow this)"
: "Tried to import async module with normal import/export (must use 'import await'/'export await' instead)"
);
error.module = module;
error.loc = dep.loc;
compilation.errors.push(error);
}
queue.add(connection.originModule);
}
}

View File

@ -222,8 +222,6 @@ const applyWebpackOptionsDefaults = options => {
const applyExperimentsDefaults = experiments => {
D(experiments, "asset", false);
D(experiments, "mjs", false);
D(experiments, "importAwait", false);
D(experiments, "importAsync", false);
D(experiments, "topLevelAwait", false);
D(experiments, "syncWebAssembly", false);
D(experiments, "asyncWebAssembly", false);

View File

@ -20,7 +20,6 @@ module.exports = class HarmonyExportDependencyParserPlugin {
constructor(options) {
const { module: moduleOptions } = options;
this.strictExportPresence = moduleOptions.strictExportPresence;
this.importAwait = options.importAwait;
}
apply(parser) {
@ -50,15 +49,9 @@ module.exports = class HarmonyExportDependencyParserPlugin {
source,
parser.state.lastHarmonyImportOrder
);
sideEffectDep.await = statement.await;
sideEffectDep.loc = Object.create(statement.loc);
sideEffectDep.loc.index = -1;
parser.state.current.addDependency(sideEffectDep);
if (statement.await && !this.importAwait) {
throw new Error(
"Used 'export await' but import-await experiment is not enabled (set experiments.importAwait: true to enable it)"
);
}
return true;
}
);

View File

@ -34,7 +34,6 @@ module.exports = class HarmonyImportDependencyParserPlugin {
const { module: moduleOptions } = options;
this.strictExportPresence = moduleOptions.strictExportPresence;
this.strictThisContextOnImports = moduleOptions.strictThisContextOnImports;
this.importAwait = options.importAwait;
}
apply(parser) {
@ -51,13 +50,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
parser.state.lastHarmonyImportOrder
);
sideEffectDep.loc = statement.loc;
sideEffectDep.await = statement.await;
parser.state.module.addDependency(sideEffectDep);
if (statement.await && !this.importAwait) {
throw new Error(
"Used 'import await' but import-await experiment is not enabled (set experiments.importAwait: true to enable it)"
);
}
return true;
}
);

View File

@ -52,7 +52,7 @@ const EMPTY_ARRAY = [];
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
const parser = AcornParser.extend(require("../parsing/importAwaitAcornPlugin"));
const parser = AcornParser;
class VariableInfo {
/**

View File

@ -1,50 +0,0 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const { tokTypes: tt } = require("acorn");
/** @typedef {typeof import("acorn").Parser} Parser */
/**
* @param {Parser} P the acorn parser
* @returns {Parser} new acorn parser
*/
module.exports = P => {
const Base = /** @type {any} */ (P);
const NewParser = /** @type {unknown} */ (class extends Base {
parseImport(node) {
this.next();
// import await '...'
if (this.type === tt.name && this.value === "await") {
node.await = true;
} else {
node.await = false;
this.pos = this.start;
}
return super.parseImport(node);
}
parseExport(node) {
this.next();
// export await '...'
if (this.type === tt.name && this.value === "await") {
node.await = true;
} else {
node.await = false;
this.pos = this.start;
}
const result = super.parseExport(node);
if (node.await && !node.source) {
this.raiseRecoverable(
node.start,
"Missing from source in export await"
);
}
return result;
}
});
return /** @type {Parser} */ (NewParser);
};

View File

@ -368,14 +368,6 @@
"description": "Support WebAssembly as asynchronous EcmaScript Module.",
"type": "boolean"
},
"importAsync": {
"description": "Allow 'import/export' syntax to import async modules.",
"type": "boolean"
},
"importAwait": {
"description": "Allow 'import/export await' syntax to import async modules.",
"type": "boolean"
},
"mjs": {
"description": "Support .mjs files as way to define strict ESM file (node.js).",
"type": "boolean"

View File

@ -91,8 +91,6 @@ describe("Defaults", () => {
"experiments": Object {
"asset": false,
"asyncWebAssembly": false,
"importAsync": false,
"importAwait": false,
"mjs": false,
"outputModule": false,
"syncWebAssembly": false,
@ -715,9 +713,8 @@ describe("Defaults", () => {
@@ ... @@
- "asyncWebAssembly": false,
+ "asyncWebAssembly": true,
@@ ... @@
- "mjs": false,
+ "asyncWebAssembly": true,
+ "mjs": true,
@@ ... @@
+ },

View File

@ -179,9 +179,7 @@ const describeCases = config => {
experiments: {
mjs: true,
asyncWebAssembly: true,
topLevelAwait: true,
importAwait: true,
importAsync: true
topLevelAwait: true
}
};
beforeAll(done => {

View File

@ -354,32 +354,6 @@ Object {
"multiple": false,
"simpleType": "boolean",
},
"experiments-import-async": Object {
"configs": Array [
Object {
"description": "Allow 'import/export' syntax to import async modules.",
"multiple": false,
"path": "experiments.importAsync",
"type": "boolean",
},
],
"description": "Allow 'import/export' syntax to import async modules.",
"multiple": false,
"simpleType": "boolean",
},
"experiments-import-await": Object {
"configs": Array [
Object {
"description": "Allow 'import/export await' syntax to import async modules.",
"multiple": false,
"path": "experiments.importAwait",
"type": "boolean",
},
],
"description": "Allow 'import/export await' syntax to import async modules.",
"multiple": false,
"simpleType": "boolean",
},
"experiments-mjs": Object {
"configs": Array [
Object {

View File

@ -4299,7 +4299,7 @@ WARNING in Terser Plugin: Dropping unused function someUnRemoteUsedFunction5 [we
`;
exports[`StatsTestCases should print correct stats for wasm-explorer-examples-sync 1`] = `
"Hash: 236a7aafb9e23319b3b2
"Hash: bcdac54c787768809ad1
Time: X ms
Built at: 1970-04-20 12:42:42
asset 0506579c50fa5de37901.module.wasm 531 bytes [emitted] [immutable]
@ -4322,17 +4322,17 @@ chunk (runtime: main) bundle.js (main) 586 bytes (javascript) 5.96 KiB (runtime)
+ 9 hidden chunk modules
chunk (runtime: main) 230.bundle.js 50 bytes (javascript) 156 bytes (webassembly) [rendered]
./Q_rsqrt.wasm 50 bytes (javascript) 156 bytes (webassembly) [built]
chunk (runtime: main) 325.bundle.js 1.54 KiB (javascript) 274 bytes (webassembly) [rendered]
chunk (runtime: main) 325.bundle.js 1.5 KiB (javascript) 274 bytes (webassembly) [rendered]
./popcnt.wasm 50 bytes (javascript) 120 bytes (webassembly) [built]
./testFunction.wasm 50 bytes (javascript) 154 bytes (webassembly) [built]
./tests.js 1.44 KiB [built]
./tests.js 1.4 KiB [built]
chunk (runtime: main) 526.bundle.js (id hint: vendors) 34 bytes [rendered] split chunk (cache group: defaultVendors)
./node_modules/env.js 34 bytes [built]
chunk (runtime: main) 780.bundle.js 110 bytes (javascript) 444 bytes (webassembly) [rendered]
./fact.wasm 50 bytes (javascript) 154 bytes (webassembly) [built]
./fast-math.wasm 60 bytes (javascript) 290 bytes (webassembly) [built]
./index.js 586 bytes [built]
./tests.js 1.44 KiB [built]
./tests.js 1.4 KiB [built]
./Q_rsqrt.wasm 50 bytes (javascript) 156 bytes (webassembly) [built]
./testFunction.wasm 50 bytes (javascript) 154 bytes (webassembly) [built]
./fact.wasm 50 bytes (javascript) 154 bytes (webassembly) [built]

View File

@ -1,6 +0,0 @@
it("should allow to use import await", () => {
return import("./reexport").then(({ default: value, other }) => {
expect(value).toBe(42);
expect(other).toBe(42);
});
});

View File

@ -1 +0,0 @@
export default 42;

View File

@ -1,4 +0,0 @@
export await { default } from "./module";
import await value from "./module";
export const other = value;

View File

@ -1,6 +0,0 @@
it("should allow to use import await", () => {
return import("./reexport").then(({ default: value, other }) => {
expect(value).toBe(42);
expect(other).toBe(42);
});
});

View File

@ -1,3 +0,0 @@
await new Promise(r => setTimeout(r, 100));
export default 42;

View File

@ -1,4 +0,0 @@
export { default } from "./module";
import value from "./module";
export const other = value;

View File

@ -1,4 +1,4 @@
it("should allow to use import await", () => {
it("should allow to use top-level-await", () => {
return import("./reexport").then(({ default: value, other }) => {
expect(value).toBe(42);
expect(other).toBe(42);

View File

@ -1,4 +1,4 @@
export await { default } from "./module";
import await value from "./module";
export { default } from "./module";
import value from "./module";
export const other = value;

View File

@ -1 +1 @@
export await * from "./module.wat";
export * from "./module.wat";

View File

@ -1 +1 @@
export await * from "./module.wat";
export * from "./module.wat";

View File

@ -1,4 +1,4 @@
import await { addNumber } from "./wasm.wat";
import { addNumber } from "./wasm.wat";
export var result = addNumber(22);

View File

@ -1,4 +1,4 @@
import await { getResult } from "./wasm.wasm";
import { getResult } from "./wasm.wasm";
export var result = getResult(1);

View File

@ -1,4 +1,4 @@
import await { getNumber as getN } from "./wasm.wasm";
import { getNumber as getN } from "./wasm.wasm";
export function getNumber() {
return getN();

View File

@ -1,5 +1,5 @@
import await * as a1 from "./mem-access.wat?1";
import await * as a2 from "./mem-access.wat?2";
import * as a1 from "./mem-access.wat?1";
import * as a2 from "./mem-access.wat?2";
a1.set(42);
export const x1 = a1.get();

View File

@ -1,6 +1,6 @@
import { trackA, results } from "./tracker";
import "./b.js";
import await "./wasm.wat";
import "./wasm.wat";
trackA();

View File

@ -1,4 +1,4 @@
import await { add, getNumber } from "./wasm.wat?1";
import { add, getNumber } from "./wasm.wat?1";
export function run() {
return add(getNumber(), 2);

View File

@ -1,8 +1,8 @@
const stringifyRequest = require("loader-utils").stringifyRequest;
module.exports.pitch = function(remainingRequest) {
module.exports.pitch = function (remainingRequest) {
return `
import await { getString as _getString, memory } from ${stringifyRequest(
import { getString as _getString, memory } from ${stringifyRequest(
this,
`${this.resourcePath}.wat!=!${remainingRequest}`
)};

View File

@ -1,8 +1,8 @@
const stringifyRequest = require("loader-utils").stringifyRequest;
module.exports.pitch = function(remainingRequest) {
module.exports.pitch = function (remainingRequest) {
return `
import await { getString as _getString, memory } from ${stringifyRequest(
import { getString as _getString, memory } from ${stringifyRequest(
this,
`${this.resourcePath}.wasm!=!wast-loader!${remainingRequest}`
)};

View File

@ -1,4 +1,4 @@
import await { getNumber } from "./wasm.wat";
import { getNumber } from "./wasm.wat";
export function run() {
return getNumber();

View File

@ -1,9 +1,9 @@
import await * as Q_rsqrt from "./Q_rsqrt.wasm";
import await * as testFunction from "./testFunction.wasm";
import await * as fact from "./fact.wasm";
import await * as popcnt from "./popcnt.wasm";
import await * as fastMath from "./fast-math.wasm";
import await * as duff from "./duff.wasm";
import * as Q_rsqrt from "./Q_rsqrt.wasm";
import * as testFunction from "./testFunction.wasm";
import * as fact from "./fact.wasm";
import * as popcnt from "./popcnt.wasm";
import * as fastMath from "./fast-math.wasm";
import * as duff from "./duff.wasm";
export function run_Q_rsqrt() {
const result = Q_rsqrt._Z7Q_rsqrtf(1/1764);

View File

@ -9,8 +9,5 @@ module.exports = {
"failing-promise-external":
"promise new Promise((resolve, reject) => setTimeout(() => reject(new Error('external reject')), 100))",
"import-external": ["import /hello/world.js", "request"]
},
experiments: {
importAsync: true
}
};

View File

@ -1,6 +1,6 @@
import { A, B, C1, C2, D1, D2, E1, E2, E3, F, G } from "./test";
export { a, b, c, d, e };
export { a, b, c, d };
if (Math.random() > 0.5) {
var a = () => A;
@ -26,21 +26,21 @@ while (Math.random() > 0.5) {
let d = () => D1;
}
if(false) {
if (false) {
E1();
}
export var e = true ? E2 : E3;
export { f, g }
export { f, g };
if(true) {
if (true) {
let inner = () => F;
var f = () => inner();
}
if(true) {
if (true) {
const inner = () => G;
var g = () => inner();

View File

@ -1,6 +1,6 @@
import await { getNumber } from "./wasm.wat?1";
import await { getNumber as getNumber2 } from "./wasm.wat?2";
import { getNumber } from "./wasm.wat?1";
import { getNumber as getNumber2 } from "./wasm.wat?2";
export function run() {
return getNumber() + getNumber2();
};
}

View File

@ -18,8 +18,7 @@ module.exports = {
webassemblyModuleFilename: "[id].[hash].wasm"
},
experiments: {
asyncWebAssembly: true,
importAwait: true
asyncWebAssembly: true
},
plugins: [
/**

View File

@ -1 +0,0 @@
module.exports = [[/experiments\.importAsync/]];

View File

@ -1,3 +0,0 @@
it("should not compile the module", function () {
expect(() => require("./module"));
});

View File

@ -1,3 +0,0 @@
import { getNumber } from "./wasm.wat";
export default getNumber();

View File

@ -1,5 +0,0 @@
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
module.exports = function(config) {
return supportsWebAssembly();
};

View File

@ -1,5 +0,0 @@
(module
(func $getNumber (export "getNumber") (result i32)
(i32.const 42))
)

View File

@ -1,15 +0,0 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
module: {
rules: [
{
test: /\.wat$/,
loader: "wast-loader",
type: "webassembly/async"
}
]
},
experiments: {
asyncWebAssembly: true
}
};

View File

@ -14,7 +14,6 @@ module.exports = {
]
},
experiments: {
syncWebAssembly: true,
importAwait: true
syncWebAssembly: true
}
};

View File

@ -1,9 +1,9 @@
import await * as Q_rsqrt from "./Q_rsqrt.wasm";
import await * as testFunction from "./testFunction.wasm";
import await * as fact from "./fact.wasm";
import await * as popcnt from "./popcnt.wasm";
import await * as fastMath from "./fast-math.wasm";
import await * as duff from "./duff.wasm";
import * as Q_rsqrt from "./Q_rsqrt.wasm";
import * as testFunction from "./testFunction.wasm";
import * as fact from "./fact.wasm";
import * as popcnt from "./popcnt.wasm";
import * as fastMath from "./fast-math.wasm";
import * as duff from "./duff.wasm";
export function run_Q_rsqrt() {
const result = Q_rsqrt._Z7Q_rsqrtf(1/1764);

View File

@ -19,7 +19,6 @@ module.exports = {
modules: true
},
experiments: {
asyncWebAssembly: true,
importAwait: true
asyncWebAssembly: true
}
};

10
types.d.ts vendored
View File

@ -2521,16 +2521,6 @@ declare interface Experiments {
*/
asyncWebAssembly?: boolean;
/**
* Allow 'import/export' syntax to import async modules.
*/
importAsync?: boolean;
/**
* Allow 'import/export await' syntax to import async modules.
*/
importAwait?: boolean;
/**
* Support .mjs files as way to define strict ESM file (node.js).
*/