Skip to content

Commit d9f267f

Browse files
revert: hold back output.environment.topLevelAwait for the patch release
The pending release is a patch, so #21867's feature half is disabled: the new `output.environment.topLevelAwait` option and the startup `await` of an async ESM entry that it gates. The option is what made the changeset minor, and the await cannot be emitted safely without it. The lib code is commented out in place with a marker so it can be reapplied after the release; the schema entry is removed instead, JSON carrying no comments, and the generated files are restored to what the generator emitted for that schema. `ModuleLibraryPlugin` still awaits a module library's entry, as it did before #21867, and the five test262 top-level-await rejection cases go back to `knownBugs`. The rest of #21867 — the `import()` options checks, the circular-reexport severity and the namespace-import assignment error — is unchanged.
1 parent fa214ac commit d9f267f

32 files changed

Lines changed: 116 additions & 275 deletions

File tree

‎.changeset/010-esm-correctness.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"webpack": minor
2+
"webpack": patch
33
---
44

5-
Add `output.environment.topLevelAwait`, await async ESM entries, and fix `import()` options, circular reexports and namespace writes.
5+
Fix `import()` options, circular reexport severity and namespace import assignment.

‎declarations/WebpackOptions.d.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,11 +3226,6 @@ export interface Environment {
32263226
* The environment supports template literals.
32273227
*/
32283228
templateLiteral?: boolean;
3229-
/**
3230-
* The environment supports top-level await ('await x' at the top level of a module).
3231-
* @since 5.111.0
3232-
*/
3233-
topLevelAwait?: boolean;
32343229
}
32353230
/**
32363231
* A custom resource-hint `<link>` for `output.html.resourceHints`. Exactly one of `href` / `chunk` / `entry` names the target.

‎lib/RuntimeTemplate.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,10 @@ class RuntimeTemplate {
569569
return this.outputOptions.environment.generator;
570570
}
571571

572-
supportsTopLevelAwait() {
573-
return this.outputOptions.environment.topLevelAwait;
574-
}
572+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
573+
// supportsTopLevelAwait() {
574+
// return this.outputOptions.environment.topLevelAwait;
575+
// }
575576

576577
supportsOptionalChaining() {
577578
return this.outputOptions.environment.optionalChaining;

‎lib/config/browserslistTargetHandler.js‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -428,25 +428,26 @@ const resolve = (browsers) => {
428428
// kaios: Not supported
429429
node: [16, 9]
430430
}),
431-
topLevelAwait: rawChecker({
432-
chrome: 89,
433-
and_chr: 89,
434-
edge: 89,
435-
firefox: 89,
436-
and_ff: 89,
437-
// ie: Not supported,
438-
opera: 75,
439-
op_mob: 63,
440-
safari: 15,
441-
ios_saf: 15,
442-
samsung: 15,
443-
android: 89,
444-
// and_qq: Not supported
445-
// baidu: Not supported
446-
// and_uc: Not supported
447-
// kaios: Not supported
448-
node: [14, 8]
449-
}),
431+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
432+
// topLevelAwait: rawChecker({
433+
// chrome: 89,
434+
// and_chr: 89,
435+
// edge: 89,
436+
// firefox: 89,
437+
// and_ff: 89,
438+
// // ie: Not supported,
439+
// opera: 75,
440+
// op_mob: 63,
441+
// safari: 15,
442+
// ios_saf: 15,
443+
// samsung: 15,
444+
// android: 89,
445+
// // and_qq: Not supported
446+
// // baidu: Not supported
447+
// // and_uc: Not supported
448+
// // kaios: Not supported
449+
// node: [14, 8]
450+
// }),
450451
spread: rawChecker({
451452
chrome: 60,
452453
and_chr: 60,

‎lib/config/defaults.js‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,12 +1747,13 @@ const applyOutputDefaults = (
17471747
"generator",
17481748
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.generator))
17491749
);
1750-
F(
1751-
environment,
1752-
"topLevelAwait",
1753-
() =>
1754-
tp && optimistic(/** @type {boolean | undefined} */ (tp.topLevelAwait))
1755-
);
1750+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
1751+
// F(
1752+
// environment,
1753+
// "topLevelAwait",
1754+
// () =>
1755+
// tp && optimistic(/** @type {boolean | undefined} */ (tp.topLevelAwait))
1756+
// );
17561757
F(
17571758
environment,
17581759
"forOf",

‎lib/config/target.js‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ const getDefaultTarget = (context) => {
8282
* @property {boolean | null} templateLiteral template literal is available
8383
* @property {boolean | null} asyncFunction async functions and await are available
8484
* @property {boolean | null} generator generator functions and yield are available
85-
* @property {boolean | null} topLevelAwait top-level await is available
8685
* @property {(boolean | null)=} deferImport deferred evaluation (`import defer`, `import.defer()`) is available (optional; absent means "assume unavailable")
8786
* @property {(boolean | null)=} sourceImport source phase imports (`import source`, `import.source()`) are available (optional; absent means "assume unavailable")
8887
*/
@@ -270,8 +269,9 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
270269
arrowFunction: v(6),
271270
asyncFunction: v(7, 6),
272271
generator: v(4),
272+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
273273
// v14.8.0
274-
topLevelAwait: v(14, 8),
274+
// topLevelAwait: v(14, 8),
275275
forOf: v(5),
276276
destructuring: v(6),
277277
bigIntLiteral: v(10, 4),
@@ -332,7 +332,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
332332
templateLiteral: true,
333333
asyncFunction: true,
334334
generator: true,
335-
topLevelAwait: true,
335+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
336+
// topLevelAwait: true,
336337
// import defer - v2.8.0
337338
deferImport: v(2, 8),
338339
// import source - v2.6.0
@@ -384,7 +385,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
384385
arrowFunction: true,
385386
asyncFunction: true,
386387
generator: true,
387-
topLevelAwait: true,
388+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
389+
// topLevelAwait: true,
388390
forOf: true,
389391
destructuring: true,
390392
bigIntLiteral: true,
@@ -442,8 +444,9 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
442444
arrowFunction: v(1, 1),
443445
asyncFunction: v(1, 7),
444446
generator: v(1, 1),
447+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
445448
// 12.0.0 - Chromium 89
446-
topLevelAwait: v(12),
449+
// topLevelAwait: v(12),
447450
forOf: v(0, 36),
448451
destructuring: v(1, 1),
449452
bigIntLiteral: v(4),
@@ -493,8 +496,9 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
493496
arrowFunction: v(0, 15),
494497
asyncFunction: v(0, 21),
495498
generator: v(0, 15),
499+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
496500
// 0.52.0 - Chromium 89
497-
topLevelAwait: v(0, 52),
501+
// topLevelAwait: v(0, 52),
498502
forOf: v(0, 13),
499503
destructuring: v(0, 15),
500504
bigIntLiteral: v(0, 32),
@@ -524,7 +528,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
524528
destructuring: v >= 2015,
525529
module: v >= 2015,
526530
asyncFunction: v >= 2017,
527-
topLevelAwait: v >= 2022,
531+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
532+
// topLevelAwait: v >= 2022,
528533
generator: v >= 2015,
529534
globalThis: v >= 2020,
530535
symbol: v >= 2015,

‎lib/javascript/JavascriptModulesPlugin.js‎

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,28 +1680,29 @@ class JavascriptModulesPlugin {
16801680
continue;
16811681
}
16821682
}
1683-
const entryOptions = chunk.getEntryOptions();
1684-
const library =
1685-
entryOptions && entryOptions.library !== undefined
1686-
? entryOptions.library
1687-
: runtimeTemplate.outputOptions.library;
1688-
// A module library awaits the entry itself, in `ModuleLibraryPlugin`.
1689-
const awaitedByLibrary =
1690-
library !== undefined && library.type === "module";
1691-
// `await` is only legal at the top level of an ESM chunk, never in
1692-
// the startup function rendered below, and only where the target
1693-
// can parse it (`target: "node14"` reads ESM but not top-level await).
1694-
const canAwaitEntry =
1695-
runtimeTemplate.isModule() &&
1696-
runtimeTemplate.supportsTopLevelAwait() &&
1697-
!awaitedByLibrary &&
1698-
!runtimeRequirements.has(RuntimeGlobals.startup) &&
1699-
!(
1700-
runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore) &&
1701-
runtimeRequirements.has(RuntimeGlobals.startupOnlyAfter)
1702-
);
1703-
/** @type {string[]} */
1704-
const awaitedEntries = [];
1683+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`.
1684+
// const entryOptions = chunk.getEntryOptions();
1685+
// const library =
1686+
// entryOptions && entryOptions.library !== undefined
1687+
// ? entryOptions.library
1688+
// : runtimeTemplate.outputOptions.library;
1689+
// // A module library awaits the entry itself, in `ModuleLibraryPlugin`.
1690+
// const awaitedByLibrary =
1691+
// library !== undefined && library.type === "module";
1692+
// // `await` is only legal at the top level of an ESM chunk, never in
1693+
// // the startup function rendered below, and only where the target
1694+
// // can parse it (`target: "node14"` reads ESM but not top-level await).
1695+
// const canAwaitEntry =
1696+
// runtimeTemplate.isModule() &&
1697+
// runtimeTemplate.supportsTopLevelAwait() &&
1698+
// !awaitedByLibrary &&
1699+
// !runtimeRequirements.has(RuntimeGlobals.startup) &&
1700+
// !(
1701+
// runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore) &&
1702+
// runtimeRequirements.has(RuntimeGlobals.startupOnlyAfter)
1703+
// );
1704+
// /** @type {string[]} */
1705+
// const awaitedEntries = [];
17051706
let i = jsEntries.length;
17061707
for (const [entryModule, entrypoint] of jsEntries) {
17071708
const chunks =
@@ -1828,19 +1829,25 @@ class JavascriptModulesPlugin {
18281829
)})`
18291830
);
18301831
} else if (useRequire) {
1831-
// An async entry nobody awaits settles after the bundle did,
1832-
// which orphans its rejection.
1833-
const awaitEntry =
1834-
canAwaitEntry && moduleGraph.isAsync(entryModule);
1835-
const target =
1836-
i === 0
1837-
? RuntimeGlobals.exports
1838-
: `${RuntimeGlobals.exports}_${i}`;
1839-
const needsDecl = i === 0 || awaitEntry;
1832+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`:
1833+
// an async entry nobody awaits settles after the bundle did, which
1834+
// orphans its rejection.
1835+
// const awaitEntry =
1836+
// canAwaitEntry && moduleGraph.isAsync(entryModule);
1837+
// const target =
1838+
// i === 0
1839+
// ? RuntimeGlobals.exports
1840+
// : `${RuntimeGlobals.exports}_${i}`;
1841+
// const needsDecl = i === 0 || awaitEntry;
1842+
// buf2.push(
1843+
// `${needsDecl ? `${exportsDecl} ${target} = ` : ""}${RuntimeGlobals.require}(${moduleIdExpr});`
1844+
// );
1845+
// if (awaitEntry) awaitedEntries.push(target);
18401846
buf2.push(
1841-
`${needsDecl ? `${exportsDecl} ${target} = ` : ""}${RuntimeGlobals.require}(${moduleIdExpr});`
1847+
`${i === 0 ? `${exportsDecl} ${RuntimeGlobals.exports} = ` : ""}${
1848+
RuntimeGlobals.require
1849+
}(${moduleIdExpr});`
18421850
);
1843-
if (awaitEntry) awaitedEntries.push(target);
18441851
} else {
18451852
if (i === 0) {
18461853
buf2.push(`${exportsDecl} ${RuntimeGlobals.exports} = {};`);
@@ -1883,14 +1890,15 @@ class JavascriptModulesPlugin {
18831890
`${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});`
18841891
);
18851892
}
1886-
// Several need one `Promise.all`, so an entry rejecting first still
1893+
// Held back for the patch release, reapply with `output.environment.topLevelAwait`:
1894+
// several need one `Promise.all`, so an entry rejecting first still
18871895
// leaves the others observed. A single one has nothing to orphan.
1888-
if (awaitedEntries.length === 1) {
1889-
buf2.push(`${awaitedEntries[0]} = await ${awaitedEntries[0]};`);
1890-
} else if (awaitedEntries.length > 1) {
1891-
const list = awaitedEntries.join(", ");
1892-
buf2.push(`[${list}] = await Promise.all([${list}]);`);
1893-
}
1896+
// if (awaitedEntries.length === 1) {
1897+
// buf2.push(`${awaitedEntries[0]} = await ${awaitedEntries[0]};`);
1898+
// } else if (awaitedEntries.length > 1) {
1899+
// const list = awaitedEntries.join(", ");
1900+
// buf2.push(`[${list}] = await Promise.all([${list}]);`);
1901+
// }
18941902
if (
18951903
runtimeRequirements.has(RuntimeGlobals.startup) ||
18961904
(runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore) &&

‎schemas/WebpackOptions.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/WebpackOptions.json‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,11 +1239,6 @@
12391239
"templateLiteral": {
12401240
"description": "The environment supports template literals.",
12411241
"type": "boolean"
1242-
},
1243-
"topLevelAwait": {
1244-
"description": "The environment supports top-level await ('await x' at the top level of a module).",
1245-
"type": "boolean",
1246-
"added": "5.111.0"
12471242
}
12481243
}
12491244
},

‎test/Defaults.unittest.js‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ describe("snapshots", () => {
205205
"spread": true,
206206
"symbol": true,
207207
"templateLiteral": true,
208-
"topLevelAwait": true,
209208
},
210209
"target": "web",
211210
},
@@ -755,7 +754,6 @@ describe("snapshots", () => {
755754
"spread": true,
756755
"symbol": true,
757756
"templateLiteral": true,
758-
"topLevelAwait": true,
759757
},
760758
"filename": "[name].js",
761759
"globalObject": "self",
@@ -4007,9 +4005,6 @@ describe("snapshots", () => {
40074005
+ "nodePrefixForCoreModules": false,
40084006
+ "optionalChaining": false,
40094007
@@ ... @@
4010-
- "topLevelAwait": true,
4011-
+ "topLevelAwait": false,
4012-
@@ ... @@
40134008
- "target": "web",
40144009
+ "target": undefined,
40154010
@@ ... @@
@@ -4057,9 +4052,6 @@ describe("snapshots", () => {
40574052
+ "nodePrefixForCoreModules": false,
40584053
+ "optionalChaining": false,
40594054
@@ ... @@
4060-
- "topLevelAwait": true,
4061-
+ "topLevelAwait": false,
4062-
@@ ... @@
40634055
- "globalObject": "self",
40644056
+ "globalObject": "typeof self !== \\"undefined\\" ? self : global",
40654057
@@ ... @@
@@ -4197,9 +4189,6 @@ describe("snapshots", () => {
41974189
+ "nodePrefixForCoreModules": false,
41984190
+ "optionalChaining": false,
41994191
@@ ... @@
4200-
- "topLevelAwait": true,
4201-
+ "topLevelAwait": false,
4202-
@@ ... @@
42034192
- "target": "web",
42044193
+ "target": undefined,
42054194
@@ ... @@
@@ -4247,9 +4236,6 @@ describe("snapshots", () => {
42474236
+ "nodePrefixForCoreModules": false,
42484237
+ "optionalChaining": false,
42494238
@@ ... @@
4250-
- "topLevelAwait": true,
4251-
+ "topLevelAwait": false,
4252-
@@ ... @@
42534239
- "globalObject": "self",
42544240
+ "globalObject": "typeof self !== \\"undefined\\" ? self : global",
42554241
@@ ... @@
@@ -4897,11 +4883,9 @@ describe("snapshots", () => {
48974883
- "spread": true,
48984884
- "symbol": true,
48994885
- "templateLiteral": true,
4900-
- "topLevelAwait": true,
49014886
+ "spread": false,
49024887
+ "symbol": false,
49034888
+ "templateLiteral": false,
4904-
+ "topLevelAwait": false,
49054889
@@ ... @@
49064890
- "chunkLoadingGlobal": "webpackChunkwebpack",
49074891
+ "chunkLoadingGlobal": "webpackChunkbrowserslist_test",
@@ -4955,11 +4939,9 @@ describe("snapshots", () => {
49554939
- "spread": true,
49564940
- "symbol": true,
49574941
- "templateLiteral": true,
4958-
- "topLevelAwait": true,
49594942
+ "spread": false,
49604943
+ "symbol": false,
49614944
+ "templateLiteral": false,
4962-
+ "topLevelAwait": false,
49634945
@@ ... @@
49644946
- "hotUpdateGlobal": "webpackHotUpdatewebpack",
49654947
+ "hotUpdateGlobal": "webpackHotUpdatebrowserslist_test",
@@ -5519,9 +5501,6 @@ describe("snapshots", () => {
55195501
+ "nodeBuiltinModuleGetter": false,
55205502
+ "nodePrefixForCoreModules": false,
55215503
@@ ... @@
5522-
- "topLevelAwait": true,
5523-
+ "topLevelAwait": false,
5524-
@@ ... @@
55255504
- "target": "web",
55265505
+ "target": "node",
55275506
@@ ... @@
@@ -5581,9 +5560,6 @@ describe("snapshots", () => {
55815560
+ "nodeBuiltinModuleGetter": false,
55825561
+ "nodePrefixForCoreModules": false,
55835562
@@ ... @@
5584-
- "topLevelAwait": true,
5585-
+ "topLevelAwait": false,
5586-
@@ ... @@
55875563
- "filename": "[name].js",
55885564
- "globalObject": "self",
55895565
+ "filename": "[name].mjs",

0 commit comments

Comments
 (0)