Skip to content

Commit 4b236c9

Browse files
committed
fix(es/minifier): Don't track usage assign
1 parent 6749e69 commit 4b236c9

File tree

39 files changed

+526
-598
lines changed

39 files changed

+526
-598
lines changed

crates/swc_ecma_minifier/src/analyzer/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ where
481481
self.data
482482
.var_or_default(left.clone())
483483
.add_infects_to(id.clone());
484-
self.data.var_or_default(id).add_infects_to(left.clone());
485484
}
486485
}
487486
}

crates/swc_ecma_minifier/src/analyzer/storage/normal.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,28 @@ impl ProgramData {
257257
}
258258

259259
if ctx.is_op_assign {
260+
println!("use {}", i.0);
260261
e.usage_count += 1;
261262
} else if is_first {
262263
if e.ref_count == 1
263264
&& ctx.in_assign_lhs
264265
&& e.var_kind != Some(VarDeclKind::Const)
265266
&& !inited
266267
{
267-
self.initialized_vars.insert(i);
268+
self.initialized_vars.insert(i.clone());
268269
e.assign_count -= 1;
269270
e.var_initialized = true;
270271
} else {
271272
e.reassigned_with_assignment = true
272273
}
273274
}
274275

276+
print!("{} infects: ", i.0);
277+
278+
for other in e.infects.clone() {
279+
print!("{}, ", other.0);
280+
}
281+
println!();
275282
for other in e.infects.clone() {
276283
self.report(other, ctx, true, dejavu)
277284
}
@@ -280,6 +287,8 @@ impl ProgramData {
280287
e.mutation_by_call_count += 1;
281288
}
282289

290+
println!("use {}", i.0);
291+
283292
e.usage_count += 1;
284293
}
285294
}

