Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: async module runtime for won't run top-level-await #17393

Merged
merged 5 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/runtime/AsyncModuleRuntimeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
`var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
`var resolveQueue = ${runtimeTemplate.basicFunction("queue", [
"if(queue && !queue.d) {",
"if(queue && queue.d < 1) {",
Template.indent([
"queue.d = 1;",
`queue.forEach(${runtimeTemplate.expressionFunction(
Expand Down Expand Up @@ -76,7 +76,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
)};`,
`${fn} = ${runtimeTemplate.basicFunction("module, body, hasAwait", [
"var queue;",
"hasAwait && ((queue = []).d = 1);",
"hasAwait && ((queue = []).d = -1);",
"var depQueues = new Set();",
"var exports = module.exports;",
"var currentDeps;",
Expand Down Expand Up @@ -124,7 +124,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
"(err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)",
"err"
)});`,
"queue && (queue.d = 0);"
"queue && queue.d < 0 && (queue.d = 0);"
])};`
]);
}
Expand Down
8 changes: 4 additions & 4 deletions test/__snapshots__/StatsTestCases.basictest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4759,7 +4759,7 @@ webpack x.x.x compiled with 1 warning in X ms"

exports[`StatsTestCases should print correct stats for wasm-explorer-examples-sync 1`] = `
"assets by path *.js 21.7 KiB
asset bundle.js 16.2 KiB [emitted] (name: main)
asset bundle.js 16.3 KiB [emitted] (name: main)
asset 325.bundle.js 3.89 KiB [emitted]
asset 795.bundle.js 557 bytes [emitted]
asset 526.bundle.js 364 bytes [emitted] (id hint: vendors)
Expand All @@ -4775,8 +4775,8 @@ assets by path *.wasm 1.37 KiB
asset 0301cb3f9f4151b567f5.module.wasm 120 bytes [emitted] [immutable]
chunk (runtime: main) 20.bundle.js 50 bytes (javascript) 531 bytes (webassembly) [rendered]
./duff.wasm 50 bytes (javascript) 531 bytes (webassembly) [built] [code generated]
chunk (runtime: main) bundle.js (main) 586 bytes (javascript) 9.14 KiB (runtime) [entry] [rendered]
runtime modules 9.14 KiB 11 modules
chunk (runtime: main) bundle.js (main) 586 bytes (javascript) 9.16 KiB (runtime) [entry] [rendered]
runtime modules 9.16 KiB 11 modules
./index.js 586 bytes [built] [code generated]
chunk (runtime: main) 189.bundle.js 50 bytes (javascript) 156 bytes (webassembly) [rendered]
./Q_rsqrt.wasm 50 bytes (javascript) 156 bytes (webassembly) [built] [code generated]
Expand All @@ -4790,7 +4790,7 @@ chunk (runtime: main) 526.bundle.js (id hint: vendors) 34 bytes [rendered] split
chunk (runtime: main) 795.bundle.js 110 bytes (javascript) 444 bytes (webassembly) [rendered]
./fact.wasm 50 bytes (javascript) 154 bytes (webassembly) [built] [code generated]
./fast-math.wasm 60 bytes (javascript) 290 bytes (webassembly) [built] [code generated]
runtime modules 9.14 KiB 11 modules
runtime modules 9.16 KiB 11 modules
cacheable modules 2.31 KiB (javascript) 1.37 KiB (webassembly)
webassembly modules 310 bytes (javascript) 1.37 KiB (webassembly)
./Q_rsqrt.wasm 50 bytes (javascript) 156 bytes (webassembly) [built] [code generated]
Expand Down
6 changes: 6 additions & 0 deletions test/cases/async-modules/issue-16097/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import i, { foo } from "./won't-run-tla";

it("should have value imported from won't-run-tla", async () => {
expect(i).toBe(42);
expect(foo).toBe(undefined);
});
4 changes: 4 additions & 0 deletions test/cases/async-modules/issue-16097/won't-run-tla.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global.someNonExistentVariable && await 'test';
const foo = global.otherSomeNonExistentVariable && await 43;
export default 42;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we improve this test, like:

global.someNonExistentVariable && await 'test';
const foo = global.otherSomeNonExistentVariable && await 43;
export default 42;
export { foo }

export { foo }