mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
f6000ac141
`f64::powf` implements IEEE 754 `pow`, which returns `1` for a base of `1` whatever the exponent. [`Number::exponentiate`](https://tc39.es/ecma262/#sec-numeric-types-number-exponentiate) instead returns `NaN` when the exponent is `NaN` (step 1), and when the base has magnitude `1` and the exponent is infinite (steps 9-10). Constant folding called `powf` directly, so: ```js 1 ** Infinity // spec: NaN oxc folded to: 1 (-1) ** Infinity // spec: NaN oxc folded to: 1 1 ** -Infinity // spec: NaN oxc folded to: 1 1 ** NaN // spec: NaN oxc folded to: 1 ``` `1` is truthy and `NaN` is not, so an `if` guarded by such an expression takes the wrong branch. The one case the two agree on — an exponent of `0` returning `1` whatever the base, including `NaN ** 0` and `Infinity ** 0` — is unchanged, since `powf` already gets it right and the spec checks the exponent before the base. `cargo minsize` shows no snapshot change. Found by the minifier fuzzer (#25594). --- Written with AI assistance (Claude Code). Reviewed by me, and every expected value in the added test was checked against Node.js. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
oxc_ecmascript
ECMAScript Operations defined in the spec https://tc39.es/ecma262/
Cargo features
side_effects: Enables side-effect analysis.constant_evaluation: Enables constant evaluation and impliesside_effects.
Tests reside in crates/oxc_minifier/tests/ecmascript due to cyclic dependency with oxc_parser.