terser 5.31.4 → 5.31.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/dist/bundle.min.js +18 -22
- package/lib/ast.js +0 -3
- package/lib/compress/drop-side-effect-free.js +1 -1
- package/lib/compress/drop-unused.js +1 -1
- package/lib/compress/index.js +13 -14
- package/lib/compress/inference.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## v5.31.
|
3
|
+
## v5.31.6
|
4
|
+
- Retain side effects in a `case` when the expression is a sequence (comma) expression
|
5
|
+
|
6
|
+
## v5.31.5
|
7
|
+
- Revert v5.31.4, which created mysterious issues #1548, #1549
|
8
|
+
|
9
|
+
## v5.31.4 (reverted)
|
4
10
|
- drop_unused: drop classes which only have side effects in the `extends` part
|
5
11
|
|
6
12
|
## v5.31.3
|
package/dist/bundle.min.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@jridgewell/source-map')) :
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', '@jridgewell/source-map'], factory) :
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Terser = {}, global.sourceMap));
|
5
|
-
}
|
5
|
+
}(this, (function (exports, sourceMap) { 'use strict';
|
6
6
|
|
7
7
|
/***********************************************************************
|
8
8
|
|
@@ -5905,9 +5905,6 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
|
|
5905
5905
|
}));
|
5906
5906
|
return found;
|
5907
5907
|
},
|
5908
|
-
body_has_side_effects(compressor) {
|
5909
|
-
return this.properties.some(prop => prop.has_side_effects(compressor));
|
5910
|
-
},
|
5911
5908
|
}, AST_Scope /* TODO a class might have a scope but it's not a scope */);
|
5912
5909
|
|
5913
5910
|
var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_ClassProperty(props) {
|
@@ -13839,7 +13836,7 @@ function is_nullish(node, compressor) {
|
|
13839
13836
|
return any(this.definitions, compressor);
|
13840
13837
|
});
|
13841
13838
|
def_has_side_effects(AST_VarDef, function() {
|
13842
|
-
return this.value;
|
13839
|
+
return this.value != null;
|
13843
13840
|
});
|
13844
13841
|
def_has_side_effects(AST_TemplateSegment, return_false);
|
13845
13842
|
def_has_side_effects(AST_TemplateString, function(compressor) {
|
@@ -14982,7 +14979,7 @@ def_drop_side_effect_free(AST_Arrow, return_null);
|
|
14982
14979
|
def_drop_side_effect_free(AST_Class, function (compressor) {
|
14983
14980
|
const with_effects = [];
|
14984
14981
|
|
14985
|
-
if (this.is_self_referential() && this.
|
14982
|
+
if (this.is_self_referential() && this.has_side_effects(compressor)) {
|
14986
14983
|
return this;
|
14987
14984
|
}
|
14988
14985
|
|
@@ -15290,7 +15287,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
15290
15287
|
});
|
15291
15288
|
}
|
15292
15289
|
if (node === self) return;
|
15293
|
-
if (node instanceof AST_Class && node.
|
15290
|
+
if (node instanceof AST_Class && node.has_side_effects(compressor)) {
|
15294
15291
|
if (node.is_self_referential()) {
|
15295
15292
|
descend();
|
15296
15293
|
} else {
|
@@ -19591,7 +19588,9 @@ def_optimize(AST_Switch, function(self, compressor) {
|
|
19591
19588
|
eliminate_branch(branch, body[body.length - 1]);
|
19592
19589
|
continue;
|
19593
19590
|
}
|
19594
|
-
if (exp instanceof AST_Node
|
19591
|
+
if (exp instanceof AST_Node && !exp.has_side_effects(compressor)) {
|
19592
|
+
exp = branch.expression.tail_node().evaluate(compressor);
|
19593
|
+
}
|
19595
19594
|
if (exp === value) {
|
19596
19595
|
exact_match = branch;
|
19597
19596
|
if (default_branch) {
|
@@ -19773,12 +19772,9 @@ def_optimize(AST_Switch, function(self, compressor) {
|
|
19773
19772
|
break DEFAULT;
|
19774
19773
|
}
|
19775
19774
|
|
19776
|
-
let sideEffect = body.find(
|
19777
|
-
|
19778
|
-
|
19779
|
-
&& branch.expression.has_side_effects(compressor)
|
19780
|
-
);
|
19781
|
-
});
|
19775
|
+
let sideEffect = body.find(
|
19776
|
+
branch => branch !== default_or_exact && branch.expression.has_side_effects(compressor)
|
19777
|
+
);
|
19782
19778
|
// If no cases cause a side-effect, we can eliminate the switch entirely.
|
19783
19779
|
if (!sideEffect) {
|
19784
19780
|
return make_node(AST_BlockStatement, self, {
|
@@ -19886,9 +19882,10 @@ def_optimize(AST_Switch, function(self, compressor) {
|
|
19886
19882
|
right: branch.expression,
|
19887
19883
|
}),
|
19888
19884
|
body: consequent,
|
19889
|
-
alternative: null
|
19890
|
-
})
|
19891
|
-
|
19885
|
+
alternative: null,
|
19886
|
+
}),
|
19887
|
+
always,
|
19888
|
+
],
|
19892
19889
|
}).optimize(compressor);
|
19893
19890
|
}
|
19894
19891
|
return self;
|
@@ -19911,13 +19908,12 @@ def_optimize(AST_Switch, function(self, compressor) {
|
|
19911
19908
|
let pblock = make_node(AST_BlockStatement, prev, { body: pbody });
|
19912
19909
|
return bblock.equivalent_to(pblock);
|
19913
19910
|
}
|
19914
|
-
function statement(
|
19915
|
-
return make_node(AST_SimpleStatement,
|
19916
|
-
body: expression
|
19917
|
-
});
|
19911
|
+
function statement(body) {
|
19912
|
+
return make_node(AST_SimpleStatement, body, { body });
|
19918
19913
|
}
|
19919
19914
|
function has_nested_break(root) {
|
19920
19915
|
let has_break = false;
|
19916
|
+
|
19921
19917
|
let tw = new TreeWalker(node => {
|
19922
19918
|
if (has_break) return true;
|
19923
19919
|
if (node instanceof AST_Lambda) return true;
|
@@ -32550,4 +32546,4 @@ exports._run_cli = run_cli;
|
|
32550
32546
|
exports.minify = minify;
|
32551
32547
|
exports.minify_sync = minify_sync;
|
32552
32548
|
|
32553
|
-
}));
|
32549
|
+
})));
|
package/lib/ast.js
CHANGED
@@ -2289,9 +2289,6 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
|
|
2289
2289
|
}));
|
2290
2290
|
return found;
|
2291
2291
|
},
|
2292
|
-
body_has_side_effects(compressor) {
|
2293
|
-
return this.properties.some(prop => prop.has_side_effects(compressor));
|
2294
|
-
},
|
2295
2292
|
}, AST_Scope /* TODO a class might have a scope but it's not a scope */);
|
2296
2293
|
|
2297
2294
|
var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_ClassProperty(props) {
|
@@ -156,7 +156,7 @@ def_drop_side_effect_free(AST_Arrow, return_null);
|
|
156
156
|
def_drop_side_effect_free(AST_Class, function (compressor) {
|
157
157
|
const with_effects = [];
|
158
158
|
|
159
|
-
if (this.is_self_referential() && this.
|
159
|
+
if (this.is_self_referential() && this.has_side_effects(compressor)) {
|
160
160
|
return this;
|
161
161
|
}
|
162
162
|
|
@@ -153,7 +153,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
153
153
|
});
|
154
154
|
}
|
155
155
|
if (node === self) return;
|
156
|
-
if (node instanceof AST_Class && node.
|
156
|
+
if (node instanceof AST_Class && node.has_side_effects(compressor)) {
|
157
157
|
if (node.is_self_referential()) {
|
158
158
|
descend();
|
159
159
|
} else {
|
package/lib/compress/index.js
CHANGED
@@ -1233,7 +1233,9 @@ def_optimize(AST_Switch, function(self, compressor) {
|
|
1233
1233
|
eliminate_branch(branch, body[body.length - 1]);
|
1234
1234
|
continue;
|
1235
1235
|
}
|
1236
|
-
if (exp instanceof AST_Node
|
1236
|
+
if (exp instanceof AST_Node && !exp.has_side_effects(compressor)) {
|
1237
|
+
exp = branch.expression.tail_node().evaluate(compressor);
|
1238
|
+
}
|
1237
1239
|
if (exp === value) {
|
1238
1240
|
exact_match = branch;
|
1239
1241
|
if (default_branch) {
|
@@ -1415,12 +1417,9 @@ def_optimize(AST_Switch, function(self, compressor) {
|
|
1415
1417
|
break DEFAULT;
|
1416
1418
|
}
|
1417
1419
|
|
1418
|
-
let sideEffect = body.find(
|
1419
|
-
|
1420
|
-
|
1421
|
-
&& branch.expression.has_side_effects(compressor)
|
1422
|
-
);
|
1423
|
-
});
|
1420
|
+
let sideEffect = body.find(
|
1421
|
+
branch => branch !== default_or_exact && branch.expression.has_side_effects(compressor)
|
1422
|
+
);
|
1424
1423
|
// If no cases cause a side-effect, we can eliminate the switch entirely.
|
1425
1424
|
if (!sideEffect) {
|
1426
1425
|
return make_node(AST_BlockStatement, self, {
|
@@ -1528,9 +1527,10 @@ def_optimize(AST_Switch, function(self, compressor) {
|
|
1528
1527
|
right: branch.expression,
|
1529
1528
|
}),
|
1530
1529
|
body: consequent,
|
1531
|
-
alternative: null
|
1532
|
-
})
|
1533
|
-
|
1530
|
+
alternative: null,
|
1531
|
+
}),
|
1532
|
+
always,
|
1533
|
+
],
|
1534
1534
|
}).optimize(compressor);
|
1535
1535
|
}
|
1536
1536
|
return self;
|
@@ -1553,13 +1553,12 @@ def_optimize(AST_Switch, function(self, compressor) {
|
|
1553
1553
|
let pblock = make_node(AST_BlockStatement, prev, { body: pbody });
|
1554
1554
|
return bblock.equivalent_to(pblock);
|
1555
1555
|
}
|
1556
|
-
function statement(
|
1557
|
-
return make_node(AST_SimpleStatement,
|
1558
|
-
body: expression
|
1559
|
-
});
|
1556
|
+
function statement(body) {
|
1557
|
+
return make_node(AST_SimpleStatement, body, { body });
|
1560
1558
|
}
|
1561
1559
|
function has_nested_break(root) {
|
1562
1560
|
let has_break = false;
|
1561
|
+
|
1563
1562
|
let tw = new TreeWalker(node => {
|
1564
1563
|
if (has_break) return true;
|
1565
1564
|
if (node instanceof AST_Lambda) return true;
|
@@ -424,7 +424,7 @@ export function is_nullish(node, compressor) {
|
|
424
424
|
return any(this.definitions, compressor);
|
425
425
|
});
|
426
426
|
def_has_side_effects(AST_VarDef, function() {
|
427
|
-
return this.value;
|
427
|
+
return this.value != null;
|
428
428
|
});
|
429
429
|
def_has_side_effects(AST_TemplateSegment, return_false);
|
430
430
|
def_has_side_effects(AST_TemplateString, function(compressor) {
|