terser 4.0.1 → 4.1.2

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.

Potentially problematic release.


This version of terser might be problematic. Click here for more details.

package/dist/bundle.js CHANGED
@@ -57,13 +57,6 @@
57
57
  return array.includes(name);
58
58
  }
59
59
 
60
- function find_if(func, array) {
61
- for (var i = 0, n = array.length; i < n; ++i) {
62
- if (func(array[i]))
63
- return array[i];
64
- }
65
- }
66
-
67
60
  class DefaultsError extends Error {
68
61
  constructor(msg, defs) {
69
62
  super();
@@ -86,15 +79,6 @@
86
79
  return ret;
87
80
  }
88
81
 
89
- function merge(obj, ext) {
90
- var count = 0;
91
- for (var i in ext) if (HOP(ext, i)) {
92
- obj[i] = ext[i];
93
- count++;
94
- }
95
- return count;
96
- }
97
-
98
82
  function noop() {}
99
83
  function return_false() { return false; }
100
84
  function return_true() { return true; }
@@ -194,13 +178,6 @@
194
178
  return new Set(words);
195
179
  }
196
180
 
197
- function all(array, predicate) {
198
- for (var i = array.length; --i >= 0;)
199
- if (!predicate(array[i]))
200
- return false;
201
- return true;
202
- }
203
-
204
181
  function map_add(map, key, value) {
205
182
  if (map.has(key)) {
206
183
  map.get(key).push(value);
@@ -231,29 +208,6 @@
231
208
  return Object.prototype.hasOwnProperty.call(obj, prop);
232
209
  }
233
210
 
234
- // return true if the node at the top of the stack (that means the
235
- // innermost node in the current output) is lexically the first in
236
- // a statement.
237
- function first_in_statement(stack) {
238
- var node = stack.parent(-1);
239
- for (var i = 0, p; p = stack.parent(i); i++) {
240
- if (p instanceof AST_Statement && p.body === node)
241
- return true;
242
- if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
243
- (p.TYPE == "Call" && p.expression === node ) ||
244
- (p instanceof AST_Dot && p.expression === node ) ||
245
- (p instanceof AST_Sub && p.expression === node ) ||
246
- (p instanceof AST_Conditional && p.condition === node ) ||
247
- (p instanceof AST_Binary && p.left === node ) ||
248
- (p instanceof AST_UnaryPostfix && p.expression === node )
249
- ) {
250
- node = p;
251
- } else {
252
- return false;
253
- }
254
- }
255
- }
256
-
257
211
  function keep_name(keep_setting, name) {
258
212
  return keep_setting === true
259
213
  || (keep_setting instanceof RegExp && keep_setting.test(name));
@@ -321,6 +275,7 @@
321
275
  var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;
322
276
  var RE_BIN_NUMBER = /^0b[01]+$/i;
323
277
  var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;
278
+ var RE_BIG_INT = /^(0[xob])?[0-9]+n$/i;
324
279
 
325
280
  var OPERATORS = makePredicate([
326
281
  "in",
@@ -644,8 +599,10 @@
644
599
  }
645
600
 
646
601
  function read_num(prefix) {
647
- var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".";
602
+ var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".", is_big_int = false;
648
603
  var num = read_while(function(ch, i) {
604
+ if (is_big_int) return false;
605
+
649
606
  var code = ch.charCodeAt(0);
650
607
  switch (code) {
651
608
  case 98: case 66: // bB
@@ -662,12 +619,24 @@
662
619
  case (after_e = false, 46): // .
663
620
  return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;
664
621
  }
622
+
623
+ if (ch === "n") {
624
+ is_big_int = true;
625
+
626
+ return true;
627
+ }
628
+
665
629
  return RE_NUM_LITERAL.test(ch);
666
630
  });
667
631
  if (prefix) num = prefix + num;
668
632
  if (RE_OCT_NUMBER.test(num) && next_token.has_directive("use strict")) {
669
633
  parse_error("Legacy octal literals are not allowed in strict mode");
670
634
  }
635
+ if (num.endsWith("n")) {
636
+ if (!has_dot && RE_BIG_INT.test(num))
637
+ return token("big_int", num.replace("n", ""));
638
+ parse_error("Invalid or unexpected token");
639
+ }
671
640
  var valid = parse_js_number(num);
672
641
  if (!isNaN(valid)) {
673
642
  return token("num", valid);
@@ -1111,7 +1080,7 @@
1111
1080
  {}
1112
1081
  );
1113
1082
 
1114
- var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "string", "regexp", "name" ]);
1083
+ var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "big_int", "string", "regexp", "name" ]);
1115
1084
 
1116
1085
  /* -----[ Parser ]----- */
1117
1086
 
@@ -1198,9 +1167,7 @@
1198
1167
  function expect(punc) { return expect_token("punc", punc); }
1199
1168
 
1200
1169
  function has_newline_before(token) {
1201
- return token.nlb || !all(token.comments_before, function(comment) {
1202
- return !comment.nlb;
1203
- });
1170
+ return token.nlb || !token.comments_before.every((comment) => !comment.nlb);
1204
1171
  }
1205
1172
 
