terser 5.3.3 → 5.3.7
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 +18 -0
- package/dist/bundle.min.js +61 -16
- package/dist/bundle.min.js.map +1 -1
- package/lib/compress/index.js +26 -15
- package/lib/output.js +4 -0
- package/lib/scope.js +27 -1
- package/lib/transform.js +5 -0
- package/package.json +2 -2
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;
|
@@ -4268,9 +4270,14 @@ AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
|
|
4268
4270
|
const defs = new Map();
|
4269
4271
|
const assignments = [];
|
4270
4272
|
value.properties.forEach(({ key, value }) => {
|
4273
|
+
const scope = find_scope(hoister);
|
4271
4274
|
const symbol = self.create_symbol(sym.CTOR, {
|
4272
4275
|
source: sym,
|
4273
|
-
scope
|
4276
|
+
scope,
|
4277
|
+
conflict_scopes: new Set([
|
4278
|
+
scope,
|
4279
|
+
...sym.definition().references.map(ref => ref.scope)
|
4280
|
+
]),
|
4274
4281
|
tentative_name: sym.name + "_" + key
|
4275
4282
|
});
|
4276
4283
|
|
@@ -4969,10 +4976,12 @@ AST_Definitions.DEFMETHOD("remove_initializers", function() {
|
|
4969
4976
|
|
4970
4977
|
AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
|
4971
4978
|
var reduce_vars = compressor.option("reduce_vars");
|
4972
|
-
var assignments =
|
4973
|
-
|
4979
|
+
var assignments = [];
|
4980
|
+
|
4981
|
+
for (const def of this.definitions) {
|
4982
|
+
if (def.value) {
|
4974
4983
|
var name = make_node(AST_SymbolRef, def.name, def.name);
|
4975
|
-
|
4984
|
+
assignments.push(make_node(AST_Assign, def, {
|
4976
4985
|
operator : "=",
|
4977
4986
|
left : name,
|
4978
4987
|
right : def.value
|
@@ -4987,13 +4996,13 @@ AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
|
|
4987
4996
|
var var_ = make_node(AST_Var, def, {
|
4988
4997
|
definitions: [ varDef ]
|
4989
4998
|
});
|
4990
|
-
|
4999
|
+
assignments.push(var_);
|
4991
5000
|
}
|
4992
|
-
|
4993
|
-
|
4994
|
-
|
4995
|
-
|
4996
|
-
|
5001
|
+
const thedef = def.name.definition();
|
5002
|
+
thedef.eliminated++;
|
5003
|
+
thedef.replaced--;
|
5004
|
+
}
|
5005
|
+
|
4997
5006
|
if (assignments.length == 0) return null;
|
4998
5007
|
return make_sequence(this, assignments);
|
4999
5008
|
});
|
@@ -6363,7 +6372,9 @@ def_optimize(AST_SymbolRef, function(self, compressor) {
|
|
6363
6372
|
&& !(parent instanceof AST_Call
|
6364
6373
|
&& (parent.is_expr_pure(compressor))
|
6365
6374
|
|| has_annotation(parent, _NOINLINE))
|
6366
|
-
&& !(
|
6375
|
+
&& !(parent instanceof AST_Export
|
6376
|
+
&& fixed instanceof AST_Lambda
|
6377
|
+
&& fixed.name);
|
6367
6378
|
|
6368
6379
|
if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
|
6369
6380
|
if (retain_top_func(fixed, compressor)) {
|
package/lib/output.js
CHANGED
package/lib/scope.js
CHANGED
@@ -493,6 +493,13 @@ AST_Scope.DEFMETHOD("conflicting_def", function (name) {
|
|
493
493
|
);
|
494
494
|
});
|
495
495
|
|
496
|
+
AST_Scope.DEFMETHOD("conflicting_def_shallow", function (name) {
|
497
|
+
return (
|
498
|
+
this.enclosed.find(def => def.name === name)
|
499
|
+
|| this.variables.has(name)
|
500
|
+
);
|
501
|
+
});
|
502
|
+
|
496
503
|
AST_Scope.DEFMETHOD("add_child_scope", function (scope) {
|
497
504
|
// `scope` is going to be moved into `this` right now.
|
498
505
|
// Update the required scopes' information
|
@@ -526,15 +533,34 @@ AST_Scope.DEFMETHOD("add_child_scope", function (scope) {
|
|
526
533
|
}
|
527
534
|
});
|
528
535
|
|
536
|
+
function find_scopes_visible_from(scopes) {
|
537
|
+
const found_scopes = new Set();
|
538
|
+
|
539
|
+
for (const scope of new Set(scopes)) {
|
540
|
+
(function bubble_up(scope) {
|
541
|
+
if (scope == null || found_scopes.has(scope)) return;
|
542
|
+
|
543
|
+
found_scopes.add(scope);
|
544
|
+
|
545
|
+
bubble_up(scope.parent_scope);
|
546
|
+
})(scope);
|
547
|
+
}
|
548
|
+
|
549
|
+
return [...found_scopes];
|
550
|
+
}
|
551
|
+
|
529
552
|
// Creates a symbol during compression
|
530
553
|
AST_Scope.DEFMETHOD("create_symbol", function(SymClass, {
|
531
554
|
source,
|
532
555
|
tentative_name,
|
533
556
|
scope,
|
557
|
+
conflict_scopes = [scope],
|
534
558
|
init = null
|
535
559
|
} = {}) {
|
536
560
|
let symbol_name;
|
537
561
|
|
562
|
+
conflict_scopes = find_scopes_visible_from(conflict_scopes);
|
563
|
+
|
538
564
|
if (tentative_name) {
|
539
565
|
// Implement hygiene (no new names are conflicting with existing names)
|
540
566
|
tentative_name =
|
@@ -542,7 +568,7 @@ AST_Scope.DEFMETHOD("create_symbol", function(SymClass, {
|
|
542
568
|
tentative_name.replace(/(?:^[^a-z_$]|[^a-z0-9_$])/ig, "_");
|
543
569
|
|
544
570
|
let i = 0;
|
545
|
-
while (
|
571
|
+
while (conflict_scopes.find(s => s.conflicting_def_shallow(symbol_name))) {
|
546
572
|
symbol_name = tentative_name + "$" + i++;
|
547
573
|
}
|
548
574
|
}
|
package/lib/transform.js
CHANGED
@@ -51,6 +51,7 @@ import {
|
|
51
51
|
AST_Call,
|
52
52
|
AST_Case,
|
53
53
|
AST_Catch,
|
54
|
+
AST_Chain,
|
54
55
|
AST_Class,
|
55
56
|
AST_Conditional,
|
56
57
|
AST_Definitions,
|
@@ -236,6 +237,10 @@ def_transform(AST_Sub, function(self, tw) {
|
|
236
237
|
self.property = self.property.transform(tw);
|
237
238
|
});
|
238
239
|
|
240
|
+
def_transform(AST_Chain, function(self, tw) {
|
241
|
+
self.expression = self.expression.transform(tw);
|
242
|
+
});
|
243
|
+
|
239
244
|
def_transform(AST_Yield, function(self, tw) {
|
240
245
|
if (self.expression) self.expression = self.expression.transform(tw);
|
241
246
|
});
|
package/package.json
CHANGED
@@ -4,9 +4,9 @@
|
|
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.7",
|
8
8
|
"engines": {
|
9
|
-
"node": ">=
|
9
|
+
"node": "^10.0.0 || ^11.0.0 || ^12.0.0 || >=14.0.0"
|
10
10
|
},
|
11
11
|
"maintainers": [
|
12
12
|
"Fábio Santos <fabiosantosart@gmail.com>"
|