terser 5.46.1 → 5.46.2
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
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v5.46.2
|
|
4
|
+
|
|
5
|
+
- `unused` option: delete computed keys of concise methods and getters/setters.
|
|
6
|
+
- `Error.cause` added to DOM properties list
|
|
7
|
+
- Don't consider `foo.bar` and `foo["bar"]` to be equivalent when property mangler is enabled with `keep_quoted=strict` option.
|
|
8
|
+
|
|
3
9
|
## v5.46.1
|
|
4
10
|
|
|
5
11
|
- Fix extremely slow (seemed like a freeze) `evaluate` of method chains
|
package/dist/bundle.min.js
CHANGED
|
@@ -11913,7 +11913,10 @@ AST_PropAccess.prototype.shallow_cmp = pass_through;
|
|
|
11913
11913
|
AST_Chain.prototype.shallow_cmp = pass_through;
|
|
11914
11914
|
|
|
11915
11915
|
AST_Dot.prototype.shallow_cmp = function(other) {
|
|
11916
|
-
return
|
|
11916
|
+
return (
|
|
11917
|
+
this.property === other.property
|
|
11918
|
+
&& !!this.quote === !!other.quote
|
|
11919
|
+
);
|
|
11917
11920
|
};
|
|
11918
11921
|
|
|
11919
11922
|
AST_DotHash.prototype.shallow_cmp = function(other) {
|
|
@@ -15809,8 +15812,8 @@ def_drop_side_effect_free([
|
|
|
15809
15812
|
AST_ConciseMethod,
|
|
15810
15813
|
AST_ObjectGetter,
|
|
15811
15814
|
AST_ObjectSetter,
|
|
15812
|
-
], function () {
|
|
15813
|
-
return this.computed_key() ? this.key : null;
|
|
15815
|
+
], function (compressor, first_in_statement) {
|
|
15816
|
+
return this.computed_key() ? this.key.drop_side_effect_free(compressor, first_in_statement) : null;
|
|
15814
15817
|
});
|
|
15815
15818
|
|
|
15816
15819
|
def_drop_side_effect_free([
|
|
@@ -16032,6 +16035,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
|
16032
16035
|
return scan_ref_scoped(node, descend);
|
|
16033
16036
|
});
|
|
16034
16037
|
self.walk(tw);
|
|
16038
|
+
|
|
16035
16039
|
// pass 2: for every used symbol we need to walk its
|
|
16036
16040
|
// initialization code to figure out if it uses other
|
|
16037
16041
|
// symbols (that may not be in_use).
|
|
@@ -16042,6 +16046,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
|
16042
16046
|
init.walk(tw);
|
|
16043
16047
|
});
|
|
16044
16048
|
});
|
|
16049
|
+
|
|
16045
16050
|
// pass 3: we should drop declarations not in_use
|
|
16046
16051
|
var tt = new TreeTransformer(
|
|
16047
16052
|
function before(node, descend, in_list) {
|
|
@@ -27128,6 +27133,7 @@ var domprops = [
|
|
|
27128
27133
|
"cast",
|
|
27129
27134
|
"catch",
|
|
27130
27135
|
"category",
|
|
27136
|
+
"cause",
|
|
27131
27137
|
"cbrt",
|
|
27132
27138
|
"cd",
|
|
27133
27139
|
"ceil",
|
|
@@ -312,8 +312,8 @@ def_drop_side_effect_free([
|
|
|
312
312
|
AST_ConciseMethod,
|
|
313
313
|
AST_ObjectGetter,
|
|
314
314
|
AST_ObjectSetter,
|
|
315
|
-
], function () {
|
|
316
|
-
return this.computed_key() ? this.key : null;
|
|
315
|
+
], function (compressor, first_in_statement) {
|
|
316
|
+
return this.computed_key() ? this.key.drop_side_effect_free(compressor, first_in_statement) : null;
|
|
317
317
|
});
|
|
318
318
|
|
|
319
319
|
def_drop_side_effect_free([
|
|
@@ -212,6 +212,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
|
212
212
|
return scan_ref_scoped(node, descend);
|
|
213
213
|
});
|
|
214
214
|
self.walk(tw);
|
|
215
|
+
|
|
215
216
|
// pass 2: for every used symbol we need to walk its
|
|
216
217
|
// initialization code to figure out if it uses other
|
|
217
218
|
// symbols (that may not be in_use).
|
|
@@ -222,6 +223,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
|
222
223
|
init.walk(tw);
|
|
223
224
|
});
|
|
224
225
|
});
|
|
226
|
+
|
|
225
227
|
// pass 3: we should drop declarations not in_use
|
|
226
228
|
var tt = new TreeTransformer(
|
|
227
229
|
function before(node, descend, in_list) {
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AST_Export,
|
|
3
|
+
AST_Import,
|
|
4
|
+
AST_Toplevel,
|
|
5
|
+
} from "../ast.js";
|
|
6
|
+
|
|
7
|
+
AST_Toplevel.DEFMETHOD("optimize_import_export", function(compressor) {
|
|
8
|
+
if (!compressor.option("import_export")) return;
|
|
9
|
+
|
|
10
|
+
// We will compare `stat` against `prev` to see if it's a compatible import/export
|
|
11
|
+
// When compatible, merge!
|
|
12
|
+
let stat_i = 1;
|
|
13
|
+
|
|
14
|
+
while (stat_i < this.body.length) {
|
|
15
|
+
const stat = this.body[stat_i];
|
|
16
|
+
const prev = this.body[stat_i - 1];
|
|
17
|
+
|
|
18
|
+
const merged_import =
|
|
19
|
+
(stat instanceof AST_Import && prev instanceof AST_Import)
|
|
20
|
+
&& merge_imports(prev, stat);
|
|
21
|
+
const merged_export =
|
|
22
|
+
(stat instanceof AST_Export && prev instanceof AST_Export)
|
|
23
|
+
&& merge_exports(prev, stat);
|
|
24
|
+
|
|
25
|
+
if (merged_import || merged_export) {
|
|
26
|
+
this.body.splice(stat_i, 1);
|
|
27
|
+
// Don't stat_i++. We can stay here.
|
|
28
|
+
} else {
|
|
29
|
+
stat_i++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/** Merge a compatible import statement. Or return false */
|
|
35
|
+
function merge_imports(into, merge_from) {
|
|
36
|
+
if (
|
|
37
|
+
// same "from"
|
|
38
|
+
into.module_name.value === merge_from.module_name.value
|
|
39
|
+
// only one can have a default import
|
|
40
|
+
&& !(into.imported_name && merge_from.imported_name)
|
|
41
|
+
// "*" not supported
|
|
42
|
+
&& can_merge_name_mappings(into.imported_names, merge_from.imported_names)
|
|
43
|
+
// "with" not supported
|
|
44
|
+
&& !into.attributes && !merge_from.attributes
|
|
45
|
+
) {
|
|
46
|
+
into.imported_name = into.imported_name || merge_from.imported_name;
|
|
47
|
+
into.imported_names = merge_name_mappings(into.imported_names, merge_from.imported_names);
|
|
48
|
+
|
|
49
|
+
return true; // `merge_from` can be safely removed
|
|
50
|
+
} else {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Merge a compatible export statement. Or return false */
|
|
56
|
+
function merge_exports(into, merge_from) {
|
|
57
|
+
if (
|
|
58
|
+
// "export function" not supported
|
|
59
|
+
!into.exported_value && !merge_from.exported_value
|
|
60
|
+
// "export from" not supported
|
|
61
|
+
&& !into.module_name && !merge_from.module_name
|
|
62
|
+
// "export default" not supported
|
|
63
|
+
&& !into.is_default && !merge_from.is_default
|
|
64
|
+
// "with" not supported
|
|
65
|
+
&& !into.attributes && !merge_from.attributes
|
|
66
|
+
) {
|
|
67
|
+
if (
|
|
68
|
+
// "export { a, b, c }"
|
|
69
|
+
into.exported_names && merge_from.exported_names
|
|
70
|
+
&& can_merge_name_mappings(into.exported_names, merge_from.exported_names)
|
|
71
|
+
) {
|
|
72
|
+
into.exported_names = merge_name_mappings(into.exported_names, merge_from.exported_names);
|
|
73
|
+
|
|
74
|
+
return true;
|
|
75
|
+
} else if (
|
|
76
|
+
// "export var xx"
|
|
77
|
+
into.exported_definition && merge_from.exported_definition
|
|
78
|
+
&& can_merge_definitions(into.exported_definition, merge_from.exported_definition)
|
|
79
|
+
) {
|
|
80
|
+
merge_definitions(into.exported_definition, merge_from.exported_definition);
|
|
81
|
+
|
|
82
|
+
return true;
|
|
83
|
+
} else {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Make sure a and b are optional AST_NameMapping*? arrays without the same names */
|
|
92
|
+
function can_merge_name_mappings(a, b) {
|
|
93
|
+
for (const mapping_array of [a, b]) {
|
|
94
|
+
for (const mapping of (mapping_array || [])) {
|
|
95
|
+
if (mapping.name.name === "*") return false;
|
|
96
|
+
if (mapping.foreign_name.name === "*") return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function merge_name_mappings(our_names, their_names) {
|
|
104
|
+
const arr_our_names = our_names || [];
|
|
105
|
+
const arr_their_names = their_names || [];
|
|
106
|
+
|
|
107
|
+
if (arr_our_names.length + arr_their_names.length > 0) {
|
|
108
|
+
return arr_our_names.concat(arr_their_names);
|
|
109
|
+
} else {
|
|
110
|
+
return our_names;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function can_merge_definitions(our_defs, their_defs) {
|
|
115
|
+
return our_defs.TYPE === their_defs.TYPE;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Merge two AST_Definitions */
|
|
119
|
+
function merge_definitions(our_defs, their_defs) {
|
|
120
|
+
our_defs.definitions.push(...their_defs.definitions);
|
|
121
|
+
}
|
package/lib/equivalent-to.js
CHANGED
|
@@ -211,7 +211,10 @@ AST_PropAccess.prototype.shallow_cmp = pass_through;
|
|
|
211
211
|
AST_Chain.prototype.shallow_cmp = pass_through;
|
|
212
212
|
|
|
213
213
|
AST_Dot.prototype.shallow_cmp = function(other) {
|
|
214
|
-
return
|
|
214
|
+
return (
|
|
215
|
+
this.property === other.property
|
|
216
|
+
&& !!this.quote === !!other.quote
|
|
217
|
+
);
|
|
215
218
|
};
|
|
216
219
|
|
|
217
220
|
AST_DotHash.prototype.shallow_cmp = function(other) {
|
package/package.json
CHANGED