terser 3.10.10 → 3.11.0
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.
Potentially problematic release.
This version of terser might be problematic. Click here for more details.
- package/README.md +2 -0
- package/bin/uglifyjs +3 -5
- package/dist/bundle.js +3 -11993
- package/dist/bundle.js.map +1 -1
- package/lib/compress.js +46 -5
- package/lib/parse.js +1 -1
- package/lib/scope.js +14 -3
- package/package.json +2 -2
package/lib/compress.js
CHANGED
@@ -854,11 +854,20 @@ merge(Compressor.prototype, {
|
|
854
854
|
});
|
855
855
|
|
856
856
|
AST_Toplevel.DEFMETHOD("reset_opt_flags", function(compressor) {
|
857
|
+
var self = this;
|
857
858
|
var reduce_vars = compressor.option("reduce_vars");
|
858
859
|
var tw = new TreeWalker(function(node, descend) {
|
859
860
|
node._squeezed = false;
|
860
861
|
node._optimized = false;
|
861
|
-
if (reduce_vars)
|
862
|
+
if (reduce_vars) {
|
863
|
+
if (compressor.top_retain) {
|
864
|
+
if (tw.parent() === self)
|
865
|
+
node._top = true;
|
866
|
+
else
|
867
|
+
delete node._top;
|
868
|
+
}
|
869
|
+
return node.reduce_vars(tw, descend, compressor);
|
870
|
+
}
|
862
871
|
});
|
863
872
|
// Stack of look-up tables to keep track of whether a `SymbolDef` has been
|
864
873
|
// properly assigned before use:
|
@@ -867,7 +876,7 @@ merge(Compressor.prototype, {
|
|
867
876
|
tw.safe_ids = Object.create(null);
|
868
877
|
tw.in_loop = null;
|
869
878
|
tw.loop_ids = Object.create(null);
|
870
|
-
|
879
|
+
self.walk(tw);
|
871
880
|
});
|
872
881
|
|
873
882
|
AST_Symbol.DEFMETHOD("fixed_value", function() {
|
@@ -4545,6 +4554,14 @@ merge(Compressor.prototype, {
|
|
4545
4554
|
return self;
|
4546
4555
|
});
|
4547
4556
|
|
4557
|
+
function retain_top_func(fn, compressor) {
|
4558
|
+
return compressor.top_retain
|
4559
|
+
&& fn instanceof AST_Defun
|
4560
|
+
&& fn._top
|
4561
|
+
&& fn.name
|
4562
|
+
&& compressor.top_retain(fn.name);
|
4563
|
+
}
|
4564
|
+
|
4548
4565
|
OPT(AST_Call, function(self, compressor) {
|
4549
4566
|
var exp = self.expression;
|
4550
4567
|
var fn = exp;
|
@@ -4553,6 +4570,7 @@ merge(Compressor.prototype, {
|
|
4553
4570
|
});
|
4554
4571
|
if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef) {
|
4555
4572
|
fn = fn.fixed_value();
|
4573
|
+
if (retain_top_func(fn, compressor)) fn = exp;
|
4556
4574
|
}
|
4557
4575
|
var is_func = fn instanceof AST_Lambda;
|
4558
4576
|
if (compressor.option("unused")
|
@@ -4884,7 +4902,8 @@ merge(Compressor.prototype, {
|
|
4884
4902
|
&& fn.is_constant_expression(exp.scope))
|
4885
4903
|
&& !self.pure
|
4886
4904
|
&& !fn.contains_this()
|
4887
|
-
&& can_inject_symbols()
|
4905
|
+
&& can_inject_symbols()
|
4906
|
+
&& !(scope instanceof AST_Class)) {
|
4888
4907
|
fn._squeezed = true;
|
4889
4908
|
return make_sequence(self, flatten_fn()).optimize(compressor);
|
4890
4909
|
}
|
@@ -5730,6 +5749,19 @@ merge(Compressor.prototype, {
|
|
5730
5749
|
return node;
|
5731
5750
|
}
|
5732
5751
|
|
5752
|
+
function within_array_or_object_literal(compressor) {
|
5753
|
+
var node, level = 0;
|
5754
|
+
while (node = compressor.parent(level++)) {
|
5755
|
+
if (node instanceof AST_Statement) return false;
|
5756
|
+
if (node instanceof AST_Array
|
5757
|
+
|| node instanceof AST_ObjectKeyVal
|
5758
|
+
|| node instanceof AST_Object) {
|
5759
|
+
return true;
|
5760
|
+
}
|
5761
|
+
}
|
5762
|
+
return false;
|
5763
|
+
}
|
5764
|
+
|
5733
5765
|
OPT(AST_SymbolRef, function(self, compressor) {
|
5734
5766
|
if (!compressor.option("ie8")
|
5735
5767
|
&& is_undeclared_ref(self)
|
@@ -5746,14 +5778,23 @@ merge(Compressor.prototype, {
|
|
5746
5778
|
var parent = compressor.parent();
|
5747
5779
|
if (compressor.option("reduce_vars") && is_lhs(self, parent) !== self) {
|
5748
5780
|
var d = self.definition();
|
5781
|
+
if (compressor.top_retain && d.global && compressor.top_retain(d)) {
|
5782
|
+
d.fixed = false;
|
5783
|
+
d.should_replace = false;
|
5784
|
+
d.single_use = false;
|
5785
|
+
return self;
|
5786
|
+
}
|
5749
5787
|
var fixed = self.fixed_value();
|
5750
5788
|
var single_use = d.single_use
|
5751
5789
|
&& !(parent instanceof AST_Call && parent.is_expr_pure(compressor));
|
5752
5790
|
if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
|
5753
|
-
if (
|
5791
|
+
if (retain_top_func(fixed, compressor)) {
|
5792
|
+
single_use = false;
|
5793
|
+
} else if (d.scope !== self.scope
|
5754
5794
|
&& (!compressor.option("reduce_funcs") && fixed instanceof AST_Lambda
|
5755
5795
|
|| d.escaped == 1
|
5756
|
-
|| fixed.inlined
|
5796
|
+
|| fixed.inlined
|
5797
|
+
|| within_array_or_object_literal(compressor))) {
|
5757
5798
|
single_use = false;
|
5758
5799
|
} else if (recursive_ref(compressor, d)) {
|
5759
5800
|
single_use = false;
|
package/lib/parse.js
CHANGED
@@ -2530,7 +2530,7 @@ function parse($TEXT, options) {
|
|
2530
2530
|
next();
|
2531
2531
|
if (is_import && is("name", "as")) {
|
2532
2532
|
next(); // The "as" word
|
2533
|
-
name = as_symbol(is_import ?
|
2533
|
+
name = as_symbol(is_import ? AST_SymbolImport : AST_SymbolExportForeign);
|
2534
2534
|
}
|
2535
2535
|
names = [map_nameAsterisk(is_import, name)];
|
2536
2536
|
}
|
package/lib/scope.js
CHANGED
@@ -60,12 +60,15 @@ function SymbolDef(scope, orig, init) {
|
|
60
60
|
|
61
61
|
SymbolDef.next_id = 1;
|
62
62
|
|
63
|
+
var MASK_EXPORT_DONT_MANGLE = 1 << 0;
|
64
|
+
var MASK_EXPORT_WANT_MANGLE = 1 << 1;
|
65
|
+
|
63
66
|
SymbolDef.prototype = {
|
64
67
|
unmangleable: function(options) {
|
65
68
|
if (!options) options = {};
|
66
69
|
|
67
70
|
return this.global && !options.toplevel
|
68
|
-
|| this.export
|
71
|
+
|| (this.export & MASK_EXPORT_DONT_MANGLE)
|
69
72
|
|| this.undeclared
|
70
73
|
|| !options.eval && this.scope.pinned()
|
71
74
|
|| (this.orig[0] instanceof AST_SymbolLambda
|
@@ -252,7 +255,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|
252
255
|
} while (tw.parent(i++) !== in_destructuring);
|
253
256
|
}
|
254
257
|
var node = tw.parent(level);
|
255
|
-
def.export = node instanceof AST_Export
|
258
|
+
if (def.export = node instanceof AST_Export && MASK_EXPORT_DONT_MANGLE) {
|
259
|
+
var exported = node.exported_definition;
|
260
|
+
if ((exported instanceof AST_Defun || exported instanceof AST_DefClass) && node.is_default) {
|
261
|
+
def.export = MASK_EXPORT_WANT_MANGLE;
|
262
|
+
}
|
263
|
+
}
|
256
264
|
}
|
257
265
|
});
|
258
266
|
self.walk(tw);
|
@@ -275,6 +283,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|
275
283
|
if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name
|
276
284
|
|| !(sym = node.scope.find_variable(name))) {
|
277
285
|
sym = self.def_global(node);
|
286
|
+
if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE;
|
278
287
|
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
|
279
288
|
sym.scope.uses_arguments = true;
|
280
289
|
}
|
@@ -570,7 +579,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|
570
579
|
|
571
580
|
function collect(symbol) {
|
572
581
|
if (!member(symbol.name, options.reserved)) {
|
573
|
-
|
582
|
+
if (!(symbol.export & MASK_EXPORT_DONT_MANGLE)) {
|
583
|
+
to_mangle.push(symbol);
|
584
|
+
}
|
574
585
|
}
|
575
586
|
}
|
576
587
|
});
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"homepage": "https://github.com/fabiosantoscode/terser",
|
5
5
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
6
6
|
"license": "BSD-2-Clause",
|
7
|
-
"version": "3.
|
7
|
+
"version": "3.11.0",
|
8
8
|
"engines": {
|
9
9
|
"node": ">=0.8.0"
|
10
10
|
},
|
@@ -49,7 +49,7 @@
|
|
49
49
|
"coveralls": "coveralls < coverage/lcov.info",
|
50
50
|
"lint": "eslint lib",
|
51
51
|
"lint-fix": "eslint --fix lib",
|
52
|
-
"prepare": "cd dist && TERSER_NO_BUNDLE=1
|
52
|
+
"prepare": "cd dist && TERSER_NO_BUNDLE=1 ../bin/uglifyjs ../lib/utils.js ../lib/ast.js ../lib/parse.js ../lib/transform.js ../lib/scope.js ../lib/output.js ../lib/compress.js ../lib/sourcemap.js ../lib/mozilla-ast.js ../lib/propmangle.js ../lib/minify.js ../tools/exports.js -mc -d \"MOZ_SourceMap=require('source-map')\" --source-map \"includeSources=true,url='bundle.js.map'\" -e \"exports:(typeof module != 'undefined' ? module.exports : Terser = {})\" -b beautify=false,ascii_only --comments /license/ -o ../dist/bundle.js"
|
53
53
|
},
|
54
54
|
"keywords": [
|
55
55
|
"uglify",
|