terser 3.10.9 → 3.10.13

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/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) return node.reduce_vars(tw, descend, compressor);
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
- this.walk(tw);
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._top
4560
+ && fn instanceof AST_Defun
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")
@@ -5033,7 +5051,7 @@ merge(Compressor.prototype, {
5033
5051
  if (value) expressions.push(make_node(AST_Assign, self, {
5034
5052
  operator: "=",
5035
5053
  left: sym,
5036
- right: value.clone(true)
5054
+ right: value.clone()
5037
5055
  }));
5038
5056
  }
5039
5057
 
@@ -5730,6 +5748,19 @@ merge(Compressor.prototype, {
5730
5748
  return node;
5731
5749
  }
5732
5750
 
5751
+ function within_array_or_object_literal(compressor) {
5752
+ var node, level = 0;
5753
+ while (node = compressor.parent(level++)) {
5754
+ if (node instanceof AST_Statement) return false;
5755
+ if (node instanceof AST_Array
5756
+ || node instanceof AST_ObjectKeyVal
5757
+ || node instanceof AST_Object) {
5758
+ return true;
5759
+ }
5760
+ }
5761
+ return false;
5762
+ }
5763
+
5733
5764
  OPT(AST_SymbolRef, function(self, compressor) {
5734
5765
  if (!compressor.option("ie8")
5735
5766
  && is_undeclared_ref(self)
@@ -5746,14 +5777,23 @@ merge(Compressor.prototype, {
5746
5777
  var parent = compressor.parent();
5747
5778
  if (compressor.option("reduce_vars") && is_lhs(self, parent) !== self) {
5748
5779
  var d = self.definition();
5780
+ if (compressor.top_retain && d.global && compressor.top_retain(d)) {
5781
+ d.fixed = false;
5782
+ d.should_replace = false;
5783
+ d.single_use = false;
5784
+ return self;
5785
+ }
5749
5786
  var fixed = self.fixed_value();
5750
5787
  var single_use = d.single_use
5751
5788
  && !(parent instanceof AST_Call && parent.is_expr_pure(compressor));
5752
5789
  if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
5753
- if (d.scope !== self.scope
5790
+ if (retain_top_func(fixed, compressor)) {
5791
+ single_use = false;
5792
+ } else if (d.scope !== self.scope
5754
5793
  && (!compressor.option("reduce_funcs") && fixed instanceof AST_Lambda
5755
5794
  || d.escaped == 1
5756
- || fixed.inlined)) {
5795
+ || fixed.inlined
5796
+ || within_array_or_object_literal(compressor))) {
5757
5797
  single_use = false;
5758
5798
  } else if (recursive_ref(compressor, d)) {
5759
5799
  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 ? AST_SymbolImportForeign : AST_SymbolExportForeign);
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
@@ -275,6 +275,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
275
275
  if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name
276
276
  || !(sym = node.scope.find_variable(name))) {
277
277
  sym = self.def_global(node);
278
+ if (node instanceof AST_SymbolExport) sym.export = node.TYPE;
278
279
  } else if (sym.scope instanceof AST_Lambda && name == "arguments") {
279
280
  sym.scope.uses_arguments = true;
280
281
  }
@@ -570,7 +571,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
570
571
 
571
572
  function collect(symbol) {
572
573
  if (!member(symbol.name, options.reserved)) {
573
- to_mangle.push(symbol);
574
+ if (!symbol.export) to_mangle.push(symbol);
574
575
  }
575
576
  }
576
577
  });
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.10.9",
7
+ "version": "3.10.13",
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 node ../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 -c defaults=false -d \"MOZ_SourceMap=require('source-map')\" --source-map \"includeSources=true,url='bundle.js.map'\" -e \"exports:(typeof module != 'undefined' ? module.exports : Terser = {})\" -b ascii_only --comments /license/ -o ../dist/bundle.js"
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",