terser 5.3.4 → 5.3.8
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 +44 -3
- package/dist/bundle.min.js.map +1 -1
- package/lib/compress/index.js +9 -2
- package/lib/output.js +4 -0
- package/lib/scope.js +27 -1
- package/lib/transform.js +5 -0
- package/package.json +11 -12
package/lib/compress/index.js
CHANGED
@@ -4270,9 +4270,14 @@ AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
|
|
4270
4270
|
const defs = new Map();
|
4271
4271
|
const assignments = [];
|
4272
4272
|
value.properties.forEach(({ key, value }) => {
|
4273
|
+
const scope = find_scope(hoister);
|
4273
4274
|
const symbol = self.create_symbol(sym.CTOR, {
|
4274
4275
|
source: sym,
|
4275
|
-
scope
|
4276
|
+
scope,
|
4277
|
+
conflict_scopes: new Set([
|
4278
|
+
scope,
|
4279
|
+
...sym.definition().references.map(ref => ref.scope)
|
4280
|
+
]),
|
4276
4281
|
tentative_name: sym.name + "_" + key
|
4277
4282
|
});
|
4278
4283
|
|
@@ -6367,7 +6372,9 @@ def_optimize(AST_SymbolRef, function(self, compressor) {
|
|
6367
6372
|
&& !(parent instanceof AST_Call
|
6368
6373
|
&& (parent.is_expr_pure(compressor))
|
6369
6374
|
|| has_annotation(parent, _NOINLINE))
|
6370
|
-
&& !(
|
6375
|
+
&& !(parent instanceof AST_Export
|
6376
|
+
&& fixed instanceof AST_Lambda
|
6377
|
+
&& fixed.name);
|
6371
6378
|
|
6372
6379
|
if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
|
6373
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.8",
|
8
8
|
"engines": {
|
9
|
-
"node": ">=
|
9
|
+
"node": ">=10"
|
10
10
|
},
|
11
11
|
"maintainers": [
|
12
12
|
"Fábio Santos <fabiosantosart@gmail.com>"
|
@@ -16,16 +16,15 @@
|
|
16
16
|
"type": "module",
|
17
17
|
"module": "./main.js",
|
18
18
|
"exports": {
|
19
|
-
".":
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
"
|
25
|
-
|
26
|
-
"./package.json"
|
27
|
-
|
28
|
-
}
|
19
|
+
".": [
|
20
|
+
{
|
21
|
+
"import": "./main.js",
|
22
|
+
"require": "./dist/bundle.min.js"
|
23
|
+
},
|
24
|
+
"./dist/bundle.min.js"
|
25
|
+
],
|
26
|
+
"./package": "./package.json",
|
27
|
+
"./package.json": "./package.json"
|
29
28
|
},
|
30
29
|
"types": "tools/terser.d.ts",
|
31
30
|
"bin": {
|