fix(es/minifier): Consider side effects of operands of binary expressions (#8929)

**Related issue:**

 - Closes #8923
This commit is contained in:
Donny/강동윤 2024-05-07 14:27:08 +09:00 committed by GitHub
parent 9bf57906c5
commit 4d4a7a9bcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 65 additions and 6 deletions

View File

@ -523,7 +523,8 @@ impl Pure<'_> {
.as_bin()
.filter(|b| b.op.precedence() == op.precedence())
.is_none()
&& !left.may_have_side_effects(&self.expr_ctx));
&& !left.may_have_side_effects(&self.expr_ctx)
&& !right.may_have_side_effects(&self.expr_ctx));
if can_swap {
report_change!("Swapping operands of binary expession");

View File

@ -1672,7 +1672,7 @@
else {
var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1), b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
S = (Math.log(Math.sqrt(b1 * b1 + 1) - b1) - r0) / rho, i = function(t) {
var x, x1, s = t * S, coshr0 = cosh(r0), u = w0 / (rho2 * d1) * (((x = Math.exp(2 * (x = rho * s + r0))) - 1) / (x + 1) * coshr0 - ((x1 = Math.exp(x1 = r0)) - 1 / x1) / 2);
var x, x1, s = t * S, coshr0 = cosh(r0), u = w0 / (rho2 * d1) * (coshr0 * (((x = Math.exp(2 * (x = rho * s + r0))) - 1) / (x + 1)) - ((x1 = Math.exp(x1 = r0)) - 1 / x1) / 2);
return [
ux0 + u * dx,
uy0 + u * dy,

View File

@ -1158,7 +1158,7 @@
},
elasticInOut: function(k) {
var s, a = 0.1;
return 0 === k ? 0 : 1 === k ? 1 : (!a || a < 1 ? (a = 1, s = 0.1) : s = 0.4 * Math.asin(1 / a) / (2 * Math.PI), (k *= 2) < 1) ? -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin(2 * Math.PI * (k - s) / 0.4) * 0.5) : a * Math.pow(2, -10 * (k -= 1)) * Math.sin(2 * Math.PI * (k - s) / 0.4) * 0.5 + 1;
return 0 === k ? 0 : 1 === k ? 1 : (!a || a < 1 ? (a = 1, s = 0.1) : s = 0.4 * Math.asin(1 / a) / (2 * Math.PI), (k *= 2) < 1) ? -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin(2 * Math.PI * (k - s) / 0.4)) : a * Math.pow(2, -10 * (k -= 1)) * Math.sin(2 * Math.PI * (k - s) / 0.4) * 0.5 + 1;
},
backIn: function(k) {
return k * k * (2.70158 * k - 1.70158);

View File

@ -2345,7 +2345,7 @@
else {
var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + 4 * d2) / (2 * w0 * 2 * d1), b1 = (w1 * w1 - w0 * w0 - 4 * d2) / (2 * w1 * 2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
S = (Math.log(Math.sqrt(b1 * b1 + 1) - b1) - r0) / rho, i = function(t) {
var x, x1, s = t * S, coshr0 = cosh(r0), u = w0 / (2 * d1) * (((x = Math.exp(2 * (x = rho * s + r0))) - 1) / (x + 1) * coshr0 - ((x1 = Math.exp(x1 = r0)) - 1 / x1) / 2);
var x, x1, s = t * S, coshr0 = cosh(r0), u = w0 / (2 * d1) * (coshr0 * (((x = Math.exp(2 * (x = rho * s + r0))) - 1) / (x + 1)) - ((x1 = Math.exp(x1 = r0)) - 1 / x1) / 2);
return [
ux0 + u * dx,
uy0 + u * dy,
@ -22643,7 +22643,7 @@
firstChild && "stack" === firstChild.type.role && (barWidth = (firstChild.props.children && firstChild.props.children[0]).props.barWidth, dataLength = firstChild.props.children.length);
var width = barWidth || this.getWidth(props, children.length, dataLength);
return {
x: width * children.length / 2 + (offset - (children.length - 1) / 2 * width)
x: width * children.length / 2 + (offset - width * ((children.length - 1) / 2))
};
}
}
@ -29100,7 +29100,7 @@
x: function() {
if (!textAnchor || "middle" === textAnchor) return flyoutCenter.x;
var sign = "end" === textAnchor ? -1 : 1;
return flyoutCenter.x - labelSize.width / 2 * sign;
return flyoutCenter.x - sign * (labelSize.width / 2);
}() + (flyoutPadding.left - flyoutPadding.right) / 2,
y: flyoutCenter.y + (flyoutPadding.top - flyoutPadding.bottom) / 2,
verticalAnchor: "middle",

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,6 @@
"use strict";
const k = (() => {
let x = '';
x *= x-- / x;
return x;
})();

View File

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