1206
1173
  function can_insert_semicolon() {
@@ -1266,6 +1233,7 @@
1266
1233
  return dir && stat.body instanceof AST_String ? new AST_Directive(stat.body) : stat;
1267
1234
  case "template_head":
1268
1235
  case "num":
1236
+ case "big_int":
1269
1237
  case "regexp":
1270
1238
  case "operator":
1271
1239
  case "atom":
@@ -1448,7 +1416,7 @@
1448
1416
  if (label.name === "await" && is_in_async()) {
1449
1417
  token_error(S.prev, "await cannot be used as label inside async function");
1450
1418
  }
1451
- if (find_if(function(l) { return l.name == label.name; }, S.labels)) {
1419
+ if (S.labels.some((l) => l.name === label.name)) {
1452
1420
  // ECMA-262, 12.12: An ECMAScript program is considered
1453
1421
  // syntactically incorrect if it contains a
1454
1422
  // LabelledStatement that is enclosed by a
@@ -1484,7 +1452,7 @@
1484
1452
  label = as_symbol(AST_LabelRef, true);
1485
1453
  }
1486
1454
  if (label != null) {
1487
- ldef = find_if(function(l) { return l.name == label.name; }, S.labels);
1455
+ ldef = S.labels.find((l) => l.name === label.name);
1488
1456
  if (!ldef)
1489
1457
  croak("Undefined label " + label.name);
1490
1458
  label.thedef = ldef;
@@ -2235,6 +2203,9 @@
2235
2203
  case "num":
2236
2204
  ret = new AST_Number({ start: tok, end: tok, value: tok.value });
2237
2205
  break;
2206
+ case "big_int":
2207
+ ret = new AST_BigInt({ start: tok, end: tok, value: tok.value });
2208
+ break;
2238
2209
  case "string":
2239
2210
  ret = new AST_String({
2240
2211
  start : tok,
@@ -2398,7 +2369,7 @@
2398
2369
  return subscripts(cls, allow_calls);
2399
2370
  }
2400
2371
  if (is("template_head")) {
2401
- return subscripts(template_string(false), allow_calls);
2372
+ return subscripts(template_string(), allow_calls);
2402
2373
  }
2403
2374
  if (ATOMIC_START_TOKEN.has(S.token.type)) {
2404
2375
  return subscripts(as_atom_node(), allow_calls);
@@ -2886,6 +2857,7 @@
2886
2857
  }
2887
2858
  case "string":
2888
2859
  case "num":
2860
+ case "big_int":
2889
2861
  case "keyword":
2890
2862
  case "atom":
2891
2863
  next();
@@ -2989,7 +2961,7 @@
2989
2961
  return subscripts(new AST_PrefixedTemplateString({
2990
2962
  start: start,
2991
2963
  prefix: expr,
2992
- template_string: template_string(true),
2964
+ template_string: template_string(),
2993
2965
  end: prev()
2994
2966
  }), allow_calls);
2995
2967
  }
@@ -3279,8 +3251,7 @@
3279
3251
 
3280
3252
  ***********************************************************************/
3281
3253
 
3282
- function DEFNODE(type, props, methods, base) {
3283
- if (arguments.length < 4) base = AST_Node;
3254
+ function DEFNODE(type, props, methods, base = AST_Node) {
3284
3255
  if (!props) props = [];
3285
3256
  else props = props.split(/\s+/);
3286
3257
  var self_props = props;
@@ -4342,6 +4313,13 @@
4342
4313
  }
4343
4314
  }, AST_Constant);
4344
4315
 
4316
+ var AST_BigInt = DEFNODE("BigInt", "value", {
4317
+ $documentation: "A big int literal",
4318
+ $propdoc: {
4319
+ value: "[string] big int value"
4320
+ }
4321
+ }, AST_Constant);
4322
+
4345
4323
  var AST_RegExp = DEFNODE("RegExp", "value", {
4346
4324
  $documentation: "A regexp literal",
4347
4325
  $propdoc: {
@@ -4496,12 +4474,13 @@
4496
4474
  };
4497
4475
 
4498
4476
  // Tree transformer helpers.
4499
- function TreeTransformer(before, after) {
4500
- TreeWalker.call(this);
4501
- this.before = before;
4502
- this.after = after;
4477
+ class TreeTransformer extends TreeWalker {
4478
+ constructor(before, after) {
4479
+ super();
4480
+ this.before = before;
4481
+ this.after = after;
4482
+ }
4503
4483
  }
4504
- TreeTransformer.prototype = new TreeWalker;
4505
4484
 
4506
4485
  var ast = /*#__PURE__*/Object.freeze({
4507
4486
  AST_Accessor: AST_Accessor,
@@ -4510,6 +4489,7 @@
4510
4489
  AST_Assign: AST_Assign,
4511
4490
  AST_Atom: AST_Atom,
4512
4491
  AST_Await: AST_Await,
4492
+ AST_BigInt: AST_BigInt,
4513
4493
  AST_Binary: AST_Binary,
4514
4494
  AST_Block: AST_Block,
4515
4495
  AST_BlockStatement: AST_BlockStatement,
@@ -4889,6 +4869,29 @@
4889
4869
 
4890
4870
  })();
4891
4871
 
4872
+ // return true if the node at the top of the stack (that means the
4873
+ // innermost node in the current output) is lexically the first in
4874
+ // a statement.
4875
+ function first_in_statement(stack) {
4876
+ let node = stack.parent(-1);
4877
+ for (let i = 0, p; p = stack.parent(i); i++) {
4878
+ if (p instanceof AST_Statement && p.body === node)
4879
+ return true;
4880
+ if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
4881
+ (p.TYPE === "Call" && p.expression === node) ||
4882
+ (p instanceof AST_Dot && p.expression === node) ||
4883
+ (p instanceof AST_Sub && p.expression === node) ||
4884
+ (p instanceof AST_Conditional && p.condition === node) ||
4885
+ (p instanceof AST_Binary && p.left === node) ||
4886
+ (p instanceof AST_UnaryPostfix && p.expression === node)
4887
+ ) {
4888
+ node = p;
4889
+ } else {
4890
+ return false;
4891
+ }
4892
+ }
4893
+ }
4894
+
4892
4895
  /***********************************************************************
4893
4896
 
4894
4897
  A JavaScript tokenizer / parser / beautifier / compressor.
@@ -5452,9 +5455,9 @@
5452
5455
  if (!token) return;
5453
5456
  var comments = token[tail ? "comments_before" : "comments_after"];
5454
5457
  if (!comments || comments._dumped === self) return;
5455
- if (!(node instanceof AST_Statement || all(comments, function(c) {
5456
- return !/comment[134]/.test(c.type);
5457
- }))) return;
5458
+ if (!(node instanceof AST_Statement || comments.every((c) =>
5459
+ !/comment[134]/.test(c.type)
5460
+ ))) return;
5458
5461
  comments._dumped = self;
5459
5462
  var insert = OUTPUT.length;
5460
5463
  comments.filter(comment_filter, node).forEach(function(c, i) {
@@ -5770,6 +5773,16 @@
5770
5773
  }
5771
5774
  });
5772
5775
 
5776
+ PARENS(AST_BigInt, function(output) {
5777
+ var p = output.parent();
5778
+ if (p instanceof AST_PropAccess && p.expression === this) {
5779
+ var value = this.getValue();
5780
+ if (value.startsWith("-")) {
5781
+ return true;
5782
+ }
5783
+ }
5784
+ });
5785
+
5773
5786
  PARENS([ AST_Assign, AST_Conditional ], function(output) {
5774
5787
  var p = output.parent();
5775
5788
  // !(a = false) → true
@@ -6714,6 +6727,9 @@
6714
6727
  output.print(make_num(self.getValue()));
6715
6728
  }
6716
6729
  });
6730
+ DEFPRINT(AST_BigInt, function(self, output) {
6731
+ output.print(self.getValue() + "n");
6732
+ });
6717
6733
 
6718
6734
  DEFPRINT(AST_RegExp, function(self, output) {
6719
6735
  var regexp = self.getValue();
@@ -6756,18 +6772,27 @@
6756
6772
  }
6757
6773
 
6758
6774
  function make_num(num) {
6759
- var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace("e+", "e") ], m;
6775
+ var str = num.toString(10).replace(/^0\./, ".").replace("e+", "e");
6776
+ var candidates = [ str ];
6760
6777
  if (Math.floor(num) === num) {
6761
- a.push(
6762
- (num >= 0 ? "0x" : "-0x") + num.toString(16).toLowerCase() // probably pointless
6763
- );
6764
- if ((m = /^(.*?)(0{3,})$/.exec(num))) {
6765
- a.push(m[1] + "e" + m[2].length);
6778
+ if (num < 0) {
6779
+ candidates.push("-0x" + (-num).toString(16).toLowerCase());
6780
+ } else {
6781
+ candidates.push("0x" + num.toString(16).toLowerCase());
6766
6782
  }
6767
- } else if ((m = /^0?\.(0+)(.*)$/.exec(num))) {
6768
- a.push(m[2] + "e-" + (m[1].length + m[2].length));
6769
6783
  }
6770
- return best_of(a);
6784
+ var match, len, digits;
6785
+ if (match = /^\.0+/.exec(str)) {
6786
+ len = match[0].length;
6787
+ digits = str.slice(len);
6788
+ candidates.push(digits + "e-" + (digits.length + len - 1));
6789
+ } else if (match = /0+$/.exec(str)) {
6790
+ len = match[0].length;
6791
+ candidates.push(str.slice(0, -len) + "e" + len);
6792
+ } else if (match = /^(\d)\.(\d+)e(-?\d+)$/.exec(str)) {
6793
+ candidates.push(match[1] + match[2] + "e" + (match[3] - match[2].length));
6794
+ }
6795
+ return best_of(candidates);
6771
6796
  }
6772
6797
 
6773
6798
  function make_block(stmt, output) {
@@ -7037,7 +7062,7 @@
7037
7062
  } else {
7038
7063
  def = defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
7039
7064
  }
7040
- if (!all(def.orig, function(sym) {
7065
+ if (!def.orig.every((sym) => {
7041
7066
  if (sym === node) return true;
7042
7067
  if (node instanceof AST_SymbolBlockDeclaration) {
7043
7068
  return sym instanceof AST_SymbolLambda;
@@ -7601,127 +7626,128 @@
7601
7626
 
7602
7627
  ***********************************************************************/
7603
7628
 
7604
- function Compressor(options, false_by_default) {
7605
- if (!(this instanceof Compressor))
7606
- return new Compressor(options, false_by_default);
7607
- TreeTransformer.call(this, this.before, this.after);
7608
- if (options.defaults !== undefined && !options.defaults) false_by_default = true;
7609
- this.options = defaults(options, {
7610
- arguments : false,
7611
- arrows : !false_by_default,
7612
- booleans : !false_by_default,
7613
- booleans_as_integers : false,
7614
- collapse_vars : !false_by_default,
7615
- comparisons : !false_by_default,
7616
- computed_props: !false_by_default,
7617
- conditionals : !false_by_default,
7618
- dead_code : !false_by_default,
7619
- defaults : true,
7620
- directives : !false_by_default,
7621
- drop_console : false,
7622
- drop_debugger : !false_by_default,
7623
- ecma : 5,
7624
- evaluate : !false_by_default,
7625
- expression : false,
7626
- global_defs : false,
7627
- hoist_funs : false,
7628
- hoist_props : !false_by_default,
7629
- hoist_vars : false,
7630
- ie8 : false,
7631
- if_return : !false_by_default,
7632
- inline : !false_by_default,
7633
- join_vars : !false_by_default,
7634
- keep_classnames: false,
7635
- keep_fargs : true,
7636
- keep_fnames : false,
7637
- keep_infinity : false,
7638
- loops : !false_by_default,
7639
- module : false,
7640
- negate_iife : !false_by_default,
7641
- passes : 1,
7642
- properties : !false_by_default,
7643
- pure_getters : !false_by_default && "strict",
7644
- pure_funcs : null,
7645
- reduce_funcs : !false_by_default,
7646
- reduce_vars : !false_by_default,
7647
- sequences : !false_by_default,
7648
- side_effects : !false_by_default,
7649
- switches : !false_by_default,
7650
- top_retain : null,
7651
- toplevel : !!(options && options["top_retain"]),
7652
- typeofs : !false_by_default,
7653
- unsafe : false,
7654
- unsafe_arrows : false,
7655
- unsafe_comps : false,
7656
- unsafe_Function: false,
7657
- unsafe_math : false,
7658
- unsafe_methods: false,
7659
- unsafe_proto : false,
7660
- unsafe_regexp : false,
7661
- unsafe_undefined: false,
7662
- unused : !false_by_default,
7663
- warnings : false,
7664
- }, true);
7665
- var global_defs = this.options["global_defs"];
7666
- if (typeof global_defs == "object") for (var key in global_defs) {
7667
- if (key[0] === "@" && HOP(global_defs, key)) {
7668
- global_defs[key.slice(1)] = parse(global_defs[key], {
7669
- expression: true
7670
- });
7629
+ class Compressor extends TreeWalker {
7630
+ constructor(options, false_by_default) {
7631
+ super();
7632
+ if (options.defaults !== undefined && !options.defaults) false_by_default = true;
7633
+ this.options = defaults(options, {
7634
+ arguments : false,
7635
+ arrows : !false_by_default,
7636
+ booleans : !false_by_default,
7637
+ booleans_as_integers : false,
7638
+ collapse_vars : !false_by_default,
7639
+ comparisons : !false_by_default,
7640
+ computed_props: !false_by_default,
7641
+ conditionals : !false_by_default,
7642
+ dead_code : !false_by_default,
7643
+ defaults : true,
7644
+ directives : !false_by_default,
7645
+ drop_console : false,
7646
+ drop_debugger : !false_by_default,
7647
+ ecma : 5,
7648
+ evaluate : !false_by_default,
7649
+ expression : false,
7650
+ global_defs : false,
7651
+ hoist_funs : false,
7652
+ hoist_props : !false_by_default,
7653
+ hoist_vars : false,
7654
+ ie8 : false,
7655
+ if_return : !false_by_default,
7656
+ inline : !false_by_default,
7657
+ join_vars : !false_by_default,
7658
+ keep_classnames: false,
7659
+ keep_fargs : true,
7660
+ keep_fnames : false,
7661
+ keep_infinity : false,
7662
+ loops : !false_by_default,
7663
+ module : false,
7664
+ negate_iife : !false_by_default,
7665
+ passes : 1,
7666
+ properties : !false_by_default,
7667
+ pure_getters : !false_by_default && "strict",
7668
+ pure_funcs : null,
7669
+ reduce_funcs : !false_by_default,
7670
+ reduce_vars : !false_by_default,
7671
+ sequences : !false_by_default,
7672
+ side_effects : !false_by_default,
7673
+ switches : !false_by_default,
7674
+ top_retain : null,
7675
+ toplevel : !!(options && options["top_retain"]),
7676
+ typeofs : !false_by_default,
7677
+ unsafe : false,
7678
+ unsafe_arrows : false,
7679
+ unsafe_comps : false,
7680
+ unsafe_Function: false,
7681
+ unsafe_math : false,
7682
+ unsafe_methods: false,
7683
+ unsafe_proto : false,
7684
+ unsafe_regexp : false,
7685
+ unsafe_undefined: false,
7686
+ unused : !false_by_default,
7687
+ warnings : false,
7688
+ }, true);
7689
+ var global_defs = this.options["global_defs"];
7690
+ if (typeof global_defs == "object") for (var key in global_defs) {
7691
+ if (key[0] === "@" && HOP(global_defs, key)) {
7692
+ global_defs[key.slice(1)] = parse(global_defs[key], {
7693
+ expression: true
7694
+ });
7695
+ }
7671
7696
  }
7672
- }
7673
- if (this.options["inline"] === true) this.options["inline"] = 3;
7674
- var pure_funcs = this.options["pure_funcs"];
7675
- if (typeof pure_funcs == "function") {
7676
- this.pure_funcs = pure_funcs;
7677
- } else {
7678
- this.pure_funcs = pure_funcs ? function(node) {
7679
- return !pure_funcs.includes(node.expression.print_to_string());
7680
- } : return_true;
7681
- }
7682
- var top_retain = this.options["top_retain"];
7683
- if (top_retain instanceof RegExp) {
7684
- this.top_retain = function(def) {
7685
- return top_retain.test(def.name);
7686
- };
7687
- } else if (typeof top_retain == "function") {
7688
- this.top_retain = top_retain;
7689
- } else if (top_retain) {
7690
- if (typeof top_retain == "string") {
7691
- top_retain = top_retain.split(/,/);
7692
- }
7693
- this.top_retain = function(def) {
7694
- return top_retain.includes(def.name);
7697
+ if (this.options["inline"] === true) this.options["inline"] = 3;
7698
+ var pure_funcs = this.options["pure_funcs"];
7699
+ if (typeof pure_funcs == "function") {
7700
+ this.pure_funcs = pure_funcs;
7701
+ } else {
7702
+ this.pure_funcs = pure_funcs ? function(node) {
7703
+ return !pure_funcs.includes(node.expression.print_to_string());
7704
+ } : return_true;
7705
+ }
7706
+ var top_retain = this.options["top_retain"];
7707
+ if (top_retain instanceof RegExp) {
7708
+ this.top_retain = function(def) {
7709
+ return top_retain.test(def.name);
7710
+ };
7711
+ } else if (typeof top_retain == "function") {
7712
+ this.top_retain = top_retain;
7713
+ } else if (top_retain) {
7714
+ if (typeof top_retain == "string") {
7715
+ top_retain = top_retain.split(/,/);
7716
+ }
7717
+ this.top_retain = function(def) {
7718
+ return top_retain.includes(def.name);
7719
+ };
7720
+ }
7721
+ if (this.options["module"]) {
7722
+ this.directives["use strict"] = true;
7723
+ this.options["toplevel"] = true;
7724
+ }
7725
+ var toplevel = this.options["toplevel"];
7726
+ this.toplevel = typeof toplevel == "string" ? {
7727
+ funcs: /funcs/.test(toplevel),
7728
+ vars: /vars/.test(toplevel)
7729
+ } : {
7730
+ funcs: toplevel,
7731
+ vars: toplevel
7695
7732
  };
7733
+ var sequences = this.options["sequences"];
7734
+ this.sequences_limit = sequences == 1 ? 800 : sequences | 0;
7735
+ this.warnings_produced = {};
7736
+ }
7737
+
7738
+ option(key) {
7739
+ return this.options[key];
7696
7740
  }
7697
- if (this.options["module"]) {
7698
- this.directives["use strict"] = true;
7699
- this.options["toplevel"] = true;
7700
- }
7701
- var toplevel = this.options["toplevel"];
7702
- this.toplevel = typeof toplevel == "string" ? {
7703
- funcs: /funcs/.test(toplevel),
7704
- vars: /vars/.test(toplevel)
7705
- } : {
7706
- funcs: toplevel,
7707
- vars: toplevel
7708
- };
7709
- var sequences = this.options["sequences"];
7710
- this.sequences_limit = sequences == 1 ? 800 : sequences | 0;
7711
- this.warnings_produced = {};
7712
- }
7713
7741
 
7714
- Compressor.prototype = new TreeTransformer;
7715
- merge(Compressor.prototype, {
7716
- option: function(key) { return this.options[key]; },
7717
- exposed: function(def) {
7742
+ exposed(def) {
7718
7743
  if (def.export) return true;
7719
7744
  if (def.global) for (var i = 0, len = def.orig.length; i < len; i++)
7720
7745
  if (!this.toplevel[def.orig[i] instanceof AST_SymbolDefun ? "funcs" : "vars"])
7721
7746
  return true;
7722
7747
  return false;
7723
- },
7724
- in_boolean_context: function() {
7748
+ }
7749
+
7750
+ in_boolean_context() {
7725
7751
  if (!this.option("booleans")) return false;
7726
7752
  var self = this.self();
7727
7753
  for (var i = 0, p; p = this.parent(i); i++) {
@@ -7741,8 +7767,9 @@
7741
7767
  return false;
7742
7768
  }
7743
7769
  }
7744
- },
7745
- compress: function(node) {
7770
+ }
7771
+
7772
+ compress(node) {
7746
7773
  node = node.resolve_defines(this);
7747
7774
  if (this.option("expression")) {
7748
7775
  node.process_expression(true);
@@ -7780,13 +7807,15 @@
7780
7807
  node.process_expression(false);
7781
7808
  }
7782
7809
  return node;
7783
- },
7784
- info: function() {
7810
+ }
7811
+
7812
+ info() {
7785
7813
  if (this.options.warnings == "verbose") {
7786
7814
  AST_Node.warn.apply(AST_Node, arguments);
7787
7815
  }
7788
- },
7789
- warn: function(text, props) {
7816
+ }
7817
+
7818
+ warn(text, props) {
7790
7819
  if (this.options.warnings) {
7791
7820
  // only emit unique warnings
7792
7821
  var message = string_template(text, props);
@@ -7795,11 +7824,12 @@
7795
7824
  AST_Node.warn.apply(AST_Node, arguments);
7796
7825
  }
7797
7826
  }
7798
- },
7799
- clear_warnings: function() {
7827
+ }
7828
+
7829
+ clear_warnings() {
7800
7830
  this.warnings_produced = {};
7801
- },
7802
- before: function(node, descend, in_list) {
7831
+ }
7832
+ before(node, descend, in_list) {
7803
7833
  if (node._squeezed) return node;
7804
7834
  var was_scope = false;
7805
7835
  if (node instanceof AST_Scope) {
@@ -7827,7 +7857,7 @@
7827
7857
  if (opt === node) opt._squeezed = true;
7828
7858
  return opt;
7829
7859
  }
7830
- });
7860
+ }
7831
7861
 
7832
7862
  (function() {
7833
7863
 
@@ -8035,7 +8065,7 @@
8035
8065
  if (!safe_to_read(tw, def)) return false;
8036
8066
  if (def.fixed === false) return false;
8037
8067
  if (def.fixed != null && (!value || def.references.length > def.assignments)) return false;
8038
- return all(def.orig, function(sym) {
8068
+ return def.orig.every((sym) => {
8039
8069
  return !(sym instanceof AST_SymbolConst
8040
8070
  || sym instanceof AST_SymbolDefun
8041
8071
  || sym instanceof AST_SymbolLambda);
@@ -8705,6 +8735,7 @@
8705
8735
  || node instanceof AST_Try
8706
8736
  || node instanceof AST_With
8707
8737
  || node instanceof AST_Yield
8738
+ || node instanceof AST_Export
8708
8739
  || parent instanceof AST_For && node !== parent.init
8709
8740
  || !replace_all
8710
8741
  && (node instanceof AST_SymbolRef && !node.is_declared(compressor))) {
@@ -8921,9 +8952,9 @@
8921
8952
  && !fn.pinned()
8922
8953
  && (iife = compressor.parent()) instanceof AST_Call
8923
8954
  && iife.expression === fn
8924
- && all(iife.args, function(arg) {
8925
- return !(arg instanceof AST_Expansion);
8926
- })) {
8955
+ && iife.args.every((arg) =>
8956
+ !(arg instanceof AST_Expansion)
8957
+ )) {
8927
8958
  var fn_strict = compressor.has_directive("use strict");
8928
8959
  if (fn_strict && !member(fn_strict, fn.body)) fn_strict = false;
8929
8960
  var len = fn.argnames.length;
@@ -8940,9 +8971,9 @@
8940
8971
  names.add(sym.name);
8941
8972
  if (sym instanceof AST_Expansion) {
8942
8973
  var elements = iife.args.slice(i);
8943
- if (all(elements, function(arg) {
8944
- return !has_overlapping_symbol(fn, arg, fn_strict);
8945
- })) {
8974
+ if (elements.every((arg) =>
8975
+ !has_overlapping_symbol(fn, arg, fn_strict)
8976
+ )) {
8946
8977
  candidates.unshift([ make_node(AST_VarDef, sym, {
8947
8978
  name: sym.expression,
8948
8979
  value: make_node(AST_Array, iife, {
@@ -9198,7 +9229,7 @@
9198
9229
  var def = sym.definition();
9199
9230
  if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false;
9200
9231
  if (def.scope.get_defun_scope() !== scope) return true;
9201
- return !all(def.references, function(ref) {
9232
+ return !def.references.every((ref) => {
9202
9233
  var s = ref.scope.get_defun_scope();
9203
9234
  // "block" scope within AST_Catch
9204
9235
  if (s.TYPE == "Scope") s = s.parent_scope;
@@ -9223,7 +9254,7 @@
9223
9254
  var seen_dirs = [];
9224
9255
  for (var i = 0; i < statements.length;) {
9225
9256
  var stat = statements[i];
9226
- if (stat instanceof AST_BlockStatement && all(stat.body, can_be_evicted_from_block)) {
9257
+ if (stat instanceof AST_BlockStatement && stat.body.every(can_be_evicted_from_block)) {
9227
9258
  CHANGED = true;
9228
9259
  eliminate_spurious_blocks(stat.body);
9229
9260
  [].splice.apply(statements, [i, 1].concat(stat.body));
@@ -9325,7 +9356,7 @@
9325
9356
  CHANGED = true;
9326
9357
  stat = stat.clone();
9327
9358
  stat.alternative = next;
9328
- statements.splice(i, 1, stat.transform(compressor));
9359
+ statements[i] = stat.transform(compressor);
9329
9360
  statements.splice(j, 1);
9330
9361
  continue;
9331
9362
  }
@@ -9339,7 +9370,7 @@
9339
9370
  stat.alternative = next || make_node(AST_Return, stat, {
9340
9371
  value: null
9341
9372
  });
9342
- statements.splice(i, 1, stat.transform(compressor));
9373
+ statements[i] = stat.transform(compressor);
9343
9374
  if (next) statements.splice(j, 1);
9344
9375
  continue;
9345
9376
  }
@@ -9363,7 +9394,7 @@
9363
9394
  })
9364
9395
  ]
9365
9396
  });
9366
- statements.splice(i, 1, stat.transform(compressor));
9397
+ statements[i] = stat.transform(compressor);
9367
9398
  statements.splice(j, 1);
9368
9399
  continue;
9369
9400
  }
@@ -9474,9 +9505,9 @@
9474
9505
  }
9475
9506
 
9476
9507
  function declarations_only(node) {
9477
- return all(node.definitions, function(var_def) {
9478
- return !var_def.value;
9479
- });
9508
+ return node.definitions.every((var_def) =>
9509
+ !var_def.value
9510
+ );
9480
9511
  }
9481
9512
 
9482
9513
  function sequencesize(statements, compressor) {
@@ -9627,7 +9658,7 @@
9627
9658
  } : function(node) {
9628
9659
  return node.key && node.key.name != prop;
9629
9660
  };
9630
- if (!all(def.value.properties, diff)) break;
9661
+ if (!def.value.properties.every(diff)) break;
9631
9662
  var p = def.value.properties.filter(function (p) { return p.key === prop; })[0];
9632
9663
  if (!p) {
9633
9664
  def.value.properties.push(make_node(AST_ObjectKeyVal, node, {
@@ -10761,13 +10792,6 @@
10761
10792
 
10762
10793
  // determine if expression is constant
10763
10794
  (function(def_is_constant_expression) {
10764
- function all(list) {
10765
- for (var i = list.length; --i >= 0;)
10766
- if (!list[i].is_constant_expression())
10767
- return false;
10768
- return true;
10769
- }
10770
-
10771
10795
  function all_refs_local(scope) {
10772
10796
  var self = this;
10773
10797
  var result = true;
@@ -10817,10 +10841,10 @@
10817
10841
  return this.left.is_constant_expression() && this.right.is_constant_expression();
10818
10842
  });
10819
10843
  def_is_constant_expression(AST_Array, function() {
10820
- return all(this.elements);
10844
+ return this.elements.every((l) => l.is_constant_expression());
10821
10845
  });
10822
10846
  def_is_constant_expression(AST_Object, function() {
10823
- return all(this.properties);
10847
+ return this.properties.every((l) => l.is_constant_expression());
10824
10848
  });
10825
10849
  def_is_constant_expression(AST_ObjectProperty, function() {
10826
10850
  return !(this.key instanceof AST_Node) && this.value.is_constant_expression();
@@ -11220,7 +11244,7 @@
11220
11244
  }
11221
11245
  if (node instanceof AST_BlockStatement) {
11222
11246
  descend(node, this);
11223
- if (in_list && all(node.body, can_be_evicted_from_block)) {
11247
+ if (in_list && node.body.every(can_be_evicted_from_block)) {
11224
11248
  return MAP.splice(node.body);
11225
11249
  }
11226
11250
  return node;
@@ -11347,10 +11371,10 @@
11347
11371
  if (vars_found > 0) {
11348
11372
  // collect only vars which don't show up in self's arguments list
11349
11373
  var defs = [];
11350
- vars.forEach(function(def, name) {
11351
- if (self instanceof AST_Lambda
11352
- && find_if(function(x) { return x.name == def.name.name; },
11353
- self.args_as_names())) {
11374
+ const is_lambda = self instanceof AST_Lambda;
11375
+ const args_as_names = is_lambda ? self.args_as_names() : null;
11376
+ vars.forEach((def, name) => {
11377
+ if (is_lambda && args_as_names.some((x) => x.name === def.name.name)) {
11354
11378
  vars.delete(name);
11355
11379
  } else {
11356
11380
  def = def.clone();
@@ -12089,8 +12113,8 @@
12089
12113
 
12090
12114
  def_optimize(AST_Try, function(self, compressor) {
12091
12115
  tighten_body(self.body, compressor);
12092
- if (self.bcatch && self.bfinally && all(self.bfinally.body, is_empty)) self.bfinally = null;
12093
- if (compressor.option("dead_code") && all(self.body, is_empty)) {
12116
+ if (self.bcatch && self.bfinally && self.bfinally.body.every(is_empty)) self.bfinally = null;
12117
+ if (compressor.option("dead_code") && self.body.every(is_empty)) {
12094
12118
  var body = [];
12095
12119
  if (self.bcatch) {
12096
12120
  extract_declarations_from_unreachable_code(compressor, self.bcatch, body);
@@ -12183,9 +12207,9 @@
12183
12207
  var exp = self.expression;
12184
12208
  var fn = exp;
12185
12209
  inline_array_like_spread(self, compressor, self.args);
12186
- var simple_args = all(self.args, function(arg) {
12187
- return !(arg instanceof AST_Expansion);
12188
- });
12210
+ var simple_args = self.args.every((arg) =>
12211
+ !(arg instanceof AST_Expansion)
12212
+ );
12189
12213
  if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef) {
12190
12214
  fn = fn.fixed_value();
12191
12215
  if (retain_top_func(fn, compressor)) fn = exp;
@@ -12278,9 +12302,9 @@
12278
12302
  break;
12279
12303
  case "RegExp":
12280
12304
  var params = [];
12281
- if (all(self.args, function(arg) {
12305
+ if (self.args.every((arg) => {
12282
12306
  var value = arg.evaluate(compressor);
12283
- params.unshift(value);
12307
+ params.push(value);
12284
12308
  return arg !== value;
12285
12309
  })) {
12286
12310
  try {
@@ -12426,9 +12450,9 @@
12426
12450
  argnames: [],
12427
12451
  body: []
12428
12452
  }).optimize(compressor);
12429
- if (all(self.args, function(x) {
12430
- return x instanceof AST_String;
12431
- })) {
12453
+ if (self.args.every((x) =>
12454
+ x instanceof AST_String
12455
+ )) {
12432
12456
  // quite a corner-case, but we can handle it:
12433
12457
  // https://github.com/mishoo/UglifyJS2/issues/203
12434
12458
  // if the code argument is a constant, then we can minify it.
@@ -12529,7 +12553,7 @@
12529
12553
  fn._squeezed = true;
12530
12554
  return make_sequence(self, flatten_fn()).optimize(compressor);
12531
12555
  }
12532
- if (compressor.option("side_effects") && !(fn.body instanceof AST_Node) && all(fn.body, is_empty)) {
12556
+ if (compressor.option("side_effects") && !(fn.body instanceof AST_Node) && fn.body.every(is_empty)) {
12533
12557
  var args = self.args.concat(make_node(AST_Undefined, self));
12534
12558
  return make_sequence(self, args).optimize(compressor);
12535
12559
  }
@@ -12570,14 +12594,14 @@
12570
12594
  for (var i = 0; i < len; i++) {
12571
12595
  var line = body[i];
12572
12596
  if (line instanceof AST_Var) {
12573
- if (stat && !all(line.definitions, function(var_def) {
12574
- return !var_def.value;
12575
- })) {
12597
+ if (stat && !line.definitions.every((var_def) =>
12598
+ !var_def.value
12599
+ )) {
12576
12600
  return false;
12577
12601
  }
12578
12602
  } else if (stat) {
12579
12603
  return false;
12580
- } else {
12604
+ } else if (!(line instanceof AST_EmptyStatement)) {
12581
12605
  stat = line;
12582
12606
  }
12583
12607
  }
@@ -12752,9 +12776,9 @@
12752
12776
  var var_def = stat.definitions[j];
12753
12777
  var name = var_def.name;
12754
12778
  append_var(decls, expressions, name, var_def.value);
12755
- if (in_loop && all(fn.argnames, function(argname) {
12756
- return argname.name != name.name;
12757
- })) {
12779
+ if (in_loop && fn.argnames.every((argname) =>
12780
+ argname.name != name.name
12781
+ )) {
12758
12782
  var def = fn.variables.get(name.name);
12759
12783
  var sym = make_node(AST_SymbolRef, name, name);
12760
12784
  def.references.push(sym);
@@ -12912,7 +12936,7 @@
12912
12936
  }
12913
12937
  // avoids infinite recursion of numerals
12914
12938
  if (self.operator != "-"
12915
- || !(e instanceof AST_Number || e instanceof AST_Infinity)) {
12939
+ || !(e instanceof AST_Number || e instanceof AST_Infinity || e instanceof AST_BigInt)) {
12916
12940
  var ev = self.evaluate(compressor);
12917
12941
  if (ev !== self) {
12918
12942
  ev = make_node_from_constant(ev, self).optimize(compressor);
@@ -13504,9 +13528,9 @@
13504
13528
  var init;
13505
13529
  if (fixed instanceof AST_This) {
13506
13530
  if (!(d.orig[0] instanceof AST_SymbolFunarg)
13507
- && all(d.references, function(ref) {
13508
- return d.scope === ref.scope;
13509
- })) {
13531
+ && d.references.every((ref) =>
13532
+ d.scope === ref.scope
13533
+ )) {
13510
13534
  init = fixed;
13511
13535
  }
13512
13536
  } else {
@@ -14117,7 +14141,7 @@
14117
14141
  for (var i = props.length; --i >= 0;) {
14118
14142
  var prop = props[i];
14119
14143
  if ("" + (prop instanceof AST_ConciseMethod ? prop.key.name : prop.key) == key) {
14120
- if (!all(props, function(prop) {
14144
+ if (!props.every((prop) => {
14121
14145
  return prop instanceof AST_ObjectKeyVal
14122
14146
  || arrows && prop instanceof AST_ConciseMethod && !prop.is_generator;
14123
14147
  })) break;
@@ -14545,21 +14569,12 @@
14545
14569
  }
14546
14570
 
14547
14571
  function add(source, gen_line, gen_col, orig_line, orig_col, name) {
14548
- var generatedPos = { line: gen_line + options.dest_line_diff, column: gen_col };
14549
14572
  if (orig_map) {
14550
14573
  var info = orig_map.originalPositionFor({
14551
14574
  line: orig_line,
14552
14575
  column: orig_col
14553
14576
  });
14554
14577
  if (info.source === null) {
14555
- if (generatedPos.column !== 0) {
14556
- generator.addMapping({
14557
- generated: generatedPos,
14558
- original: null,
14559
- source: null,
14560
- name: null
14561
- });
14562
- }
14563
14578
  return;
14564
14579
  }
14565
14580
  source = info.source;
@@ -14568,7 +14583,7 @@
14568
14583
  name = info.name || name;
14569
14584
  }
14570
14585
  generator.addMapping({
14571
- generated : generatedPos,
14586
+ generated : { line: gen_line + options.dest_line_diff, column: gen_col },
14572
14587
  original : { line: orig_line + options.orig_line_diff, column: orig_col },
14573
14588
  source : source,
14574
14589
  name : name
@@ -20637,6 +20652,12 @@
20637
20652
  toplevel = toplevel.wrap_enclose(options.enclose);
20638
20653
  }
20639
20654
  if (timings) timings.rename = Date.now();
20655
+ // disable rename on harmony due to expand_names bug in for-of loops
20656
+ // https://github.com/mishoo/UglifyJS2/issues/2794
20657
+ if (0 && options.rename) {
20658
+ toplevel.figure_out_scope(options.mangle);
20659
+ toplevel.expand_names(options.mangle);
20660
+ }
20640
20661
  if (timings) timings.compress = Date.now();
20641
20662
  if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
20642
20663
  if (timings) timings.scope = Date.now();
@@ -21181,6 +21202,13 @@
21181
21202
  end : my_end_token(M),
21182
21203
  name : M.name
21183
21204
  });
21205
+ },
21206
+ BigIntLiteral(M) {
21207
+ return new AST_BigInt({
21208
+ start : my_start_token(M),
21209
+ end : my_end_token(M),
21210
+ value : M.value
21211
+ });
21184
21212
  }
21185
21213
  };
21186
21214
 
@@ -21650,6 +21678,11 @@
21650
21678
  };
21651
21679
  });
21652
21680
 
21681
+ def_to_moz(AST_BigInt, M => ({
21682
+ type: "BigIntLiteral",
21683
+ value: M.value
21684
+ }));
21685
+
21653
21686
  AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
21654
21687
  AST_Null.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
21655
21688
  AST_Hole.DEFMETHOD("to_mozilla_ast", function To_Moz_ArrayHole() { return null; });
@@ -21831,9 +21864,6 @@
21831
21864
  }
21832
21865
  })();
21833
21866
 
21834
- // API
21835
-
21836
- exports.minify = minify;
21837
21867
  exports.AST_Accessor = AST_Accessor;
21838
21868
  exports.AST_Array = AST_Array;
21839
21869
  exports.AST_Arrow = AST_Arrow;
@@ -21855,17 +21885,17 @@
21855
21885
  exports.AST_Const = AST_Const;
21856
21886
  exports.AST_Constant = AST_Constant;
21857
21887
  exports.AST_Continue = AST_Continue;
21888
+ exports.AST_DWLoop = AST_DWLoop;
21858
21889
  exports.AST_Debugger = AST_Debugger;
21890
+ exports.AST_DefClass = AST_DefClass;
21859
21891
  exports.AST_Default = AST_Default;
21860
21892
  exports.AST_DefaultAssign = AST_DefaultAssign;
21861
- exports.AST_DefClass = AST_DefClass;
21862
21893
  exports.AST_Definitions = AST_Definitions;
21863
21894
  exports.AST_Defun = AST_Defun;
21864
21895
  exports.AST_Destructuring = AST_Destructuring;
21865
21896
  exports.AST_Directive = AST_Directive;
21866
21897
  exports.AST_Do = AST_Do;
21867
21898
  exports.AST_Dot = AST_Dot;
21868
- exports.AST_DWLoop = AST_DWLoop;
21869
21899
  exports.AST_EmptyStatement = AST_EmptyStatement;
21870
21900
  exports.AST_Exit = AST_Exit;
21871
21901
  exports.AST_Expansion = AST_Expansion;
@@ -21883,13 +21913,13 @@
21883
21913
  exports.AST_IterationStatement = AST_IterationStatement;
21884
21914
  exports.AST_Jump = AST_Jump;
21885
21915
  exports.AST_Label = AST_Label;
21886
- exports.AST_LabeledStatement = AST_LabeledStatement;
21887
21916
  exports.AST_LabelRef = AST_LabelRef;
21917
+ exports.AST_LabeledStatement = AST_LabeledStatement;
21888
21918
  exports.AST_Lambda = AST_Lambda;
21889
21919
  exports.AST_Let = AST_Let;
21890
21920
  exports.AST_LoopControl = AST_LoopControl;
21891
- exports.AST_NameMapping = AST_NameMapping;
21892
21921
  exports.AST_NaN = AST_NaN;
21922
+ exports.AST_NameMapping = AST_NameMapping;
21893
21923
  exports.AST_New = AST_New;
21894
21924
  exports.AST_NewTarget = AST_NewTarget;
21895
21925
  exports.AST_Node = AST_Node;
@@ -21949,19 +21979,20 @@
21949
21979
  exports.AST_While = AST_While;
21950
21980
  exports.AST_With = AST_With;
21951
21981
  exports.AST_Yield = AST_Yield;
21982
+ exports.Compressor = Compressor;
21983
+ exports.OutputStream = OutputStream;
21952
21984
  exports.TreeTransformer = TreeTransformer;
21953
21985
  exports.TreeWalker = TreeWalker;
21986
+ exports.base54 = base54;
21987
+ exports.default_options = default_options;
21954
21988
  exports.defaults = defaults;
21989
+ exports.mangle_properties = mangle_properties;
21990
+ exports.minify = minify;
21991
+ exports.parse = parse;
21955
21992
  exports.push_uniq = push_uniq;
21993
+ exports.reserve_quoted_keys = reserve_quoted_keys;
21956
21994
  exports.string_template = string_template;
21957
- exports.base54 = base54;
21958
- exports.Compressor = Compressor;
21959
21995
  exports.to_ascii = to_ascii;
21960
- exports.OutputStream = OutputStream;
21961
- exports.parse = parse;
21962
- exports.mangle_properties = mangle_properties;
21963
- exports.reserve_quoted_keys = reserve_quoted_keys;
21964
- exports.default_options = default_options;
21965
21996
 
21966
21997
  }));
21967
21998
  //# sourceMappingURL=bundle.js.map