crates/swc_ecma_minifier/tests/benches-full/d3.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -6401,7 +6401,7 @@
64016401
return randomUniform.source = sourceRandomUniform, randomUniform;
64026402
}(defaultSource$1), int = function sourceRandomInt(source) {
64036403
function randomInt(min, max) {
6404-
return arguments.length < 2 && (max = min, min = 0), min = Math.floor(min), max = Math.floor(max) - min, function() {
6404+
return arguments.length < 2 && (max = min, min = 0), max = Math.floor(max) - (min = Math.floor(min)), function() {
64056405
return Math.floor(source() * max + min);
64066406
};
64076407
}
@@ -6412,7 +6412,7 @@
64126412
return mu = null == mu ? 0 : +mu, sigma = null == sigma ? 1 : +sigma, function() {
64136413
var y;
64146414
if (null != x) y = x, x = null;
6415-
else do x = 2 * source() - 1, y = 2 * source() - 1, r = x * x + y * y;
6415+
else do r = (x = 2 * source() - 1) * x + (y = 2 * source() - 1) * y;
64166416
while (!r || r > 1)
64176417
return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
64186418
};
@@ -7419,14 +7419,14 @@
74197419
return pad$1(d.getFullYear() % 100, p, 2);
74207420
}
74217421
function formatYearISO(d, p) {
7422-
return d = dISO(d), pad$1(d.getFullYear() % 100, p, 2);
7422+
return pad$1((d = dISO(d)).getFullYear() % 100, p, 2);
74237423
}
74247424
function formatFullYear(d, p) {
74257425
return pad$1(d.getFullYear() % 10000, p, 4);
74267426
}
74277427
function formatFullYearISO(d, p) {
74287428
var day = d.getDay();
7429-
return d = day >= 4 || 0 === day ? thursday(d) : thursday.ceil(d), pad$1(d.getFullYear() % 10000, p, 4);
7429+
return pad$1((d = day >= 4 || 0 === day ? thursday(d) : thursday.ceil(d)).getFullYear() % 10000, p, 4);
74307430
}
74317431
function formatZone(d) {
74327432
var z = d.getTimezoneOffset();
@@ -7483,14 +7483,14 @@
74837483
return pad$1(d.getUTCFullYear() % 100, p, 2);
74847484
}
74857485
function formatUTCYearISO(d, p) {
7486-
return d = UTCdISO(d), pad$1(d.getUTCFullYear() % 100, p, 2);
7486+
return pad$1((d = UTCdISO(d)).getUTCFullYear() % 100, p, 2);
74877487
}
74887488
function formatUTCFullYear(d, p) {
74897489
return pad$1(d.getUTCFullYear() % 10000, p, 4);
74907490
}
74917491
function formatUTCFullYearISO(d, p) {
74927492
var day = d.getUTCDay();
7493-
return d = day >= 4 || 0 === day ? utcThursday(d) : utcThursday.ceil(d), pad$1(d.getUTCFullYear() % 10000, p, 4);
7493+
return pad$1((d = day >= 4 || 0 === day ? utcThursday(d) : utcThursday.ceil(d)).getUTCFullYear() % 10000, p, 4);
74947494
}
74957495
function formatUTCZone() {
74967496
return "+0000";
@@ -7710,7 +7710,7 @@
77107710
};
77117711
}
77127712
return scale.domain = function(_) {
7713-
return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [
7713+
return arguments.length ? ([x0, x1] = _, k10 = (t0 = transform(x0 = +x0)) === (t1 = transform(x1 = +x1)) ? 0 : 1 / (t1 - t0), scale) : [
77147714
x0,
77157715
x1
77167716
];
@@ -7721,7 +7721,7 @@
77217721
}, scale.range = range(interpolate), scale.rangeRound = range(interpolateRound), scale.unknown = function(_) {
77227722
return arguments.length ? (unknown = _, scale) : unknown;
77237723
}, function(t) {
7724-
return transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale;
7724+
return transform = t, k10 = (t0 = t(x0)) === (t1 = t(x1)) ? 0 : 1 / (t1 - t0), scale;
77257725
};
77267726
}
77277727
function copy$1(source, target) {
@@ -9389,7 +9389,7 @@
93899389
if (data) {
93909390
if (data.index > node.index) {
93919391
var x = xi - data.x - data.vx, y = yi - data.y - data.vy, l = x * x + y * y;
9392-
l < r * r && (0 === x && (x = jiggle(random), l += x * x), 0 === y && (y = jiggle(random), l += y * y), l = (r - (l = Math.sqrt(l))) / l * strength, node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj)), node.vy += (y *= l) * r, data.vx -= x * (r = 1 - r), data.vy -= y * r);
9392+
l < r * r && (0 === x && (l += (x = jiggle(random)) * x), 0 === y && (l += (y = jiggle(random)) * y), l = (r - (l = Math.sqrt(l))) / l * strength, node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj)), node.vy += (y *= l) * r, data.vx -= x * (r = 1 - r), data.vy -= y * r);
93939393
}
93949394
return;
93959395
}
@@ -9420,7 +9420,7 @@
94209420
return 1 / Math.min(count[link.source.index], count[link.target.index]);
94219421
}, distance = constant$7(30), iterations = 1;
94229422
function force(alpha) {
9423-
for(var k = 0, n = links.length; k < iterations; ++k)for(var link, source, target, x, y, l, b, i = 0; i < n; ++i)source = (link = links[i]).source, x = (target = link.target).x + target.vx - source.x - source.vx || jiggle(random), y = target.y + target.vy - source.y - source.vy || jiggle(random), l = ((l = Math.sqrt(x * x + y * y)) - distances[i]) / l * alpha * strengths[i], x *= l, y *= l, target.vx -= x * (b = bias[i]), target.vy -= y * b, source.vx += x * (b = 1 - b), source.vy += y * b;
9423+
for(var k = 0, n = links.length; k < iterations; ++k)for(var link, source, target, x, y, l, b, i = 0; i < n; ++i)source = (link = links[i]).source, l = ((l = Math.sqrt((x = (target = link.target).x + target.vx - source.x - source.vx || jiggle(random)) * x + (y = target.y + target.vy - source.y - source.vy || jiggle(random)) * y)) - distances[i]) / l * alpha * strengths[i], x *= l, y *= l, target.vx -= x * (b = bias[i]), target.vy -= y * b, source.vx += x * (b = 1 - b), source.vy += y * b;
94249424
}
94259425
function initialize() {
94269426
if (nodes) {
@@ -9479,9 +9479,9 @@
94799479
function apply(quad, x1, _, x2) {
94809480
if (!quad.value) return !0;
94819481
var x = quad.x - node.x, y = quad.y - node.y, w = x2 - x1, l = x * x + y * y;
9482-
if (w * w / theta2 < l) return l < distanceMax2 && (0 === x && (x = jiggle(random), l += x * x), 0 === y && (y = jiggle(random), l += y * y), l < distanceMin2 && (l = Math.sqrt(distanceMin2 * l)), node.vx += x * quad.value * alpha / l, node.vy += y * quad.value * alpha / l), !0;
9482+
if (w * w / theta2 < l) return l < distanceMax2 && (0 === x && (l += (x = jiggle(random)) * x), 0 === y && (l += (y = jiggle(random)) * y), l < distanceMin2 && (l = Math.sqrt(distanceMin2 * l)), node.vx += x * quad.value * alpha / l, node.vy += y * quad.value * alpha / l), !0;
94839483
if (!quad.length && !(l >= distanceMax2)) {
9484-
(quad.data !== node || quad.next) && (0 === x && (x = jiggle(random), l += x * x), 0 === y && (y = jiggle(random), l += y * y), l < distanceMin2 && (l = Math.sqrt(distanceMin2 * l)));
9484+
(quad.data !== node || quad.next) && (0 === x && (l += (x = jiggle(random)) * x), 0 === y && (l += (y = jiggle(random)) * y), l < distanceMin2 && (l = Math.sqrt(distanceMin2 * l)));
94859485
do quad.data !== node && (w = strengths[quad.data.index] * alpha / l, node.vx += x * w, node.vy += y * w);
94869486
while (quad = quad.next)
94879487
}

0 commit comments

Comments
 (0)