Commit b830786
authored
fix(es/minifier): use numeric literals for non-finite values (#12048)
**Description:**
The optimizer currently represents `NaN` and infinities in several
forms, including identifiers, divisions, and numeric literals. As these
forms move through multiple optimization passes, they can be folded
inconsistently and acquire incorrect truthiness or stringification.
This PR canonicalizes non-finite optimization results as raw-free
`Lit::Num` values. Minifier and simplifier helpers then preserve
ECMAScript behavior for these numbers, while codegen remains responsible
for choosing valid output syntax.
**Related issue (if exists):**
- #12043
- #12047
- #12050
- **#12048** (current)
- #12051
- #12052
- #12053
- #12054
- #12055
- #12056
- #12057
- #12058
- #12049
- #12059
- #120601 parent b71793f commit b830786
109 files changed
Lines changed: 943 additions & 769 deletions
File tree
- .changeset
- crates
- swc_ecma_minifier
- src
- compress
- optimize
- pure
- util
- tests
- benches-full
- fixture
- issues
- 2257/full
- 2779/1
- 5682
- 6957/number-tostring
- 8813
- d3-color/1
- firebase-firestore/1
- moment/1
- non-finite-conditional-arithmetic
- non-finite-number-method-call
- numeric-property-key
- quagga2/1.4.2/1
- string-from-char-code-uint16
- vercel/005
- next
- 33265/static/chunks
- d6e1aeb5-38a8d7ae57119c23
- pages/index-cb36c1bf7f830e3c
- feedback-2/codemirror
- feedback-3/579-dcac359116b2707c
- feedback-util-promisify/chunks/pages/_app-72ad41192608e93a
- react-ace/chunks/8a28b14e.d8fbda268ed281a1
- react-pdf-renderer
- syncfusion/933-e9f9a6bf671b96fc
- wrap-contracts
- non-finite-number-literals
- full/vercel/ms/1
- projects/output
- terser/compress
- conditionals
- equality_conditionals_false
- equality_conditionals_true
- to_and_or
- evaluate
- Infinity_NaN_undefined_LHS
- and
- issue_1760_1
- issue_2207_3
- negative_zero
- or
- pow_nan
- pow_spec
- pow_with_number_constants
- string_charCodeAt
- unsafe_array_bad_index
- unsafe_array
- unsafe_string_bad_index
- expression
- pow_with_number_constants
- pow_with_parentheses
- functions/issue_2620_4
- inline/inline_annotation_2
- issue_1105/Infinity_not_in_with_scope
- issue_597
- NaN_and_Infinity_must_have_parens_evaluate
- NaN_and_Infinity_must_have_parens
- NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined_evaluate
- NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined
- beautify_off_1
- beautify_on_1
- issue_1724
- numbers/unary_binary_parenthesis
- object/convert_computed_props_to_regular_ones
- properties/join_object_assignments_NaN_1
- reduce_vars
- lvalues_def_1
- lvalues_def_2
- template_string/template_string_with_predefined_constants
- swc_ecma_transforms_optimization
- src
- simplify
- branch
- expr
- tests/json-parse/non-finite-number
- swc_ecma_utils/src
- swc/tests
- tsc-references
- vercel
- full-compact/d3-color/1/output
- full
- d3-color/1/output
- ms/1/output
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 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
0 commit comments