Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es/minifier): Improve bool negation #10236

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
27d7c8f
change order
kdy1 Mar 20, 2025
f410b2b
Remove usage of `negate_cost`
kdy1 Mar 20, 2025
665806d
lints
kdy1 Mar 20, 2025
5b529e5
negate_bool_for_expr_stmt
kdy1 Mar 20, 2025
eea5dcf
negate_bool_preserving_semantics
kdy1 Mar 20, 2025
ae7bc57
Remove old code for negating
kdy1 Mar 20, 2025
ed9b0c7
Fix context passed to negate_cost
kdy1 Mar 20, 2025
bfb4318
Improve negate_bool_preserving_semantics
kdy1 Mar 20, 2025
1d4729e
lints
kdy1 Mar 20, 2025
d597218
Update test refs
kdy1 Mar 20, 2025
e8f61f5
Doc
kdy1 Mar 23, 2025
a628fac
Exmaple
kdy1 Mar 23, 2025
83db427
Enable tests
kdy1 Mar 23, 2025
f5fb69a
negate_cost
kdy1 Mar 23, 2025
c4cd1de
negate_iife
kdy1 Mar 23, 2025
35d0dcd
negate_iife
kdy1 Mar 23, 2025
43edecc
Update test refs
kdy1 Mar 23, 2025
cf25637
Add a test
kdy1 Mar 23, 2025
baa57e4
IMprove negate_cost
kdy1 Mar 23, 2025
43f3d6f
Update test refs
kdy1 Mar 23, 2025
6d621be
Remove wrong impl
kdy1 Mar 23, 2025
84dabc9
Improve tests
kdy1 Mar 23, 2025
4404fdb
fix test
kdy1 Mar 23, 2025
05a497d
Add a test
kdy1 Mar 23, 2025
e44c1a7
fixup
kdy1 Mar 23, 2025
cab37c8
build
kdy1 Mar 23, 2025
4858af1
negate_cost
kdy1 Mar 23, 2025
f3945e1
negate_cost
kdy1 Mar 23, 2025
cda8110
Improve negate_cost
kdy1 Mar 23, 2025
f139d17
Improve negate_cost
kdy1 Mar 23, 2025
c6e6fe9
Add a test
kdy1 Mar 23, 2025
eb01505
parenthesis
kdy1 Mar 23, 2025
7c759a0
Optimize negate
kdy1 Mar 23, 2025
4285011
More work
kdy1 Mar 23, 2025
29b4534
more work
kdy1 Mar 23, 2025
14f4b14
Update test refs
kdy1 Mar 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
@@ -1,5 +1,5 @@
foo({
bar: function(data, baz) {
!(!(baz ? data.quxA : data.quxB) && !(baz ? data.corgeA : data.corgeB) && (baz ? data.get("waldo") : data.waldo)) && ((baz ? data.quxA : data.quxB) || (baz ? data.get("waldo") : data.waldo) || (baz ? !data.corgeA : !data.corgeB)) || pass();
!(!(baz ? data.quxA : data.quxB) && !(baz ? data.corgeA : data.corgeB) && (baz ? data.get("waldo") : data.waldo)) ? !(baz ? data.quxA : data.quxB) && !(baz ? data.get("waldo") : data.waldo) && (baz ? data.corgeA : data.corgeB) && pass() : pass();
}
});
8 changes: 4 additions & 4 deletions crates/swc/tests/fixture/issues-4xxx/4816/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export function left() {
return(// left binop
check() || action(), foo());
!check() && action(), foo());
}
export function right() {
return check() || // right binop
return !check() && // right binop
action(), foo();
}
export function between() {
// between
return check() || action(), foo();
return !check() && action(), foo();
}
export function end() {
return check() || action(), foo();
return !check() && action(), foo();
} // end
24 changes: 12 additions & 12 deletions crates/swc/tests/libs-size.snapshot.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
| File | Original Size | Compressed Size | Gzipped Size |
| --- | --- | --- | --- |
| antd.js | 6.38 MiB | 2.05 MiB | 444.49 KiB |
| d3.js | 542.74 KiB | 259.02 KiB | 85.06 KiB |
| echarts.js | 3.41 MiB | 971.32 KiB | 313.36 KiB |
| jquery.js | 280.89 KiB | 87.12 KiB | 30.16 KiB |
| lodash.js | 531.35 KiB | 68.18 KiB | 24.52 KiB |
| moment.js | 169.83 KiB | 57.03 KiB | 18.21 KiB |
| react.js | 70.45 KiB | 22.28 KiB | 8.00 KiB |
| terser.js | 1.08 MiB | 444.90 KiB | 120.46 KiB |
| three.js | 1.19 MiB | 627.93 KiB | 154.57 KiB |
| typescript.js | 10.45 MiB | 3.17 MiB | 845.79 KiB |
| victory.js | 2.30 MiB | 689.66 KiB | 153.66 KiB |
| vue.js | 334.13 KiB | 112.95 KiB | 41.68 KiB |
| antd.js | 6.38 MiB | 2.05 MiB | 444.74 KiB |
| d3.js | 542.74 KiB | 259.08 KiB | 85.08 KiB |
| echarts.js | 3.41 MiB | 971.88 KiB | 313.57 KiB |
| jquery.js | 280.89 KiB | 87.22 KiB | 30.20 KiB |
| lodash.js | 531.35 KiB | 68.21 KiB | 24.54 KiB |
| moment.js | 169.83 KiB | 57.06 KiB | 18.24 KiB |
| react.js | 70.45 KiB | 22.29 KiB | 8.01 KiB |
| terser.js | 1.08 MiB | 445.08 KiB | 120.46 KiB |
| three.js | 1.19 MiB | 628.00 KiB | 154.59 KiB |
| typescript.js | 10.45 MiB | 3.17 MiB | 846.55 KiB |
| victory.js | 2.30 MiB | 689.76 KiB | 153.78 KiB |
| vue.js | 334.13 KiB | 113.04 KiB | 41.72 KiB |
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ global = this, factory = function(exports1) {
});
class _default {
}
}, "object" == typeof module && "object" == typeof module.exports ? factory(exports) : "function" == typeof define && define.amd ? define([
}, "object" != typeof module || "object" != typeof module.exports ? "function" == typeof define && define.amd ? define([
"exports"
], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.aTs = {});
], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.aTs = {}) : factory(exports);
//// [b.ts]
var global, factory;
global = this, factory = function(exports1) {
Expand All @@ -26,6 +26,6 @@ global = this, factory = function(exports1) {
return _default;
}
});
}, "object" == typeof module && "object" == typeof module.exports ? factory(exports) : "function" == typeof define && define.amd ? define([
}, "object" != typeof module || "object" != typeof module.exports ? "function" == typeof define && define.amd ? define([
"exports"
], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.bTs = {});
], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.bTs = {}) : factory(exports);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
_didIteratorError = !0, _iteratorError = err;
} finally{
try {
_iteratorNormalCompletion || null == _iterator.return || _iterator.return();
!_iteratorNormalCompletion && null != _iterator.return && _iterator.return();
} finally{
if (_didIteratorError) throw _iteratorError;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//// [callChain.2.ts]
var _o3_b;
null == o1 || o1(), null == o2 || o2.b(), null === (_o3_b = o3.b) || void 0 === _o3_b || _o3_b.call(o3).c;
null == o1 || o1(), null == o2 || o2.b(), null !== (_o3_b = o3.b) && void 0 !== _o3_b && _o3_b.call(o3).c;
14 changes: 7 additions & 7 deletions crates/swc/tests/tsc-references/callChain.2.minified.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ null == o1 || o1(), null == o1 || o1(1), null == o1 || o1.apply(void 0, [
2,
3,
4
]), null === (_o3_b6 = o3.b) || void 0 === _o3_b6 || _o3_b6.call(o3).c, null === (_o3_b7 = o3.b) || void 0 === _o3_b7 || _o3_b7.call(o3, 1).c, null === (_o3_b8 = o3.b) || void 0 === _o3_b8 || _o3_b8.call.apply(_o3_b8, [
]), null !== (_o3_b6 = o3.b) && void 0 !== _o3_b6 && _o3_b6.call(o3).c, null !== (_o3_b7 = o3.b) && void 0 !== _o3_b7 && _o3_b7.call(o3, 1).c, null !== (_o3_b8 = o3.b) && void 0 !== _o3_b8 && _o3_b8.call.apply(_o3_b8, [
o3,
1,
2
]).c, null === (_o3_b9 = o3.b) || void 0 === _o3_b9 || _o3_b9.call.apply(_o3_b9, [
]).c, null !== (_o3_b9 = o3.b) && void 0 !== _o3_b9 && _o3_b9.call.apply(_o3_b9, [
o3,
1,
2,
3,
4
]).c, null === (_o3_b10 = o3.b) || void 0 === _o3_b10 || _o3_b10.call(o3).c, null === (_o3_b11 = o3.b) || void 0 === _o3_b11 || _o3_b11.call(o3, 1).c, null === (_o3_b12 = o3.b) || void 0 === _o3_b12 || _o3_b12.call.apply(_o3_b12, [
]).c, null !== (_o3_b10 = o3.b) && void 0 !== _o3_b10 && _o3_b10.call(o3).c, null !== (_o3_b11 = o3.b) && void 0 !== _o3_b11 && _o3_b11.call(o3, 1).c, null !== (_o3_b12 = o3.b) && void 0 !== _o3_b12 && _o3_b12.call.apply(_o3_b12, [
o3,
1,
2
]).c, null === (_o3_b13 = o3.b) || void 0 === _o3_b13 || _o3_b13.call.apply(_o3_b13, [
]).c, null !== (_o3_b13 = o3.b) && void 0 !== _o3_b13 && _o3_b13.call.apply(_o3_b13, [
o3,
1,
2,
3,
4
]).c, null === (_o3_b14 = o3.b) || void 0 === _o3_b14 || _o3_b14.call(o3).c, null === (_o3_b15 = o3.b) || void 0 === _o3_b15 || _o3_b15.call(o3, 1).c, null === (_o3_b16 = o3.b) || void 0 === _o3_b16 || _o3_b16.call.apply(_o3_b16, [
]).c, null !== (_o3_b14 = o3.b) && void 0 !== _o3_b14 && _o3_b14.call(o3).c, null !== (_o3_b15 = o3.b) && void 0 !== _o3_b15 && _o3_b15.call(o3, 1).c, null !== (_o3_b16 = o3.b) && void 0 !== _o3_b16 && _o3_b16.call.apply(_o3_b16, [
o3,
1,
2
]).c, null === (_o3_b17 = o3.b) || void 0 === _o3_b17 || _o3_b17.call.apply(_o3_b17, [
]).c, null !== (_o3_b17 = o3.b) && void 0 !== _o3_b17 && _o3_b17.call.apply(_o3_b17, [
o3,
1,
2,
3,
4
]).c, null == o4 || o4(incr), null === (_o5 = o5()) || void 0 === _o5 || _o5(), null == o2 || o2.b().toString, null == o2 || o2.b().toString;
]).c, null == o4 || o4(incr), null === (_o5 = o5()) || void 0 === _o5 || _o5(), null != o2 && o2.b().toString, null != o2 && o2.b().toString;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ global = this, factory = function(exports1, _class_call_check) {
_class_call_check._(this, C);
};
C.x = 1;
}, "object" == typeof module && "object" == typeof module.exports ? factory(exports, require("@swc/helpers/_/_class_call_check")) : "function" == typeof define && define.amd ? define([
}, "object" != typeof module || "object" != typeof module.exports ? "function" == typeof define && define.amd ? define([
"exports",
"@swc/helpers/_/_class_call_check"
], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.classStaticBlock24Ts = {}, global.classCallCheck);
], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.classStaticBlock24Ts = {}, global.classCallCheck) : factory(exports, require("@swc/helpers/_/_class_call_check"));
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//// [controlFlowNullishCoalesce.ts]
var a;
null != o ? o : a = 1, a.toString(), null == o || o;
null == o ? a = 1 : o, a.toString(), null == o || o;

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

Loading
Loading