Visitar URL original
revert: hold back output.environment.topLevelAwait for the patch rele… · webpack/webpack@1e2941b · GitHub
Skip to content

Commit 1e2941b

Browse files
revert: hold back output.environment.topLevelAwait for the patch release (#21881)
* 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. * chore(changeset): keep the description within 80 characters * chore: drop the commented-out held-back code for short notes Commented-out blocks broke the repository's limit of two short lines per comment in lib/ and test/. Keep one note where the absence needs explaining — the missing environment default, and the entry that is no longer awaited — and leave the implementation to the commit history: reverting this pull request restores it.
1 parent e5b1995 commit 1e2941b

32 files changed

Lines changed: 30 additions & 280 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 writes.

‎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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,6 @@ class RuntimeTemplate {
569569
return this.outputOptions.environment.generator;
570570
}
571571

572-
supportsTopLevelAwait() {
573-
return this.outputOptions.environment.topLevelAwait;
574-
}
575-
576572
supportsOptionalChaining() {
577573
return this.outputOptions.environment.optionalChaining;
578574
}

‎lib/config/browserslistTargetHandler.js‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -428,25 +428,6 @@ 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-
}),
450431
spread: rawChecker({
451432
chrome: 60,
452433
and_chr: 60,

‎lib/config/defaults.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,12 +1747,8 @@ 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+
// No `topLevelAwait` here: the option is held back from the patch release,
1751+
// so nothing derives it from `tp` yet. Reapply by reverting #21881.
17561752
F(
17571753
environment,
17581754
"forOf",

‎lib/config/target.js‎

Lines changed: 0 additions & 10 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,6 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
270269
arrowFunction: v(6),
271270
asyncFunction: v(7, 6),
272271
generator: v(4),
273-
// v14.8.0
274-
topLevelAwait: v(14, 8),
275272
forOf: v(5),
276273
destructuring: v(6),
277274
bigIntLiteral: v(10, 4),
@@ -332,7 +329,6 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
332329
templateLiteral: true,
333330
asyncFunction: true,
334331
generator: true,
335-
topLevelAwait: true,
336332
// import defer - v2.8.0
337333
deferImport: v(2, 8),
338334
// import source - v2.6.0
@@ -384,7 +380,6 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
384380
arrowFunction: true,
385381
asyncFunction: true,
386382
generator: true,
387-
topLevelAwait: true,
388383
forOf: true,
389384
destructuring: true,
390385
bigIntLiteral: true,
@@ -442,8 +437,6 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
442437
arrowFunction: v(1, 1),
443438
asyncFunction: v(1, 7),
444439
generator: v(1, 1),
445-
// 12.0.0 - Chromium 89
446-
topLevelAwait: v(12),
447440
forOf: v(0, 36),
448441
destructuring: v(1, 1),
449442
bigIntLiteral: v(4),
@@ -493,8 +486,6 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
493486
arrowFunction: v(0, 15),
494487
asyncFunction: v(0, 21),
495488
generator: v(0, 15),
496-
// 0.52.0 - Chromium 89
497-
topLevelAwait: v(0, 52),
498489
forOf: v(0, 13),
499490
destructuring: v(0, 15),
500491
bigIntLiteral: v(0, 32),
@@ -524,7 +515,6 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
524515
destructuring: v >= 2015,
525516
module: v >= 2015,
526517
asyncFunction: v >= 2017,
527-
topLevelAwait: v >= 2022,
528518
generator: v >= 2015,
529519
globalThis: v >= 2020,
530520
symbol: v >= 2015,

‎lib/javascript/JavascriptModulesPlugin.js‎

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,28 +1680,8 @@ 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+
// An async entry is not awaited here: that needs top-level `await`,
1684+
// gated on an option held back from the patch release (revert #21881).
17051685
let i = jsEntries.length;
17061686
for (const [entryModule, entrypoint] of jsEntries) {
17071687
const chunks =
@@ -1828,19 +1808,11 @@ class JavascriptModulesPlugin {
18281808
)})`
18291809
);
18301810
} 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;
18401811
buf2.push(
1841-
`${needsDecl ? `${exportsDecl} ${target} = ` : ""}${RuntimeGlobals.require}(${moduleIdExpr});`
1812+
`${i === 0 ? `${exportsDecl} ${RuntimeGlobals.exports} = ` : ""}${
1813+
RuntimeGlobals.require
1814+
}(${moduleIdExpr});`
18421815
);
1843-
if (awaitEntry) awaitedEntries.push(target);
18441816
} else {
18451817
if (i === 0) {
18461818
buf2.push(`${exportsDecl} ${RuntimeGlobals.exports} = {};`);
@@ -1883,14 +1855,6 @@ class JavascriptModulesPlugin {
18831855
`${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});`
18841856
);
18851857
}
1886-
// Several need one `Promise.all`, so an entry rejecting first still
1887-
// 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-
}
18941858
if (
18951859
runtimeRequirements.has(RuntimeGlobals.startup) ||
18961860
(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)