Skip to content

Commit 589bcd7

Browse files
authored
feat(es/minifier): Merge alt's cons with cons (#10256)
**Description:** I'd argue that this should be added even solely for symmetry.
1 parent 7af0436 commit 589bcd7

File tree

27 files changed

+95
-67
lines changed

27 files changed

+95
-67
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
| File | Original Size | Compressed Size | Gzipped Size |
22
| --- | --- | --- | --- |
3-
| antd.js | 6.38 MiB | 2.05 MiB | 444.51 KiB |
3+
| antd.js | 6.38 MiB | 2.05 MiB | 444.49 KiB |
44
| d3.js | 542.74 KiB | 259.02 KiB | 85.06 KiB |
5-
| echarts.js | 3.41 MiB | 971.32 KiB | 313.35 KiB |
5+
| echarts.js | 3.41 MiB | 971.32 KiB | 313.36 KiB |
66
| jquery.js | 280.89 KiB | 87.12 KiB | 30.16 KiB |
77
| lodash.js | 531.35 KiB | 68.18 KiB | 24.52 KiB |
8-
| moment.js | 169.83 KiB | 57.03 KiB | 18.20 KiB |
8+
| moment.js | 169.83 KiB | 57.03 KiB | 18.21 KiB |
99
| react.js | 70.45 KiB | 22.28 KiB | 8.00 KiB |
10-
| terser.js | 1.08 MiB | 444.92 KiB | 120.46 KiB |
11-
| three.js | 1.19 MiB | 628.03 KiB | 154.56 KiB |
10+
| terser.js | 1.08 MiB | 444.90 KiB | 120.46 KiB |
11+
| three.js | 1.19 MiB | 627.93 KiB | 154.57 KiB |
1212
| typescript.js | 10.45 MiB | 3.17 MiB | 845.79 KiB |
13-
| victory.js | 2.30 MiB | 689.67 KiB | 153.65 KiB |
13+
| victory.js | 2.30 MiB | 689.66 KiB | 153.66 KiB |
1414
| vue.js | 334.13 KiB | 112.95 KiB | 41.68 KiB |

crates/swc/tests/tsc-references/controlFlowOptionalChain.2.minified.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/swc/tests/tsc-references/parserRealSource8.2.minified.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/swc_ecma_minifier/src/compress/optimize/conditionals.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,26 @@ impl Optimizer<'_> {
622622
)
623623
}
624624

