terser 5.44.1 → 5.45.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.45.0
4
+
5
+ - Produce `void 0` instead of `undefined`, which is more safe
6
+
3
7
  ## v5.44.1
4
8
 
5
9
  - fix bitwise optimization changing the result of `&&`, `||`
@@ -132,6 +132,15 @@ function make_node(ctor, orig, props) {
132
132
  return new ctor(props);
133
133
  }
134
134
 
135
+ /** Makes a `void 0` expression. Use instead of AST_Undefined which may conflict
136
+ * with an existing variable called `undefined` */
137
+ function make_void_0(orig) {
138
+ return make_node(AST_UnaryPrefix, orig, {
139
+ operator: "void",
140
+ expression: make_node(AST_Number, orig, { value: 0 })
141
+ });
142
+ }
143
+
135
144
  function push_uniq(array, el) {
136
145
  if (!array.includes(el))
137
146
  array.push(el);
@@ -13558,7 +13567,7 @@ function make_node_from_constant(val, orig) {
13558
13567
  case "boolean":
13559
13568
  return make_node(val ? AST_True : AST_False, orig);
13560
13569
  case "undefined":
13561
- return make_node(AST_Undefined, orig);
13570
+ return make_void_0(orig);
13562
13571
  default:
13563
13572
  if (val === null) {
13564
13573
  return make_node(AST_Null, orig, { value: null });
@@ -16408,7 +16417,7 @@ function safe_to_read(tw, def) {
16408
16417
  if (def.fixed == null) {
16409
16418
  var orig = def.orig[0];
16410
16419
  if (orig instanceof AST_SymbolFunarg || orig.name == "arguments") return false;
16411
- def.fixed = make_node(AST_Undefined, orig);
16420
+ def.fixed = make_void_0(orig);
16412
16421
  }
16413
16422
  return true;
16414
16423
  }
@@ -16706,7 +16715,7 @@ function mark_lambda(tw, descend, compressor) {
16706
16715
  if (d.orig.length > 1) return;
16707
16716
  if (d.fixed === undefined && (!this.uses_arguments || tw.has_directive("use strict"))) {
16708
16717
  d.fixed = function() {
16709
- return iife.args[i] || make_node(AST_Undefined, iife);
16718
+ return iife.args[i] || make_void_0(iife);
16710
16719
  };
16711
16720
  tw.loop_ids.set(d.id, tw.in_loop);
16712
16721
  mark(tw, d, true);
@@ -17630,7 +17639,7 @@ function tighten_body(statements, compressor) {
17630
17639
  }
17631
17640
  } else {
17632
17641
  if (!arg) {
17633
- arg = make_node(AST_Undefined, sym).transform(compressor);
17642
+ arg = make_void_0(sym).transform(compressor);
17634
17643
  } else if (arg instanceof AST_Lambda && arg.pinned()
17635
17644
  || has_overlapping_symbol(fn, arg, fn_strict)) {
17636
17645
  arg = null;
@@ -17870,7 +17879,7 @@ function tighten_body(statements, compressor) {
17870
17879
  found = true;
17871
17880
  if (node instanceof AST_VarDef) {
17872
17881
  node.value = node.name instanceof AST_SymbolConst
17873
- ? make_node(AST_Undefined, node.value) // `const` always needs value.
17882
+ ? make_void_0(node.value) // `const` always needs value.
17874
17883
  : null;
17875
17884
  return node;
17876
17885
  }
@@ -18309,7 +18318,7 @@ function tighten_body(statements, compressor) {
18309
18318
  var stat = statements[i];
18310
18319
  if (prev) {
18311
18320
  if (stat instanceof AST_Exit) {
18312
- stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat).transform(compressor));
18321
+ stat.value = cons_seq(stat.value || make_void_0(stat).transform(compressor));
18313
18322
  } else if (stat instanceof AST_For) {
18314
18323
  if (!(stat.init instanceof AST_DefinitionsLike)) {
18315
18324
  const abort = walk(prev.body, node => {
@@ -18813,7 +18822,7 @@ function inline_into_call(self, compressor) {
18813
18822
  if (returned) {
18814
18823
  returned = returned.clone(true);
18815
18824
  } else {
18816
- returned = make_node(AST_Undefined, self);
18825
+ returned = make_void_0(self);
18817
18826
  }
18818
18827
  const args = self.args.concat(returned);
18819
18828
  return make_sequence(self, args).optimize(compressor);
@@ -18829,7 +18838,7 @@ function inline_into_call(self, compressor) {
18829
18838
  && returned.name === fn.argnames[0].name
18830
18839
  ) {
18831
18840
  const replacement =
18832
- (self.args[0] || make_node(AST_Undefined)).optimize(compressor);
18841
+ (self.args[0] || make_void_0()).optimize(compressor);
18833
18842
 
18834
18843
  let parent;
18835
18844
  if (
@@ -18911,7 +18920,7 @@ function inline_into_call(self, compressor) {
18911
18920
 
18912
18921
  const can_drop_this_call = is_regular_func && compressor.option("side_effects") && fn.body.every(is_empty);
18913
18922
  if (can_drop_this_call) {
18914
- var args = self.args.concat(make_node(AST_Undefined, self));
18923
+ var args = self.args.concat(make_void_0(self));
18915
18924
  return make_sequence(self, args).optimize(compressor);
18916
18925
  }
18917
18926
 
@@ -18930,9 +18939,9 @@ function inline_into_call(self, compressor) {
18930
18939
  return self;
18931
18940
 
18932
18941
  function return_value(stat) {
18933
- if (!stat) return make_node(AST_Undefined, self);
18942
+ if (!stat) return make_void_0(self);
18934
18943
  if (stat instanceof AST_Return) {
18935
- if (!stat.value) return make_node(AST_Undefined, self);
18944
+ if (!stat.value) return make_void_0(self);
18936
18945
  return stat.value.clone(true);
18937
18946
  }
18938
18947
  if (stat instanceof AST_SimpleStatement) {
@@ -19078,7 +19087,7 @@ function inline_into_call(self, compressor) {
19078
19087
  } else {
19079
19088
  var symbol = make_node(AST_SymbolVar, name, name);
19080
19089
  name.definition().orig.push(symbol);
19081
- if (!value && in_loop) value = make_node(AST_Undefined, self);
19090
+ if (!value && in_loop) value = make_void_0(self);
19082
19091
  append_var(decls, expressions, symbol, value);
19083
19092
  }
19084
19093
  }
@@ -19105,7 +19114,7 @@ function inline_into_call(self, compressor) {
19105
19114
  operator: "=",
19106
19115
  logical: false,
19107
19116
  left: sym,
19108
- right: make_node(AST_Undefined, name)
19117
+ right: make_void_0(name),
19109
19118
  }));
19110
19119
  }
19111
19120
  }
@@ -19602,7 +19611,7 @@ AST_Toplevel.DEFMETHOD("drop_console", function(options) {
19602
19611
  set_flag(exp.expression, SQUEEZED);
19603
19612
  self.args = [];
19604
19613
  } else {
19605
- return make_node(AST_Undefined, self);
19614
+ return make_void_0(self);
19606
19615
  }
19607
19616
  }
19608
19617
  });
@@ -19630,12 +19639,7 @@ AST_Scope.DEFMETHOD("process_expression", function(insert, compressor) {
19630
19639
  : make_node(AST_EmptyStatement, node);
19631
19640
  }
19632
19641
  return make_node(AST_SimpleStatement, node, {
19633
- body: node.value || make_node(AST_UnaryPrefix, node, {
19634
- operator: "void",
19635
- expression: make_node(AST_Number, node, {
19636
- value: 0
19637
- })
19638
- })
19642
+ body: node.value || make_void_0(node)
19639
19643
  });
19640
19644
  }
19641
19645
  if (node instanceof AST_Class || node instanceof AST_Lambda && node !== self) {
@@ -20238,8 +20242,8 @@ def_optimize(AST_If, function(self, compressor) {
20238
20242
  return make_node(self.body.CTOR, self, {
20239
20243
  value: make_node(AST_Conditional, self, {
20240
20244
  condition : self.condition,
20241
- consequent : self.body.value || make_node(AST_Undefined, self.body),
20242
- alternative : self.alternative.value || make_node(AST_Undefined, self.alternative)
20245
+ consequent : self.body.value || make_void_0(self.body),
20246
+ alternative : self.alternative.value || make_void_0(self.alternative),
20243
20247
  }).transform(compressor)
20244
20248
  }).optimize(compressor);
20245
20249
  }
@@ -20792,7 +20796,7 @@ def_optimize(AST_Call, function(self, compressor) {
20792
20796
  const value = condition.evaluate(compressor);
20793
20797
 
20794
20798
  if (value === 1 || value === true) {
20795
- return make_node(AST_Undefined, self);
20799
+ return make_void_0(self).optimize(compressor);
20796
20800
  }
20797
20801
  }
20798
20802
  }
@@ -21154,6 +21158,10 @@ def_optimize(AST_UnaryPrefix, function(self, compressor) {
21154
21158
  ) {
21155
21159
  return make_sequence(self, [e, make_node(AST_True, self)]).optimize(compressor);
21156
21160
  }
21161
+ // Short-circuit common `void 0`
21162
+ if (self.operator === "void" && e instanceof AST_Number && e.value === 0) {
21163
+ return unsafe_undefined_ref(self, compressor) || self;
21164
+ }
21157
21165
  var seq = self.lift_sequences(compressor);
21158
21166
  if (seq !== self) {
21159
21167
  return seq;
@@ -21164,7 +21172,7 @@ def_optimize(AST_UnaryPrefix, function(self, compressor) {
21164
21172
  self.expression = e;
21165
21173
  return self;
21166
21174
  } else {
21167
- return make_node(AST_Undefined, self).optimize(compressor);
21175
+ return make_void_0(self).optimize(compressor);
21168
21176
  }
21169
21177
  }
21170
21178
  if (compressor.in_boolean_context()) {
@@ -21350,7 +21358,7 @@ def_optimize(AST_Binary, function(self, compressor) {
21350
21358
  if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor)
21351
21359
  : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) {
21352
21360
  self.right = expr;
21353
- self.left = make_node(AST_Undefined, self.left).optimize(compressor);
21361
+ self.left = make_void_0(self.left).optimize(compressor);
21354
21362
  if (self.operator.length == 2) self.operator += "=";
21355
21363
  }
21356
21364
  } else if (compressor.option("typeofs")
@@ -21363,7 +21371,7 @@ def_optimize(AST_Binary, function(self, compressor) {
21363
21371
  if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor)
21364
21372
  : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) {
21365
21373
  self.left = expr;
21366
- self.right = make_node(AST_Undefined, self.right).optimize(compressor);
21374
+ self.right = make_void_0(self.right).optimize(compressor);
21367
21375
  if (self.operator.length == 2) self.operator += "=";
21368
21376
  }
21369
21377
  } else if (self.left instanceof AST_SymbolRef
@@ -22004,7 +22012,8 @@ function is_atomic(lhs, self) {
22004
22012
  return lhs instanceof AST_SymbolRef || lhs.TYPE === self.TYPE;
22005
22013
  }
22006
22014
 
22007
- def_optimize(AST_Undefined, function(self, compressor) {
22015
+ /** Apply the `unsafe_undefined` option: find a variable called `undefined` and turn `self` into a reference to it. */
22016
+ function unsafe_undefined_ref(self, compressor) {
22008
22017
  if (compressor.option("unsafe_undefined")) {
22009
22018
  var undef = find_variable(compressor, "undefined");
22010
22019
  if (undef) {
@@ -22017,14 +22026,15 @@ def_optimize(AST_Undefined, function(self, compressor) {
22017
22026
  return ref;
22018
22027
  }
22019
22028
  }
22029
+ return null;
22030
+ }
22031
+
22032
+ def_optimize(AST_Undefined, function(self, compressor) {
22033
+ var symbolref = unsafe_undefined_ref(self, compressor);
22034
+ if (symbolref) return symbolref;
22020
22035
  var lhs = compressor.is_lhs();
22021
22036
  if (lhs && is_atomic(lhs, self)) return self;
22022
- return make_node(AST_UnaryPrefix, self, {
22023
- operator: "void",
22024
- expression: make_node(AST_Number, self, {
22025
- value: 0
22026
- })
22027
- });
22037
+ return make_void_0(self);
22028
22038
  });
22029
22039
 
22030
22040
  def_optimize(AST_Infinity, function(self, compressor) {
@@ -22711,7 +22721,7 @@ def_optimize(AST_Sub, function(self, compressor) {
22711
22721
  }
22712
22722
  }
22713
22723
  if (retValue instanceof AST_Expansion) break FLATTEN;
22714
- retValue = retValue instanceof AST_Hole ? make_node(AST_Undefined, retValue) : retValue;
22724
+ retValue = retValue instanceof AST_Hole ? make_void_0(retValue) : retValue;
22715
22725
  if (!flatten) values.unshift(retValue);
22716
22726
  while (--i >= 0) {
22717
22727
  var value = elements[i];
@@ -22750,7 +22760,7 @@ def_optimize(AST_Chain, function (self, compressor) {
22750
22760
  if (parent instanceof AST_UnaryPrefix && parent.operator === "delete") {
22751
22761
  return make_node_from_constant(0, self);
22752
22762
  }
22753
- return make_node(AST_Undefined, self);
22763
+ return make_void_0(self).optimize(compressor);
22754
22764
  }
22755
22765
  if (
22756
22766
  self.expression instanceof AST_PropAccess
@@ -87,7 +87,7 @@ import {
87
87
  walk_abort,
88
88
  walk_parent,
89
89
  } from "../ast.js";
90
- import { make_node, regexp_source_fix, string_template, makePredicate } from "../utils/index.js";
90
+ import { make_node, make_void_0, regexp_source_fix, string_template, makePredicate } from "../utils/index.js";
91
91
  import { first_in_statement } from "../utils/first_in_statement.js";
92
92
  import { has_flag, TOP } from "./compressor-flags.js";
93
93
 
@@ -148,7 +148,7 @@ export function make_node_from_constant(val, orig) {
148
148
  case "boolean":
149
149
  return make_node(val ? AST_True : AST_False, orig);
150
150
  case "undefined":
151
- return make_node(AST_Undefined, orig);
151
+ return make_void_0(orig);
152
152
  default:
153
153
  if (val === null) {
154
154
  return make_node(AST_Null, orig, { value: null });
@@ -146,6 +146,7 @@ import {
146
146
  defaults,
147
147
  HOP,
148
148
  make_node,
149
+ make_void_0,
149
150
  makePredicate,
150
151
  MAP,
151
152
  remove,
@@ -562,7 +563,7 @@ AST_Toplevel.DEFMETHOD("drop_console", function(options) {
562
563
  set_flag(exp.expression, SQUEEZED);
563
564
  self.args = [];
564
565
  } else {
565
- return make_node(AST_Undefined, self);
566
+ return make_void_0(self);
566
567
  }
567
568
  }
568
569
  });
@@ -590,12 +591,7 @@ AST_Scope.DEFMETHOD("process_expression", function(insert, compressor) {
590
591
  : make_node(AST_EmptyStatement, node);
591
592
  }
592
593
  return make_node(AST_SimpleStatement, node, {
593
- body: node.value || make_node(AST_UnaryPrefix, node, {
594
- operator: "void",
595
- expression: make_node(AST_Number, node, {
596
- value: 0
597
- })
598
- })
594
+ body: node.value || make_void_0(node)
599
595
  });
600
596
  }
601
597
  if (node instanceof AST_Class || node instanceof AST_Lambda && node !== self) {
@@ -1198,8 +1194,8 @@ def_optimize(AST_If, function(self, compressor) {
1198
1194
  return make_node(self.body.CTOR, self, {
1199
1195
  value: make_node(AST_Conditional, self, {
1200
1196
  condition : self.condition,
1201
- consequent : self.body.value || make_node(AST_Undefined, self.body),
1202
- alternative : self.alternative.value || make_node(AST_Undefined, self.alternative)
1197
+ consequent : self.body.value || make_void_0(self.body),
1198
+ alternative : self.alternative.value || make_void_0(self.alternative),
1203
1199
  }).transform(compressor)
1204
1200
  }).optimize(compressor);
1205
1201
  }
@@ -1752,7 +1748,7 @@ def_optimize(AST_Call, function(self, compressor) {
1752
1748
  const value = condition.evaluate(compressor);
1753
1749
 
1754
1750
  if (value === 1 || value === true) {
1755
- return make_node(AST_Undefined, self);
1751
+ return make_void_0(self).optimize(compressor);
1756
1752
  }
1757
1753
  }
1758
1754
  }
@@ -2114,6 +2110,10 @@ def_optimize(AST_UnaryPrefix, function(self, compressor) {
2114
2110
  ) {
2115
2111
  return make_sequence(self, [e, make_node(AST_True, self)]).optimize(compressor);
2116
2112
  }
2113
+ // Short-circuit common `void 0`
2114
+ if (self.operator === "void" && e instanceof AST_Number && e.value === 0) {
2115
+ return unsafe_undefined_ref(self, compressor) || self;
2116
+ }
2117
2117
  var seq = self.lift_sequences(compressor);
2118
2118
  if (seq !== self) {
2119
2119
  return seq;
@@ -2124,7 +2124,7 @@ def_optimize(AST_UnaryPrefix, function(self, compressor) {
2124
2124
  self.expression = e;
2125
2125
  return self;
2126
2126
  } else {
2127
- return make_node(AST_Undefined, self).optimize(compressor);
2127
+ return make_void_0(self).optimize(compressor);
2128
2128
  }
2129
2129
  }
2130
2130
  if (compressor.in_boolean_context()) {
@@ -2310,7 +2310,7 @@ def_optimize(AST_Binary, function(self, compressor) {
2310
2310
  if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor)
2311
2311
  : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) {
2312
2312
  self.right = expr;
2313
- self.left = make_node(AST_Undefined, self.left).optimize(compressor);
2313
+ self.left = make_void_0(self.left).optimize(compressor);
2314
2314
  if (self.operator.length == 2) self.operator += "=";
2315
2315
  }
2316
2316
  } else if (compressor.option("typeofs")
@@ -2323,7 +2323,7 @@ def_optimize(AST_Binary, function(self, compressor) {
2323
2323
  if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor)
2324
2324
  : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) {
2325
2325
  self.left = expr;
2326
- self.right = make_node(AST_Undefined, self.right).optimize(compressor);
2326
+ self.right = make_void_0(self.right).optimize(compressor);
2327
2327
  if (self.operator.length == 2) self.operator += "=";
2328
2328
  }
2329
2329
  } else if (self.left instanceof AST_SymbolRef
@@ -2964,7 +2964,8 @@ function is_atomic(lhs, self) {
2964
2964
  return lhs instanceof AST_SymbolRef || lhs.TYPE === self.TYPE;
2965
2965
  }
2966
2966
 
2967
- def_optimize(AST_Undefined, function(self, compressor) {
2967
+ /** Apply the `unsafe_undefined` option: find a variable called `undefined` and turn `self` into a reference to it. */
2968
+ function unsafe_undefined_ref(self, compressor) {
2968
2969
  if (compressor.option("unsafe_undefined")) {
2969
2970
  var undef = find_variable(compressor, "undefined");
2970
2971
  if (undef) {
@@ -2977,14 +2978,15 @@ def_optimize(AST_Undefined, function(self, compressor) {
2977
2978
  return ref;
2978
2979
  }
2979
2980
  }
2981
+ return null;
2982
+ }
2983
+
2984
+ def_optimize(AST_Undefined, function(self, compressor) {
2985
+ var symbolref = unsafe_undefined_ref(self, compressor);
2986
+ if (symbolref) return symbolref;
2980
2987
  var lhs = compressor.is_lhs();
2981
2988
  if (lhs && is_atomic(lhs, self)) return self;
2982
- return make_node(AST_UnaryPrefix, self, {
2983
- operator: "void",
2984
- expression: make_node(AST_Number, self, {
2985
- value: 0
2986
- })
2987
- });
2989
+ return make_void_0(self);
2988
2990
  });
2989
2991
 
2990
2992
  def_optimize(AST_Infinity, function(self, compressor) {
@@ -3671,7 +3673,7 @@ def_optimize(AST_Sub, function(self, compressor) {
3671
3673
  }
3672
3674
  }
3673
3675
  if (retValue instanceof AST_Expansion) break FLATTEN;
3674
- retValue = retValue instanceof AST_Hole ? make_node(AST_Undefined, retValue) : retValue;
3676
+ retValue = retValue instanceof AST_Hole ? make_void_0(retValue) : retValue;
3675
3677
  if (!flatten) values.unshift(retValue);
3676
3678
  while (--i >= 0) {
3677
3679
  var value = elements[i];
@@ -3710,7 +3712,7 @@ def_optimize(AST_Chain, function (self, compressor) {
3710
3712
  if (parent instanceof AST_UnaryPrefix && parent.operator === "delete") {
3711
3713
  return make_node_from_constant(0, self);
3712
3714
  }
3713
- return make_node(AST_Undefined, self);
3715
+ return make_void_0(self).optimize(compressor);
3714
3716
  }
3715
3717
  if (
3716
3718
  self.expression instanceof AST_PropAccess
@@ -76,7 +76,6 @@ import {
76
76
  AST_This,
77
77
  AST_Toplevel,
78
78
  AST_UnaryPrefix,
79
- AST_Undefined,
80
79
  AST_Var,
81
80
  AST_VarDef,
82
81
 
@@ -86,7 +85,7 @@ import {
86
85
  _NOINLINE,
87
86
  _PURE,
88
87
  } from "../ast.js";
89
- import { make_node, has_annotation } from "../utils/index.js";
88
+ import { make_node, make_void_0, has_annotation } from "../utils/index.js";
90
89
  import "../size.js";
91
90
 
92
91
  import "./evaluate.js";
@@ -358,7 +357,7 @@ export function inline_into_call(self, compressor) {
358
357
  if (returned) {
359
358
  returned = returned.clone(true);
360
359
  } else {
361
- returned = make_node(AST_Undefined, self);
360
+ returned = make_void_0(self);
362
361
  }
363
362
  const args = self.args.concat(returned);
364
363
  return make_sequence(self, args).optimize(compressor);
@@ -374,7 +373,7 @@ export function inline_into_call(self, compressor) {
374
373
  && returned.name === fn.argnames[0].name
375
374
  ) {
376
375
  const replacement =
377
- (self.args[0] || make_node(AST_Undefined)).optimize(compressor);
376
+ (self.args[0] || make_void_0()).optimize(compressor);
378
377
 
379
378
  let parent;
380
379
  if (
@@ -456,7 +455,7 @@ export function inline_into_call(self, compressor) {
456
455
 
457
456
  const can_drop_this_call = is_regular_func && compressor.option("side_effects") && fn.body.every(is_empty);
458
457
  if (can_drop_this_call) {
459
- var args = self.args.concat(make_node(AST_Undefined, self));
458
+ var args = self.args.concat(make_void_0(self));
460
459
  return make_sequence(self, args).optimize(compressor);
461
460
  }
462
461
 
@@ -475,9 +474,9 @@ export function inline_into_call(self, compressor) {
475
474
  return self;
476
475
 
477
476
  function return_value(stat) {
478
- if (!stat) return make_node(AST_Undefined, self);
477
+ if (!stat) return make_void_0(self);
479
478
  if (stat instanceof AST_Return) {
480
- if (!stat.value) return make_node(AST_Undefined, self);
479
+ if (!stat.value) return make_void_0(self);
481
480
  return stat.value.clone(true);
482
481
  }
483
482
  if (stat instanceof AST_SimpleStatement) {
@@ -623,7 +622,7 @@ export function inline_into_call(self, compressor) {
623
622
  } else {
624
623
  var symbol = make_node(AST_SymbolVar, name, name);
625
624
  name.definition().orig.push(symbol);
626
- if (!value && in_loop) value = make_node(AST_Undefined, self);
625
+ if (!value && in_loop) value = make_void_0(self);
627
626
  append_var(decls, expressions, symbol, value);
628
627
  }
629
628
  }
@@ -650,7 +649,7 @@ export function inline_into_call(self, compressor) {
650
649
  operator: "=",
651
650
  logical: false,
652
651
  left: sym,
653
- right: make_node(AST_Undefined, name)
652
+ right: make_void_0(name),
654
653
  }));
655
654
  }
656
655
  }
@@ -87,7 +87,6 @@ import {
87
87
  AST_Try,
88
88
  AST_Unary,
89
89
  AST_UnaryPrefix,
90
- AST_Undefined,
91
90
  AST_UsingDef,
92
91
  AST_VarDef,
93
92
  AST_VarDefLike,
@@ -98,7 +97,7 @@ import {
98
97
  walk_body,
99
98
  walk_parent,
100
99
  } from "../ast.js";
101
- import { HOP, make_node, noop } from "../utils/index.js";
100
+ import { HOP, make_node, make_void_0, noop } from "../utils/index.js";
102
101
 
103
102
  import { lazy_op, is_modified, is_lhs } from "./inference.js";
104
103
  import { INLINED, clear_flag } from "./compressor-flags.js";
@@ -172,7 +171,7 @@ function safe_to_read(tw, def) {
172
171
  if (def.fixed == null) {
173
172
  var orig = def.orig[0];
174
173
  if (orig instanceof AST_SymbolFunarg || orig.name == "arguments") return false;
175
- def.fixed = make_node(AST_Undefined, orig);
174
+ def.fixed = make_void_0(orig);
176
175
  }
177
176
  return true;
178
177
  }
@@ -470,7 +469,7 @@ function mark_lambda(tw, descend, compressor) {
470
469
  if (d.orig.length > 1) return;
471
470
  if (d.fixed === undefined && (!this.uses_arguments || tw.has_directive("use strict"))) {
472
471
  d.fixed = function() {
473
- return iife.args[i] || make_node(AST_Undefined, iife);
472
+ return iife.args[i] || make_void_0(iife);
474
473
  };
475
474
  tw.loop_ids.set(d.id, tw.in_loop);
476
475
  mark(tw, d, true);
@@ -106,7 +106,6 @@ import {
106
106
  AST_Unary,
107
107
  AST_UnaryPostfix,
108
108
  AST_UnaryPrefix,
109
- AST_Undefined,
110
109
  AST_Using,
111
110
  AST_Var,
112
111
  AST_VarDef,
@@ -122,6 +121,7 @@ import {
122
121
  } from "../ast.js";
123
122
  import {
124
123
  make_node,
124
+ make_void_0,
125
125
  MAP,
126
126
  member,
127
127
  remove,
@@ -635,7 +635,7 @@ export function tighten_body(statements, compressor) {
635
635
  }
636
636
  } else {
637
637
  if (!arg) {
638
- arg = make_node(AST_Undefined, sym).transform(compressor);
638
+ arg = make_void_0(sym).transform(compressor);
639
639
  } else if (arg instanceof AST_Lambda && arg.pinned()
640
640
  || has_overlapping_symbol(fn, arg, fn_strict)) {
641
641
  arg = null;
@@ -875,7 +875,7 @@ export function tighten_body(statements, compressor) {
875
875
  found = true;
876
876
  if (node instanceof AST_VarDef) {
877
877
  node.value = node.name instanceof AST_SymbolConst
878
- ? make_node(AST_Undefined, node.value) // `const` always needs value.
878
+ ? make_void_0(node.value) // `const` always needs value.
879
879
  : null;
880
880
  return node;
881
881
  }
@@ -1314,7 +1314,7 @@ export function tighten_body(statements, compressor) {
1314
1314
  var stat = statements[i];
1315
1315
  if (prev) {
1316
1316
  if (stat instanceof AST_Exit) {
1317
- stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat).transform(compressor));
1317
+ stat.value = cons_seq(stat.value || make_void_0(stat).transform(compressor));
1318
1318
  } else if (stat instanceof AST_For) {
1319
1319
  if (!(stat.init instanceof AST_DefinitionsLike)) {
1320
1320
  const abort = walk(prev.body, node => {
@@ -43,7 +43,7 @@
43
43
 
44
44
  "use strict";
45
45
 
46
- import { AST_Node } from "../ast.js";
46
+ import { AST_Node, AST_Number, AST_UnaryPrefix } from "../ast.js";
47
47
 
48
48
  function characters(str) {
49
49
  return str.split("");
@@ -130,6 +130,15 @@ function make_node(ctor, orig, props) {
130
130
  return new ctor(props);
131
131
  }
132
132
 
133
+ /** Makes a `void 0` expression. Use instead of AST_Undefined which may conflict
134
+ * with an existing variable called `undefined` */
135
+ function make_void_0(orig) {
136
+ return make_node(AST_UnaryPrefix, orig, {
137
+ operator: "void",
138
+ expression: make_node(AST_Number, orig, { value: 0 })
139
+ });
140
+ }
141
+
133
142
  function push_uniq(array, el) {
134
143
  if (!array.includes(el))
135
144
  array.push(el);
@@ -272,6 +281,7 @@ export {
272
281
  HOP,
273
282
  keep_name,
274
283
  make_node,
284
+ make_void_0,
275
285
  makePredicate,
276
286
  map_add,
277
287
  map_from_object,
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.44.1",
7
+ "version": "5.45.0",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },
@@ -61,6 +61,10 @@
61
61
  "semver": "^7.5.1",
62
62
  "source-map": "~0.8.0-beta.0"
63
63
  },
64
+ "overrides": {
65
+ "serialize-javascript": "6.0.2",
66
+ "js-yaml": "4.1.1"
67
+ },
64
68
  "scripts": {
65
69
  "test": "node test/compress.js && mocha test/mocha",
66
70
  "test:compress": "node test/compress.js",