Skip to content

Commit 9f86c19

Browse files
test(javascript): fail where webpack's output is bigger than swc's recorded one (#22389)
* test(javascript): fail where webpack's output is bigger than swc's recorded one Co-authored-by: aryanraj45 <[email protected]> * test(javascript): list what swc does that webpack does not yet, by test Group the 422 swc tests whose output is bigger than swc's recorded one by the transform swc applies, and read swc's camelCase `topLevel` mangle key. Co-authored-by: aryanraj45 <[email protected]> * test(javascript): key swc tests by a `/`-separated name on every platform Co-authored-by: aryanraj45 <[email protected]> * test(javascript): size terser's cases against what swc's port of them records Co-authored-by: aryanraj45 <[email protected]> * test(javascript): list the swc-port cases where swc's output is smaller Co-authored-by: aryanraj45 <[email protected]> --------- Co-authored-by: aryanraj45 <[email protected]>
1 parent 0ff635c commit 9f86c19

4 files changed

Lines changed: 1045 additions & 32 deletions

File tree

‎TESTING_DOCS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Directories come first, in alphabetical order, then the individual files worth t
5959

6060
#### `swc/`
6161

62-
- **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 each fixture's recorded `output.js` is what `JS_MINIFY_REPORT=<file>` compares sizes against.
62+
- **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

6565
#### `terser/`

‎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. `JS_MINIFY_REPORT=<file>` lists where swc's recorded output is smaller — leads for printing less, never a failure. 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. `JS_MINIFY_REPORT=<file>` writes where swc's recorded output is smaller.
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.

0 commit comments

Comments
 (0)