terser 5.41.0 → 5.43.0

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.
package/lib/ast.js CHANGED
@@ -2150,12 +2150,10 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_Obje
2150
2150
  }
2151
2151
  }, AST_ObjectProperty);
2152
2152
 
2153
- var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator async", function AST_ConciseMethod(props) {
2153
+ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static", function AST_ConciseMethod(props) {
2154
2154
  if (props) {
2155
2155
  this.quote = props.quote;
2156
2156
  this.static = props.static;
2157
- this.is_generator = props.is_generator;
2158
- this.async = props.async;
2159
2157
  this.key = props.key;
2160
2158
  this.value = props.value;
2161
2159
  this.start = props.start;
@@ -2168,8 +2166,6 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
2168
2166
  $propdoc: {
2169
2167
  quote: "[string|undefined] the original quote character, if any",
2170
2168
  static: "[boolean] is this method static (classes only)",
2171
- is_generator: "[boolean] is this a generator method",
2172
- async: "[boolean] is this method async",
2173
2169
  },
2174
2170
  $documentation: "An ES6 concise method inside an object or class",
2175
2171
  computed_key() {
@@ -2177,11 +2173,9 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
2177
2173
  }
2178
2174
  }, AST_ObjectProperty);
2179
2175
 
2180
- var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
2176
+ var AST_PrivateMethod = DEFNODE("PrivateMethod", "static", function AST_PrivateMethod(props) {
2181
2177
  if (props) {
2182
2178
  this.static = props.static;
2183
- this.is_generator = props.is_generator;
2184
- this.async = props.async;
2185
2179
  this.key = props.key;
2186
2180
  this.value = props.value;
2187
2181
  this.start = props.start;
@@ -2191,6 +2185,9 @@ var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(
2191
2185
  this.flags = 0;
2192
2186
  }, {
2193
2187
  $documentation: "A private class method inside a class",
2188
+ $propdoc: {
2189
+ static: "[boolean] is this a static private method",
2190
+ },
2194
2191
  computed_key() {
2195
2192
  return false;
2196
2193
  },
@@ -3181,6 +3178,28 @@ class TreeWalker {
3181
3178
  }
3182
3179
  }
3183
3180
 
3181
+ is_within_loop() {
3182
+ let i = this.stack.length - 1;
3183
+ let child = this.stack[i];
3184
+ while (i--) {
3185
+ const node = this.stack[i];
3186
+
3187
+ if (node instanceof AST_Lambda) return false;
3188
+ if (
3189
+ node instanceof AST_IterationStatement
3190
+ // exclude for-loop bits that only run once
3191
+ && !((node instanceof AST_For) && child === node.init)
3192
+ && !((node instanceof AST_ForIn || node instanceof AST_ForOf) && child === node.object)
3193
+ ) {
3194
+ return true;
3195
+ }
3196
+
3197
+ child = node;
3198
+ }
3199
+
3200
+ return false;
3201
+ }
3202
+
3184
3203
  find_scope() {
3185
3204
  var stack = this.stack;
3186
3205
  for (var i = stack.length; --i >= 0;) {
@@ -3522,7 +3522,7 @@ AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
3522
3522
  if ("" + (prop instanceof AST_ConciseMethod ? prop.key.name : prop.key) == key) {
3523
3523
  const all_props_flattenable = props.every((p) =>
3524
3524
  (p instanceof AST_ObjectKeyVal
3525
- || arrows && p instanceof AST_ConciseMethod && !p.is_generator
3525
+ || arrows && p instanceof AST_ConciseMethod && !p.value.is_generator
3526
3526
  )
3527
3527
  && !p.computed_key()
3528
3528
  );
@@ -4008,7 +4008,7 @@ def_optimize(AST_ConciseMethod, function(self, compressor) {
4008
4008
  // p(){return x;} ---> p:()=>x
4009
4009
  if (compressor.option("arrows")
4010
4010
  && compressor.parent() instanceof AST_Object
4011
- && !self.is_generator
4011
+ && !self.value.is_generator
4012
4012
  && !self.value.uses_arguments
4013
4013
  && !self.value.pinned()
4014
4014
  && self.value.body.length == 1
@@ -4016,8 +4016,8 @@ def_optimize(AST_ConciseMethod, function(self, compressor) {
4016
4016
  && self.value.body[0].value
4017
4017
  && !self.value.contains_this()) {
4018
4018
  var arrow = make_node(AST_Arrow, self.value, self.value);
4019
- arrow.async = self.async;
4020
- arrow.is_generator = self.is_generator;
4019
+ arrow.async = self.value.async;
4020
+ arrow.is_generator = self.value.is_generator;
4021
4021
  return make_node(AST_ObjectKeyVal, self, {
4022
4022
  key: self.key instanceof AST_SymbolMethod ? self.key.name : self.key,
4023
4023
  value: arrow,
@@ -4045,8 +4045,6 @@ def_optimize(AST_ObjectKeyVal, function(self, compressor) {
4045
4045
  && !value.contains_this();
4046
4046
  if ((is_arrow_with_block || value instanceof AST_Function) && !value.name) {
4047
4047
  return make_node(AST_ConciseMethod, self, {
4048
- async: value.async,
4049
- is_generator: value.is_generator,
4050
4048
  key: key instanceof AST_Node ? key : make_node(AST_SymbolMethod, self, {
4051
4049
  name: key,
4052
4050
  }),
@@ -187,6 +187,8 @@ export function inline_into_symbolref(self, compressor) {
187
187
  return self;
188
188
  }
189
189
 
190
+ if (dont_inline_lambda_in_loop(compressor, fixed)) return self;
191
+
190
192
  let single_use = def.single_use
191
193
  && !(parent instanceof AST_Call
192
194
  && (parent.is_callee_pure(compressor))
@@ -340,6 +342,11 @@ export function inline_into_call(self, compressor) {
340
342
  fn = fixed;
341
343
  }
342
344
 
345
+ if (
346
+ dont_inline_lambda_in_loop(compressor, fn)
347
+ && !has_annotation(self, _INLINE)
348
+ ) return self;
349
+
343
350
  var is_func = fn instanceof AST_Lambda;
344
351
 
345
352
  var stat = is_func && fn.body[0];
@@ -667,3 +674,11 @@ export function inline_into_call(self, compressor) {
667
674
  return expressions.map(exp => exp.clone(true));
668
675
  }
669
676
  }
677
+
678
+ /** prevent inlining functions into loops, for performance reasons */
679
+ function dont_inline_lambda_in_loop(compressor, maybe_lambda) {
680
+ return (
681
+ (maybe_lambda instanceof AST_Lambda || maybe_lambda instanceof AST_Class)
682
+ && !!compressor.is_within_loop()
683
+ );
684
+ }
@@ -249,11 +249,11 @@ AST_ObjectGetter.prototype.shallow_cmp = function(other) {
249
249
  };
250
250
 
251
251
  AST_ConciseMethod.prototype.shallow_cmp = function(other) {
252
- return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async;
252
+ return this.static === other.static;
253
253
  };
254
254
 
255
255
  AST_PrivateMethod.prototype.shallow_cmp = function(other) {
256
- return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async;
256
+ return this.static === other.static;
257
257
  };
258
258
 
259
259
  AST_Class.prototype.shallow_cmp = function(other) {