Repository navigation
Commit 394a05f
authored
fix: import() options, circular reexport severity, async ESM entry and namespace import assignment (#21867)
* test(test262): correct four recorded causes
The two jest cases are not a drain-timing problem: the abandoned rejection
reaches neither unhandledRejection nor uncaughtException while the test
body runs, so the runner cannot capture it at all.
The two deferred-namespace cases are not blocked on unknowable exports —
the call site has the module graph. Sealing the proxy target needs those
names emitted at each deferred import, which costs bytes.
* test(test262): assert the rejections two cases abandon on purpose
Both bundles pass every assertion; each drops a rejected promise by design,
which jest records against the running test. The rejection is not visible
through process events on the sandboxed process, but it is in jest's own
state, which the environment already exposes.
Assert the expected count and clear it the way rejectionHandled would, so a
change in what they abandon fails instead of passing quietly.
* test(test262): record what the two deferred-namespace cases really need
Extensibility is only the first assertion of exotic-object-behavior; it also
wants ownKeys to be the sorted exports plus @@toStringTag, so __esModule
would have to go. That is the namespace-object trade-off, not defer-local.
* test: unskip dynamic imports whose specifier names no module
`import()` stringifies its argument, so `import(import(...))` asks for
"[object Promise]" and `import(typeof x)` for "object". webpack builds and
runs both correctly and the promise rejects, which is what the spec requires
and what Node.js does unbundled — the only fallout is a rejection the test
abandons and jest attributes to it.
Assert those alongside the two already tracked, now by reason as well as
count, and drop the twelve files from knownBugs.
* fix: keep the options argument of a computed-request import()
`import(`./${name}.js`, options)` goes through the context-dependency path,
which replaced everything after the request with `)` and so dropped the
options expression. The spec evaluates it right after the request, and it can
have side effects, so keep its source in place as a second argument the
context module ignores.
Also run the test262 suite with `output.strictModuleErrorHandling`, which is
what a Cyclic Module Record's [[EvaluationError]] asks for, and drop the three
files the two changes fix.
* fix: parenthesize the preserved import() options argument
A comma expression spliced in bare splits into extra arguments the context
module ignores; wrapping it keeps the call shape the source had.
* fix: check the options of a computed-request import(), and keep a comma expression whole
The context-dependency path passed the options as a second argument the
context module ignores, which reads as if it took one and skipped the checks
the spec asks for. Wrap the call the way the static-request path already does
instead, with the request and the options as its two arguments so they are
evaluated in that order, and share the check between the two paths.
An options range excludes any parentheses the source had, so `import(req, (a,
b))` split into arguments of its own and bound the check's parameter to `a`.
That rejected valid code with a TypeError on the static path already.
* fix: let exportsPresence decide how a circular reexport is reported
The circular-reexport diagnostic was built off the export-presence path
entirely, so it could be neither escalated nor suppressed: setting
`reexportExportsPresence: "error"` still only warned, and setting it to
`false" still warned. The spec makes a cycle in ResolveExport a link error,
the same as the ambiguous star export next to it, which does honour the
option.
Keep the default as it is — a cycle warns, skipping the promotion to an error
that AUTO gives a strict harmony module — but let an explicit setting say
whether and how it is reported.
* fix: await an async entry in an ESM bundle
An entry using top-level await produces a promise the startup code kept for
itself: the bundle settled before the entry did, and a rejecting entry left
its rejection with no one to hand it to, so it surfaced as a process-level
unhandled rejection instead of failing the bundle.
Only `output.library.type: "module"` awaited it. Move that await into the
generic startup, where it covers plain `output.module` too, and drop the
library plugin's copy so it is still emitted once.
* test(test262): record why the two production-only skips are not bugs
Both fire only where the class or the export is unused, and development
observes the same as the spec either way.
* test(test262): run unscopables-ignored with the parsers off
It only needs a bare global reference left alone, which is what the eval
cases next to it already ask for.
* fix: report an assignment to a namespace import
`import * as ns from "./x"; ns = null;` silently succeeded and left every
later read of `ns` looking at the assigned value. A real ES module throws a
TypeError there, and webpack already keeps that throw for a named import by
bailing out of concatenation so the write still lands on the namespace's
getter-only property. A namespace import is the binding itself, and nothing
webpack can emit for it throws: the declaration has to stay a `var` because a
runtime-condition import must be function-scoped and HMR accept reassigns it.
Report it at build time instead, which is what Rollup and esbuild do.
* chore: fold the branch's changesets into one
* chore: format a CHANGELOG entry prettier rejects
The released entry for #20889 fails `fmt:check` on prettier 3.9.6, which
stops the lint chain before spellcheck on every pull request.
* fix: await every async entry, and keep options webpack cannot read
Two defects a review found.
The entry await was gated on the last entry and spliced into the startup
buffer, so an earlier async entry still settled after the bundle did, and the
`await` would have been a syntax error inside the synchronous startup function
that `RuntimeGlobals.startup` renders. Capture each async entry instead and
await them after the loop, only where the startup lands at the top level of an
ESM chunk.
`isStaticStringAttributes` returned true for a key that is not `with` or
`assert`, so `import(request, { unused: effect() })` dropped `effect()`. Only
those two keys can be read at build time; anything else keeps the argument.
* test: cover the import() options checks
The null, non-object `with` and non-string attribute branches had no test,
on either the static or the computed-request path.
* fix: observe every async entry together, and gate the cases on Node.js 14.8
Awaiting the entries one by one leaves the rest unobserved once one rejects,
so a second failing entry became an unhandled rejection. Await them in a
single `Promise.all`.
The two cases need top-level await, which the runner's `vm.SourceTextModule`
cannot parse before Node.js 14.8, and both fixtures now settle on a task so
they fail when startup returns too early.
* test: assert the TypeError, and check 'with' on a computed request
The option assertions matched only the message, so a change to a plain Error
would have passed, and only the static request exercised the 'with' check.
* perf: await a lone async entry without Promise.all
The code size report grew from 3 changed assets to 9 when the await became a
`Promise.all`, which every ESM bundle with one async entry pays for. A single
promise has nothing to orphan, so keep the short form for it.
* feat(config): add output.environment.topLevelAwait
Awaiting an async ESM entry emits top-level await, which a target can read
ESM without supporting: `target: "node14"` (added in v14.8) then produced a
bundle it cannot parse. Gate the await on a new environment flag, derived
from the node/deno/bun/electron/nwjs/esX presets and the browserslist data,
so such targets fall back to not awaiting.
Also classify the flag in the ecma-conformance helper, which needed the
walk to track function nesting to tell top-level await from nested await,
and drop `globalThis` from the namespace-assignment fixture so it runs on
Node 10.
* test: read electron 10 back as ES2021
Chromium 85 has no top-level await, so the new environment flag makes the
version ladder answer 2021. The case still shows `module: false` is ignored:
without that, only the ES5 rung would match.
* fix: keep awaiting an async entry a module library exports
The topLevelAwait gate also suppressed the await `ModuleLibraryPlugin` has
always emitted, so an async ESM library built for `target: "node14"` handed
its consumers unsettled exports instead of values. Restore that plugin to
what it was and let it own the await, gating only the startup await this
branch adds.
* test: drive the multi-entry await through Promise.all
The case had one async entry among two, so it took the single-await path and
nothing exercised the `Promise.all` the multiple-entry fix added. Make both
entries async and assert both settled.1 parent ae4b153 commit 394a05f
58 files changed
Lines changed: 771 additions & 153 deletions
File tree
- .changeset
- declarations
- lib
- config
- dependencies
- errors
- javascript
- util
- schemas
- test
- __snapshots__
- configCases
- ecmaVersion
- browserslist-config-env-extends
- browserslist-config-env
- browserslist-config-extends
- browserslist-config
- browserslist-env
- browserslist-extends
- browserslist-query-with-config-file
- browserslist-query
- browserslist
- errors
- assign-to-namespace-import
- circular-reexport-error
- circular-reexport-silenced
- module
- async-entry-await-multiple
- async-entry-await
- parsing/import-options-side-effects
- helpers
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
817 | 817 | | |
818 | 818 | | |
819 | 819 | | |
820 | | - | |
| 820 | + | |
821 | 821 | | |
822 | 822 | | |
823 | 823 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3226 | 3226 | | |
3227 | 3227 | | |
3228 | 3228 | | |
| 3229 | + | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
3229 | 3234 | | |
3230 | 3235 | | |
3231 | 3236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
566 | 570 | | |
567 | 571 | | |
568 | 572 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
431 | 450 | | |
432 | 451 | | |
433 | 452 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1747 | 1747 | | |
1748 | 1748 | | |
1749 | 1749 | | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
1750 | 1756 | | |
1751 | 1757 | | |
1752 | 1758 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
| 273 | + | |
| 274 | + | |
272 | 275 | | |
273 | 276 | | |
274 | 277 | | |
| |||
329 | 332 | | |
330 | 333 | | |
331 | 334 | | |
| 335 | + | |
332 | 336 | | |
333 | 337 | | |
334 | 338 | | |
| |||
380 | 384 | | |
381 | 385 | | |
382 | 386 | | |
| 387 | + | |
383 | 388 | | |
384 | 389 | | |
385 | 390 | | |
| |||
437 | 442 | | |
438 | 443 | | |
439 | 444 | | |
| 445 | + | |
| 446 | + | |
440 | 447 | | |
441 | 448 | | |
442 | 449 | | |
| |||
486 | 493 | | |
487 | 494 | | |
488 | 495 | | |
| 496 | + | |
| 497 | + | |
489 | 498 | | |
490 | 499 | | |
491 | 500 | | |
| |||
515 | 524 | | |
516 | 525 | | |
517 | 526 | | |
| 527 | + | |
518 | 528 | | |
519 | 529 | | |
520 | 530 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
30 | 28 | | |
31 | 29 | | |
32 | 30 | | |
| |||
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | | - | |
53 | | - | |
| 50 | + | |
54 | 51 | | |
55 | 52 | | |
56 | 53 | | |
57 | 54 | | |
58 | 55 | | |
59 | 56 | | |
60 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
61 | 74 | | |
62 | 75 | | |
63 | 76 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1072 | 1072 | | |
1073 | 1073 | | |
1074 | 1074 | | |
1075 | | - | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
1076 | 1079 | | |
1077 | 1080 | | |
1078 | 1081 | | |
| |||
1082 | 1085 | | |
1083 | 1086 | | |
1084 | 1087 | | |
1085 | | - | |
1086 | | - | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
1087 | 1101 | | |
1088 | | - | |
| 1102 | + | |
1089 | 1103 | | |
1090 | | - | |
| 1104 | + | |
1091 | 1105 | | |
1092 | 1106 | | |
1093 | 1107 | | |
| |||
1115 | 1129 | | |
1116 | 1130 | | |
1117 | 1131 | | |
1118 | | - | |
1119 | | - | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
1120 | 1140 | | |
1121 | | - | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
1122 | 1144 | | |
1123 | 1145 | | |
1124 | 1146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
393 | 394 | | |
394 | 395 | | |
395 | 396 | | |
396 | | - | |
397 | | - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
398 | 400 | | |
399 | 401 | | |
400 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
401 | 411 | | |
402 | 412 | | |
403 | 413 | | |
| |||
0 commit comments