Skip to content

Commit d37872d

Browse files
feat(javascript): run a statement-level IIFE's body in place (#22393)
* feat(javascript): run a statement-level IIFE's body in place Add an `improve` phase, switchable like `correct`, which after compressing writes a statement calling a function in place, with nothing passed, as its body: spliced into the list, or a block when it declares something scoped. The corpora suite accepts a difference only where switching both phases off gives terser's bytes back, and fails where `improve` writes more. * feat(javascript): unwrap calls in place inside a statement's sequence terser joins adjacent statements into one sequence first, so split it at each call run in place. A body kept in a block is written as one block. * perf(javascript): skip the in-place call walk when compression met none The improve phase now notes during compression whether any statement calls a function in place, and walks the finished tree read-only only then, instead of rebuilding every statement list on each compress. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(javascript): keep @__NOINLINE__ and yield/await IIFEs as calls The improve phase moved a function's body into its caller even when the call was marked @__NOINLINE__, which terser honors, or when the body named yield or await, which a generator or async caller reads as its own. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * test(javascript): hold the JS minifier to oxc-minify and oxc's own tests Adds oxc's minifier tests as a corpus, read from the inputs its Rust tests pass (TypeScript left out), held to terser's bytes like the others. Under the default minimizer's options every source but test262's is also minified by oxc-minify, in a child process since an oxc panic aborts it: webpack's output may be no bigger than oxc's unless OXC_SMALLER says why, and an oxc output that misprints is no lead. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * docs(javascript): say test262 is left out of the oxc comparison Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 195edfd commit d37872d

20 files changed

Lines changed: 4093 additions & 361 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Run a statement-level IIFE's body in place in webpack's JavaScript minifier.

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ jobs:
306306
# what its input prints, an output printing it too. It uploads, as
307307
# the one suite reaching every compressor phase the printer owns.
308308
- language: minify-corpora
309-
submodules: test/external/terser test/external/test262-cases test/external/swc
309+
submodules: test/external/terser test/external/test262-cases test/external/swc test/external/oxc
310310
script: cover:minify-corpora
311311
flags: minify-corpora
312312
# Runs terser's fuzzer against webpack's minifier: fixed seeds, so the

‎.gitmodules‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
[submodule "test/external/swc"]
1717
path = test/external/swc
1818
url = https://github.com/swc-project/swc
19+
[submodule "test/external/oxc"]
20+
path = test/external/oxc
21+
url = https://github.com/oxc-project/oxc

