terser 3.10.11 → 3.10.12

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")
@@ -5746,11 +5764,19 @@ merge(Compressor.prototype, {
5746
5764
  var parent = compressor.parent();
5747
5765
  if (compressor.option("reduce_vars") && is_lhs(self, parent) !== self) {
5748
5766
  var d = self.definition();
5767
+ if (compressor.top_retain && d.global && compressor.top_retain(d)) {
5768
+ d.fixed = false;
5769
+ d.should_replace = false;
5770
+ d.single_use = false;
5771
+ return self;
5772
+ }
5749
5773
  var fixed = self.fixed_value();
5750
5774
  var single_use = d.single_use
5751
5775
  && !(parent instanceof AST_Call && parent.is_expr_pure(compressor));
5752
5776
  if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
5753
- if (d.scope !== self.scope
5777
+ if (retain_top_func(fixed, compressor)) {
5778
+ single_use = false;
5779
+ } else if (d.scope !== self.scope
5754
5780
  && (!compressor.option("reduce_funcs") && fixed instanceof AST_Lambda
5755
5781
  || d.escaped == 1
5756
5782
  || fixed.inlined)) {
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.11",
7
+ "version": "3.10.12",
8
8
  "engines": {
9
9
  "node": ">=0.8.0"
10
10
  },