terser 5.19.2 → 5.19.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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.19.4
4
+ - Prevent creating very deeply nested ternaries from a long list of `if..return`
5
+ - Prevent inlining classes into other functions, to avoid constructors being compared.
6
+
7
+ ## v5.19.3
8
+ - Fix side effect detection of `optional?.chains`.
9
+ - Add roundRect to domprops.js (#1426)
10
+
3
11
  ## v5.19.2
4
12
  - fix performance hit from avoiding HTML comments in the output
5
13
 
package/LICENSE CHANGED
@@ -1,5 +1,3 @@
1
- Terser is released under the BSD license:
2
-
3
1
  Copyright 2012-2018 (c) Mihai Bazon <mihai.bazon@gmail.com>
4
2
 
5
3
  Redistribution and use in source and binary forms, with or without
package/bin/terser.mjs ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ import "../tools/exit.cjs";
6
+
7
+ import fs from "fs";
8
+ import path from "path";
9
+ import program from "commander";
10
+
11
+ import { _run_cli as run_cli } from "../main.js";
12
+
13
+ const packageJson= JSON.parse( fs.readFileSync( new URL("./package.json", import.meta.url)));
14
+
15
+ run_cli({ program, packageJson, fs, path }).catch((error) => {
16
+ console.error(error);
17
+ process.exitCode = 1;
18
+ });
@@ -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
 
@@ -13690,16 +13690,27 @@ function is_nullish(node, compressor) {
13690
13690
  return any(this.elements, compressor);
13691
13691
  });
13692
13692
  def_has_side_effects(AST_Dot, function(compressor) {
13693
- if (is_nullish(this, compressor)) return false;
13694
- return !this.optional && this.expression.may_throw_on_access(compressor)
13695
- || this.expression.has_side_effects(compressor);
13693
+ if (is_nullish(this, compressor)) {
13694
+ return this.expression.has_side_effects(compressor);
13695
+ }
13696
+ if (!this.optional && this.expression.may_throw_on_access(compressor)) {
13697
+ return true;
13698
+ }
13699
+
13700
+ return this.expression.has_side_effects(compressor);
13696
13701
  });
13697
13702
  def_has_side_effects(AST_Sub, function(compressor) {
13698
- if (is_nullish(this, compressor)) return false;
13703
+ if (is_nullish(this, compressor)) {
13704
+ return this.expression.has_side_effects(compressor);
13705
+ }
13706
+ if (!this.optional && this.expression.may_throw_on_access(compressor)) {
13707
+ return true;
13708
+ }
13699
13709
 
13700
- return !this.optional && this.expression.may_throw_on_access(compressor)
13701
- || this.expression.has_side_effects(compressor)
13702
- || this.property.has_side_effects(compressor);
13710
+ var property = this.property.has_side_effects(compressor);
13711
+ if (property && this.optional) return true; // "?." is a condition
13712
+
13713
+ return property || this.expression.has_side_effects(compressor);
13703
13714
  });
