fix(es/minifier): Fix operand handling of ** (#8933)

**Related issue:**

 - Closes #8924
This commit is contained in:
Donny/강동윤 2024-05-08 10:37:57 +09:00 committed by GitHub
parent bd6873ece4
commit c9d72cdc6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 88 additions and 12 deletions

View File

@ -354,12 +354,20 @@ impl Optimizer<'_> {
self.changed = true;
report_change!("evaluate: Evaluated `{:?} ** {:?}`", l, r);
let value = l.powf(r);
*e = Expr::Lit(Lit::Num(Number {
span: bin.span,
value,
raw: None,
}));
if l.is_nan() || r.is_nan() {
*e = Expr::Ident(Ident::new(
"NaN".into(),
bin.span.with_ctxt(
SyntaxContext::empty().apply_mark(self.marks.unresolved_mark),
),
));
} else {
*e = Expr::Lit(Lit::Num(Number {
span: bin.span,
value: l.powf(r),
raw: None,
}));
};
}
}
}

View File

@ -1552,7 +1552,7 @@ impl Optimizer<'_> {
}
}
if match &*b {
match &*b {
Expr::Arrow(..)
| Expr::Fn(..)
| Expr::Class(..)
@ -1560,13 +1560,27 @@ impl Optimizer<'_> {
| Expr::Await(..)
| Expr::Yield(..)
| Expr::Tpl(..)
| Expr::TaggedTpl(..) => true,
| Expr::TaggedTpl(..) => return Ok(false),
Expr::Assign(AssignExpr {
op: op!("**="),
right,
..
})
| Expr::Bin(BinExpr {
op: op!("**"),
right,
..
}) => {
if is_pure_undefined(&self.expr_ctx, right) {
return Ok(false);
}
}
Expr::Unary(UnaryExpr {
op: op!("delete"), ..
}) => true,
_ => false,
} {
return Ok(false);
}) => return Ok(false),
_ => {}
}
match a {

View File

@ -0,0 +1,47 @@
{
"defaults": true,
"arguments": false,
"arrows": true,
"booleans": true,
"booleans_as_integers": false,
"collapse_vars": true,
"comparisons": true,
"computed_props": true,
"conditionals": true,
"dead_code": true,
"directives": true,
"drop_console": false,
"drop_debugger": true,
"evaluate": true,
"expression": false,
"hoist_funs": false,
"hoist_props": true,
"hoist_vars": false,
"if_return": true,
"join_vars": true,
"keep_classnames": false,
"keep_fargs": true,
"keep_fnames": false,
"keep_infinity": false,
"loops": true,
"negate_iife": true,
"properties": true,
"reduce_funcs": false,
"reduce_vars": false,
"side_effects": true,
"switches": true,
"typeofs": true,
"unsafe": false,
"unsafe_arrows": false,
"unsafe_comps": false,
"unsafe_Function": false,
"unsafe_math": false,
"unsafe_symbols": false,
"unsafe_methods": false,
"unsafe_proto": false,
"unsafe_regexp": false,
"unsafe_undefined": false,
"unused": true,
"const_to_let": true,
"pristine_globals": true
}

View File

@ -0,0 +1,5 @@
"use strict";
const k = (() => {
let x = 1; x **= undefined;
return x;
})();

View File

@ -0,0 +1,2 @@
"use strict";
const k = NaN;