terser 3.10.13 → 3.13.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.

Potentially problematic release.


This version of terser might be problematic. Click here for more details.

package/lib/compress.js CHANGED
@@ -2063,10 +2063,19 @@ merge(Compressor.prototype, {
2063
2063
  return node.key.name != prop;
2064
2064
  };
2065
2065
  if (!all(def.value.properties, diff)) break;
2066
- def.value.properties.push(make_node(AST_ObjectKeyVal, node, {
2067
- key: prop,
2068
- value: node.right
2069
- }));
2066
+ var p = def.value.properties.filter(function (p) { return p.key === prop; })[0];
2067
+ if (!p) {
2068
+ def.value.properties.push(make_node(AST_ObjectKeyVal, node, {
2069
+ key: prop,
2070
+ value: node.right
2071
+ }));
2072
+ } else {
2073
+ p.value = new AST_Sequence({
2074
+ start: p.start,
2075
+ expressions: [p.value.clone(), node.right.clone()],
2076
+ end: p.end
2077
+ });
2078
+ }
2070
2079
  exprs.shift();
2071
2080
  trimmed = true;
2072
2081
  } while (exprs.length);
@@ -4556,8 +4565,8 @@ merge(Compressor.prototype, {
4556
4565
 
4557
4566
  function retain_top_func(fn, compressor) {
4558
4567
  return compressor.top_retain
4559
- && fn._top
4560
4568
  && fn instanceof AST_Defun
4569
+ && fn._top
4561
4570
  && fn.name
4562
4571
  && compressor.top_retain(fn.name);
4563
4572
  }
@@ -4902,7 +4911,8 @@ merge(Compressor.prototype, {
4902
4911
  && fn.is_constant_expression(exp.scope))
4903
4912
  && !self.pure
4904
4913
  && !fn.contains_this()
4905
- && can_inject_symbols()) {
4914
+ && can_inject_symbols()
4915
+ && !(scope instanceof AST_Class)) {
4906
4916
  fn._squeezed = true;
4907
4917
  return make_sequence(self, flatten_fn()).optimize(compressor);
4908
4918
  }
package/lib/output.js CHANGED
@@ -1228,6 +1228,13 @@ function OutputStream(options) {
1228
1228
  /* -----[ if ]----- */
1229
1229
  function make_then(self, output) {
1230
1230
  var b = self.body;
1231
+ if (b.print_to_string() === "") {
1232
+ output.newline();
1233
+ var indent = new Array(output.next_indent()).join(" ");
1234
+ output.print(indent + ";");
1235
+ output.newline();
1236
+ return;
1237
+ }
1231
1238
  if (output.option("braces")
1232
1239
  || output.option("ie8") && b instanceof AST_Do)
1233
1240
  return make_block(b, output);
@@ -1261,7 +1268,7 @@ function OutputStream(options) {
1261
1268
  output.space();
1262
1269
  if (self.alternative) {
1263
1270
  make_then(self, output);
1264
- output.space();
1271
+ if (self.body.print_to_string() !== "") output.space();
1265
1272
  output.print("else");
1266
1273
  output.space();
1267
1274
  if (self.alternative instanceof AST_If)
package/lib/parse.js CHANGED
@@ -2906,6 +2906,7 @@ function parse($TEXT, options) {
2906
2906
 
2907
2907
  // In ES6, AssignmentExpression can also be an ArrowFunction
2908
2908
  var maybe_assign = function(no_in) {
2909
+ handle_regexp();
2909
2910
  var start = S.token;
2910
2911
 
2911
2912
  if (start.type == "name" && start.value == "yield") {
package/lib/propmangle.js CHANGED
@@ -43,7 +43,10 @@
43
43
 
44
44
  "use strict";
45
45
 
46
+ var domprops = require("../tools/domprops.json");
47
+
46
48
  function find_builtins(reserved) {
49
+ reserved.push.apply(reserved, domprops);
47
50
 
48
51
  // Compatibility fix for some standard defined globals not defined on every js environment
49
52
  var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"];
@@ -127,7 +130,7 @@ function mangle_properties(ast, options) {
127
130
  }, true);
128
131
 
129
132
  var reserved = options.reserved;
130
- if (!Array.isArray(reserved)) reserved = [];
133
+ if (!Array.isArray(reserved)) reserved = [reserved];
131
134
  if (!options.builtins) find_builtins(reserved);
132
135
 
133
136
  var cname = -1;
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,7 +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);
278
- if (node instanceof AST_SymbolExport) sym.export = node.TYPE;
286
+ if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE;
279
287
  } else if (sym.scope instanceof AST_Lambda && name == "arguments") {
280
288
  sym.scope.uses_arguments = true;
281
289
  }
@@ -571,7 +579,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
571
579
 
572
580
  function collect(symbol) {
573
581
  if (!member(symbol.name, options.reserved)) {
574
- if (!symbol.export) to_mangle.push(symbol);
582
+ if (!(symbol.export & MASK_EXPORT_DONT_MANGLE)) {
583
+ to_mangle.push(symbol);
584
+ }
575
585
  }
576
586
  }
577
587
  });
package/lib/utils.js CHANGED
@@ -315,6 +315,7 @@ Dictionary.fromObject = function(obj) {
315
315
  dict._size = merge(dict._values, obj);
316
316
  return dict;
317
317
  };
318
+ exports.Dictionary = Dictionary;
318
319
 
319
320
  function HOP(obj, prop) {
320
321
  return Object.prototype.hasOwnProperty.call(obj, prop);
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.13",
7
+ "version": "3.13.1",
8
8
  "engines": {
9
9
  "node": ">=0.8.0"
10
10
  },
@@ -15,6 +15,7 @@
15
15
  ],
16
16
  "repository": "https://github.com/fabiosantoscode/terser.git",
17
17
  "main": "dist/bundle.js",
18
+ "types": "tools/terser.d.ts",
18
19
  "bin": {
19
20
  "terser": "bin/uglifyjs"
20
21
  },
@@ -32,11 +33,13 @@
32
33
  "source-map-support": "~0.5.6"
33
34
  },
34
35
  "devDependencies": {
35
- "acorn": "~5.7.1",
36
+ "acorn": "^6.0.4",
36
37
  "coveralls": "^3.0.2",
38
+ "csv": "^5.0.0",
37
39
  "es6-promise": "^4.2.5",
38
40
  "escodegen": "^1.9.1",
39
41
  "eslint": "^4.19.1",
42
+ "eslump": "^2.0.0",
40
43
  "istanbul": "^0.4.5",
41
44
  "mocha": "^3.0.0",
42
45
  "mochallel": "^1.8.2",
@@ -98,7 +101,7 @@
98
101
  }
99
102
  },
100
103
  "pre-commit": [
101
- "lint",
104
+ "lint-fix",
102
105
  "test"
103
106
  ]
104
107
  }
@@ -1,8 +1,6 @@
1
1
  "use strict"
2
2
 
3
- var semver = require("semver");
4
-
5
- if (semver.satisfies(process.version, ">=10")) {
3
+ if (Number((/([0-9]+)\./.exec(process.version) || [])[1]) >= 10) {
6
4
  var Console = require("console").Console;
7
5
  global.console = new Console({
8
6
  stdout: process.stdout,
package/tools/node.js CHANGED
@@ -23,7 +23,7 @@ try {
23
23
  var instrumenter = new istanbul.Instrumenter();
24
24
  } catch (ex) {}
25
25
 
26
- new Function("MOZ_SourceMap", "exports", function() {
26
+ new Function("MOZ_SourceMap", "exports", "require", function() {
27
27
  var code = FILES.map(function(file) {
28
28
  var contents = fs.readFileSync(file, "utf8");
29
29
  if (instrumenter && global.__IS_TESTING__) return instrumenter.instrumentSync(contents, file);
@@ -32,7 +32,8 @@ new Function("MOZ_SourceMap", "exports", function() {
32
32
  return code.join("\n\n");
33
33
  }())(
34
34
  require("source-map"),
35
- UglifyJS
35
+ UglifyJS,
36
+ require
36
37
  );
37
38
 
38
39
  function infer_options(options) {