terser 3.10.8 → 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() {
@@ -4174,22 +4183,8 @@ merge(Compressor.prototype, {
4174
4183
  }
4175
4184
  }
4176
4185
 
4177
- function use_increment(self) {
4178
- if (self.step instanceof AST_Assign
4179
- && self.step.operator === "+="
4180
- && self.step.left instanceof AST_Symbol
4181
- && self.step.right.print_to_string() === "1"
4182
- ) {
4183
- self.step = make_node(AST_UnaryPrefix, self.step, {
4184
- operator: "++",
4185
- expression: self.step.left
4186
- });
4187
- }
4188
- }
4189
-
4190
4186
  OPT(AST_For, function(self, compressor) {
4191
4187
  if (!compressor.option("loops")) return self;
4192
- use_increment(self);
4193
4188
  if (compressor.option("side_effects") && self.init) {
4194
4189
  self.init = self.init.drop_side_effect_free(compressor);
4195
4190
  }
@@ -4559,6 +4554,14 @@ merge(Compressor.prototype, {
4559
4554
  return self;
4560
4555
  });
4561
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
+
4562
4565
  OPT(AST_Call, function(self, compressor) {
4563
4566
  var exp = self.expression;
4564
4567
  var fn = exp;
@@ -4567,6 +4570,7 @@ merge(Compressor.prototype, {
4567
4570
  });
4568
4571
  if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef) {
4569
4572
  fn = fn.fixed_value();
4573
+ if (retain_top_func(fn, compressor)) fn = exp;
4570
4574
  }
4571
4575
  var is_func = fn instanceof AST_Lambda;
4572
4576
  if (compressor.option("unused")
@@ -5047,7 +5051,7 @@ merge(Compressor.prototype, {
5047
5051
  if (value) expressions.push(make_node(AST_Assign, self, {
5048
5052
  operator: "=",
5049
5053
  left: sym,
5050
- right: value.clone(true)
5054
+ right: value.clone()
5051
5055
  }));
5052
5056
  }
5053
5057
 
@@ -5760,11 +5764,19 @@ merge(Compressor.prototype, {
5760
5764
  var parent = compressor.parent();
5761
5765
  if (compressor.option("reduce_vars") && is_lhs(self, parent) !== self) {
5762
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
+ }
5763
5773
  var fixed = self.fixed_value();
5764
5774
  var single_use = d.single_use
5765
5775
  && !(parent instanceof AST_Call && parent.is_expr_pure(compressor));
5766
5776
  if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
5767
- if (d.scope !== self.scope
5777
+ if (retain_top_func(fixed, compressor)) {
5778
+ single_use = false;
5779
+ } else if (d.scope !== self.scope
5768
5780
  && (!compressor.option("reduce_funcs") && fixed instanceof AST_Lambda
5769
5781
  || d.escaped == 1
5770
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.8",
7
+ "version": "3.10.12",
8
8
  "engines": {
9
9
  "node": ">=0.8.0"
10
10
  },
@@ -39,8 +39,7 @@
39
39
  "eslint": "^4.19.1",
40
40
  "istanbul": "^0.4.5",
41
41
  "mocha": "^3.0.0",
42
- "mochallel": "^1.7.9",
43
- "multiprocess-map": "^1.4.2",
42
+ "mochallel": "^1.8.2",
44
43
  "pre-commit": "^1.2.2",
45
44
  "semver": "~5.5.0"
46
45
  },
@@ -50,7 +49,7 @@
50
49
  "coveralls": "coveralls < coverage/lcov.info",
51
50
  "lint": "eslint lib",
52
51
  "lint-fix": "eslint --fix lib",
53
- "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"
54
53
  },
55
54
  "keywords": [
56
55
  "uglify",