terser 5.3.1 → 5.3.5

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.
@@ -4140,9 +4140,12 @@ AST_Scope.DEFMETHOD("hoist_declarations", function(compressor) {
4140
4140
  hoisted.push(node);
4141
4141
  return make_node(AST_EmptyStatement, node);
4142
4142
  }
4143
- if (hoist_vars && node instanceof AST_Var) {
4143
+ if (
4144
+ hoist_vars
4145
+ && node instanceof AST_Var
4146
+ && !node.definitions.some(def => def.name instanceof AST_Destructuring)
4147
+ ) {
4144
4148
  node.definitions.forEach(function(def) {
4145
- if (def.name instanceof AST_Destructuring) return;
4146
4149
  vars.set(def.name.name, def);
4147
4150
  ++vars_found;
4148
4151
  });
@@ -4222,8 +4225,7 @@ AST_Scope.DEFMETHOD("hoist_declarations", function(compressor) {
4222
4225
  continue;
4223
4226
  }
4224
4227
  if (self.body[i] instanceof AST_BlockStatement) {
4225
- var tmp = [ i, 1 ].concat(self.body[i].body);
4226
- self.body.splice.apply(self.body, tmp);
4228
+ self.body.splice(i, 1, ...self.body[i].body);
4227
4229
  continue;
4228
4230
  }
4229
4231
  break;
@@ -4969,10 +4971,12 @@ AST_Definitions.DEFMETHOD("remove_initializers", function() {
4969
4971
 
4970
4972
  AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
4971
4973
  var reduce_vars = compressor.option("reduce_vars");
4972
- var assignments = this.definitions.reduce(function(a, def) {
4973
- if (def.value && !(def.name instanceof AST_Destructuring)) {
4974
+ var assignments = [];
4975
+
4976
+ for (const def of this.definitions) {
4977
+ if (def.value) {
4974
4978
  var name = make_node(AST_SymbolRef, def.name, def.name);
4975
- a.push(make_node(AST_Assign, def, {
4979
+ assignments.push(make_node(AST_Assign, def, {
4976
4980
  operator : "=",
4977
4981
  left : name,
4978
4982
  right : def.value
@@ -4987,13 +4991,13 @@ AST_Definitions.DEFMETHOD("to_assignments", function(compressor) {
4987
4991
  var var_ = make_node(AST_Var, def, {
4988
4992
  definitions: [ varDef ]
4989
4993
  });
4990
- a.push(var_);
4994
+ assignments.push(var_);
4991
4995
  }
4992
- def = def.name.definition();
4993
- def.eliminated++;
4994
- def.replaced--;
4995
- return a;
4996
- }, []);
4996
+ const thedef = def.name.definition();
4997
+ thedef.eliminated++;
4998
+ thedef.replaced--;
4999
+ }
5000
+
4997
5001
  if (assignments.length == 0) return null;
4998
5002
  return make_sequence(this, assignments);
4999
5003
  });
@@ -5020,7 +5024,7 @@ function retain_top_func(fn, compressor) {
5020
5024
  def_optimize(AST_Call, function(self, compressor) {
5021
5025
  var exp = self.expression;
5022
5026
  var fn = exp;
5023
- inline_array_like_spread(self, compressor, self.args);
5027
+ inline_array_like_spread(self.args);
5024
5028
  var simple_args = self.args.every((arg) =>
5025
5029
  !(arg instanceof AST_Expansion)
5026
5030
  );
@@ -5980,7 +5984,7 @@ def_optimize(AST_Binary, function(self, compressor) {
5980
5984
  && self.left.left.getValue() == ""
5981
5985
  && self.right.is_string(compressor)) {
5982
5986
  self.left = self.left.right;
5983
- return self.transform(compressor);
5987
+ return self;
5984
5988
  }
5985
5989
  }
5986
5990
  if (compressor.option("evaluate")) {
@@ -6079,25 +6083,6 @@ def_optimize(AST_Binary, function(self, compressor) {
6079
6083
  var associative = true;
6080
6084
  switch (self.operator) {
6081
6085
  case "+":
6082
- // "foo" + ("bar" + x) => "foobar" + x
6083
- if (self.left instanceof AST_Constant
6084
- && self.right instanceof AST_Binary
6085
- && self.right.operator == "+"
6086
- && self.right.is_string(compressor)) {
6087
- var binary = make_node(AST_Binary, self, {
6088
- operator: "+",
6089
- left: self.left,
6090
- right: self.right.left,
6091
- });
6092
- var l = binary.optimize(compressor);
6093
- if (binary !== l) {
6094
- self = make_node(AST_Binary, self, {
6095
- operator: "+",
6096
- left: l,
6097
- right: self.right.right
6098
- });
6099
- }
6100
- }
6101
6086
  // (x + "foo") + "bar" => x + "foobar"
6102
6087
  if (self.right instanceof AST_Constant
6103
6088
  && self.left instanceof AST_Binary
@@ -6306,10 +6291,10 @@ def_optimize(AST_Binary, function(self, compressor) {
6306
6291
  ) {
6307
6292
  self.left = make_node(AST_Binary, self.left, {
6308
6293
  operator : self.operator,
6309
- left : self.left,
6310
- right : self.right.left
6294
+ left : self.left.transform(compressor),
6295
+ right : self.right.left.transform(compressor)
6311
6296
  });
6312
- self.right = self.right.right;
6297
+ self.right = self.right.right.transform(compressor);
6313
6298
  return self.transform(compressor);
6314
6299
  }
6315
6300
  var ev = self.evaluate(compressor);
@@ -6382,7 +6367,9 @@ def_optimize(AST_SymbolRef, function(self, compressor) {
6382
6367
  && !(parent instanceof AST_Call
6383
6368
  && (parent.is_expr_pure(compressor))
6384
6369
  || has_annotation(parent, _NOINLINE))
6385
- && !(fixed instanceof AST_Defun && parent instanceof AST_Export);
6370
+ && !(parent instanceof AST_Export
6371
+ && fixed instanceof AST_Lambda
6372
+ && fixed.name);
6386
6373
 
6387
6374
  if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
6388
6375
  if (retain_top_func(fixed, compressor)) {
@@ -7326,12 +7313,15 @@ function literals_in_boolean_context(self, compressor) {
7326
7313
  return self;
7327
7314
  }
7328
7315
 
7329
- function inline_array_like_spread(self, compressor, elements) {
7316
+ function inline_array_like_spread(elements) {
7330
7317
  for (var i = 0; i < elements.length; i++) {
7331
7318
  var el = elements[i];
7332
7319
  if (el instanceof AST_Expansion) {
7333
7320
  var expr = el.expression;
7334
- if ( expr instanceof AST_Array) {
7321
+ if (
7322
+ expr instanceof AST_Array
7323
+ && !expr.elements.some(elm => elm instanceof AST_Hole)
7324
+ ) {
7335
7325
  elements.splice(i, 1, ...expr.elements);
7336
7326
  // Step back one, as the element at i is now new.
7337
7327
  i--;
@@ -7340,7 +7330,6 @@ function inline_array_like_spread(self, compressor, elements) {
7340
7330
  // We therefore can’t optimize anything else, unlike with object spread.
7341
7331
  }
7342
7332
  }
7343
- return self;
7344
7333
  }
7345
7334
 
7346
7335
  def_optimize(AST_Array, function(self, compressor) {
@@ -7348,21 +7337,20 @@ def_optimize(AST_Array, function(self, compressor) {
7348
7337
  if (optimized !== self) {
7349
7338
  return optimized;
7350
7339
  }
7351
- return inline_array_like_spread(self, compressor, self.elements);
7340
+ inline_array_like_spread(self.elements);
7341
+ return self;
7352
7342
  });
7353
7343
 
7354
- def_optimize(AST_Object, function(self, compressor) {
7355
- var optimized = literals_in_boolean_context(self, compressor);
7356
- if (optimized !== self) {
7357
- return optimized;
7358
- }
7359
- var props = self.properties;
7344
+ function inline_object_prop_spread(props) {
7360
7345
  for (var i = 0; i < props.length; i++) {
7361
7346
  var prop = props[i];
7362
7347
  if (prop instanceof AST_Expansion) {
7363
- var expr = prop.expression;
7364
- if (expr instanceof AST_Object) {
7365
- props.splice.apply(props, [i, 1].concat(prop.expression.properties));
7348
+ const expr = prop.expression;
7349
+ if (
7350
+ expr instanceof AST_Object
7351
+ && expr.properties.every(prop => prop instanceof AST_ObjectKeyVal)
7352
+ ) {
7353
+ props.splice(i, 1, ...expr.properties);
7366
7354
  // Step back one, as the property at i is now new.
7367
7355
  i--;
7368
7356
  } else if (expr instanceof AST_Constant
@@ -7374,6 +7362,14 @@ def_optimize(AST_Object, function(self, compressor) {
7374
7362
  }
7375
7363
  }
7376
7364
  }
7365
+ }
7366
+
7367
+ def_optimize(AST_Object, function(self, compressor) {
7368
+ var optimized = literals_in_boolean_context(self, compressor);
7369
+ if (optimized !== self) {
7370
+ return optimized;
7371
+ }
7372
+ inline_object_prop_spread(self.properties);
7377
7373
  return self;
7378
7374
  });
7379
7375
 
package/lib/minify.js CHANGED
@@ -205,10 +205,7 @@ async function minify(files, options) {
205
205
  }
206
206
  if (!HOP(options.format, "code") || options.format.code) {
207
207
  if (options.sourceMap) {
208
- if (typeof options.sourceMap.content == "string") {
209
- options.sourceMap.content = JSON.parse(options.sourceMap.content);
210
- }
211
- options.format.source_map = SourceMap({
208
+ options.format.source_map = await SourceMap({
212
209
  file: options.sourceMap.filename,
213
210
  orig: options.sourceMap.content,
214
211
  root: options.sourceMap.root
@@ -246,6 +243,9 @@ async function minify(files, options) {
246
243
  options.nameCache.props = cache_to_json(options.mangle.properties.cache);
247
244
  }
248
245
  }
246
+ if (options.format && options.format.source_map) {
247
+ options.format.source_map.destroy();
248
+ }
249
249
  if (timings) {
250
250
  timings.end = Date.now();
251
251
  result.timings = {
package/lib/output.js CHANGED
@@ -893,6 +893,14 @@ function OutputStream(options) {
893
893
 
894
894
  PARENS(AST_Arrow, function(output) {
895
895
  var p = output.parent();
896
+
897
+ if (
898
+ output.option("wrap_func_args")
899
+ && p instanceof AST_Call
900
+ && p.args.includes(this)
901
+ ) {
902
+ return true;
903
+ }
896
904
  return p instanceof AST_PropAccess && p.expression === this;
897
905
  });
898
906
 
package/lib/sourcemap.js CHANGED
@@ -49,7 +49,7 @@ import {
49
49
  } from "./utils/index.js";
50
50
 
51
51
  // a small wrapper around fitzgen's source-map library
52
- function SourceMap(options) {
52
+ async function SourceMap(options) {
53
53
  options = defaults(options, {
54
54
  file : null,
55
55
  root : null,
@@ -58,13 +58,15 @@ function SourceMap(options) {
58
58
  orig_line_diff : 0,
59
59
  dest_line_diff : 0,
60
60
  });
61
+
62
+ var orig_map;
61
63
  var generator = new MOZ_SourceMap.SourceMapGenerator({
62
64
  file : options.file,
63
65
  sourceRoot : options.root
64
66
  });
65
- var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
66
67
 
67
- if (orig_map) {
68
+ if (options.orig) {
69
+ orig_map = await new MOZ_SourceMap.SourceMapConsumer(options.orig);
68
70
  orig_map.sources.forEach(function(source) {
69
71
  var sourceContent = orig_map.sourceContentFor(source, true);
70
72
  if (sourceContent) {
@@ -94,10 +96,16 @@ function SourceMap(options) {
94
96
  name : name
95
97
  });
96
98
  }
99
+
97
100
  return {
98
101
  add : add,
99
102
  get : function() { return generator; },
100
- toString : function() { return JSON.stringify(generator.toJSON()); }
103
+ toString : function() { return generator.toString(); },
104
+ destroy : function () {
105
+ if (orig_map && orig_map.destroy) {
106
+ orig_map.destroy();
107
+ }
108
+ }
101
109
  };
102
110
  }
103
111
 
package/lib/transform.js CHANGED
@@ -51,6 +51,7 @@ import {
51
51
  AST_Call,
52
52
  AST_Case,
53
53
  AST_Catch,
54
+ AST_Chain,
54
55
  AST_Class,
55
56
  AST_Conditional,
56
57
  AST_Definitions,
@@ -236,6 +237,10 @@ def_transform(AST_Sub, function(self, tw) {
236
237
  self.property = self.property.transform(tw);
237
238
  });
238
239
 
240
+ def_transform(AST_Chain, function(self, tw) {
241
+ self.expression = self.expression.transform(tw);
242
+ });
243
+
239
244
  def_transform(AST_Yield, function(self, tw) {
240
245
  if (self.expression) self.expression = self.expression.transform(tw);
241
246
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "homepage": "https://terser.org",
5
5
  "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
6
6
  "license": "BSD-2-Clause",
7
- "version": "5.3.1",
7
+ "version": "5.3.5",
8
8
  "engines": {
9
9
  "node": ">=6.0.0"
10
10
  },
@@ -44,8 +44,8 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "commander": "^2.20.0",
47
- "source-map": "~0.6.1",
48
- "source-map-support": "~0.5.12"
47
+ "source-map": "~0.7.2",
48
+ "source-map-support": "~0.5.19"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@ls-lint/ls-lint": "^1.9.2",
package/tools/terser.d.ts CHANGED
@@ -144,6 +144,8 @@ export interface MinifyOptions {
144
144
  module?: boolean;
145
145
  nameCache?: object;
146
146
  format?: FormatOptions;
147
+ /** @deprecated */
148
+ output?: FormatOptions;
147
149
  parse?: ParseOptions;
148
150
  safari10?: boolean;
149
151
  sourceMap?: boolean | SourceMapOptions;