terser 5.3.0 → 5.3.4
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 +20 -0
- package/bin/terser.mjs +21 -0
- package/dist/bundle.min.js +74 -60
- package/dist/bundle.min.js.map +1 -1
- package/lib/compress/index.js +48 -52
- package/lib/equivalent-to.js +3 -0
- package/lib/minify.js +4 -4
- package/lib/output.js +8 -0
- package/lib/sourcemap.js +12 -4
- package/package.json +4 -3
- package/tools/terser.d.ts +2 -0
package/lib/compress/index.js
CHANGED
@@ -4140,9 +4140,12 @@ AST_Scope.DEFMETHOD("hoist_declarations", function(compressor) {
|
|
4140
4140
|
hoisted.push(node);
|
4141
4141
|
return make_node(AST_EmptyStatement, node);
|
4142
4142
|
}
|
4143
|
-
if (
|
4143
|
+
if (
|
4144
|
+
hoist_vars
|
4145
|
+
&& node instanceof AST_Var
|
4146
|
+
&& !node.definitions.some(def => def.name instanceof AST_Destructuring)
|
4147
|
+
) {
|
4144
4148
|
node.definitions.forEach(function(def) {
|
4145
|
-
if (def.name instanceof AST_Destructuring) return;
|
4146
4149
|
vars.set(def.name.name, def);
|
4147
4150
|
++vars_found;
|
4148
4151
|
});
|
@@ -4222,8 +4225,7 @@ AST_Scope.DEFMETHOD("hoist_declarations", function(compressor) {
|
|
4222
4225
|
continue;
|
4223
4226
|
}
|
4224
4227
|
if (self.body[i] instanceof AST_BlockStatement) {
|
4225
|
-
|
4226
|
-
self.body.splice.apply(self.body, tmp);
|
4228
|
+
self.body.splice(i, 1, ...self.body[i].body);
|
4227
4229
|
continue;
|
4228
4230
|
}
|
4229
4231
|
break;
|
@@ -4969,10 +4971,12 @@ AST_Definitions.DEFMETHOD("remove_initializers", function() {
|
|
4969
4971
|
|
4970
4972
|
AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
|
4971
4973
|
var reduce_vars = compressor.option("reduce_vars");
|
4972
|
-
var assignments =
|
4973
|
-
|
4974
|
+
var assignments = [];
|
4975
|
+
|
4976
|
+
for (const def of this.definitions) {
|
4977
|
+
if (def.value) {
|
4974
4978
|
var name = make_node(AST_SymbolRef, def.name, def.name);
|
4975
|
-
|
4979
|
+
assignments.push(make_node(AST_Assign, def, {
|
4976
4980
|
operator : "=",
|
4977
4981
|
left : name,
|
4978
4982
|
right : def.value
|
@@ -4987,13 +4991,13 @@ AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
|
|
4987
4991
|
var var_ = make_node(AST_Var, def, {
|
4988
4992
|
definitions: [ varDef ]
|
4989
4993
|
});
|
4990
|
-
|
4994
|
+
assignments.push(var_);
|
4991
4995
|
}
|
4992
|
-
|
4993
|
-
|
4994
|
-
|
4995
|
-
|
4996
|
-
|
4996
|
+
const thedef = def.name.definition();
|
4997
|
+
thedef.eliminated++;
|
4998
|
+
thedef.replaced--;
|
4999
|
+
}
|
5000
|
+
|
4997
5001
|
if (assignments.length == 0) return null;
|
4998
5002
|
return make_sequence(this, assignments);
|
4999
5003
|
});
|
@@ -5020,7 +5024,7 @@ function retain_top_func(fn, compressor) {
|
|
5020
5024
|
def_optimize(AST_Call, function(self, compressor) {
|
5021
5025
|
var exp = self.expression;
|
5022
5026
|
var fn = exp;
|
5023
|
-
inline_array_like_spread(self
|
5027
|
+
inline_array_like_spread(self.args);
|
5024
5028
|
var simple_args = self.args.every((arg) =>
|
5025
5029
|
!(arg instanceof AST_Expansion)
|
5026
5030
|
);
|
@@ -5980,7 +5984,7 @@ def_optimize(AST_Binary, function(self, compressor) {
|
|
5980
5984
|
&& self.left.left.getValue() == ""
|
5981
5985
|
&& self.right.is_string(compressor)) {
|
5982
5986
|
self.left = self.left.right;
|
5983
|
-
return self
|
5987
|
+
return self;
|
5984
5988
|
}
|
5985
5989
|
}
|
5986
5990
|
if (compressor.option("evaluate")) {
|
@@ -6079,25 +6083,6 @@ def_optimize(AST_Binary, function(self, compressor) {
|
|
6079
6083
|
var associative = true;
|
6080
6084
|
switch (self.operator) {
|
6081
6085
|
case "+":
|
6082
|
-
// "foo" + ("bar" + x) => "foobar" + x
|
6083
|
-
if (self.left instanceof AST_Constant
|
6084
|
-
&& self.right instanceof AST_Binary
|
6085
|
-
&& self.right.operator == "+"
|
6086
|
-
&& self.right.is_string(compressor)) {
|
6087
|
-
var binary = make_node(AST_Binary, self, {
|
6088
|
-
operator: "+",
|
6089
|
-
left: self.left,
|
6090
|
-
right: self.right.left,
|
6091
|
-
});
|
6092
|
-
var l = binary.optimize(compressor);
|
6093
|
-
if (binary !== l) {
|
6094
|
-
self = make_node(AST_Binary, self, {
|
6095
|
-
operator: "+",
|
6096
|
-
left: l,
|
6097
|
-
right: self.right.right
|
6098
|
-
});
|
6099
|
-
}
|
6100
|
-
}
|
6101
6086
|
// (x + "foo") + "bar" => x + "foobar"
|
6102
6087
|
if (self.right instanceof AST_Constant
|
6103
6088
|
&& self.left instanceof AST_Binary
|
@@ -6306,10 +6291,10 @@ def_optimize(AST_Binary, function(self, compressor) {
|
|
6306
6291
|
) {
|
6307
6292
|
self.left = make_node(AST_Binary, self.left, {
|
6308
6293
|
operator : self.operator,
|
6309
|
-
left : self.left,
|
6310
|
-
right : self.right.left
|
6294
|
+
left : self.left.transform(compressor),
|
6295
|
+
right : self.right.left.transform(compressor)
|
6311
6296
|
});
|
6312
|
-
self.right = self.right.right;
|
6297
|
+
self.right = self.right.right.transform(compressor);
|
6313
6298
|
return self.transform(compressor);
|
6314
6299
|
}
|
6315
6300
|
var ev = self.evaluate(compressor);
|
@@ -6412,7 +6397,8 @@ def_optimize(AST_SymbolRef, function(self, compressor) {
|
|
6412
6397
|
&& !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
|
6413
6398
|
|| parent instanceof AST_Call
|
6414
6399
|
&& parent.expression === self
|
6415
|
-
&& !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
|
6400
|
+
&& !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
|
6401
|
+
&& !(fixed.name && fixed.name.definition().recursive_refs > 0);
|
6416
6402
|
}
|
6417
6403
|
if (single_use && fixed instanceof AST_Class) {
|
6418
6404
|
const extends_inert = !fixed.extends
|
@@ -7325,12 +7311,15 @@ function literals_in_boolean_context(self, compressor) {
|
|
7325
7311
|
return self;
|
7326
7312
|
}
|
7327
7313
|
|
7328
|
-
function inline_array_like_spread(
|
7314
|
+
function inline_array_like_spread(elements) {
|
7329
7315
|
for (var i = 0; i < elements.length; i++) {
|
7330
7316
|
var el = elements[i];
|
7331
7317
|
if (el instanceof AST_Expansion) {
|
7332
7318
|
var expr = el.expression;
|
7333
|
-
if (
|
7319
|
+
if (
|
7320
|
+
expr instanceof AST_Array
|
7321
|
+
&& !expr.elements.some(elm => elm instanceof AST_Hole)
|
7322
|
+
) {
|
7334
7323
|
elements.splice(i, 1, ...expr.elements);
|
7335
7324
|
// Step back one, as the element at i is now new.
|
7336
7325
|
i--;
|
@@ -7339,7 +7328,6 @@ function inline_array_like_spread(self, compressor, elements) {
|
|
7339
7328
|
// We therefore can’t optimize anything else, unlike with object spread.
|
7340
7329
|
}
|
7341
7330
|
}
|
7342
|
-
return self;
|
7343
7331
|
}
|
7344
7332
|
|
7345
7333
|
def_optimize(AST_Array, function(self, compressor) {
|
@@ -7347,21 +7335,20 @@ def_optimize(AST_Array, function(self, compressor) {
|
|
7347
7335
|
if (optimized !== self) {
|
7348
7336
|
return optimized;
|
7349
7337
|
}
|
7350
|
-
|
7338
|
+
inline_array_like_spread(self.elements);
|
7339
|
+
return self;
|
7351
7340
|
});
|
7352
7341
|
|
7353
|
-
|
7354
|
-
var optimized = literals_in_boolean_context(self, compressor);
|
7355
|
-
if (optimized !== self) {
|
7356
|
-
return optimized;
|
7357
|
-
}
|
7358
|
-
var props = self.properties;
|
7342
|
+
function inline_object_prop_spread(props) {
|
7359
7343
|
for (var i = 0; i < props.length; i++) {
|
7360
7344
|
var prop = props[i];
|
7361
7345
|
if (prop instanceof AST_Expansion) {
|
7362
|
-
|
7363
|
-
if (
|
7364
|
-
|
7346
|
+
const expr = prop.expression;
|
7347
|
+
if (
|
7348
|
+
expr instanceof AST_Object
|
7349
|
+
&& expr.properties.every(prop => prop instanceof AST_ObjectKeyVal)
|
7350
|
+
) {
|
7351
|
+
props.splice(i, 1, ...expr.properties);
|
7365
7352
|
// Step back one, as the property at i is now new.
|
7366
7353
|
i--;
|
7367
7354
|
} else if (expr instanceof AST_Constant
|
@@ -7373,6 +7360,14 @@ def_optimize(AST_Object, function(self, compressor) {
|
|
7373
7360
|
}
|
7374
7361
|
}
|
7375
7362
|
}
|
7363
|
+
}
|
7364
|
+
|
7365
|
+
def_optimize(AST_Object, function(self, compressor) {
|
7366
|
+
var optimized = literals_in_boolean_context(self, compressor);
|
7367
|
+
if (optimized !== self) {
|
7368
|
+
return optimized;
|
7369
|
+
}
|
7370
|
+
inline_object_prop_spread(self.properties);
|
7376
7371
|
return self;
|
7377
7372
|
});
|
7378
7373
|
|
@@ -7572,7 +7567,8 @@ def_optimize(AST_Destructuring, function(self, compressor) {
|
|
7572
7567
|
&& compressor.option("unused")
|
7573
7568
|
&& !self.is_array
|
7574
7569
|
&& Array.isArray(self.names)
|
7575
|
-
&& !is_destructuring_export_decl(compressor)
|
7570
|
+
&& !is_destructuring_export_decl(compressor)
|
7571
|
+
&& !(self.names[self.names.length - 1] instanceof AST_Expansion)) {
|
7576
7572
|
var keep = [];
|
7577
7573
|
for (var i = 0; i < self.names.length; i++) {
|
7578
7574
|
var elem = self.names[i];
|
package/lib/equivalent-to.js
CHANGED
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
AST_Block,
|
8
8
|
AST_Call,
|
9
9
|
AST_Catch,
|
10
|
+
AST_Chain,
|
10
11
|
AST_Class,
|
11
12
|
AST_ClassProperty,
|
12
13
|
AST_ConciseMethod,
|
@@ -226,6 +227,8 @@ AST_Sequence.prototype.shallow_cmp = pass_through;
|
|
226
227
|
|
227
228
|
AST_PropAccess.prototype.shallow_cmp = pass_through;
|
228
229
|
|
230
|
+
AST_Chain.prototype.shallow_cmp = pass_through;
|
231
|
+
|
229
232
|
AST_Dot.prototype.shallow_cmp = mkshallow({
|
230
233
|
property: "eq"
|
231
234
|
});
|
package/lib/minify.js
CHANGED
@@ -205,10 +205,7 @@ async function minify(files, options) {
|
|
205
205
|
}
|
206
206
|
if (!HOP(options.format, "code") || options.format.code) {
|
207
207
|
if (options.sourceMap) {
|
208
|
-
|
209
|
-
options.sourceMap.content = JSON.parse(options.sourceMap.content);
|
210
|
-
}
|
211
|
-
options.format.source_map = SourceMap({
|
208
|
+
options.format.source_map = await SourceMap({
|
212
209
|
file: options.sourceMap.filename,
|
213
210
|
orig: options.sourceMap.content,
|
214
211
|
root: options.sourceMap.root
|
@@ -246,6 +243,9 @@ async function minify(files, options) {
|
|
246
243
|
options.nameCache.props = cache_to_json(options.mangle.properties.cache);
|
247
244
|
}
|
248
245
|
}
|
246
|
+
if (options.format && options.format.source_map) {
|
247
|
+
options.format.source_map.destroy();
|
248
|
+
}
|
249
249
|
if (timings) {
|
250
250
|
timings.end = Date.now();
|
251
251
|
result.timings = {
|
package/lib/output.js
CHANGED
@@ -893,6 +893,14 @@ function OutputStream(options) {
|
|
893
893
|
|
894
894
|
PARENS(AST_Arrow, function(output) {
|
895
895
|
var p = output.parent();
|
896
|
+
|
897
|
+
if (
|
898
|
+
output.option("wrap_func_args")
|
899
|
+
&& p instanceof AST_Call
|
900
|
+
&& p.args.includes(this)
|
901
|
+
) {
|
902
|
+
return true;
|
903
|
+
}
|
896
904
|
return p instanceof AST_PropAccess && p.expression === this;
|
897
905
|
});
|
898
906
|
|
package/lib/sourcemap.js
CHANGED
@@ -49,7 +49,7 @@ import {
|
|
49
49
|
} from "./utils/index.js";
|
50
50
|
|
51
51
|
// a small wrapper around fitzgen's source-map library
|
52
|
-
function SourceMap(options) {
|
52
|
+
async function SourceMap(options) {
|
53
53
|
options = defaults(options, {
|
54
54
|
file : null,
|
55
55
|
root : null,
|
@@ -58,13 +58,15 @@ function SourceMap(options) {
|
|
58
58
|
orig_line_diff : 0,
|
59
59
|
dest_line_diff : 0,
|
60
60
|
});
|
61
|
+
|
62
|
+
var orig_map;
|
61
63
|
var generator = new MOZ_SourceMap.SourceMapGenerator({
|
62
64
|
file : options.file,
|
63
65
|
sourceRoot : options.root
|
64
66
|
});
|
65
|
-
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
|
66
67
|
|
67
|
-
if (
|
68
|
+
if (options.orig) {
|
69
|
+
orig_map = await new MOZ_SourceMap.SourceMapConsumer(options.orig);
|
68
70
|
orig_map.sources.forEach(function(source) {
|
69
71
|
var sourceContent = orig_map.sourceContentFor(source, true);
|
70
72
|
if (sourceContent) {
|
@@ -94,10 +96,16 @@ function SourceMap(options) {
|
|
94
96
|
name : name
|
95
97
|
});
|
96
98
|
}
|
99
|
+
|
97
100
|
return {
|
98
101
|
add : add,
|
99
102
|
get : function() { return generator; },
|
100
|
-
toString : function() { return
|
103
|
+
toString : function() { return generator.toString(); },
|
104
|
+
destroy : function () {
|
105
|
+
if (orig_map && orig_map.destroy) {
|
106
|
+
orig_map.destroy();
|
107
|
+
}
|
108
|
+
}
|
101
109
|
};
|
102
110
|
}
|
103
111
|
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"homepage": "https://terser.org",
|
5
5
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
6
6
|
"license": "BSD-2-Clause",
|
7
|
-
"version": "5.3.
|
7
|
+
"version": "5.3.4",
|
8
8
|
"engines": {
|
9
9
|
"node": ">=6.0.0"
|
10
10
|
},
|
@@ -44,8 +44,8 @@
|
|
44
44
|
],
|
45
45
|
"dependencies": {
|
46
46
|
"commander": "^2.20.0",
|
47
|
-
"source-map": "~0.
|
48
|
-
"source-map-support": "~0.5.
|
47
|
+
"source-map": "~0.7.2",
|
48
|
+
"source-map-support": "~0.5.19"
|
49
49
|
},
|
50
50
|
"devDependencies": {
|
51
51
|
"@ls-lint/ls-lint": "^1.9.2",
|
@@ -142,6 +142,7 @@
|
|
142
142
|
}
|
143
143
|
},
|
144
144
|
"pre-commit": [
|
145
|
+
"build",
|
145
146
|
"lint-fix",
|
146
147
|
"ls-lint",
|
147
148
|
"test"
|
package/tools/terser.d.ts
CHANGED