terser 5.31.6 → 5.32.0
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 +6 -0
- package/dist/bundle.min.js +50 -16
- package/lib/compress/evaluate.js +17 -6
- package/lib/mozilla-ast.js +33 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.32.0
|
4
|
+
|
5
|
+
- `import("module")` can now be input and output from ESTree AST (#1557)
|
6
|
+
- `BigInt` literals can now be input and output from ESTree AST (#1555)
|
7
|
+
- `typeof` an object or array (`typeof {}` and `typeof []`) can now be statically evaluated. (#1546)
|
8
|
+
|
3
9
|
## v5.31.6
|
4
10
|
- Retain side effects in a `case` when the expression is a sequence (comma) expression
|
5
11
|
|
package/dist/bundle.min.js
CHANGED
@@ -7571,6 +7571,19 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7571
7571
|
});
|
7572
7572
|
},
|
7573
7573
|
|
7574
|
+
ImportExpression: function(M) {
|
7575
|
+
return new AST_Call({
|
7576
|
+
start: my_start_token(M),
|
7577
|
+
end: my_end_token(M),
|
7578
|
+
expression: from_moz({
|
7579
|
+
type: "Identifier",
|
7580
|
+
name: "import"
|
7581
|
+
}),
|
7582
|
+
optional: false,
|
7583
|
+
args: [from_moz(M.source)]
|
7584
|
+
});
|
7585
|
+
},
|
7586
|
+
|
7574
7587
|
ExportAllDeclaration: function(M) {
|
7575
7588
|
var foreign_name = M.exported == null ?
|
7576
7589
|
new AST_SymbolExportForeign({ name: "*" }) :
|
@@ -7638,6 +7651,11 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7638
7651
|
args.value = { source, flags };
|
7639
7652
|
return new AST_RegExp(args);
|
7640
7653
|
}
|
7654
|
+
const bi = typeof M.value === "bigint" ? M.value.toString() : M.bigint;
|
7655
|
+
if (typeof bi === "string") {
|
7656
|
+
args.value = bi;
|
7657
|
+
return new AST_BigInt(args);
|
7658
|
+
}
|
7641
7659
|
if (val === null) return new AST_Null(args);
|
7642
7660
|
switch (typeof val) {
|
7643
7661
|
case "string":
|
@@ -7705,14 +7723,6 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7705
7723
|
});
|
7706
7724
|
},
|
7707
7725
|
|
7708
|
-
BigIntLiteral(M) {
|
7709
|
-
return new AST_BigInt({
|
7710
|
-
start : my_start_token(M),
|
7711
|
-
end : my_end_token(M),
|
7712
|
-
value : M.value
|
7713
|
-
});
|
7714
|
-
},
|
7715
|
-
|
7716
7726
|
EmptyStatement: function(M) {
|
7717
7727
|
return new AST_EmptyStatement({
|
7718
7728
|
start: my_start_token(M),
|
@@ -8185,6 +8195,14 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8185
8195
|
};
|
8186
8196
|
});
|
8187
8197
|
def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
|
8198
|
+
if (M.expression instanceof AST_SymbolRef && M.expression.name === "import") {
|
8199
|
+
const [source] = M.args.map(to_moz);
|
8200
|
+
return {
|
8201
|
+
type: "ImportExpression",
|
8202
|
+
source,
|
8203
|
+
};
|
8204
|
+
}
|
8205
|
+
|
8188
8206
|
return {
|
8189
8207
|
type: "CallExpression",
|
8190
8208
|
callee: to_moz(M.expression),
|
@@ -8730,8 +8748,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8730
8748
|
});
|
8731
8749
|
|
8732
8750
|
def_to_moz(AST_BigInt, M => ({
|
8733
|
-
type: "
|
8734
|
-
value
|
8751
|
+
type: "Literal",
|
8752
|
+
// value cannot be represented natively
|
8753
|
+
// see: https://github.com/estree/estree/blob/master/es2020.md#bigintliteral
|
8754
|
+
value: null,
|
8755
|
+
// `M.value` is a string that may be a hex number representation.
|
8756
|
+
// but "bigint" property should have only decimal digits
|
8757
|
+
bigint: typeof BigInt === "function" ? BigInt(M.value).toString() : M.value,
|
8735
8758
|
}));
|
8736
8759
|
|
8737
8760
|
AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
|
@@ -14579,14 +14602,25 @@ def_eval(AST_Object, function (compressor, depth) {
|
|
14579
14602
|
var non_converting_unary = makePredicate("! typeof void");
|
14580
14603
|
def_eval(AST_UnaryPrefix, function (compressor, depth) {
|
14581
14604
|
var e = this.expression;
|
14582
|
-
// Function would be evaluated to an array and so typeof would
|
14583
|
-
// incorrectly return 'object'. Hence making is a special case.
|
14584
14605
|
if (compressor.option("typeofs")
|
14585
|
-
&& this.operator == "typeof"
|
14586
|
-
|
14606
|
+
&& this.operator == "typeof") {
|
14607
|
+
// Function would be evaluated to an array and so typeof would
|
14608
|
+
// incorrectly return 'object'. Hence making is a special case.
|
14609
|
+
if (e instanceof AST_Lambda
|
14587
14610
|
|| e instanceof AST_SymbolRef
|
14588
|
-
&& e.fixed_value() instanceof AST_Lambda)
|
14589
|
-
|
14611
|
+
&& e.fixed_value() instanceof AST_Lambda) {
|
14612
|
+
return typeof function () { };
|
14613
|
+
}
|
14614
|
+
if (
|
14615
|
+
(e instanceof AST_Object
|
14616
|
+
|| e instanceof AST_Array
|
14617
|
+
|| (e instanceof AST_SymbolRef
|
14618
|
+
&& (e.fixed_value() instanceof AST_Object
|
14619
|
+
|| e.fixed_value() instanceof AST_Array)))
|
14620
|
+
&& !e.has_side_effects(compressor)
|
14621
|
+
) {
|
14622
|
+
return typeof {};
|
14623
|
+
}
|
14590
14624
|
}
|
14591
14625
|
if (!non_converting_unary.has(this.operator))
|
14592
14626
|
depth++;
|
package/lib/compress/evaluate.js
CHANGED
@@ -218,14 +218,25 @@ def_eval(AST_Object, function (compressor, depth) {
|
|
218
218
|
var non_converting_unary = makePredicate("! typeof void");
|
219
219
|
def_eval(AST_UnaryPrefix, function (compressor, depth) {
|
220
220
|
var e = this.expression;
|
221
|
-
// Function would be evaluated to an array and so typeof would
|
222
|
-
// incorrectly return 'object'. Hence making is a special case.
|
223
221
|
if (compressor.option("typeofs")
|
224
|
-
&& this.operator == "typeof"
|
225
|
-
|
222
|
+
&& this.operator == "typeof") {
|
223
|
+
// Function would be evaluated to an array and so typeof would
|
224
|
+
// incorrectly return 'object'. Hence making is a special case.
|
225
|
+
if (e instanceof AST_Lambda
|
226
226
|
|| e instanceof AST_SymbolRef
|
227
|
-
&& e.fixed_value() instanceof AST_Lambda)
|
228
|
-
|
227
|
+
&& e.fixed_value() instanceof AST_Lambda) {
|
228
|
+
return typeof function () { };
|
229
|
+
}
|
230
|
+
if (
|
231
|
+
(e instanceof AST_Object
|
232
|
+
|| e instanceof AST_Array
|
233
|
+
|| (e instanceof AST_SymbolRef
|
234
|
+
&& (e.fixed_value() instanceof AST_Object
|
235
|
+
|| e.fixed_value() instanceof AST_Array)))
|
236
|
+
&& !e.has_side_effects(compressor)
|
237
|
+
) {
|
238
|
+
return typeof {};
|
239
|
+
}
|
229
240
|
}
|
230
241
|
if (!non_converting_unary.has(this.operator))
|
231
242
|
depth++;
|
package/lib/mozilla-ast.js
CHANGED
@@ -595,6 +595,19 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
595
595
|
});
|
596
596
|
},
|
597
597
|
|
598
|
+
ImportExpression: function(M) {
|
599
|
+
return new AST_Call({
|
600
|
+
start: my_start_token(M),
|
601
|
+
end: my_end_token(M),
|
602
|
+
expression: from_moz({
|
603
|
+
type: "Identifier",
|
604
|
+
name: "import"
|
605
|
+
}),
|
606
|
+
optional: false,
|
607
|
+
args: [from_moz(M.source)]
|
608
|
+
});
|
609
|
+
},
|
610
|
+
|
598
611
|
ExportAllDeclaration: function(M) {
|
599
612
|
var foreign_name = M.exported == null ?
|
600
613
|
new AST_SymbolExportForeign({ name: "*" }) :
|
@@ -662,6 +675,11 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
662
675
|
args.value = { source, flags };
|
663
676
|
return new AST_RegExp(args);
|
664
677
|
}
|
678
|
+
const bi = typeof M.value === "bigint" ? M.value.toString() : M.bigint;
|
679
|
+
if (typeof bi === "string") {
|
680
|
+
args.value = bi;
|
681
|
+
return new AST_BigInt(args);
|
682
|
+
}
|
665
683
|
if (val === null) return new AST_Null(args);
|
666
684
|
switch (typeof val) {
|
667
685
|
case "string":
|
@@ -729,14 +747,6 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
729
747
|
});
|
730
748
|
},
|
731
749
|
|
732
|
-
BigIntLiteral(M) {
|
733
|
-
return new AST_BigInt({
|
734
|
-
start : my_start_token(M),
|
735
|
-
end : my_end_token(M),
|
736
|
-
value : M.value
|
737
|
-
});
|
738
|
-
},
|
739
|
-
|
740
750
|
EmptyStatement: function(M) {
|
741
751
|
return new AST_EmptyStatement({
|
742
752
|
start: my_start_token(M),
|
@@ -1209,6 +1219,14 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1209
1219
|
};
|
1210
1220
|
});
|
1211
1221
|
def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
|
1222
|
+
if (M.expression instanceof AST_SymbolRef && M.expression.name === "import") {
|
1223
|
+
const [source] = M.args.map(to_moz);
|
1224
|
+
return {
|
1225
|
+
type: "ImportExpression",
|
1226
|
+
source,
|
1227
|
+
};
|
1228
|
+
}
|
1229
|
+
|
1212
1230
|
return {
|
1213
1231
|
type: "CallExpression",
|
1214
1232
|
callee: to_moz(M.expression),
|
@@ -1754,8 +1772,13 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1754
1772
|
});
|
1755
1773
|
|
1756
1774
|
def_to_moz(AST_BigInt, M => ({
|
1757
|
-
type: "
|
1758
|
-
value
|
1775
|
+
type: "Literal",
|
1776
|
+
// value cannot be represented natively
|
1777
|
+
// see: https://github.com/estree/estree/blob/master/es2020.md#bigintliteral
|
1778
|
+
value: null,
|
1779
|
+
// `M.value` is a string that may be a hex number representation.
|
1780
|
+
// but "bigint" property should have only decimal digits
|
1781
|
+
bigint: typeof BigInt === "function" ? BigInt(M.value).toString() : M.value,
|
1759
1782
|
}));
|
1760
1783
|
|
1761
1784
|
AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
|