625+
// a ? c() : b ? c() : d() => a || b ? c() : d()
626+
(cons, Expr::Cond(alt)) if cons.eq_ignore_span(&*alt.cons) => {
627+
report_change!("conditionals: a ? c() : b ? c() : d() => a || b ? c() : d()");
628+
Some(
629+
CondExpr {
630+
span: DUMMY_SP,
631+
test: BinExpr {
632+
span: DUMMY_SP,
633+
left: test.take(),
634+
op: op!("||"),
635+
right: alt.test.take(),
636+
}
637+
.into(),
638+
cons: alt.cons.take(),
639+
alt: alt.alt.take(),
640+
}
641+
.into(),
642+
)
643+
}
644+
625645
// z ? "fuji" : (condition(), "fuji");
626646
// =>
627647
// (z || condition(), "fuji");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28789,7 +28789,7 @@
2878928789
// if totalLen is Longer createCurveness
2879028790
var totalLen = getEdgeMapLengthWithKey(getKeyOfEdges(edge.node1, edge.node2, seriesModel), seriesModel) + getEdgeMapLengthWithKey(getKeyOfEdges(edge.node2, edge.node1, seriesModel), seriesModel);
2879128791
createCurveness(seriesModel, totalLen), edge.lineStyle = edge.lineStyle || {};
28792-
var curKey = getKeyOfEdges(edge.node1, edge.node2, seriesModel), curvenessList = seriesModel.__curvenessList, parityCorrection = isArrayParam ? 0 : totalLen % 2 ? 0 : 1;
28792+
var curKey = getKeyOfEdges(edge.node1, edge.node2, seriesModel), curvenessList = seriesModel.__curvenessList, parityCorrection = isArrayParam || totalLen % 2 ? 0 : 1;
2879328793
if (edgeArray.isForward) return curvenessList[parityCorrection + edgeIndex];
2879428794
var len = getEdgeMapLengthWithKey(getOppositeKey(curKey), seriesModel), resValue = curvenessList[edgeIndex + len + parityCorrection];
2879528795
return needReverse ? isArrayParam ? autoCurvenessParams && 0 === autoCurvenessParams[0] ? (len + parityCorrection) % 2 ? resValue : -resValue : ((len % 2 ? 0 : 1) + parityCorrection) % 2 ? resValue : -resValue : (len + parityCorrection) % 2 ? resValue : -resValue : curvenessList[edgeIndex + len + parityCorrection];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
]), this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase(), this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
295295
if (strict) if ('MMM' === format) return -1 !== (ii = indexOf.call(this._shortMonthsParse, llc)) ? ii : null;
296296
else return -1 !== (ii = indexOf.call(this._longMonthsParse, llc)) ? ii : null;
297-
return 'MMM' === format ? -1 !== (ii = indexOf.call(this._shortMonthsParse, llc)) ? ii : -1 !== (ii = indexOf.call(this._longMonthsParse, llc)) ? ii : null : -1 !== (ii = indexOf.call(this._longMonthsParse, llc)) ? ii : -1 !== (ii = indexOf.call(this._shortMonthsParse, llc)) ? ii : null;
297+
return 'MMM' === format ? -1 !== (ii = indexOf.call(this._shortMonthsParse, llc)) || -1 !== (ii = indexOf.call(this._longMonthsParse, llc)) ? ii : null : -1 !== (ii = indexOf.call(this._longMonthsParse, llc)) || -1 !== (ii = indexOf.call(this._shortMonthsParse, llc)) ? ii : null;
298298
}
299299
// MOMENTS
300300
function setMonth(mom, value) {
@@ -463,7 +463,7 @@
463463
if (strict) if ('dddd' === format) return -1 !== (ii = indexOf.call(this._weekdaysParse, llc)) ? ii : null;
464464
else if ('ddd' === format) return -1 !== (ii = indexOf.call(this._shortWeekdaysParse, llc)) ? ii : null;
465465
else return -1 !== (ii = indexOf.call(this._minWeekdaysParse, llc)) ? ii : null;
466-
return 'dddd' === format ? -1 !== (ii = indexOf.call(this._weekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._shortWeekdaysParse, llc)) ? ii : -1 !== (ii = indexOf.call(this._minWeekdaysParse, llc)) ? ii : null : 'ddd' === format ? -1 !== (ii = indexOf.call(this._shortWeekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._weekdaysParse, llc)) ? ii : -1 !== (ii = indexOf.call(this._minWeekdaysParse, llc)) ? ii : null : -1 !== (ii = indexOf.call(this._minWeekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._weekdaysParse, llc)) ? ii : -1 !== (ii = indexOf.call(this._shortWeekdaysParse, llc)) ? ii : null;
466+
return 'dddd' === format ? -1 !== (ii = indexOf.call(this._weekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._shortWeekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._minWeekdaysParse, llc)) ? ii : null : 'ddd' === format ? -1 !== (ii = indexOf.call(this._shortWeekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._weekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._minWeekdaysParse, llc)) ? ii : null : -1 !== (ii = indexOf.call(this._minWeekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._weekdaysParse, llc)) || -1 !== (ii = indexOf.call(this._shortWeekdaysParse, llc)) ? ii : null;
467467
}
468468
function computeWeekdaysParse() {
469469
function cmpLenRev(a, b) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8636,7 +8636,7 @@
86368636
stat.body = make_sequence(stat.body, exprs);
86378637
}
86388638
statements[++j] = stat;
8639-
} else stat instanceof AST_Switch ? stat.expression = extract_object_assignments(stat.expression) : stat instanceof AST_With ? stat.expression = extract_object_assignments(stat.expression) : statements[++j] = stat;
8639+
} else stat instanceof AST_Switch || stat instanceof AST_With ? stat.expression = extract_object_assignments(stat.expression) : statements[++j] = stat;
86408640
}
86418641
function extract_object_assignments(value) {
86428642
statements[++j] = stat;

0 commit comments

Comments
 (0)