terser 5.7.2 → 5.11.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 +36 -0
- package/README.md +21 -2
- package/dist/bundle.min.js +705 -213
- package/lib/ast.js +6 -4
- package/lib/compress/drop-side-effect-free.js +9 -12
- package/lib/compress/evaluate.js +15 -12
- package/lib/compress/index.js +368 -66
- package/lib/compress/inference.js +27 -13
- package/lib/compress/native-objects.js +1 -0
- package/lib/compress/tighten-body.js +29 -7
- package/lib/minify.js +3 -1
- package/lib/mozilla-ast.js +48 -6
- package/lib/output.js +81 -26
- package/lib/parse.js +24 -8
- package/lib/propmangle.js +57 -34
- package/lib/scope.js +42 -21
- package/lib/transform.js +2 -2
- package/package.json +9 -9
- package/tools/terser.d.ts +36 -0
package/lib/ast.js
CHANGED
@@ -889,12 +889,13 @@ var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", {
|
|
889
889
|
},
|
890
890
|
});
|
891
891
|
|
892
|
-
var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", {
|
892
|
+
var AST_Import = DEFNODE("Import", "imported_name imported_names module_name assert_clause", {
|
893
893
|
$documentation: "An `import` statement",
|
894
894
|
$propdoc: {
|
895
895
|
imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
|
896
896
|
imported_names: "[AST_NameMapping*] The names of non-default imported variables",
|
897
897
|
module_name: "[AST_String] String literal describing where this module came from",
|
898
|
+
assert_clause: "[AST_Object?] The import assertion"
|
898
899
|
},
|
899
900
|
_walk: function(visitor) {
|
900
901
|
return visitor._visit(this, function() {
|
@@ -923,14 +924,15 @@ var AST_ImportMeta = DEFNODE("ImportMeta", null, {
|
|
923
924
|
$documentation: "A reference to import.meta",
|
924
925
|
});
|
925
926
|
|
926
|
-
var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name", {
|
927
|
+
var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name assert_clause", {
|
927
928
|
$documentation: "An `export` statement",
|
928
929
|
$propdoc: {
|
929
930
|
exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition",
|
930
931
|
exported_value: "[AST_Node?] An exported value",
|
931
932
|
exported_names: "[AST_NameMapping*?] List of exported names",
|
932
933
|
module_name: "[AST_String?] Name of the file to load exports from",
|
933
|
-
is_default: "[Boolean] Whether this is the default exported value of this module"
|
934
|
+
is_default: "[Boolean] Whether this is the default exported value of this module",
|
935
|
+
assert_clause: "[AST_Object?] The import assertion"
|
934
936
|
},
|
935
937
|
_walk: function (visitor) {
|
936
938
|
return visitor._visit(this, function () {
|
@@ -1330,7 +1332,7 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", {
|
|
1330
1332
|
}
|
1331
1333
|
}, AST_ObjectProperty);
|
1332
1334
|
|
1333
|
-
var AST_ClassPrivateProperty = DEFNODE("
|
1335
|
+
var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", {
|
1334
1336
|
$documentation: "A class property for a private property",
|
1335
1337
|
}, AST_ClassProperty);
|
1336
1338
|
|
@@ -73,13 +73,12 @@ import {
|
|
73
73
|
AST_TemplateString,
|
74
74
|
AST_This,
|
75
75
|
AST_Unary,
|
76
|
-
AST_Undefined,
|
77
76
|
} from "../ast.js";
|
78
77
|
import { make_node, return_null, return_this } from "../utils/index.js";
|
79
78
|
import { first_in_statement } from "../utils/first_in_statement.js";
|
80
79
|
|
81
80
|
import { pure_prop_access_globals } from "./native-objects.js";
|
82
|
-
import { lazy_op, unary_side_effects,
|
81
|
+
import { lazy_op, unary_side_effects, is_nullish_shortcircuited } from "./inference.js";
|
83
82
|
import { WRITE_ONLY, set_flag, clear_flag } from "./compressor-flags.js";
|
84
83
|
import { make_sequence, is_func_expr, is_iife_call } from "./common.js";
|
85
84
|
|
@@ -121,8 +120,8 @@ def_drop_side_effect_free(AST_Constant, return_null);
|
|
121
120
|
def_drop_side_effect_free(AST_This, return_null);
|
122
121
|
|
123
122
|
def_drop_side_effect_free(AST_Call, function (compressor, first_in_statement) {
|
124
|
-
if (
|
125
|
-
return
|
123
|
+
if (is_nullish_shortcircuited(this, compressor)) {
|
124
|
+
return this.expression.drop_side_effect_free(compressor, first_in_statement);
|
126
125
|
}
|
127
126
|
|
128
127
|
if (!this.is_callee_pure(compressor)) {
|
@@ -298,21 +297,19 @@ def_drop_side_effect_free(AST_Array, function (compressor, first_in_statement) {
|
|
298
297
|
});
|
299
298
|
|
300
299
|
def_drop_side_effect_free(AST_Dot, function (compressor, first_in_statement) {
|
301
|
-
if (this
|
302
|
-
return
|
300
|
+
if (is_nullish_shortcircuited(this, compressor)) {
|
301
|
+
return this.expression.drop_side_effect_free(compressor, first_in_statement);
|
303
302
|
}
|
304
|
-
if (this.expression.may_throw_on_access(compressor))
|
305
|
-
return this;
|
303
|
+
if (this.expression.may_throw_on_access(compressor)) return this;
|
306
304
|
|
307
305
|
return this.expression.drop_side_effect_free(compressor, first_in_statement);
|
308
306
|
});
|
309
307
|
|
310
308
|
def_drop_side_effect_free(AST_Sub, function (compressor, first_in_statement) {
|
311
|
-
if (this
|
312
|
-
return
|
309
|
+
if (is_nullish_shortcircuited(this, compressor)) {
|
310
|
+
return this.expression.drop_side_effect_free(compressor, first_in_statement);
|
313
311
|
}
|
314
|
-
if (this.expression.may_throw_on_access(compressor))
|
315
|
-
return this;
|
312
|
+
if (this.expression.may_throw_on_access(compressor)) return this;
|
316
313
|
|
317
314
|
var expression = this.expression.drop_side_effect_free(compressor, first_in_statement);
|
318
315
|
if (!expression)
|
package/lib/compress/evaluate.js
CHANGED
@@ -82,6 +82,9 @@ function def_eval(node, func) {
|
|
82
82
|
node.DEFMETHOD("_eval", func);
|
83
83
|
}
|
84
84
|
|
85
|
+
// Used to propagate a nullish short-circuit signal upwards through the chain.
|
86
|
+
export const nullish = Symbol("This AST_Chain is nullish");
|
87
|
+
|
85
88
|
// If the node has been successfully reduced to a constant,
|
86
89
|
// then its value is returned; otherwise the element itself
|
87
90
|
// is returned.
|
@@ -93,7 +96,7 @@ AST_Node.DEFMETHOD("evaluate", function (compressor) {
|
|
93
96
|
var val = this._eval(compressor, 1);
|
94
97
|
if (!val || val instanceof RegExp)
|
95
98
|
return val;
|
96
|
-
if (typeof val == "function" || typeof val == "object")
|
99
|
+
if (typeof val == "function" || typeof val == "object" || val == nullish)
|
97
100
|
return this;
|
98
101
|
return val;
|
99
102
|
});
|
@@ -338,11 +341,8 @@ const regexp_flags = new Set([
|
|
338
341
|
]);
|
339
342
|
|
340
343
|
def_eval(AST_PropAccess, function (compressor, depth) {
|
341
|
-
|
342
|
-
|
343
|
-
if (obj == null)
|
344
|
-
return undefined;
|
345
|
-
}
|
344
|
+
const obj = this.expression._eval(compressor, depth);
|
345
|
+
if (obj === nullish || (this.optional && obj == null)) return nullish;
|
346
346
|
if (compressor.option("unsafe")) {
|
347
347
|
var key = this.property;
|
348
348
|
if (key instanceof AST_Node) {
|
@@ -397,16 +397,19 @@ def_eval(AST_PropAccess, function (compressor, depth) {
|
|
397
397
|
|
398
398
|
def_eval(AST_Chain, function (compressor, depth) {
|
399
399
|
const evaluated = this.expression._eval(compressor, depth);
|
400
|
-
return evaluated ===
|
400
|
+
return evaluated === nullish
|
401
|
+
? undefined
|
402
|
+
: evaluated === this.expression
|
403
|
+
? this
|
404
|
+
: evaluated;
|
401
405
|
});
|
402
406
|
|
403
407
|
def_eval(AST_Call, function (compressor, depth) {
|
404
408
|
var exp = this.expression;
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
}
|
409
|
+
|
410
|
+
const callee = exp._eval(compressor, depth);
|
411
|
+
if (callee === nullish || (this.optional && callee == null)) return nullish;
|
412
|
+
|
410
413
|
if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
|
411
414
|
var key = exp.property;
|
412
415
|
if (key instanceof AST_Node) {
|