You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e8b9ec1
Browse filesBrowse the repository at this point in the historyBrowse files
test(javascript): record where terser refuses or misreads what the printer reads
Reading a source with webpack's parser rather than terser's ported one leaves
757 differences over the comparison corpora, none of them webpack's. 704 are a
source the spec allows and terser refuses: an escape anywhere in an identifier
name, a trailing comma in an argument list, a regular expression after the ogham
space mark, `let` as a name outside strict mode, `yield` naming a function
inside a generator, `export * as default from`, a field named `get` before a
generator, and an escape no cooked template value can read.
The other 53 are bytes where terser reads or prints the program differently: a
`let` or `async` before a line break, which the semicolon inserted after it
leaves a name; a line continuation's own break written into the string it holds
nothing of; and a binary, octal or hex property key quoted as it is written,
naming the property `0b1` where it is `1`.
`REFUSED_BY_REFERENCE` lists the parse errors with what makes each source legal
and `REFERENCE_MISPRINTS` the cases by name. Both fail where the reference stops
differing, and an accepted output still runs against what its test prints.
Copy file name to clipboardExpand all lines: docs/syntax.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,5 +38,5 @@ Read this before touching the CSS, HTML or JavaScript parser, printer or minifie
38
38
39
39
-`syntax.js` reaches `parser` and `printer` through getters: parsing never loads the printer, and the printer loads the parser for its `parse` phase, which reads an asset with it — building the printer's tree as each statement finishes, rather than converting a tree. `parse.webpackParser` defaults to true and turns that off; terser's own parser reads what it reads its own way (`parse.expression`, `parse.strict`, TypeScript, a line opening an HTML comment) and whatever webpack's parser refuses.
40
40
-`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 for every asset; terser is a devDependency the tests compare against, and nothing in `lib/` loads it. `createModules` builds what terser's modules exported — the node classes from `nodeClasses()` (`createAst`), the parser (`createLenientParser`), 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`, leaving to the lenient parser a source read unlike the spec; `syntax-printer-terser-parser.unittest.js` holds the ported parser to terser's own 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`.
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 for every asset; terser is a devDependency the tests compare against, and nothing in `lib/` loads it. `createModules` builds what terser's modules exported — the node classes from `nodeClasses()` (`createAst`), the parser (`createLenientParser`), 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`, leaving to the lenient parser a source read unlike the spec; `syntax-printer-terser-parser.unittest.js` holds the ported parser to terser's own 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. Where the reference instead refuses a source the spec allows, the parse error it answers with is listed in `REFUSED_BY_REFERENCE` with what makes the source legal; where it reads or prints one differently, the case is listed in `REFERENCE_MISPRINTS` with what it gets wrong — a listed one webpack must still run correctly, and one the reference stops differing on 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
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.
0 commit comments