terser 5.37.0 → 5.38.1
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 +9 -0
- package/README.md +2 -5
- package/dist/bundle.min.js +23 -7
- package/lib/compress/evaluate.js +7 -2
- package/lib/compress/index.js +15 -5
- package/lib/parse.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.38.1
|
4
|
+
|
5
|
+
- Fix inlining non-call expressions into an `optional_call?.()`
|
6
|
+
|
7
|
+
## v5.38.0
|
8
|
+
|
9
|
+
- Remove `console` method-of-method calls (eg `console.log.apply()`) when `drop_console` option is used (#1585)
|
10
|
+
- Remove more object spreads, such as `{ ...void !0 }` (#1142)
|
11
|
+
|
3
12
|
## v5.37.0
|
4
13
|
|
5
14
|
- Reserved object properties from chrome extensions (domprops)
|
package/README.md
CHANGED
@@ -647,7 +647,7 @@ console.log(result.map); // source map
|
|
647
647
|
Note that the source map is not saved in a file, it's just returned in
|
648
648
|
`result.map`. The value passed for `sourceMap.url` is only used to set
|
649
649
|
`//# sourceMappingURL=out.js.map` in `result.code`. The value of
|
650
|
-
`filename` is only used to set `file` attribute (see [the spec]
|
650
|
+
`filename` is only used to set `file` attribute (see [the spec](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k))
|
651
651
|
in source map file.
|
652
652
|
|
653
653
|
You can set option `sourceMap.url` to be `"inline"` and source map will
|
@@ -1233,7 +1233,7 @@ Terser has its own abstract syntax tree format; for
|
|
1233
1233
|
we can't easily change to using the SpiderMonkey AST internally. However,
|
1234
1234
|
Terser now has a converter which can import a SpiderMonkey AST.
|
1235
1235
|
|
1236
|
-
For example [Acorn]
|
1236
|
+
For example [Acorn](https://github.com/acornjs/acorn) is a super-fast parser that produces a
|
1237
1237
|
SpiderMonkey AST. It has a small CLI utility that parses one file and dumps
|
1238
1238
|
the AST in JSON on the standard output. To use Terser to mangle and
|
1239
1239
|
compress that:
|
@@ -1257,9 +1257,6 @@ Acorn is really fast (e.g. 250ms instead of 380ms on some 650K code), but
|
|
1257
1257
|
converting the SpiderMonkey tree that Acorn produces takes another 150ms so
|
1258
1258
|
in total it's a bit more than just using Terser's own parser.
|
1259
1259
|
|
1260
|
-
[acorn]: https://github.com/ternjs/acorn
|
1261
|
-
[sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k
|
1262
|
-
|
1263
1260
|
### Terser Fast Minify Mode
|
1264
1261
|
|
1265
1262
|
It's not well known, but whitespace removal and symbol mangling accounts
|
package/dist/bundle.min.js
CHANGED
@@ -3286,6 +3286,7 @@ function parse($TEXT, options) {
|
|
3286
3286
|
return subscripts(call, true, is_chain);
|
3287
3287
|
}
|
3288
3288
|
|
3289
|
+
// Optional chain
|
3289
3290
|
if (is("punc", "?.")) {
|
3290
3291
|
next();
|
3291
3292
|
|
@@ -14575,8 +14576,13 @@ AST_Node.DEFMETHOD("is_constant", function () {
|
|
14575
14576
|
return !(this instanceof AST_RegExp);
|
14576
14577
|
} else {
|
14577
14578
|
return this instanceof AST_UnaryPrefix
|
14578
|
-
&& this.
|
14579
|
-
&&
|
14579
|
+
&& unaryPrefix.has(this.operator)
|
14580
|
+
&& (
|
14581
|
+
// `this.expression` may be an `AST_RegExp`,
|
14582
|
+
// so not only `.is_constant()`.
|
14583
|
+
this.expression instanceof AST_Constant
|
14584
|
+
|| this.expression.is_constant()
|
14585
|
+
);
|
14580
14586
|
}
|
14581
14587
|
});
|
14582
14588
|
|
@@ -18982,17 +18988,19 @@ AST_Toplevel.DEFMETHOD("drop_console", function(options) {
|
|
18982
18988
|
return;
|
18983
18989
|
}
|
18984
18990
|
|
18985
|
-
if (isArray && !options.includes(exp.property)) {
|
18986
|
-
return;
|
18987
|
-
}
|
18988
|
-
|
18989
18991
|
var name = exp.expression;
|
18992
|
+
var property = exp.property;
|
18990
18993
|
var depth = 2;
|
18991
18994
|
while (name.expression) {
|
18995
|
+
property = name.property;
|
18992
18996
|
name = name.expression;
|
18993
18997
|
depth++;
|
18994
18998
|
}
|
18995
18999
|
|
19000
|
+
if (isArray && !options.includes(property)) {
|
19001
|
+
return;
|
19002
|
+
}
|
19003
|
+
|
18996
19004
|
if (is_undeclared_ref(name) && name.name == "console") {
|
18997
19005
|
if (
|
18998
19006
|
depth === 3
|
@@ -22130,7 +22138,15 @@ def_optimize(AST_Chain, function (self, compressor) {
|
|
22130
22138
|
}
|
22131
22139
|
return make_node(AST_Undefined, self);
|
22132
22140
|
}
|
22133
|
-
|
22141
|
+
if (
|
22142
|
+
self.expression instanceof AST_PropAccess
|
22143
|
+
|| self.expression instanceof AST_Call
|
22144
|
+
) {
|
22145
|
+
return self;
|
22146
|
+
} else {
|
22147
|
+
// Keep the AST valid, in case the child swapped itself
|
22148
|
+
return self.expression;
|
22149
|
+
}
|
22134
22150
|
});
|
22135
22151
|
|
22136
22152
|
def_optimize(AST_Dot, function(self, compressor) {
|
package/lib/compress/evaluate.js
CHANGED
@@ -117,8 +117,13 @@ AST_Node.DEFMETHOD("is_constant", function () {
|
|
117
117
|
return !(this instanceof AST_RegExp);
|
118
118
|
} else {
|
119
119
|
return this instanceof AST_UnaryPrefix
|
120
|
-
&& this.
|
121
|
-
&&
|
120
|
+
&& unaryPrefix.has(this.operator)
|
121
|
+
&& (
|
122
|
+
// `this.expression` may be an `AST_RegExp`,
|
123
|
+
// so not only `.is_constant()`.
|
124
|
+
this.expression instanceof AST_Constant
|
125
|
+
|| this.expression.is_constant()
|
126
|
+
);
|
122
127
|
}
|
123
128
|
});
|
124
129
|
|
package/lib/compress/index.js
CHANGED
@@ -524,17 +524,19 @@ AST_Toplevel.DEFMETHOD("drop_console", function(options) {
|
|
524
524
|
return;
|
525
525
|
}
|
526
526
|
|
527
|
-
if (isArray && !options.includes(exp.property)) {
|
528
|
-
return;
|
529
|
-
}
|
530
|
-
|
531
527
|
var name = exp.expression;
|
528
|
+
var property = exp.property;
|
532
529
|
var depth = 2;
|
533
530
|
while (name.expression) {
|
531
|
+
property = name.property;
|
534
532
|
name = name.expression;
|
535
533
|
depth++;
|
536
534
|
}
|
537
535
|
|
536
|
+
if (isArray && !options.includes(property)) {
|
537
|
+
return;
|
538
|
+
}
|
539
|
+
|
538
540
|
if (is_undeclared_ref(name) && name.name == "console") {
|
539
541
|
if (
|
540
542
|
depth === 3
|
@@ -3672,7 +3674,15 @@ def_optimize(AST_Chain, function (self, compressor) {
|
|
3672
3674
|
}
|
3673
3675
|
return make_node(AST_Undefined, self);
|
3674
3676
|
}
|
3675
|
-
|
3677
|
+
if (
|
3678
|
+
self.expression instanceof AST_PropAccess
|
3679
|
+
|| self.expression instanceof AST_Call
|
3680
|
+
) {
|
3681
|
+
return self;
|
3682
|
+
} else {
|
3683
|
+
// Keep the AST valid, in case the child swapped itself
|
3684
|
+
return self.expression;
|
3685
|
+
}
|
3676
3686
|
});
|
3677
3687
|
|
3678
3688
|
def_optimize(AST_Dot, function(self, compressor) {
|
package/lib/parse.js
CHANGED