terser 5.31.2 → 5.31.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.31.4
4
+ - drop_unused: drop classes which only have side effects in the `extends` part
5
+
6
+ ## v5.31.3
7
+ - drop_unused: drop unused parameters from IIFEs in some more situations.
8
+
3
9
  ## v5.31.2
4
10
  - drop_unused: scan variables in self-referential class declarations that contain side effects.
5
11
  - Don't add parens to arrow function when it's the default for an argument (#1540)
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@jridgewell/source-map')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@jridgewell/source-map'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Terser = {}, global.sourceMap));
5
- }(this, (function (exports, sourceMap) { 'use strict';
5
+ })(this, (function (exports, sourceMap) { 'use strict';
6
6
 
7
7
  /***********************************************************************
8
8
 
@@ -5905,6 +5905,9 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
5905
5905
  }));
5906
5906
  return found;
5907
5907
  },
5908
+ body_has_side_effects(compressor) {
5909
+ return this.properties.some(prop => prop.has_side_effects(compressor));
5910
+ },
5908
5911
  }, AST_Scope /* TODO a class might have a scope but it's not a scope */);
5909
5912
 
5910
5913
  var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_ClassProperty(props) {
@@ -14979,7 +14982,7 @@ def_drop_side_effect_free(AST_Arrow, return_null);
14979
14982
  def_drop_side_effect_free(AST_Class, function (compressor) {
14980
14983
  const with_effects = [];
14981
14984
 
14982
- if (this.is_self_referential() && this.has_side_effects(compressor)) {
14985
+ if (this.is_self_referential() && this.body_has_side_effects(compressor)) {
14983
14986
  return this;
14984
14987
  }
14985
14988
 
@@ -15287,7 +15290,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
15287
15290
  });
15288
15291
  }
15289
15292
  if (node === self) return;
15290
- if (node instanceof AST_Class && node.has_side_effects(compressor)) {
15293
+ if (node instanceof AST_Class && node.body_has_side_effects(compressor)) {
15291
15294
  if (node.is_self_referential()) {
15292
15295
  descend();
15293
15296
  } else {
@@ -15391,7 +15394,13 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
15391
15394
  if (!in_use_ids.has(def.id) || def.orig.length > 1) node.name = null;
15392
15395
  }
15393
15396
  if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
15394
- var trim = !compressor.option("keep_fargs");
15397
+ var trim =
15398
+ !compressor.option("keep_fargs")
15399
+ // Is this an IIFE that won't refer to its name?
15400
+ || parent instanceof AST_Call
15401
+ && parent.expression === node
15402
+ && !node.pinned()
15403
+ && (!node.name || node.name.unreferenced());
15395
15404
  for (var a = node.argnames, i = a.length; --i >= 0;) {
15396
15405
  var sym = a[i];
15397
15406
  if (sym instanceof AST_Expansion) {
@@ -32541,4 +32550,4 @@ exports._run_cli = run_cli;
32541
32550
  exports.minify = minify;
32542
32551
  exports.minify_sync = minify_sync;
32543
32552
 
32544
- })));
32553
+ }));
package/lib/ast.js CHANGED
@@ -2289,6 +2289,9 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
2289
2289
  }));
2290
2290
  return found;
2291
2291
  },
2292
+ body_has_side_effects(compressor) {
2293
+ return this.properties.some(prop => prop.has_side_effects(compressor));
2294
+ },
2292
2295
  }, AST_Scope /* TODO a class might have a scope but it's not a scope */);
2293
2296
 
2294
2297
  var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_ClassProperty(props) {
@@ -156,7 +156,7 @@ def_drop_side_effect_free(AST_Arrow, return_null);
156
156
  def_drop_side_effect_free(AST_Class, function (compressor) {
157
157
  const with_effects = [];
158
158
 
159
- if (this.is_self_referential() && this.has_side_effects(compressor)) {
159
+ if (this.is_self_referential() && this.body_has_side_effects(compressor)) {
160
160
  return this;
161
161
  }
162
162
 
@@ -45,6 +45,7 @@ import {
45
45
  AST_Accessor,
46
46
  AST_Assign,
47
47
  AST_BlockStatement,
48
+ AST_Call,
48
49
  AST_Class,
49
50
  AST_ClassExpression,
50
51
  AST_ClassStaticBlock,
@@ -152,7 +153,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
152
153
  });
153
154
  }
154
155
  if (node === self) return;
155
- if (node instanceof AST_Class && node.has_side_effects(compressor)) {
156
+ if (node instanceof AST_Class && node.body_has_side_effects(compressor)) {
156
157
  if (node.is_self_referential()) {
157
158
  descend();
158
159
  } else {
@@ -256,7 +257,13 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
256
257
  if (!in_use_ids.has(def.id) || def.orig.length > 1) node.name = null;
257
258
  }
258
259
  if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
259
- var trim = !compressor.option("keep_fargs");
260
+ var trim =
261
+ !compressor.option("keep_fargs")
262
+ // Is this an IIFE that won't refer to its name?
263
+ || parent instanceof AST_Call
264
+ && parent.expression === node
265
+ && !node.pinned()
266
+ && (!node.name || node.name.unreferenced());
260
267
  for (var a = node.argnames, i = a.length; --i >= 0;) {
261
268
  var sym = a[i];
262
269
  if (sym instanceof AST_Expansion) {
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.31.2",
7
+ "version": "5.31.4",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },