fix: resolve execution order issue from extra await in async modules

This commit is contained in:
Xiao 2025-08-17 23:05:52 +08:00 committed by GitHub
parent c92deaf02c
commit 8db97f863f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 30 additions and 1 deletions

View File

@ -62,9 +62,12 @@ class AwaitDependenciesInitFragment extends InitFragment {
this.dependencies.size === 1 ||
!runtimeTemplate.supportsDestructuring()
) {
templateInput.push(
"var __webpack_async_dependencies_result__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);"
);
for (const [index, importVar] of importVars.entries()) {
templateInput.push(
`${importVar} = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[${index}];`
`${importVar} = __webpack_async_dependencies_result__[${index}];`
);
}
} else {

View File

@ -0,0 +1,2 @@
await 1;
export const a = "a"

View File

@ -0,0 +1,2 @@
await 1;
export const b = "b"

View File

@ -0,0 +1,4 @@
import {a} from "./a";
import {b} from "./b";
export const c = a + b

View File

@ -0,0 +1,3 @@
import {c} from "./c";
export const d = c

View File

@ -0,0 +1,5 @@
it("should work", () => {
return import("./d").then(d => {
expect(d.d).toBe("ab");
});
});

View File

@ -0,0 +1,10 @@
"use strict";
/** @type {import("../../../../").Configuration} */
module.exports = {
output: {
environment: {
destructuring: false
}
}
};