13704
13715
  def_has_side_effects(AST_Chain, function (compressor) {
13705
13716
  return this.expression.has_side_effects(compressor);
@@ -15039,7 +15050,9 @@ def_drop_side_effect_free(AST_Dot, function (compressor, first_in_statement) {
15039
15050
  if (is_nullish_shortcircuited(this, compressor)) {
15040
15051
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
15041
15052
  }
15042
- if (this.expression.may_throw_on_access(compressor)) return this;
15053
+ if (!this.optional && this.expression.may_throw_on_access(compressor)) {
15054
+ return this;
15055
+ }
15043
15056
 
15044
15057
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
15045
15058
  });
@@ -15048,15 +15061,17 @@ def_drop_side_effect_free(AST_Sub, function (compressor, first_in_statement) {
15048
15061
  if (is_nullish_shortcircuited(this, compressor)) {
15049
15062
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
15050
15063
  }
15051
- if (this.expression.may_throw_on_access(compressor)) return this;
15064
+ if (!this.optional && this.expression.may_throw_on_access(compressor)) {
15065
+ return this;
15066
+ }
15052
15067
 
15053
- var expression = this.expression.drop_side_effect_free(compressor, first_in_statement);
15054
- if (!expression)
15055
- return this.property.drop_side_effect_free(compressor, first_in_statement);
15056
15068
  var property = this.property.drop_side_effect_free(compressor);
15057
- if (!property)
15058
- return expression;
15059
- return make_sequence(this, [expression, property]);
15069
+ if (property && this.optional) return this;
15070
+
15071
+ var expression = this.expression.drop_side_effect_free(compressor, first_in_statement);
15072
+
15073
+ if (expression && property) return make_sequence(this, [expression, property]);
15074
+ return expression || property;
15060
15075
  });
15061
15076
 
15062
15077
  def_drop_side_effect_free(AST_Chain, function (compressor, first_in_statement) {
@@ -17147,7 +17162,11 @@ function tighten_body(statements, compressor) {
17147
17162
  var self = compressor.self();
17148
17163
  var multiple_if_returns = has_multiple_if_returns(statements);
17149
17164
  var in_lambda = self instanceof AST_Lambda;
17150
- for (var i = statements.length; --i >= 0;) {
17165
+ // Prevent extremely deep nesting
17166
+ // https://github.com/terser/terser/issues/1432
17167
+ // https://github.com/webpack/webpack/issues/17548
17168
+ const iteration_start = Math.min(statements.length, 500);
17169
+ for (var i = iteration_start; --i >= 0;) {
17151
17170
  var stat = statements[i];
17152
17171
  var j = next_index(i);
17153
17172
  var next = statements[j];
@@ -17770,6 +17789,10 @@ function inline_into_symbolref(self, compressor) {
17770
17789
  && !fixed.may_throw(compressor);
17771
17790
  }
17772
17791
 
17792
+ if (fixed instanceof AST_Class && def.scope !== self.scope) {
17793
+ return self;
17794
+ }
17795
+
17773
17796
  if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
17774
17797
  if (retain_top_func(fixed, compressor)) {
17775
17798
  single_use = false;
@@ -28528,6 +28551,7 @@ var domprops = [
28528
28551
  "rotationAngle",
28529
28552
  "rotationRate",
28530
28553
  "round",
28554
+ "roundRect",
28531
28555
  "row-gap",
28532
28556
  "rowGap",
28533
28557
  "rowIndex",
@@ -30969,4 +30993,4 @@ exports._default_options = _default_options;
30969
30993
  exports._run_cli = run_cli;
30970
30994
  exports.minify = minify;
30971
30995
 
30972
- }));
30996
+ })));
@@ -321,7 +321,9 @@ def_drop_side_effect_free(AST_Dot, function (compressor, first_in_statement) {
321
321
  if (is_nullish_shortcircuited(this, compressor)) {
322
322
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
323
323
  }
324
- if (this.expression.may_throw_on_access(compressor)) return this;
324
+ if (!this.optional && this.expression.may_throw_on_access(compressor)) {
325
+ return this;
326
+ }
325
327
 
326
328
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
327
329
  });
@@ -330,15 +332,17 @@ def_drop_side_effect_free(AST_Sub, function (compressor, first_in_statement) {
330
332
  if (is_nullish_shortcircuited(this, compressor)) {
331
333
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
332
334
  }
333
- if (this.expression.may_throw_on_access(compressor)) return this;
335
+ if (!this.optional && this.expression.may_throw_on_access(compressor)) {
336
+ return this;
337
+ }
334
338
 
335
- var expression = this.expression.drop_side_effect_free(compressor, first_in_statement);
336
- if (!expression)
337
- return this.property.drop_side_effect_free(compressor, first_in_statement);
338
339
  var property = this.property.drop_side_effect_free(compressor);
339
- if (!property)
340
- return expression;
341
- return make_sequence(this, [expression, property]);
340
+ if (property && this.optional) return this;
341
+
342
+ var expression = this.expression.drop_side_effect_free(compressor, first_in_statement);
343
+
344
+ if (expression && property) return make_sequence(this, [expression, property]);
345
+ return expression || property;
342
346
  });
343
347
 
344
348
  def_drop_side_effect_free(AST_Chain, function (compressor, first_in_statement) {
@@ -77,10 +77,6 @@ import {
77
77
  TreeTransformer,
78
78
  TreeWalker,
79
79
  walk,
80
-
81
- _INLINE,
82
- _NOINLINE,
83
- _PURE
84
80
  } from "../ast.js";
85
81
  import {
86
82
  keep_name,
@@ -137,9 +137,7 @@ import {
137
137
  walk,
138
138
  walk_abort,
139
139
 
140
- _INLINE,
141
140
  _NOINLINE,
142
- _PURE
143
141
  } from "../ast.js";
144
142
  import {
145
143
  defaults,
@@ -377,16 +377,27 @@ export function is_nullish(node, compressor) {
377
377
  return any(this.elements, compressor);
378
378
  });
379
379
  def_has_side_effects(AST_Dot, function(compressor) {
380
- if (is_nullish(this, compressor)) return false;
381
- return !this.optional && this.expression.may_throw_on_access(compressor)
382
- || this.expression.has_side_effects(compressor);
380
+ if (is_nullish(this, compressor)) {
381
+ return this.expression.has_side_effects(compressor);
382
+ }
383
+ if (!this.optional && this.expression.may_throw_on_access(compressor)) {
384
+ return true;
385
+ }
386
+
387
+ return this.expression.has_side_effects(compressor);
383
388
  });
384
389
  def_has_side_effects(AST_Sub, function(compressor) {
385
- if (is_nullish(this, compressor)) return false;
390
+ if (is_nullish(this, compressor)) {
391
+ return this.expression.has_side_effects(compressor);
392
+ }
393
+ if (!this.optional && this.expression.may_throw_on_access(compressor)) {
394
+ return true;
395
+ }
386
396
 
387
- return !this.optional && this.expression.may_throw_on_access(compressor)
388
- || this.expression.has_side_effects(compressor)
389
- || this.property.has_side_effects(compressor);
397
+ var property = this.property.has_side_effects(compressor);
398
+ if (property && this.optional) return true; // "?." is a condition
399
+
400
+ return property || this.expression.has_side_effects(compressor);
390
401
  });
391
402
  def_has_side_effects(AST_Chain, function (compressor) {
392
403
  return this.expression.has_side_effects(compressor);
@@ -174,6 +174,10 @@ export function inline_into_symbolref(self, compressor) {
174
174
  && !fixed.may_throw(compressor);
175
175
  }
176
176
 
177
+ if (fixed instanceof AST_Class && def.scope !== self.scope) {
178
+ return self;
179
+ }
180
+
177
181
  if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
178
182
  if (retain_top_func(fixed, compressor)) {
179
183
  single_use = false;
@@ -96,10 +96,6 @@ import {
96
96
  walk_body,
97
97
 
98
98
  TreeWalker,
99
-
100
- _INLINE,
101
- _NOINLINE,
102
- _PURE
103
99
  } from "../ast.js";
104
100
  import { HOP, make_node, noop } from "../utils/index.js";
105
101
 
@@ -981,7 +981,11 @@ export function tighten_body(statements, compressor) {
981
981
  var self = compressor.self();
982
982
  var multiple_if_returns = has_multiple_if_returns(statements);
983
983
  var in_lambda = self instanceof AST_Lambda;
984
- for (var i = statements.length; --i >= 0;) {
984
+ // Prevent extremely deep nesting
985
+ // https://github.com/terser/terser/issues/1432
986
+ // https://github.com/webpack/webpack/issues/17548
987
+ const iteration_start = Math.min(statements.length, 500);
988
+ for (var i = iteration_start; --i >= 0;) {
985
989
  var stat = statements[i];
986
990
  var j = next_index(i);
987
991
  var next = statements[j];
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.19.2",
7
+ "version": "5.19.4",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },
package/tools/domprops.js CHANGED
@@ -6570,6 +6570,7 @@ export var domprops = [
6570
6570
  "rotationAngle",
6571
6571
  "rotationRate",
6572
6572
  "round",
6573
+ "roundRect",
6573
6574
  "row-gap",
6574
6575
  "rowGap",
6575
6576
  "rowIndex",