‎.prettierignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test/external/test262-cases/**/*.*
2525
test/external/wpt/**
2626
test/external/terser/**
2727
test/external/swc/**
28+
test/external/oxc/**
2829

2930
# Ignore some folders
3031
benchmark/

‎TESTING_DOCS.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Directories come first, in alphabetical order, then the individual files worth t
3535

3636
### `external/`
3737

38-
- **Purpose**: Every git submodule webpack checks out for testing — today the four spec corpora below and terser's and swc's own tests. Nothing here is webpack's to edit: each directory belongs to its upstream project, and this repository only pins a commit.
38+
- **Purpose**: Every git submodule webpack checks out for testing — today the four spec corpora below and terser's, swc's and oxc's own tests. Nothing here is webpack's to edit: each directory belongs to its upstream project, and this repository only pins a commit.
3939

4040
#### `test262-cases/`
4141

@@ -62,9 +62,14 @@ Directories come first, in alphabetical order, then the individual files worth t
6262
- **Purpose**: swc's repository, read only under `crates/swc_ecma_minifier/tests`: its fixtures with their configs, the tests `exec.rs` and `mangle.rs` write inline, and the libraries it measures itself on. Each is held to terser's bytes like the terser corpora; a test with an `expected.stdout`, and every `exec.rs` test, also has its outputs run, and webpack's output may be no bigger than each fixture's recorded `output.js`, nor than what swc's port of a terser case records when its `passing.txt` lists it, unless `SWC_SMALLER` lists why.
6363
- **Usage**: Git submodule — initialize with `git submodule update --init --depth 1 test/external/swc`. Test runner: `test/specCases/minify-corpora.spectest.js` (`yarn test:minify-corpora`).
6464

65+
#### `oxc/`
66+
67+
- **Purpose**: oxc's repository, pinned to the commit that released webpack's `oxc-minify` devDependency and read only under `crates/oxc_minifier/tests`: the source each `test…(` helper call in its Rust tests passes first, but TypeScript. Each is held to terser's bytes like the other corpora, and under the default minimizer's options every source of every corpus but test262 is also minified by `oxc-minify`: webpack's output may be no bigger than oxc's unless `OXC_SMALLER` lists why, and an oxc output that misprints is no lead.
68+
- **Usage**: Git submodule — initialize with `git submodule update --init --depth 1 test/external/oxc`. Test runner: `test/specCases/minify-corpora.spectest.js` (`yarn test:minify-corpora`), which also fails when the pin and the installed `oxc-minify` disagree.
69+
6570
#### `terser/`
6671

67-
- **Purpose**: terser's own repository, pinned to webpack's `terser` devDependency. Its `test/compress` cases and `test/input` files are two of the six corpora `lib/javascript/syntax-printer.js` is held to (test262 and swc's fixtures, `exec.rs` and `mangle.rs` tests are the other four): each source is minified by terser as published and by webpack's printer under several option sets, and the outputs, or the errors, must be byte-for-byte the same, but for what webpack's `correct` phase fixes. A case stating its `expect_stdout` also has each output run in terser's sandbox, which must print it — or, for `expect_stdout: true`, do whatever its input does, a throw or silence included.
72+
- **Purpose**: terser's own repository, pinned to webpack's `terser` devDependency. Its `test/compress` cases and `test/input` files are two of the seven corpora `lib/javascript/syntax-printer.js` is held to (test262, swc's fixtures, `exec.rs` and `mangle.rs` tests, and oxc's tests are the other five): each source is minified by terser as published and by webpack's printer under several option sets, and the outputs, or the errors, must be byte-for-byte the same, but for what webpack's `correct` phase fixes. A case stating its `expect_stdout` also has each output run in terser's sandbox, which must print it — or, for `expect_stdout: true`, do whatever its input does, a throw or silence included.
6873
- **Usage**: Git submodule — initialize with `git submodule update --init --depth 1 test/external/terser`. Test runner: `test/specCases/minify-corpora.spectest.js` (`yarn test:minify-corpora`), which also fails when the pin and the installed `terser` disagree, so bumping the dependency means moving the pin with it. A new corpus is one entry in its `CORPORA` list.
6974

7075
### `fixtures/`
@@ -271,6 +276,7 @@ Git submodules, all under `test/external/`, checked out on demand: `yarn setup`
271276
- `test/external/css-parsing-tests` — [CourtBouillon/css-parsing-tests](https://github.com/CourtBouillon/css-parsing-tests); fetched by `parser (css)`
272277
- `test/external/terser` — [terser/terser](https://github.com/terser/terser), pinned to the installed `terser`'s version; fetched by `parser (minify-corpora)`
273278
- `test/external/swc` — [swc-project/swc](https://github.com/swc-project/swc), read only under `crates/swc_ecma_minifier/tests`; fetched by `parser (minify-corpora)`
279+
- `test/external/oxc` — [oxc-project/oxc](https://github.com/oxc-project/oxc), pinned to the installed `oxc-minify`'s release and read only under `crates/oxc_minifier/tests`; fetched by `parser (minify-corpora)`
274280

275281
```sh
276282
git submodule update --init --recursive --depth 1 # check out the commits the repo pins

‎cspell.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@
618618
"test/external/html5lib-tests/**",
619619
"test/external/terser/**",
620620
"test/external/swc/**",
621+
"test/external/oxc/**",
621622
"**/*.svg",
622623
"*.log",
623624
"**/*.wasm",

‎docs/architecture.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Every schema is derived from the module declaring its options by `generate-schem
8383
- `templates/` — suite drivers (`TestCases.js`, `ConfigTestCases.js`, `HotTestCases.js`, `WatchTestCases.js`); the top-level `*.test.js` / `*.basictest.js` / `*.longtest.js` are thin shims over them. Each exports `describeCases(config)` and resolves case directories against `test/`, never its own. The shims' option sets live together in `templates/variants.js` (re-exported as `variants`) so suite differences read side by side; there's one shim per entry because jest parallelizes per file, not per describe.
8484
- `harness/` — what runs the suites: jest lifecycle (`globalSetup.js`, `globalTeardown.js`, `setupTestFramework.js`), the `patch-node-env.js` environment, the crash reporter, the case `runner/`, the `snapshot/` resolver, and `runtimes/` (preload/setup files for Bun and Deno). Reusable assertions and fixtures go in `helpers/`.
8585
- `RoundTripConfigCases` re-bundles the output of `configCases` that have a `roundTrip.js`.
86-
- `external/` — what webpack doesn't maintain: every git submodule (today the four spec corpora below and terser's and swc's own tests) — upstream's to change, ours only to pin. `external/wpt/` (web-platform-tests), checked out one commit deep by `parser (html)` and `syntax-equivalence`, holds the HTML tree-construction corpus since html5lib-tests dropped it.
86+
- `external/` — what webpack doesn't maintain: every git submodule (today the four spec corpora below and terser's, swc's and oxc's own tests) — upstream's to change, ours only to pin. `external/wpt/` (web-platform-tests), checked out one commit deep by `parser (html)` and `syntax-equivalence`, holds the HTML tree-construction corpus since html5lib-tests dropped it.
8787
- `fixtures/acorn-corpus.json` — acorn's test suite, vendored rather than pinned as a submodule ([details](../TESTING_DOCS.md#external-test-corpora)).
8888

8989
**Git submodules and other external corpora** — what each is, which CI job fetches it and how to update the pins: [TESTING_DOCS.md](../TESTING_DOCS.md#external-test-corpora).

‎docs/syntax.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ Read this before touching the CSS, HTML or JavaScript parser, printer or minifie
3838

3939
- `syntax.js` reaches `parser` and `printer` through getters: parsing never loads the printer, and the printer loads the parser only for its `parse` phase.
4040
- `syntax-parser.js` — tokenizer, acorn-derived core and every production in one file (any parse reaches the productions, and the coming struct-of-arrays rewrite moves node creation through them). `regexp.js` (pattern validator) is the one on-demand piece, reached only for a pattern the host engine rejected — never `require` it from a build path.
41-
- `syntax-printer.js` — webpack's JavaScript minifier, terser's design ported to write byte for byte what terser writes; `jsMinify.js` (the `minify` the default minimizer dispatches JS to) goes through it when given `printer: true` — which `optimization.minimizeOptions.javascript` defaults to under `experiments.futureDefaults` — and through terser as published otherwise — the user's own, as `terser-webpack-plugin` brings it, since webpack lists terser only as a devDependency; the printer itself never loads terser. `createModules` builds what terser's modules exported — the node classes from `nodeClasses()` (`createAst`), the parser (`createTerserParser`), the compressor and the output stream — and each entry of `PHASES` installs one part onto them: add phases there and nowhere else. `correct` wraps the methods with which terser writes a wrong program and changes only that output; `corrections.enabled` switches it off. The `parse` phase builds the tree from `syntax-parser.js` (`createTerserTree`), leaving to the ported parser a source terser reads unlike the spec; `syntax-printer-parse.unittest.js` holds that to terser's parse over acorn's corpus, `syntax-printer-terser-parser.unittest.js` the ported parser and `syntax-printer-estree.unittest.js` the ESTree conversion. `test/specCases/minify-corpora.spectest.js` holds the whole printer to terser's output, errors included, over each corpus in its `CORPORA` list (add a new one there) under the option sets in `OPTION_SETS`, and runs each output whose test states what its input prints (terser's `expect_stdout`, swc's `expected.stdout` and `exec.rs`) in terser's sandbox. A byte difference is accepted only where switching the `correct` phase off gives terser's bytes back; what it fixes is listed in `CORRECTED` (printing right with the phase, as terser without), and an output misprinting as terser's by an option's own contract in `INHERITED`, each with the reason — an entry that stops matching fails until retired. Each output is also sized against swc's recorded one, a fixture's `output.js` or, for one of terser's cases, what swc's port of it records (gzip decides, raw breaks a tie): one bigger fails unless `test/helpers/swcSmaller.js` lists it under what swc does that webpack does not yet, and a listed one no longer bigger fails until retired. `JS_MINIFY_REPORT=<file>` tallies where webpack's is worse, the same and better. terser's corpus submodule is pinned to the `terser` devDependency — bump both together, and regenerate `data.js`.
42-
- `yarn test:minify-corpora` — webpack's JS minifier vs the published one it replaces, byte for byte (errors included), over every JS corpus: terser's own `test/compress` and `test/input`, test262, and swc's minifier tests; where a test states what its input prints, the output is also run and must print it. Each output must also be no bigger than swc's recorded one unless `SWC_SMALLER` lists why; `JS_MINIFY_REPORT=<file>` tallies worse, the same and better.
41+
- `syntax-printer.js` — webpack's JavaScript minifier, terser's design ported to write byte for byte what terser writes; `jsMinify.js` (the `minify` the default minimizer dispatches JS to) goes through it when given `printer: true` — which `optimization.minimizeOptions.javascript` defaults to under `experiments.futureDefaults` — and through terser as published otherwise — the user's own, as `terser-webpack-plugin` brings it, since webpack lists terser only as a devDependency; the printer itself never loads terser. `createModules` builds what terser's modules exported — the node classes from `nodeClasses()` (`createAst`), the parser (`createTerserParser`), the compressor and the output stream — and each entry of `PHASES` installs one part onto them: add phases there and nowhere else. `correct` wraps the methods with which terser writes a wrong program and changes only that output; `corrections.enabled` switches it off. `improve` writes less where terser's longer program provably runs the same — after compressing, a statement calling a function in place with nothing passed runs its body there — and `improvements.enabled` switches it off. The `parse` phase builds the tree from `syntax-parser.js` (`createTerserTree`), leaving to the ported parser a source terser reads unlike the spec; `syntax-printer-parse.unittest.js` holds that to terser's parse over acorn's corpus, `syntax-printer-terser-parser.unittest.js` the ported parser and `syntax-printer-estree.unittest.js` the ESTree conversion. `test/specCases/minify-corpora.spectest.js` holds the whole printer to terser's output, errors included, over each corpus in its `CORPORA` list (add a new one there) under the option sets in `OPTION_SETS`, and runs each output whose test states what its input prints (terser's `expect_stdout`, swc's `expected.stdout` and `exec.rs`) in terser's sandbox. A byte difference is accepted only where switching the `correct` and `improve` phases off gives terser's bytes back, and fails where `improve` writes more than without it; what it fixes is listed in `CORRECTED` (printing right with the phase, as terser without), and an output misprinting as terser's by an option's own contract in `INHERITED`, each with the reason — an entry that stops matching fails until retired. Each output is also sized against swc's recorded one, a fixture's `output.js` or, for one of terser's cases, what swc's port of it records (gzip decides, raw breaks a tie): one bigger fails unless `test/helpers/swcSmaller.js` lists it under what swc does that webpack does not yet, and a listed one no longer bigger fails until retired. Under the default minimizer's options each source of every corpus but test262 is also minified by `oxc-minify`, held the same way to `test/helpers/oxcSmaller.js`; an oxc output that misprints is no lead. `JS_MINIFY_REPORT=<file>` tallies where webpack's is worse, the same and better. terser's corpus submodule is pinned to the `terser` devDependency — bump both together, and regenerate `data.js`.
42+
- `yarn test:minify-corpora` — webpack's JS minifier vs the published one it replaces, byte for byte (errors included), over every JS corpus: terser's own `test/compress` and `test/input`, test262, swc's minifier tests and oxc's; where a test states what its input prints, the output is also run and must print it. Each output must also be no bigger than swc's recorded one unless `SWC_SMALLER` lists why, and every output outside test262 no bigger than `oxc-minify`'s unless `OXC_SMALLER` does; `JS_MINIFY_REPORT=<file>` tallies worse, the same and better.

‎eslint.config.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default defineConfig([
7474
"test/external/wpt/**/*.*",
7575
"test/external/terser/**",
7676
"test/external/swc/**",
77+
"test/external/oxc/**",
7778

7879
// Ignore some folders
7980
"benchmark",

‎jest.config.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const config = {
2424
"<rootDir>/node_modules",
2525
"<rootDir>/test/external/wpt",
2626
"<rootDir>/test/external/swc",
27+
"<rootDir>/test/external/oxc",
2728
"<rootDir>/test/js",
2829
"<rootDir>/test/fixtures/temp-cache-fixture",
2930
"<rootDir>/test/fixtures/temp-",
@@ -37,6 +38,7 @@ const config = {
3738
"<rootDir>/.git",
3839
"<rootDir>/test/external/wpt",
3940
"<rootDir>/test/external/swc",
41+
"<rootDir>/test/external/oxc",
4042
"<rootDir>/node_modules/webpack/node_modules",
4143
"<rootDir>/test/js",
4244
"<rootDir>/test/fixtures/temp-cache-fixture",

0 commit comments

Comments
 (0)