Repository navigation
Commit f9524b3
authored
fix(javascript): fix minified code that threw, read the wrong binding or no longer parsed (#22473)
* test(test262): build production unminified as well
Since the minified modes replaced it, production only ran through a
minimizer, so a failure of webpack's own production optimizations was
listed in MINIFIED_FAILURES as the minimizer's. An unminified production
mode tells the two apart.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test(test262): accept a parse error only where one is reported or thrown
A negative parse test passed on any thrown value, so a bundle that ran
into the test's unreachable call passed too. It now needs webpack's parse
error or a SyntaxError from the engine. The top-level `return` cases are
built as CommonJS, so they are listed as a deliberate divergence.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep a switch whose case test reads a binding declared in its body
A case test is evaluated in the switch's block, so the rewrites to `if` and
to a block moved it out of the scope of a `let`, `const` or `class` its body
declares: `case (f = () => x, 1): let x = 2` became `if (1 == (f = () => x,
1)) { let x = 2 }`, where `x` is no longer declared. The correction leaves
such a switch as written, as oxc does.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): minify a function body that declares `arguments` with `let`
The minifier declares a function's own `arguments` as a parameter, so a
`let` or `const arguments` in the body read as a redeclaration and failed
the build, as terser's check does. Under the parameter scopes the correct
phase turns on, such a declaration shadows the function's own instead; a
parameter written `arguments` beside it the parser still refuses. 12
test262 cases leave the printer's list.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep a spread, a throwing accessor and a strict empty body the minifier dropped
An unused `[...it]` or a pure call's `...it` dropped to `it`, skipping the
iteration a generator observes. A read of `arguments.callee`, or of a
function's `caller` or `arguments`, and a write to one, dropped where strict
code throws. An empty function's `"use strict"` went, so its `caller` no
longer threw.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep a BigInt operation that throws the minifier dropped
An unused `1n + 1`, `1n / 0n`, `2n ** -1n`, `5n >>> 1n` or `Symbol() + 0n`
went, and with it the TypeError or RangeError it throws. The check reads only
a BigInt literal, a wrapped one or a `Symbol()` call, so an operation on
neither costs nothing more.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep a `for` head's `let` in the loop when dropping an unused name beside it
Dropping `n` from `for (let i = 0, n = f(); ...)` kept `f()` as a
statement, which moved `let i` before the loop: closures reading `i` shared
one binding, and two such loops redeclared `i`, a SyntaxError. The unused
name now stays in the head, carrying its initializer's effects, as oxc does.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep an async generator's `return undefined`, which awaits
`return undefined` or `return void 0` in an async generator awaits the
value, a tick a bare `return` does not take; the minifier wrote it as a
bare `return`, or dropped it, changing when the generator settles.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep an unused class whose heritage is no constructor
`class extends (() => {})` or `class extends 1` throws a TypeError as it is
defined; the minifier dropped such a class nobody read.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep an array element's position when dropping an unused update in it
`[--b, f(), g()][1]` with `b` read nowhere else lost its first element,
so the index read `g()` where it read `f()`; terser's fuzzer found it. The
dropped update now leaves a `0` in its place outside a sequence.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep a static member computed as `prototype` computed
`static ["prototype"]() {}` throws a TypeError as the class is defined;
the minifier wrote it as `static prototype() {}`, an early error that
stops the whole script from parsing, and dropped an unused class declaring
one, or extending a local async or generator function.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test(test262): list as terser's alone the cases the printer now runs right
The spreads, `arguments.callee`, function `caller`, BigInt, class
heritage and static `prototype` cases, the `for` and `switch` scopes and the
async generator's `return undefined` pass with webpack's printer, so each
moves from the groups both minifiers fail to terser's own.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): name a catch parameter after the function around it in a switch's discriminant
A switch's block scope opens before the function scopes of its
discriminant, so counting the scopes opened placed a catch parameter
there before its function in the mangler's walk: the parameter took the
name an outer variable it reads got next, or kept the name of the `var`
it redeclares while that `var`'s reads were renamed. Each catch parameter
is now named where the walk meets its own scope; terser's fuzzer found it.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* docs(changeset): fold the printer fixes into one entry
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): drop an empty strict function's directive where it is called in place
Nothing reads `caller` of a function called where it is written, so its
lone `"use strict"` goes as terser drops it, and the empty call with it, as
oxc writes. The corpora list oxc dropping a class extending a regular
expression, which throws as it is defined, and no longer list terser
refusing `let arguments`: the uncorrected printer refuses it too.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test: keep a spread class key out of the case terser writes alike
Spreading a non-iterable throws, which the printer now keeps.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(javascript): keep the conversions, reads and writes oxc keeps that terser assumes away
As oxc reads them, an operation converting a side that may be an object or
a symbol (`o + 1`, `x - 1`, `-x`, `${o}`), an object spreading what may hold
getters, a write to a key that converts or to a primitive's property, a
`let` read before its declaration, a getter on an object handed to
`Object.defineProperty`, a write to a `const` or a class expression's own
name, `this` before `super()`, a class extending itself, a name read in a
`with`, and a block's async or generator function read outside it all run
or throw. Each is kept where terser dropped it or moved it.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test(test262): list as terser's alone the conversions, spreads and TDZ reads the printer now keeps
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): reduce the conversions and spreads kept to what oxc keeps
Where oxc proves a conversion or a spread runs no code, drop it: a literal
converting with the builtins, a `Math` or `Number` constant, a function's
own `arguments` spread, a spread string, function or setter. Where it may
run code, keep only that part: a template's or concatenation's conversions
(`a${b}c` as `${b}`, `"a" + b` as `"" + b`) and an object's spreads. Also
keep a concatenation's conversion where only its truth is read, and merge
an async generator's returns wherever that adds or drops no awaited value.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): read a literal as gaining a getter only where it escapes itself
terser counts a property read off a literal and stored as the literal
escaping, so `var push = array.push` kept every unused `array.slice`.
Track the literal's own escape apart. List what swc still writes shorter
by dropping conversions oxc keeps, and what oxc drops in a `with` body.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep a class whose static key may name `prototype`, and a block's async function in its block
A static member whose computed key a variable may hold as `"prototype"`
throws as the class is defined, so the class is kept unless the key is
known to be something else. Folding a `switch` no longer writes a block's
async or generator function as a `var`, which only a plain function is.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test(minify): list the classes oxc drops though a static key may name `prototype`
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* refactor(javascript): read a static key of no known value in `definesStaticPrototype`
The check `main` added for a static `prototype` key now also takes a
computed key of no known value as one, unless a number or a well-known
symbol, so the class heritage check no longer repeats it.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test: list as terser's alone the test262 cases webpack's printer now passes
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(javascript): keep a read of a lexical binding that may run before its declaration
`{ x; let x; }`, a `typeof x` before `let x`, a closure read in a `for-of`
head of the loop's own binding, and a closure called before its `let` all
throw a ReferenceError, which dropping the unused read lost.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* feat(javascript): add `pure_conversions` and keep private names under `keep_fnames`
`compress.pure_conversions`, on by default as terser assumes, can be
turned off to keep a comparison or a computed key converting what may be
an object or a symbol, whose `valueOf`, `toString` or throw then still
runs. `keep_fnames: true` now also keeps private names, which a private
method's `name` reads.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* feat(javascript): add `pure_heritage`, and keep the name a literal gives a class
`compress.pure_heritage`, on by default as terser assumes, can be turned
off to keep a class nobody reads where it extends what may be no
constructor. Under `keep_classnames` or `keep_fnames`, `{ default: class
{} }.default`, which names the class `default`, is no longer flattened
into the bare class.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test(test262): run the printer with its assumptions off, and keep names in both minified modes
test262 reads functions' and classes' `name`, converts objects whose
conversions throw, and extends what is no constructor, all on purpose.
Both minified modes now keep names, and the printer runs with
`pure_conversions` and `pure_heritage` off, so 194 of its 195 listed
failures pass and leave the list; terser's name cases leave it too.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* docs(changeset): name the options the printer fixes add
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): keep `pure_conversions` and `pure_heritage` on under `defaults: false`
Both name assumptions terser makes whatever its other options are, not passes to turn off with the rest.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test(test262): share the options terser supports between both minified modes
Both modes keep names and turn `pure_getters` off, each commented with
what test262 does on purpose; the printer adds only its own switches.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test(test262): drop the 30 cases terser passes with `pure_getters` off
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* fix(javascript): never quote a kept private name
terser prints a private member's name as a property's, quoting one it does
not take for an identifier, so a kept non-ASCII name printed as `#"ࢶ"`, a
SyntaxError. The correct phase prints it as a name, as `this.#x` already is.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b
* test(javascript): retire an swc size entry the minifier no longer needs
Dropping an empty constructor and the `new` arguments nothing reads now
writes `fixture/issues/11684/class-decl` as small as swc does.
Claude-Session: https://claude.ai/code/session_019cRZoHW2M4sCbrLFgrAc6b1 parent 86d31e0 commit f9524b3
10 files changed
Lines changed: 2514 additions & 712 deletions
File tree
- .changeset
- lib/javascript
- test
- helpers
- specCases
- unitCases
- __snapshots__
| 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 | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1624 | 1624 | | |
1625 | 1625 | | |
1626 | 1626 | | |
| 1627 | + | |
| 1628 | + | |
1627 | 1629 | | |
1628 | 1630 | | |
1629 | 1631 | | |
| |||
1674 | 1676 | | |
1675 | 1677 | | |
1676 | 1678 | | |
1677 | | - | |
| 1679 | + | |
1678 | 1680 | | |
1679 | 1681 | | |
1680 | 1682 | | |
| |||
1684 | 1686 | | |
1685 | 1687 | | |
1686 | 1688 | | |
1687 | | - | |
1688 | | - | |
| 1689 | + | |
1689 | 1690 | | |
1690 | 1691 | | |
1691 | 1692 | | |
| |||
1805 | 1806 | | |
1806 | 1807 | | |
1807 | 1808 | | |
1808 | | - | |
1809 | | - | |
1810 | 1809 | | |
1811 | 1810 | | |
1812 | 1811 | | |
| |||
1829 | 1828 | | |
1830 | 1829 | | |
1831 | 1830 | | |
1832 | | - | |
| 1831 | + | |
1833 | 1832 | | |
1834 | 1833 | | |
1835 | | - | |
1836 | | - | |
1837 | 1834 | | |
1838 | 1835 | | |
1839 | 1836 | | |
| |||
1859 | 1856 | | |
1860 | 1857 | | |
1861 | 1858 | | |
1862 | | - | |
1863 | 1859 | | |
1864 | 1860 | | |
1865 | 1861 | | |
| |||
2085 | 2081 | | |
2086 | 2082 | | |
2087 | 2083 | | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
2088 | 2090 | | |
2089 | | - | |
| 2091 | + | |
| 2092 | + | |
2090 | 2093 | | |
2091 | | - | |
| 2094 | + | |
2092 | 2095 | | |
2093 | 2096 | | |
2094 | 2097 | | |
| |||
2110 | 2113 | | |
2111 | 2114 | | |
2112 | 2115 | | |
2113 | | - | |
2114 | 2116 | | |
2115 | 2117 | | |
2116 | 2118 | | |
| |||
2152 | 2154 | | |
2153 | 2155 | | |
2154 | 2156 | | |
2155 | | - | |
| 2157 | + | |
| 2158 | + | |
| 2159 | + | |
2156 | 2160 | | |
2157 | 2161 | | |
2158 | 2162 | | |
| |||
2754 | 2758 | | |
2755 | 2759 | | |
2756 | 2760 | | |
2757 | | - | |
2758 | | - | |
| 2761 | + | |
2759 | 2762 | | |
2760 | 2763 | | |
2761 | 2764 | | |
| |||
2849 | 2852 | | |
2850 | 2853 | | |
2851 | 2854 | | |
2852 | | - | |
2853 | 2855 | | |
2854 | 2856 | | |
2855 | 2857 | | |
| |||
0 commit comments