Skip to content

Commit

Permalink
fix(es/minifier): Fix regression due to #10056 (#10134)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #10133
  • Loading branch information
kdy1 authored Mar 4, 2025
1 parent 7bea830 commit b145275
Show file tree
Hide file tree
Showing 33 changed files with 197 additions and 103 deletions.
6 changes: 6 additions & 0 deletions .changeset/blue-crabs-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_minifier: patch
swc_core: patch
---

fix(es/minifier): Fix regression
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//// [circularImportAlias.ts]
var B, A, B1, A1;
var B, A, B1, D, A1;
import { _ as _call_super } from "@swc/helpers/_/_call_super";
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _inherits } from "@swc/helpers/_/_inherits";
(B1 = B || (B = {})).a = A, B1.D = /*#__PURE__*/ function(_B_a_C) {
(B1 = B || (B = {})).a = A, D = /*#__PURE__*/ function(_B_a_C) {
function D() {
return _class_call_check(this, D), _call_super(this, D, arguments);
}
return _inherits(D, _B_a_C), D;
}(B1.a.C), (A1 = A || (A = {})).C = function C() {
}(B1.a.C), B1.D = D, (A1 = A || (A = {})).C = function C() {
_class_call_check(this, C);
}, A1.b = B, new B.a.C();
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//// [compoundExponentiationAssignmentLHSIsReference.ts]
var value, x3, x1 = Math.pow(x1, value);
x3.a = Math.pow(x3.a, value), x3.a = Math.pow(x3.a, value), x1 = Math.pow(x1, value), x3.a = Math.pow(x3.a, value), x3.a = Math.pow(x3.a, value);
var value, x3, x1 = Math.pow(x1, value), ref = x3.a;
x3.a = Math.pow(ref, value);
var ref1 = x3.a;
x3.a = Math.pow(ref1, value), x1 = Math.pow(x1, value);
var ref2 = x3.a;
x3.a = Math.pow(ref2, value);
var ref3 = x3.a;
x3.a = Math.pow(ref3, value);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default function v(e) {
if ("s" in a) return new Date(1000 * a.s + ("L" in a ? a.L : 0));
if (!e || "Z" in a || (a.Z = 0), "p" in a && (a.H = a.H % 12 + 12 * a.p), void 0 === a.m && (a.m = "q" in a ? a.q : 0), "V" in a) {
if (a.V < 1 || a.V > 53) return null;
"w" in a || (a.w = 1), "Z" in a ? (c = (o = (c = s(h(a.y, 0, 1))).getUTCDay()) > 4 || 0 === o ? f.ceil(c) : f(c), a.y = (c = i.offset(c, (a.V - 1) * 7)).getUTCFullYear(), a.m = c.getUTCMonth(), a.d = c.getUTCDate() + (a.w + 6) % 7) : (c = (o = (c = g(h(a.y, 0, 1))).getDay()) > 4 || 0 === o ? r.ceil(c) : r(c), a.y = (c = t.offset(c, (a.V - 1) * 7)).getFullYear(), a.m = c.getMonth(), a.d = c.getDate() + (a.w + 6) % 7);
"w" in a || (a.w = 1), "Z" in a ? (c = (o = (c = s(h(a.y, 0, 1))).getUTCDay()) > 4 || 0 === o ? f.ceil(c) : f(c), c = i.offset(c, (a.V - 1) * 7), a.y = c.getUTCFullYear(), a.m = c.getUTCMonth(), a.d = c.getUTCDate() + (a.w + 6) % 7) : (c = (o = (c = g(h(a.y, 0, 1))).getDay()) > 4 || 0 === o ? r.ceil(c) : r(c), c = t.offset(c, (a.V - 1) * 7), a.y = c.getFullYear(), a.m = c.getMonth(), a.d = c.getDate() + (a.w + 6) % 7);
} else ("W" in a || "U" in a) && ("w" in a || (a.w = "u" in a ? a.u % 7 : +("W" in a)), o = "Z" in a ? s(h(a.y, 0, 1)).getUTCDay() : g(h(a.y, 0, 1)).getDay(), a.m = 0, a.d = "W" in a ? (a.w + 6) % 7 + 7 * a.W - (o + 5) % 7 : a.w + 7 * a.U - (o + 6) % 7);
return "Z" in a ? (a.H += a.Z / 100 | 0, a.M += a.Z % 100, s(a)) : g(a);
};
Expand Down
3 changes: 2 additions & 1 deletion crates/swc_ecma_minifier/scripts/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ set -eu

export RUST_LOG=trace
# export SWC_CHECK=1
export MIMALLOC_SHOW_STATS=0

cargo test --features concurrent --features debug --test exec --test terser_exec $@
cargo test -q --features concurrent --features debug --test exec --test terser_exec $@
20 changes: 20 additions & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1838,9 +1838,29 @@ impl Optimizer<'_> {
if let Some(left_obj) = b_left.obj.as_ident() {
if let Some(usage) = self.data.vars.get(&left_obj.to_id()) {
if left_obj.ctxt != self.ctx.expr_ctx.unresolved_ctxt
&& !usage.inline_prevented
&& !usage.reassigned
&& !b_left.prop.is_computed()
{
match &*a {
Mergable::Var(a) => {
if is_ident_used_by(left_obj.to_id(), &**a) {
return Ok(false);
}
}
Mergable::Expr(a) => {
if is_ident_used_by(left_obj.to_id(), &**a) {
return Ok(false);
}
}
Mergable::FnDecl(a) => {
if is_ident_used_by(left_obj.to_id(), &**a) {
return Ok(false);
}
}
Mergable::Drop => return Ok(false),
}

return self.merge_sequential_expr(a, &mut b_assign.right);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/tests/benches-full/d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7458,7 +7458,7 @@ function(global, factory) {
// Convert day-of-week and week-of-year to day-of-year.
if (!Z || "Z" in d || (d.Z = 0), "p" in d && (d.H = d.H % 12 + 12 * d.p), void 0 === d.m && (d.m = "q" in d ? d.q : 0), "V" in d) {
if (d.V < 1 || d.V > 53) return null;
"w" in d || (d.w = 1), "Z" in d ? (week = (day$1 = (week = utcDate(newDate(d.y, 0, 1))).getUTCDay()) > 4 || 0 === day$1 ? utcMonday.ceil(week) : utcMonday(week), d.y = (week = utcDay.offset(week, (d.V - 1) * 7)).getUTCFullYear(), d.m = week.getUTCMonth(), d.d = week.getUTCDate() + (d.w + 6) % 7) : (week = (day$1 = (week = localDate(newDate(d.y, 0, 1))).getDay()) > 4 || 0 === day$1 ? monday.ceil(week) : monday(week), d.y = (week = day.offset(week, (d.V - 1) * 7)).getFullYear(), d.m = week.getMonth(), d.d = week.getDate() + (d.w + 6) % 7);
"w" in d || (d.w = 1), "Z" in d ? (week = (day$1 = (week = utcDate(newDate(d.y, 0, 1))).getUTCDay()) > 4 || 0 === day$1 ? utcMonday.ceil(week) : utcMonday(week), week = utcDay.offset(week, (d.V - 1) * 7), d.y = week.getUTCFullYear(), d.m = week.getUTCMonth(), d.d = week.getUTCDate() + (d.w + 6) % 7) : (week = (day$1 = (week = localDate(newDate(d.y, 0, 1))).getDay()) > 4 || 0 === day$1 ? monday.ceil(week) : monday(week), week = day.offset(week, (d.V - 1) * 7), d.y = week.getFullYear(), d.m = week.getMonth(), d.d = week.getDate() + (d.w + 6) % 7);
} else ("W" in d || "U" in d) && ("w" in d || (d.w = "u" in d ? d.u % 7 : +("W" in d)), day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay(), d.m = 0, d.d = "W" in d ? (d.w + 6) % 7 + 7 * d.W - (day$1 + 5) % 7 : d.w + 7 * d.U - (day$1 + 6) % 7);
return(// If a time zone is specified, all fields are interpreted as UTC and then
// offset according to the specified time zone.
Expand Down
Loading

0 comments on commit b145275

Please sign in to comment.