terser 5.19.1 → 5.19.3

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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.19.3
4
+ - Fix side effect detection of `optional?.chains`.
5
+ - Add roundRect to domprops.js (#1426)
6
+
7
+ ## v5.19.2
8
+ - fix performance hit from avoiding HTML comments in the output
9
+
3
10
  ## v5.19.1
4
11
  - Better avoid outputting `</script>` and HTML comments.
5
12
  - Fix unused variables in class static blocks not being dropped correctly.
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
 
@@ -8954,18 +8954,6 @@ class Rope {
8954
8954
  this.current += str;
8955
8955
  }
8956
8956
 
8957
- endsWith(str) {
8958
- const { committed, current } = this;
8959
- const len = str.length;
8960
- if (committed.length >= len) {
8961
- return committed.slice(committed.length - str.length) === str;
8962
- } else {
8963
- // `str` is small and this is a rare case so keep it simple
8964
- const last_bit = committed.slice(-len) + current;
8965
- return last_bit.endsWith(str);
8966
- }
8967
- }
8968
-
8969
8957
  insertAt(char, index) {
8970
8958
  const { committed, current } = this;
8971
8959
  if (index < committed.length) {
@@ -9347,10 +9335,6 @@ function OutputStream(options) {
9347
9335
  might_need_semicolon = true;
9348
9336
  };
9349
9337
 
9350
- function ends_with(str) {
9351
- return OUTPUT.endsWith(str);
9352
- }
9353
-
9354
9338
  function force_semicolon() {
9355
9339
  might_need_semicolon = false;
9356
9340
  print(";");
@@ -9620,7 +9604,6 @@ function OutputStream(options) {
9620
9604
  comma : comma,
9621
9605
  colon : colon,
9622
9606
  last : function() { return last; },
9623
- ends_with : ends_with,
9624
9607
  semicolon : semicolon,
9625
9608
  force_semicolon : force_semicolon,
9626
9609
  to_utf8 : to_utf8,
@@ -10744,7 +10727,8 @@ function OutputStream(options) {
10744
10727
  });
10745
10728
  DEFPRINT(AST_UnaryPrefix, function(self, output) {
10746
10729
  var op = self.operator;
10747
- if (op === "--" && output.ends_with("<!")) {
10730
+ if (op === "--" && output.last().endsWith("!")) {
10731
+ // avoid printing "<!--"
10748
10732
  output.print(" ");
10749
10733
  }
10750
10734
  output.print(op);
@@ -10764,7 +10748,7 @@ function OutputStream(options) {
10764
10748
  var op = self.operator;
10765
10749
  self.left.print(output);
10766
10750
  if (op[0] == ">" /* ">>" ">>>" ">" ">=" */
10767
- && output.ends_with("--")) {
10751
+ && output.last().endsWith("--")) {
10768
10752
  // space is mandatory to avoid outputting -->
10769
10753
  output.print(" ");
10770
10754
  } else {
@@ -11083,7 +11067,7 @@ function OutputStream(options) {
11083
11067
 
11084
11068
  // Avoid outputting end of script tag
11085
11069
  source = source.replace(r_slash_script, slash_script_replace);
11086
- if (r_starts_with_script.test(source) && output.ends_with("<")) {
11070
+ if (r_starts_with_script.test(source) && output.last().endsWith("<")) {
11087
11071
  output.print(" ");
11088
11072
  }
11089
11073
 
@@ -13706,16 +13690,27 @@ function is_nullish(node, compressor) {
13706
13690
  return any(this.elements, compressor);
13707
13691
  });
13708
13692
  def_has_side_effects(AST_Dot, function(compressor) {
13709
- if (is_nullish(this, compressor)) return false;
13710
- return !this.optional && this.expression.may_throw_on_access(compressor)
13711
- || 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);
13712
13701
  });
13713
13702
  def_has_side_effects(AST_Sub, function(compressor) {
13714
- 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
+ }
13715
13709
 
13716
- return !this.optional && this.expression.may_throw_on_access(compressor)
13717
- || this.expression.has_side_effects(compressor)
13718
- || 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);
13719
13714
  });
13720
13715
  def_has_side_effects(AST_Chain, function (compressor) {
13721
13716
  return this.expression.has_side_effects(compressor);
@@ -15055,7 +15050,9 @@ def_drop_side_effect_free(AST_Dot, function (compressor, first_in_statement) {
15055
15050
  if (is_nullish_shortcircuited(this, compressor)) {
15056
15051
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
15057
15052
  }
15058
- 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
+ }
15059
15056
 
15060
15057
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
15061
15058
  });
@@ -15064,15 +15061,17 @@ def_drop_side_effect_free(AST_Sub, function (compressor, first_in_statement) {
15064
15061
  if (is_nullish_shortcircuited(this, compressor)) {
15065
15062
  return this.expression.drop_side_effect_free(compressor, first_in_statement);
15066
15063
  }
15067
- 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
+ }
15068
15067
 
15069
- var expression = this.expression.drop_side_effect_free(compressor, first_in_statement);
15070
- if (!expression)
15071
- return this.property.drop_side_effect_free(compressor, first_in_statement);
15072
15068
  var property = this.property.drop_side_effect_free(compressor);
15073
- if (!property)
15074
- return expression;
15075
- 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;
15076
15075
  });
15077
15076
 
15078
15077
  def_drop_side_effect_free(AST_Chain, function (compressor, first_in_statement) {
@@ -28544,6 +28543,7 @@ var domprops = [
28544
28543
  "rotationAngle",
28545
28544
  "rotationRate",
28546
28545
  "round",
28546
+ "roundRect",
28547
28547
  "row-gap",
28548
28548
  "rowGap",
28549
28549
  "rowIndex",
@@ -30985,4 +30985,4 @@ exports._default_options = _default_options;
30985
30985
  exports._run_cli = run_cli;
30986
30986
  exports.minify = minify;
30987
30987
 
30988
- }));
30988
+ })));
@@ -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);
@@ -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
 
package/lib/output.js CHANGED
@@ -190,18 +190,6 @@ class Rope {
190
190
  this.current += str;
191
191
  }
192
192
 
193
- endsWith(str) {
194
- const { committed, current } = this;
195
- const len = str.length;
196
- if (committed.length >= len) {
197
- return committed.slice(committed.length - str.length) === str;
198
- } else {
199
- // `str` is small and this is a rare case so keep it simple
200
- const last_bit = committed.slice(-len) + current;
201
- return last_bit.endsWith(str);
202
- }
203
- }
204
-
205
193
  insertAt(char, index) {
206
194
  const { committed, current } = this;
207
195
  if (index < committed.length) {
@@ -583,10 +571,6 @@ function OutputStream(options) {
583
571
  might_need_semicolon = true;
584
572
  };
585
573
 
586
- function ends_with(str) {
587
- return OUTPUT.endsWith(str);
588
- }
589
-
590
574
  function force_semicolon() {
591
575
  might_need_semicolon = false;
592
576
  print(";");
@@ -856,7 +840,6 @@ function OutputStream(options) {
856
840
  comma : comma,
857
841
  colon : colon,
858
842
  last : function() { return last; },
859
- ends_with : ends_with,
860
843
  semicolon : semicolon,
861
844
  force_semicolon : force_semicolon,
862
845
  to_utf8 : to_utf8,
@@ -1980,7 +1963,8 @@ function OutputStream(options) {
1980
1963
  });
1981
1964
  DEFPRINT(AST_UnaryPrefix, function(self, output) {
1982
1965
  var op = self.operator;
1983
- if (op === "--" && output.ends_with("<!")) {
1966
+ if (op === "--" && output.last().endsWith("!")) {
1967
+ // avoid printing "<!--"
1984
1968
  output.print(" ");
1985
1969
  }
1986
1970
  output.print(op);
@@ -2000,7 +1984,7 @@ function OutputStream(options) {
2000
1984
  var op = self.operator;
2001
1985
  self.left.print(output);
2002
1986
  if (op[0] == ">" /* ">>" ">>>" ">" ">=" */
2003
- && output.ends_with("--")) {
1987
+ && output.last().endsWith("--")) {
2004
1988
  // space is mandatory to avoid outputting -->
2005
1989
  output.print(" ");
2006
1990
  } else {
@@ -2319,7 +2303,7 @@ function OutputStream(options) {
2319
2303
 
2320
2304
  // Avoid outputting end of script tag
2321
2305
  source = source.replace(r_slash_script, slash_script_replace);
2322
- if (r_starts_with_script.test(source) && output.ends_with("<")) {
2306
+ if (r_starts_with_script.test(source) && output.last().endsWith("<")) {
2323
2307
  output.print(" ");
2324
2308
  }
2325
2309
 
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.1",
7
+ "version": "5.19.3",
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",