terser 5.5.1 → 5.7.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.
@@ -1,10 +1,12 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('source-map')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'source-map'], factory) :
4
- (global = global || self, factory(global.Terser = {}, global.sourceMap));
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Terser = {}, global.sourceMap));
5
5
  }(this, (function (exports, MOZ_SourceMap) { 'use strict';
6
6
 
7
- MOZ_SourceMap = MOZ_SourceMap && Object.prototype.hasOwnProperty.call(MOZ_SourceMap, 'default') ? MOZ_SourceMap['default'] : MOZ_SourceMap;
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var MOZ_SourceMap__default = /*#__PURE__*/_interopDefaultLegacy(MOZ_SourceMap);
8
10
 
9
11
  /***********************************************************************
10
12
 
@@ -202,7 +204,7 @@ function mergeSort(array, cmp) {
202
204
  function makePredicate(words) {
203
205
  if (!Array.isArray(words)) words = words.split(" ");
204
206
 
205
- return new Set(words);
207
+ return new Set(words.sort());
206
208
  }
207
209
 
208
210
  function map_add(map, key, value) {
@@ -241,6 +243,7 @@ function keep_name(keep_setting, name) {
241
243
  }
242
244
 
243
245
  var lineTerminatorEscape = {
246
+ "\0": "0",
244
247
  "\n": "n",
245
248
  "\r": "r",
246
249
  "\u2028": "u2028",
@@ -248,7 +251,8 @@ var lineTerminatorEscape = {
248
251
  };
249
252
  function regexp_source_fix(source) {
250
253
  // V8 does not escape line terminators in regexp patterns in node 12
251
- return source.replace(/[\n\r\u2028\u2029]/g, function (match, offset) {
254
+ // We'll also remove literal \0
255
+ return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) {
252
256
  var escaped = source[offset - 1] == "\\"
253
257
  && (source[offset - 2] != "\\"
254
258
  || /(?:^|[^\\])(?:\\{2})*$/.test(source.slice(0, offset - 1)));
@@ -1035,6 +1039,11 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
1035
1039
  : token("keyword", word);
1036
1040
  }
1037
1041
 
1042
+ function read_private_word() {
1043
+ next();
1044
+ return token("privatename", read_name());
1045
+ }
1046
+
1038
1047
  function with_eof_error(eof_error, cont) {
1039
1048
  return function(x) {
1040
1049
  try {
@@ -1104,6 +1113,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
1104
1113
  if (PUNC_CHARS.has(ch)) return token("punc", next());
1105
1114
  if (OPERATOR_CHARS.has(ch)) return read_operator();
1106
1115
  if (code == 92 || is_identifier_start(ch)) return read_word();
1116
+ if (code == 35) return read_private_word();
1107
1117
  break;
1108
1118
  }
1109
1119
  parse_error("Unexpected character '" + ch + "'");
@@ -1304,6 +1314,13 @@ function parse($TEXT, options) {
1304
1314
  return S.in_async === S.in_function;
1305
1315
  }
1306
1316
 
1317
+ function can_await() {
1318
+ return (
1319
+ S.in_async === S.in_function
1320
+ || S.in_function === 0 && S.input.has_directive("use strict")
1321
+ );
1322
+ }
1323
+
1307
1324
  function semicolon(optional) {
1308
1325
  if (is("punc", ";")) next();
1309
1326
  else if (!optional && !can_insert_semicolon()) unexpected();
@@ -1442,7 +1459,7 @@ function parse($TEXT, options) {
1442
1459
  if (is_if_body) {
1443
1460
  croak("classes are not allowed as the body of an if");
1444
1461
  }
1445
- return class_(AST_DefClass);
1462
+ return class_(AST_DefClass, is_export_default);
1446
1463
 
1447
1464
  case "function":
1448
1465
  next();
@@ -1588,7 +1605,7 @@ function parse($TEXT, options) {
1588
1605
  var for_await_error = "`for await` invalid in this context";
1589
1606
  var await_tok = S.token;
1590
1607
  if (await_tok.type == "name" && await_tok.value == "await") {
1591
- if (!is_in_async()) {
1608
+ if (!can_await()) {
1592
1609
  token_error(await_tok, for_await_error);
1593
1610
  }
1594
1611
  next();
@@ -2085,7 +2102,7 @@ function parse($TEXT, options) {
2085
2102
 
2086
2103
  function _await_expression() {
2087
2104
  // Previous token must be "await" and not be interpreted as an identifier
2088
- if (!is_in_async()) {
2105
+ if (!can_await()) {
2089
2106
  croak("Unexpected await expression outside async function",
2090
2107
  S.prev.line, S.prev.col, S.prev.pos);
2091
2108
  }
@@ -2637,7 +2654,7 @@ function parse($TEXT, options) {
2637
2654
  return new AST_Object({ properties: a });
2638
2655
  });
2639
2656
 
2640
- function class_(KindOfClass) {
2657
+ function class_(KindOfClass, is_export_default) {
2641
2658
  var start, method, class_name, extends_, a = [];
2642
2659
 
2643
2660
  S.input.push_directives_stack(); // Push directive stack, but not scope stack
@@ -2648,7 +2665,11 @@ function parse($TEXT, options) {
2648
2665
  }
2649
2666
 
2650
2667
  if (KindOfClass === AST_DefClass && !class_name) {
2651
- unexpected();
2668
+ if (is_export_default) {
2669
+ KindOfClass = AST_ClassExpression;
2670
+ } else {
2671
+ unexpected();
2672
+ }
2652
2673
  }
2653
2674
 
2654
2675
  if (S.token.value == "extends") {
@@ -2681,9 +2702,9 @@ function parse($TEXT, options) {
2681
2702
  }
2682
2703
 
2683
2704
  function concise_method_or_getset(name, start, is_class) {
2684
- var get_method_name_ast = function(name, start) {
2705
+ const get_symbol_ast = (name, SymbolClass = AST_SymbolMethod) => {
2685
2706
  if (typeof name === "string" || typeof name === "number") {
2686
- return new AST_SymbolMethod({
2707
+ return new SymbolClass({
2687
2708
  start,
2688
2709
  name: "" + name,
2689
2710
  end: prev()
@@ -2693,43 +2714,74 @@ function parse($TEXT, options) {
2693
2714
  }
2694
2715
  return name;
2695
2716
  };
2696
- const get_class_property_key_ast = (name) => {
2697
- if (typeof name === "string" || typeof name === "number") {
2698
- return new AST_SymbolClassProperty({
2699
- start: property_token,
2700
- end: property_token,
2701
- name: "" + name
2702
- });
2703
- } else if (name === null) {
2704
- unexpected();
2705
- }
2706
- return name;
2707
- };
2717
+
2718
+ const is_not_method_start = () =>
2719
+ !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("operator", "=");
2720
+
2708
2721
  var is_async = false;
2709
2722
  var is_static = false;
2710
2723
  var is_generator = false;
2711
- var property_token = start;
2712
- if (is_class && name === "static" && !is("punc", "(")) {
2724
+ var is_private = false;
2725
+ var accessor_type = null;
2726
+
2727
+ if (is_class && name === "static" && is_not_method_start()) {
2713
2728
  is_static = true;
2714
- property_token = S.token;
2715
2729
  name = as_property_name();
2716
2730
  }
2717
- if (name === "async" && !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("operator", "=")) {
2731
+ if (name === "async" && is_not_method_start()) {
2718
2732
  is_async = true;
2719
- property_token = S.token;
2720
2733
  name = as_property_name();
2721
2734
  }
2722
- if (name === null) {
2735
+ if (prev().type === "operator" && prev().value === "*") {
2723
2736
  is_generator = true;
2724
- property_token = S.token;
2725
2737
  name = as_property_name();
2726
- if (name === null) {
2727
- unexpected();
2738
+ }
2739
+ if ((name === "get" || name === "set") && is_not_method_start()) {
2740
+ accessor_type = name;
2741
+ name = as_property_name();
2742
+ }
2743
+ if (prev().type === "privatename") {
2744
+ is_private = true;
2745
+ }
2746
+
2747
+ const property_token = prev();
2748
+
2749
+ if (accessor_type != null) {
2750
+ if (!is_private) {
2751
+ const AccessorClass = accessor_type === "get"
2752
+ ? AST_ObjectGetter
2753
+ : AST_ObjectSetter;
2754
+
2755
+ name = get_symbol_ast(name);
2756
+ return new AccessorClass({
2757
+ start,
2758
+ static: is_static,
2759
+ key: name,
2760
+ quote: name instanceof AST_SymbolMethod ? property_token.quote : undefined,
2761
+ value: create_accessor(),
2762
+ end: prev()
2763
+ });
2764
+ } else {
2765
+ const AccessorClass = accessor_type === "get"
2766
+ ? AST_PrivateGetter
2767
+ : AST_PrivateSetter;
2768
+
2769
+ return new AccessorClass({
2770
+ start,
2771
+ static: is_static,
2772
+ key: get_symbol_ast(name),
2773
+ value: create_accessor(),
2774
+ end: prev(),
2775
+ });
2728
2776
  }
2729
2777
  }
2778
+
2730
2779
  if (is("punc", "(")) {
2731
- name = get_method_name_ast(name, start);
2732
- var node = new AST_ConciseMethod({
2780
+ name = get_symbol_ast(name);
2781
+ const AST_MethodVariant = is_private
2782
+ ? AST_PrivateMethod
2783
+ : AST_ConciseMethod;
2784
+ var node = new AST_MethodVariant({
2733
2785
  start : start,
2734
2786
  static : is_static,
2735
2787
  is_generator: is_generator,
@@ -2742,42 +2794,18 @@ function parse($TEXT, options) {
2742
2794
  });
2743
2795
  return node;
2744
2796
  }
2745
- const setter_token = S.token;
2746
- if (name == "get") {
2747
- if (!is("punc") || is("punc", "[")) {
2748
- name = get_method_name_ast(as_property_name(), start);
2749
- return new AST_ObjectGetter({
2750
- start : start,
2751
- static: is_static,
2752
- key : name,
2753
- quote : name instanceof AST_SymbolMethod ?
2754
- setter_token.quote : undefined,
2755
- value : create_accessor(),
2756
- end : prev()
2757
- });
2758
- }
2759
- } else if (name == "set") {
2760
- if (!is("punc") || is("punc", "[")) {
2761
- name = get_method_name_ast(as_property_name(), start);
2762
- return new AST_ObjectSetter({
2763
- start : start,
2764
- static: is_static,
2765
- key : name,
2766
- quote : name instanceof AST_SymbolMethod ?
2767
- setter_token.quote : undefined,
2768
- value : create_accessor(),
2769
- end : prev()
2770
- });
2771
- }
2772
- }
2797
+
2773
2798
  if (is_class) {
2774
- const key = get_class_property_key_ast(name);
2799
+ const key = get_symbol_ast(name, AST_SymbolClassProperty);
2775
2800
  const quote = key instanceof AST_SymbolClassProperty
2776
2801
  ? property_token.quote
2777
2802
  : undefined;
2803
+ const AST_ClassPropertyVariant = is_private
2804
+ ? AST_ClassPrivateProperty
2805
+ : AST_ClassProperty;
2778
2806
  if (is("operator", "=")) {
2779
2807
  next();
2780
- return new AST_ClassProperty({
2808
+ return new AST_ClassPropertyVariant({
2781
2809
  start,
2782
2810
  static: is_static,
2783
2811
  quote,
@@ -2785,8 +2813,14 @@ function parse($TEXT, options) {
2785
2813
  value: expression(false),
2786
2814
  end: prev()
2787
2815
  });
2788
- } else if (is("name") || is("punc", ";") || is("punc", "}")) {
2789
- return new AST_ClassProperty({
2816
+ } else if (
2817
+ is("name")
2818
+ || is("privatename")
2819
+ || is("operator", "*")
2820
+ || is("punc", ";")
2821
+ || is("punc", "}")
2822
+ ) {
2823
+ return new AST_ClassPropertyVariant({
2790
2824
  start,
2791
2825
  static: is_static,
2792
2826
  quote,
@@ -2988,8 +3022,17 @@ function parse($TEXT, options) {
2988
3022
  semicolon();
2989
3023
  } else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {
2990
3024
  unexpected(node.start);
2991
- } else if (node instanceof AST_Definitions || node instanceof AST_Lambda || node instanceof AST_DefClass) {
3025
+ } else if (
3026
+ node instanceof AST_Definitions
3027
+ || node instanceof AST_Defun
3028
+ || node instanceof AST_DefClass
3029
+ ) {
2992
3030
  exported_definition = node;
3031
+ } else if (
3032
+ node instanceof AST_ClassExpression
3033
+ || node instanceof AST_Function
3034
+ ) {
3035
+ exported_value = node;
2993
3036
  } else if (node instanceof AST_SimpleStatement) {
2994
3037
  exported_value = node.body;
2995
3038
  } else {
@@ -3025,6 +3068,7 @@ function parse($TEXT, options) {
3025
3068
  }
3026
3069
  /* falls through */
3027
3070
  case "name":
3071
+ case "privatename":
3028
3072
  case "string":
3029
3073
  case "num":
3030
3074
  case "big_int":
@@ -3039,7 +3083,7 @@ function parse($TEXT, options) {
3039
3083
 
3040
3084
  function as_name() {
3041
3085
  var tmp = S.token;
3042
- if (tmp.type != "name") unexpected();
3086
+ if (tmp.type != "name" && tmp.type != "privatename") unexpected();
3043
3087
  next();
3044
3088
  return tmp.value;
3045
3089
  }
@@ -3110,7 +3154,8 @@ function parse($TEXT, options) {
3110
3154
  var start = expr.start;
3111
3155
  if (is("punc", ".")) {
3112
3156
  next();
3113
- return subscripts(new AST_Dot({
3157
+ const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
3158
+ return subscripts(new AST_DotVariant({
3114
3159
  start : start,
3115
3160
  expression : expr,
3116
3161
  optional : false,
@@ -3161,8 +3206,9 @@ function parse($TEXT, options) {
3161
3206
  annotate(call);
3162
3207
 
3163
3208
  chain_contents = subscripts(call, true, true);
3164
- } else if (is("name")) {
3165
- chain_contents = subscripts(new AST_Dot({
3209
+ } else if (is("name") || is("privatename")) {
3210
+ const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
3211
+ chain_contents = subscripts(new AST_DotVariant({
3166
3212
  start,
3167
3213
  expression: expr,
3168
3214
  optional: true,
@@ -3233,13 +3279,9 @@ function parse($TEXT, options) {
3233
3279
 
3234
3280
  var maybe_unary = function(allow_calls, allow_arrows) {
3235
3281
  var start = S.token;
3236
- if (start.type == "name" && start.value == "await") {
3237
- if (is_in_async()) {
3238
- next();
3239
- return _await_expression();
3240
- } else if (S.input.has_directive("use strict")) {
3241
- token_error(S.token, "Unexpected await identifier inside strict mode");
3242
- }
3282
+ if (start.type == "name" && start.value == "await" && can_await()) {
3283
+ next();
3284
+ return _await_expression();
3243
3285
  }
3244
3286
  if (is("operator") && UNARY_PREFIX.has(start.value)) {
3245
3287
  next();
@@ -3967,6 +4009,21 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator as
3967
4009
 
3968
4010
  if (this.name) push(this.name);
3969
4011
  },
4012
+ is_braceless() {
4013
+ return this.body[0] instanceof AST_Return && this.body[0].value;
4014
+ },
4015
+ // Default args and expansion don't count, so .argnames.length doesn't cut it
4016
+ length_property() {
4017
+ let length = 0;
4018
+
4019
+ for (const arg of this.argnames) {
4020
+ if (arg instanceof AST_SymbolFunarg || arg instanceof AST_Destructuring) {
4021
+ length++;
4022
+ }
4023
+ }
4024
+
4025
+ return length;
4026
+ }
3970
4027
  }, AST_Scope);
3971
4028
 
3972
4029
  var AST_Accessor = DEFNODE("Accessor", null, {
@@ -4452,7 +4509,7 @@ var AST_PropAccess = DEFNODE("PropAccess", "expression property optional", {
4452
4509
  $documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`",
4453
4510
  $propdoc: {
4454
4511
  expression: "[AST_Node] the “container” expression",
4455
- property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node",
4512
+ property: "[AST_Node|string] the property to access. For AST_Dot & AST_DotHash this is always a plain string, while for AST_Sub it's an arbitrary AST_Node",
4456
4513
 
4457
4514
  optional: "[boolean] whether this is an optional property access (IE ?.)"
4458
4515
  }
@@ -4473,6 +4530,18 @@ var AST_Dot = DEFNODE("Dot", "quote", {
4473
4530
  },
4474
4531
  }, AST_PropAccess);
4475
4532
 
4533
+ var AST_DotHash = DEFNODE("DotHash", "", {
4534
+ $documentation: "A dotted property access to a private property",
4535
+ _walk: function(visitor) {
4536
+ return visitor._visit(this, function() {
4537
+ this.expression._walk(visitor);
4538
+ });
4539
+ },
4540
+ _children_backwards(push) {
4541
+ push(this.expression);
4542
+ },
4543
+ }, AST_PropAccess);
4544
+
4476
4545
  var AST_Sub = DEFNODE("Sub", null, {
4477
4546
  $documentation: "Index-style property access, i.e. `a[\"foo\"]`",
4478
4547
  _walk: function(visitor) {
@@ -4490,7 +4559,7 @@ var AST_Sub = DEFNODE("Sub", null, {
4490
4559
  var AST_Chain = DEFNODE("Chain", "expression", {
4491
4560
  $documentation: "A chain expression like a?.b?.(c)?.[d]",
4492
4561
  $propdoc: {
4493
- expression: "[AST_Call|AST_Dot|AST_Sub] chain element."
4562
+ expression: "[AST_Call|AST_Dot|AST_DotHash|AST_Sub] chain element."
4494
4563
  },
4495
4564
  _walk: function (visitor) {
4496
4565
  return visitor._visit(this, function() {
@@ -4646,6 +4715,26 @@ var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
4646
4715
  }
4647
4716
  }, AST_ObjectProperty);
4648
4717
 
4718
+ var AST_PrivateSetter = DEFNODE("PrivateSetter", "static", {
4719
+ $propdoc: {
4720
+ static: "[boolean] whether this is a static private setter"
4721
+ },
4722
+ $documentation: "A private setter property",
4723
+ computed_key() {
4724
+ return false;
4725
+ }
4726
+ }, AST_ObjectProperty);
4727
+
4728
+ var AST_PrivateGetter = DEFNODE("PrivateGetter", "static", {
4729
+ $propdoc: {
4730
+ static: "[boolean] whether this is a static private getter"
4731
+ },
4732
+ $documentation: "A private getter property",
4733
+ computed_key() {
4734
+ return false;
4735
+ }
4736
+ }, AST_ObjectProperty);
4737
+
4649
4738
  var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", {
4650
4739
  $propdoc: {
4651
4740
  quote: "[string|undefined] the original quote character, if any",
@@ -4681,6 +4770,10 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
4681
4770
  }
4682
4771
  }, AST_ObjectProperty);
4683
4772
 
4773
+ var AST_PrivateMethod = DEFNODE("PrivateMethod", "", {
4774
+ $documentation: "A private class method inside a class",
4775
+ }, AST_ConciseMethod);
4776
+
4684
4777
  var AST_Class = DEFNODE("Class", "name extends properties", {
4685
4778
  $propdoc: {
4686
4779
  name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",
@@ -4730,6 +4823,10 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", {
4730
4823
  }
4731
4824
  }, AST_ObjectProperty);
4732
4825
 
4826
+ var AST_ClassPrivateProperty = DEFNODE("ClassProperty", "", {
4827
+ $documentation: "A class property for a private property",
4828
+ }, AST_ClassProperty);
4829
+
4733
4830
  var AST_DefClass = DEFNODE("DefClass", null, {
4734
4831
  $documentation: "A class definition",
4735
4832
  }, AST_Class);
@@ -5130,6 +5227,7 @@ AST_Catch: AST_Catch,
5130
5227
  AST_Chain: AST_Chain,
5131
5228
  AST_Class: AST_Class,
5132
5229
  AST_ClassExpression: AST_ClassExpression,
5230
+ AST_ClassPrivateProperty: AST_ClassPrivateProperty,
5133
5231
  AST_ClassProperty: AST_ClassProperty,
5134
5232
  AST_ConciseMethod: AST_ConciseMethod,
5135
5233
  AST_Conditional: AST_Conditional,
@@ -5146,6 +5244,7 @@ AST_Destructuring: AST_Destructuring,
5146
5244
  AST_Directive: AST_Directive,
5147
5245
  AST_Do: AST_Do,
5148
5246
  AST_Dot: AST_Dot,
5247
+ AST_DotHash: AST_DotHash,
5149
5248
  AST_DWLoop: AST_DWLoop,
5150
5249
  AST_EmptyStatement: AST_EmptyStatement,
5151
5250
  AST_Exit: AST_Exit,
@@ -5183,6 +5282,9 @@ AST_ObjectKeyVal: AST_ObjectKeyVal,
5183
5282
  AST_ObjectProperty: AST_ObjectProperty,
5184
5283
  AST_ObjectSetter: AST_ObjectSetter,
5185
5284
  AST_PrefixedTemplateString: AST_PrefixedTemplateString,
5285
+ AST_PrivateGetter: AST_PrivateGetter,
5286
+ AST_PrivateMethod: AST_PrivateMethod,
5287
+ AST_PrivateSetter: AST_PrivateSetter,
5186
5288
  AST_PropAccess: AST_PropAccess,
5187
5289
  AST_RegExp: AST_RegExp,
5188
5290
  AST_Return: AST_Return,
@@ -5786,6 +5888,23 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
5786
5888
  static : M.static,
5787
5889
  });
5788
5890
  },
5891
+ PropertyDefinition: function(M) {
5892
+ let key;
5893
+ if (M.computed) {
5894
+ key = from_moz(M.key);
5895
+ } else {
5896
+ if (M.key.type !== "Identifier") throw new Error("Non-Identifier key in PropertyDefinition");
5897
+ key = from_moz(M.key);
5898
+ }
5899
+
5900
+ return new AST_ClassProperty({
5901
+ start : my_start_token(M),
5902
+ end : my_end_token(M),
5903
+ key,
5904
+ value : from_moz(M.value),
5905
+ static : M.static,
5906
+ });
5907
+ },
5789
5908
  ArrayExpression: function(M) {
5790
5909
  return new AST_Array({
5791
5910
  start : my_start_token(M),
@@ -5974,7 +6093,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
5974
6093
  : p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef
5975
6094
  : p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
5976
6095
  : p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)
5977
- : p.type == "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty)
6096
+ : p.type == "PropertyDefinition" || p.type === "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty)
5978
6097
  : p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
5979
6098
  : p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
5980
6099
  : p.type == "CatchClause" ? AST_SymbolCatch
@@ -6273,6 +6392,19 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
6273
6392
  };
6274
6393
  });
6275
6394
 
6395
+ def_to_moz(AST_DotHash, function To_Moz_PrivateMemberExpression(M) {
6396
+ return {
6397
+ type: "MemberExpression",
6398
+ object: to_moz(M.expression),
6399
+ computed: false,
6400
+ property: {
6401
+ type: "PrivateIdentifier",
6402
+ name: M.property
6403
+ },
6404
+ optional: M.optional
6405
+ };
6406
+ });
6407
+
6276
6408
  def_to_moz(AST_PropAccess, function To_Moz_MemberExpression(M) {
6277
6409
  var isComputed = M instanceof AST_Sub;
6278
6410
  return {
@@ -6365,12 +6497,38 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
6365
6497
  if (M instanceof AST_ObjectSetter) {
6366
6498
  kind = "set";
6367
6499
  }
6500
+ if (M instanceof AST_PrivateGetter || M instanceof AST_PrivateSetter) {
6501
+ const kind = M instanceof AST_PrivateGetter ? "get" : "set";
6502
+ return {
6503
+ type: "MethodDefinition",
6504
+ computed: false,
6505
+ kind: kind,
6506
+ static: M.static,
6507
+ key: {
6508
+ type: "PrivateIdentifier",
6509
+ name: M.key.name
6510
+ },
6511
+ value: to_moz(M.value)
6512
+ };
6513
+ }
6514
+ if (M instanceof AST_ClassPrivateProperty) {
6515
+ return {
6516
+ type: "PropertyDefinition",
6517
+ key: {
6518
+ type: "PrivateIdentifier",
6519
+ name: M.key.name
6520
+ },
6521
+ value: to_moz(M.value),
6522
+ computed: false,
6523
+ static: M.static
6524
+ };
6525
+ }
6368
6526
  if (M instanceof AST_ClassProperty) {
6369
6527
  return {
6370
- type: "FieldDefinition",
6371
- computed,
6528
+ type: "PropertyDefinition",
6372
6529
  key,
6373
6530
  value: to_moz(M.value),
6531
+ computed,
6374
6532
  static: M.static
6375
6533
  };
6376
6534
  }
@@ -6405,13 +6563,21 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
6405
6563
  value: to_moz(M.value)
6406
6564
  };
6407
6565
  }
6566
+
6567
+ const key = M instanceof AST_PrivateMethod
6568
+ ? {
6569
+ type: "PrivateIdentifier",
6570
+ name: M.key.name
6571
+ }
6572
+ : to_moz(M.key);
6573
+
6408
6574
  return {
6409
6575
  type: "MethodDefinition",
6410
- computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
6411
6576
  kind: M.key === "constructor" ? "constructor" : "method",
6577
+ key,
6578
+ value: to_moz(M.value),
6579
+ computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
6412
6580
  static: M.static,
6413
- key: to_moz(M.key),
6414
- value: to_moz(M.value)
6415
6581
  };
6416
6582
  });
6417
6583
 
@@ -7515,6 +7681,7 @@ function OutputStream(options) {
7515
7681
  var p = output.parent();
7516
7682
  return p instanceof AST_PropAccess && p.expression === this
7517
7683
  || p instanceof AST_Call && p.expression === this
7684
+ || p instanceof AST_Binary && p.operator === "**" && p.left === this
7518
7685
  || output.option("safari10") && p instanceof AST_UnaryPrefix;
7519
7686
  });
7520
7687
 
@@ -8390,6 +8557,15 @@ function OutputStream(options) {
8390
8557
  output.print_name(prop);
8391
8558
  }
8392
8559
  });
8560
+ DEFPRINT(AST_DotHash, function(self, output) {
8561
+ var expr = self.expression;
8562
+ expr.print(output);
8563
+ var prop = self.property;
8564
+
8565
+ if (self.optional) output.print("?");
8566
+ output.print(".#");
8567
+ output.print_name(prop);
8568
+ });
8393
8569
  DEFPRINT(AST_Sub, function(self, output) {
8394
8570
  self.expression.print(output);
8395
8571
  if (self.optional) output.print("?.");
@@ -8593,6 +8769,23 @@ function OutputStream(options) {
8593
8769
  self.value.print(output);
8594
8770
  }
8595
8771
  });
8772
+ DEFPRINT(AST_ClassPrivateProperty, (self, output) => {
8773
+ if (self.static) {
8774
+ output.print("static");
8775
+ output.space();
8776
+ }
8777
+
8778
+ output.print("#");
8779
+
8780
+ print_property_name(self.key.name, self.quote, output);
8781
+
8782
+ if (self.value) {
8783
+ output.print("=");
8784
+ self.value.print(output);
8785
+ }
8786
+
8787
+ output.semicolon();
8788
+ });
8596
8789
  DEFPRINT(AST_ClassProperty, (self, output) => {
8597
8790
  if (self.static) {
8598
8791
  output.print("static");
@@ -8614,7 +8807,7 @@ function OutputStream(options) {
8614
8807
 
8615
8808
  output.semicolon();
8616
8809
  });
8617
- AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, output) {
8810
+ AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, is_private, output) {
8618
8811
  var self = this;
8619
8812
  if (self.static) {
8620
8813
  output.print("static");
@@ -8625,6 +8818,7 @@ function OutputStream(options) {
8625
8818
  output.space();
8626
8819
  }
8627
8820
  if (self.key instanceof AST_SymbolMethod) {
8821
+ if (is_private) output.print("#");
8628
8822
  print_property_name(self.key.name, self.quote, output);
8629
8823
  } else {
8630
8824
  output.with_square(function() {
@@ -8634,10 +8828,27 @@ function OutputStream(options) {
8634
8828
  self.value._do_print(output, true);
8635
8829
  });
8636
8830
  DEFPRINT(AST_ObjectSetter, function(self, output) {
8637
- self._print_getter_setter("set", output);
8831
+ self._print_getter_setter("set", false, output);
8638
8832
  });
8639
8833
  DEFPRINT(AST_ObjectGetter, function(self, output) {
8640
- self._print_getter_setter("get", output);
8834
+ self._print_getter_setter("get", false, output);
8835
+ });
8836
+ DEFPRINT(AST_PrivateSetter, function(self, output) {
8837
+ self._print_getter_setter("set", true, output);
8838
+ });
8839
+ DEFPRINT(AST_PrivateGetter, function(self, output) {
8840
+ self._print_getter_setter("get", true, output);
8841
+ });
8842
+ DEFPRINT(AST_PrivateMethod, function(self, output) {
8843
+ var type;
8844
+ if (self.is_generator && self.async) {
8845
+ type = "async*";
8846
+ } else if (self.is_generator) {
8847
+ type = "*";
8848
+ } else if (self.async) {
8849
+ type = "async";
8850
+ }
8851
+ self._print_getter_setter(type, true, output);
8641
8852
  });
8642
8853
  DEFPRINT(AST_ConciseMethod, function(self, output) {
8643
8854
  var type;
@@ -8648,7 +8859,7 @@ function OutputStream(options) {
8648
8859
  } else if (self.async) {
8649
8860
  type = "async";
8650
8861
  }
8651
- self._print_getter_setter(type, output);
8862
+ self._print_getter_setter(type, false, output);
8652
8863
  });
8653
8864
  AST_Symbol.DEFMETHOD("_do_print", function(output) {
8654
8865
  var def = this.definition();
@@ -8688,7 +8899,9 @@ function OutputStream(options) {
8688
8899
  source = regexp_source_fix(source);
8689
8900
  flags = flags ? sort_regexp_flags(flags) : "";
8690
8901
  source = source.replace(r_slash_script, slash_script_replace);
8902
+
8691
8903
  output.print(output.to_utf8(`/${source}/${flags}`));
8904
+
8692
8905
  const parent = output.parent();
8693
8906
  if (
8694
8907
  parent instanceof AST_Binary
@@ -9909,7 +10122,9 @@ AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
9909
10122
  if (this instanceof AST_Symbol && !this.unmangleable(options)) {
9910
10123
  base54.consider(this.name, -1);
9911
10124
  } else if (options.properties) {
9912
- if (this instanceof AST_Dot) {
10125
+ if (this instanceof AST_DotHash) {
10126
+ base54.consider("#" + this.property, -1);
10127
+ } else if (this instanceof AST_Dot) {
9913
10128
  base54.consider(this.property, -1);
9914
10129
  } else if (this instanceof AST_Sub) {
9915
10130
  skip_string(this.property);
@@ -9982,6 +10197,12 @@ AST_Node.prototype.size = function (compressor, stack) {
9982
10197
  let size = 0;
9983
10198
  walk_parent(this, (node, info) => {
9984
10199
  size += node._size(info);
10200
+
10201
+ // Braceless arrow functions have fake "return" statements
10202
+ if (node instanceof AST_Arrow && node.is_braceless()) {
10203
+ size += node.body[0].value._size(info);
10204
+ return true;
10205
+ }
9985
10206
  }, stack || (compressor && compressor.stack));
9986
10207
 
9987
10208
  // just to save a bit of memory
@@ -10026,7 +10247,6 @@ AST_With.prototype._size = () => 6;
10026
10247
 
10027
10248
  AST_Expansion.prototype._size = () => 3;
10028
10249
 
10029
- /*#__INLINE__*/
10030
10250
  const lambda_modifiers = func =>
10031
10251
  (func.is_generator ? 1 : 0) + (func.async ? 6 : 0);
10032
10252
 
@@ -10055,7 +10275,9 @@ AST_Arrow.prototype._size = function () {
10055
10275
  args_and_arrow += 2;
10056
10276
  }
10057
10277
 
10058
- return lambda_modifiers(this) + args_and_arrow + (Array.isArray(this.body) ? list_overhead(this.body) : this.body._size());
10278
+ const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2;
10279
+
10280
+ return lambda_modifiers(this) + args_and_arrow + body_overhead;
10059
10281
  };
10060
10282
 
10061
10283
  AST_Destructuring.prototype._size = () => 2;
@@ -10197,6 +10419,13 @@ AST_Dot.prototype._size = function () {
10197
10419
  return this.property.length + 1;
10198
10420
  };
10199
10421
 
10422
+ AST_DotHash.prototype._size = function () {
10423
+ if (this.optional) {
10424
+ return this.property.length + 3;
10425
+ }
10426
+ return this.property.length + 2;
10427
+ };
10428
+
10200
10429
  AST_Sub.prototype._size = function () {
10201
10430
  return this.optional ? 4 : 2;
10202
10431
  };
@@ -10264,6 +10493,14 @@ AST_ConciseMethod.prototype._size = function () {
10264
10493
  return static_size(this.static) + key_size(this.key) + lambda_modifiers(this);
10265
10494
  };
10266
10495
 
10496
+ AST_PrivateMethod.prototype._size = function () {
10497
+ return AST_ConciseMethod.prototype._size.call(this) + 1;
10498
+ };
10499
+
10500
+ AST_PrivateGetter.prototype._size = AST_PrivateSetter.prototype._size = function () {
10501
+ return AST_ConciseMethod.prototype._size.call(this) + 4;
10502
+ };
10503
+
10267
10504
  AST_Class.prototype._size = function () {
10268
10505
  return (
10269
10506
  (this.name ? 8 : 7)
@@ -10279,6 +10516,10 @@ AST_ClassProperty.prototype._size = function () {
10279
10516
  );
10280
10517
  };
10281
10518
 
10519
+ AST_ClassPrivateProperty.prototype._size = function () {
10520
+ return AST_ClassProperty.prototype._size.call(this) + 1;
10521
+ };
10522
+
10282
10523
  AST_Symbol.prototype._size = function () {
10283
10524
  return !mangle_options || this.definition().unmangleable(mangle_options)
10284
10525
  ? this.name.length
@@ -10411,11 +10652,8 @@ const TOP = 0b0000010000000000;
10411
10652
 
10412
10653
  const CLEAR_BETWEEN_PASSES = SQUEEZED | OPTIMIZED | TOP;
10413
10654
 
10414
- /*@__INLINE__*/
10415
10655
  const has_flag = (node, flag) => node.flags & flag;
10416
- /*@__INLINE__*/
10417
10656
  const set_flag = (node, flag) => { node.flags |= flag; };
10418
- /*@__INLINE__*/
10419
10657
  const clear_flag = (node, flag) => { node.flags &= ~flag; };
10420
10658
 
10421
10659
  class Compressor extends TreeWalker {
@@ -10458,7 +10696,7 @@ class Compressor extends TreeWalker {
10458
10696
  properties : !false_by_default,
10459
10697
  pure_getters : !false_by_default && "strict",
10460
10698
  pure_funcs : null,
10461
- reduce_funcs : null, // legacy
10699
+ reduce_funcs : !false_by_default,
10462
10700
  reduce_vars : !false_by_default,
10463
10701
  sequences : !false_by_default,
10464
10702
  side_effects : !false_by_default,
@@ -10758,7 +10996,7 @@ function is_modified(compressor, tw, node, value, level, immutable) {
10758
10996
  && parent.expression === node
10759
10997
  && !(value instanceof AST_Arrow)
10760
10998
  && !(value instanceof AST_Class)
10761
- && !parent.is_expr_pure(compressor)
10999
+ && !parent.is_callee_pure(compressor)
10762
11000
  && (!(value instanceof AST_Function)
10763
11001
  || !(parent instanceof AST_New) && value.contains_this())) {
10764
11002
  return true;
@@ -11063,9 +11301,6 @@ function is_modified(compressor, tw, node, value, level, immutable) {
11063
11301
  return true;
11064
11302
  });
11065
11303
  def_reduce_vars(AST_Call, function (tw) {
11066
- // TODO this block should just be { return } but
11067
- // for some reason the _walk function of AST_Call walks the callee last
11068
-
11069
11304
  this.expression.walk(tw);
11070
11305
 
11071
11306
  if (this.optional) {
@@ -11618,8 +11853,11 @@ function tighten_body(statements, compressor) {
11618
11853
  || node instanceof AST_Debugger
11619
11854
  || node instanceof AST_Destructuring
11620
11855
  || node instanceof AST_Expansion
11621
- && node.expression instanceof AST_Symbol
11622
- && node.expression.definition().references.length > 1
11856
+ && node.expression instanceof AST_Symbol
11857
+ && (
11858
+ node.expression instanceof AST_This
11859
+ || node.expression.definition().references.length > 1
11860
+ )
11623
11861
  || node instanceof AST_IterationStatement && !(node instanceof AST_For)
11624
11862
  || node instanceof AST_LoopControl
11625
11863
  || node instanceof AST_Try
@@ -12788,7 +13026,13 @@ function is_undefined(node, compressor) {
12788
13026
  });
12789
13027
  def_may_throw_on_access(AST_Dot, function(compressor) {
12790
13028
  if (!is_strict(compressor)) return false;
12791
- if (this.expression instanceof AST_Function && this.property == "prototype") return false;
13029
+
13030
+ if (this.property == "prototype") {
13031
+ return !(
13032
+ this.expression instanceof AST_Function
13033
+ || this.expression instanceof AST_Class
13034
+ );
13035
+ }
12792
13036
  return true;
12793
13037
  });
12794
13038
  def_may_throw_on_access(AST_Chain, function(compressor) {
@@ -13130,9 +13374,7 @@ var static_fns = convert_to_predicate({
13130
13374
  if (compressor.option("unsafe")) {
13131
13375
  var fn = function() {};
13132
13376
  fn.node = this;
13133
- fn.toString = function() {
13134
- return this.node.print_to_string();
13135
- };
13377
+ fn.toString = () => this.print_to_string();
13136
13378
  return fn;
13137
13379
  }
13138
13380
  return this;
@@ -13313,6 +13555,14 @@ var static_fns = convert_to_predicate({
13313
13555
  "POSITIVE_INFINITY",
13314
13556
  ],
13315
13557
  });
13558
+ const regexp_flags = new Set([
13559
+ "dotAll",
13560
+ "global",
13561
+ "ignoreCase",
13562
+ "multiline",
13563
+ "sticky",
13564
+ "unicode",
13565
+ ]);
13316
13566
  def_eval(AST_PropAccess, function(compressor, depth) {
13317
13567
  if (this.optional) {
13318
13568
  const obj = this.expression._eval(compressor, depth);
@@ -13345,12 +13595,19 @@ var static_fns = convert_to_predicate({
13345
13595
  val = global_objs[exp.name];
13346
13596
  } else {
13347
13597
  val = exp._eval(compressor, depth + 1);
13598
+ if (val instanceof RegExp) {
13599
+ if (key == "source") {
13600
+ return regexp_source_fix(val.source);
13601
+ } else if (key == "flags" || regexp_flags.has(key)) {
13602
+ return val[key];
13603
+ }
13604
+ }
13348
13605
  if (!val || val === exp || !HOP(val, key)) return this;
13349
13606
  if (typeof val == "function") switch (key) {
13350
13607
  case "name":
13351
13608
  return val.node.name ? val.node.name.name : "";
13352
13609
  case "length":
13353
- return val.node.argnames.length;
13610
+ return val.node.length_property();
13354
13611
  default:
13355
13612
  return this;
13356
13613
  }
@@ -13402,6 +13659,7 @@ var static_fns = convert_to_predicate({
13402
13659
  var arg = this.args[i];
13403
13660
  var value = arg._eval(compressor, depth);
13404
13661
  if (arg === value) return this;
13662
+ if (arg instanceof AST_Lambda) return this;
13405
13663
  args.push(value);
13406
13664
  }
13407
13665
  try {
@@ -13501,7 +13759,7 @@ var static_fns = convert_to_predicate({
13501
13759
  });
13502
13760
 
13503
13761
  var global_pure_fns = makePredicate("Boolean decodeURI decodeURIComponent Date encodeURI encodeURIComponent Error escape EvalError isFinite isNaN Number Object parseFloat parseInt RangeError ReferenceError String SyntaxError TypeError unescape URIError");
13504
- AST_Call.DEFMETHOD("is_expr_pure", function(compressor) {
13762
+ AST_Call.DEFMETHOD("is_callee_pure", function(compressor) {
13505
13763
  if (compressor.option("unsafe")) {
13506
13764
  var expr = this.expression;
13507
13765
  var first_arg = (this.args && this.args[0] && this.args[0].evaluate(compressor));
@@ -13571,7 +13829,7 @@ const pure_prop_access_globals = new Set([
13571
13829
  });
13572
13830
  def_has_side_effects(AST_Call, function(compressor) {
13573
13831
  if (
13574
- !this.is_expr_pure(compressor)
13832
+ !this.is_callee_pure(compressor)
13575
13833
  && (!this.expression.is_call_pure(compressor)
13576
13834
  || this.expression.has_side_effects(compressor))
13577
13835
  ) {
@@ -13635,7 +13893,7 @@ const pure_prop_access_globals = new Set([
13635
13893
  def_has_side_effects(AST_ObjectProperty, function(compressor) {
13636
13894
  return (
13637
13895
  this.computed_key() && this.key.has_side_effects(compressor)
13638
- || this.value.has_side_effects(compressor)
13896
+ || this.value && this.value.has_side_effects(compressor)
13639
13897
  );
13640
13898
  });
13641
13899
  def_has_side_effects(AST_ClassProperty, function(compressor) {
@@ -13733,7 +13991,7 @@ const pure_prop_access_globals = new Set([
13733
13991
  def_may_throw(AST_Call, function(compressor) {
13734
13992
  if (this.optional && is_nullish(this.expression)) return false;
13735
13993
  if (any(this.args, compressor)) return true;
13736
- if (this.is_expr_pure(compressor)) return false;
13994
+ if (this.is_callee_pure(compressor)) return false;
13737
13995
  if (this.expression.may_throw(compressor)) return true;
13738
13996
  return !(this.expression instanceof AST_Lambda)
13739
13997
  || any(this.expression.body, compressor);
@@ -13763,7 +14021,7 @@ const pure_prop_access_globals = new Set([
13763
14021
  });
13764
14022
  def_may_throw(AST_ObjectProperty, function(compressor) {
13765
14023
  // TODO key may throw too
13766
- return this.value.may_throw(compressor);
14024
+ return this.value ? this.value.may_throw(compressor) : false;
13767
14025
  });
13768
14026
  def_may_throw(AST_ClassProperty, function(compressor) {
13769
14027
  return (
@@ -13897,7 +14155,7 @@ const pure_prop_access_globals = new Set([
13897
14155
  return this.properties.every((l) => l.is_constant_expression());
13898
14156
  });
13899
14157
  def_is_constant_expression(AST_ObjectProperty, function() {
13900
- return !(this.key instanceof AST_Node) && this.value.is_constant_expression();
14158
+ return !!(!(this.key instanceof AST_Node) && this.value && this.value.is_constant_expression());
13901
14159
  });
13902
14160
  })(function(node, func) {
13903
14161
  node.DEFMETHOD("is_constant_expression", func);
@@ -14611,7 +14869,7 @@ AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
14611
14869
  return make_node(AST_Undefined, this);
14612
14870
  }
14613
14871
 
14614
- if (!this.is_expr_pure(compressor)) {
14872
+ if (!this.is_callee_pure(compressor)) {
14615
14873
  if (this.expression.is_call_pure(compressor)) {
14616
14874
  var exprs = this.args.slice();
14617
14875
  exprs.unshift(this.expression.expression);
@@ -14724,7 +14982,7 @@ AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
14724
14982
  def_drop_side_effect_free(AST_ObjectProperty, function(compressor, first_in_statement) {
14725
14983
  const computed_key = this instanceof AST_ObjectKeyVal && this.key instanceof AST_Node;
14726
14984
  const key = computed_key && this.key.drop_side_effect_free(compressor, first_in_statement);
14727
- const value = this.value.drop_side_effect_free(compressor, first_in_statement);
14985
+ const value = this.value && this.value.drop_side_effect_free(compressor, first_in_statement);
14728
14986
  if (key && value) {
14729
14987
  return make_sequence(this, [key, value]);
14730
14988
  }
@@ -15631,7 +15889,7 @@ def_optimize(AST_Call, function(self, compressor) {
15631
15889
 
15632
15890
  var stat = is_func && fn.body[0];
15633
15891
  var is_regular_func = is_func && !fn.is_generator && !fn.async;
15634
- var can_inline = is_regular_func && compressor.option("inline") && !self.is_expr_pure(compressor);
15892
+ var can_inline = is_regular_func && compressor.option("inline") && !self.is_callee_pure(compressor);
15635
15893
  if (can_inline && stat instanceof AST_Return) {
15636
15894
  let returned = stat.value;
15637
15895
  if (!returned || returned.is_constant_expression()) {
@@ -16657,19 +16915,26 @@ def_optimize(AST_SymbolRef, function(self, compressor) {
16657
16915
  let fixed = self.fixed_value();
16658
16916
  let single_use = def.single_use
16659
16917
  && !(parent instanceof AST_Call
16660
- && (parent.is_expr_pure(compressor))
16918
+ && (parent.is_callee_pure(compressor))
16661
16919
  || has_annotation(parent, _NOINLINE))
16662
16920
  && !(parent instanceof AST_Export
16663
16921
  && fixed instanceof AST_Lambda
16664
16922
  && fixed.name);
16665
16923
 
16924
+ if (single_use && fixed instanceof AST_Node) {
16925
+ single_use =
16926
+ !fixed.has_side_effects(compressor)
16927
+ && !fixed.may_throw(compressor);
16928
+ }
16929
+
16666
16930
  if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
16667
16931
  if (retain_top_func(fixed, compressor)) {
16668
16932
  single_use = false;
16669
16933
  } else if (def.scope !== self.scope
16670
16934
  && (def.escaped == 1
16671
16935
  || has_flag(fixed, INLINED)
16672
- || within_array_or_object_literal(compressor))) {
16936
+ || within_array_or_object_literal(compressor)
16937
+ || !compressor.option("reduce_funcs"))) {
16673
16938
  single_use = false;
16674
16939
  } else if (recursive_ref(compressor, def)) {
16675
16940
  single_use = false;
@@ -16685,6 +16950,7 @@ def_optimize(AST_SymbolRef, function(self, compressor) {
16685
16950
  }
16686
16951
  }
16687
16952
  }
16953
+
16688
16954
  if (single_use && fixed instanceof AST_Lambda) {
16689
16955
  single_use =
16690
16956
  def.scope === self.scope
@@ -16694,15 +16960,6 @@ def_optimize(AST_SymbolRef, function(self, compressor) {
16694
16960
  && !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
16695
16961
  && !(fixed.name && fixed.name.definition().recursive_refs > 0);
16696
16962
  }
16697
- if (single_use && fixed instanceof AST_Class) {
16698
- const extends_inert = !fixed.extends
16699
- || !fixed.extends.may_throw(compressor)
16700
- && !fixed.extends.has_side_effects(compressor);
16701
- single_use = extends_inert
16702
- && !fixed.properties.some(prop =>
16703
- prop.may_throw(compressor) || prop.has_side_effects(compressor)
16704
- );
16705
- }
16706
16963
 
16707
16964
  if (single_use && fixed) {
16708
16965
  if (fixed instanceof AST_DefClass) {
@@ -16779,6 +17036,7 @@ def_optimize(AST_SymbolRef, function(self, compressor) {
16779
17036
  }
16780
17037
  }
16781
17038
  }
17039
+
16782
17040
  return self;
16783
17041
  });
16784
17042
 
@@ -17365,27 +17623,40 @@ function safe_to_flatten(value, compressor) {
17365
17623
 
17366
17624
  AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
17367
17625
  if (!compressor.option("properties")) return;
17626
+ if (key === "__proto__") return;
17627
+
17368
17628
  var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 2015;
17369
17629
  var expr = this.expression;
17370
17630
  if (expr instanceof AST_Object) {
17371
17631
  var props = expr.properties;
17632
+
17372
17633
  for (var i = props.length; --i >= 0;) {
17373
17634
  var prop = props[i];
17635
+
17374
17636
  if ("" + (prop instanceof AST_ConciseMethod ? prop.key.name : prop.key) == key) {
17375
- if (!props.every((prop) => {
17376
- return prop instanceof AST_ObjectKeyVal
17377
- || arrows && prop instanceof AST_ConciseMethod && !prop.is_generator;
17378
- })) break;
17379
- if (!safe_to_flatten(prop.value, compressor)) break;
17637
+ const all_props_flattenable = props.every((p) =>
17638
+ (p instanceof AST_ObjectKeyVal
17639
+ || arrows && p instanceof AST_ConciseMethod && !p.is_generator
17640
+ )
17641
+ && !p.computed_key()
17642
+ );
17643
+
17644
+ if (!all_props_flattenable) return;
17645
+ if (!safe_to_flatten(prop.value, compressor)) return;
17646
+
17380
17647
  return make_node(AST_Sub, this, {
17381
17648
  expression: make_node(AST_Array, expr, {
17382
17649
  elements: props.map(function(prop) {
17383
17650
  var v = prop.value;
17384
- if (v instanceof AST_Accessor) v = make_node(AST_Function, v, v);
17651
+ if (v instanceof AST_Accessor) {
17652
+ v = make_node(AST_Function, v, v);
17653
+ }
17654
+
17385
17655
  var k = prop.key;
17386
17656
  if (k instanceof AST_Node && !(k instanceof AST_SymbolMethod)) {
17387
17657
  return make_sequence(prop, [ k, v ]);
17388
17658
  }
17659
+
17389
17660
  return v;
17390
17661
  })
17391
17662
  }),
@@ -17982,13 +18253,13 @@ async function SourceMap(options) {
17982
18253
  });
17983
18254
 
17984
18255
  var orig_map;
17985
- var generator = new MOZ_SourceMap.SourceMapGenerator({
18256
+ var generator = new MOZ_SourceMap__default['default'].SourceMapGenerator({
17986
18257
  file : options.file,
17987
18258
  sourceRoot : options.root
17988
18259
  });
17989
18260
 
17990
18261
  if (options.orig) {
17991
- orig_map = await new MOZ_SourceMap.SourceMapConsumer(options.orig);
18262
+ orig_map = await new MOZ_SourceMap__default['default'].SourceMapConsumer(options.orig);
17992
18263
  orig_map.sources.forEach(function(source) {
17993
18264
  var sourceContent = orig_map.sourceContentFor(source, true);
17994
18265
  if (sourceContent) {
@@ -22153,6 +22424,7 @@ var domprops = [
22153
22424
  "exponent",
22154
22425
  "exponentialRampToValueAtTime",
22155
22426
  "exportKey",
22427
+ "exports",
22156
22428
  "extend",
22157
22429
  "extensions",
22158
22430
  "extentNode",
@@ -25936,7 +26208,10 @@ function mangle_properties(ast, options) {
25936
26208
  if (!options.builtins) find_builtins(reserved);
25937
26209
 
25938
26210
  var cname = -1;
26211
+ var cprivate = -1;
26212
+
25939
26213
  var cache;
26214
+ var private_cache = new Map();
25940
26215
  if (options.cache) {
25941
26216
  cache = options.cache.props;
25942
26217
  cache.forEach(function(mangled_name) {
@@ -25959,12 +26234,20 @@ function mangle_properties(ast, options) {
25959
26234
 
25960
26235
  var names_to_mangle = new Set();
25961
26236
  var unmangleable = new Set();
26237
+ var private_properties = new Set();
25962
26238
 
25963
26239
  var keep_quoted_strict = options.keep_quoted === "strict";
25964
26240
 
25965
26241
  // step 1: find candidates to mangle
25966
26242
  ast.walk(new TreeWalker(function(node) {
25967
- if (node instanceof AST_ObjectKeyVal) {
26243
+ if (
26244
+ node instanceof AST_ClassPrivateProperty
26245
+ || node instanceof AST_PrivateMethod
26246
+ ) {
26247
+ private_properties.add(node.key.name);
26248
+ } else if (node instanceof AST_DotHash) {
26249
+ private_properties.add(node.property);
26250
+ } else if (node instanceof AST_ObjectKeyVal) {
25968
26251
  if (typeof node.key == "string" &&
25969
26252
  (!keep_quoted_strict || !node.quote)) {
25970
26253
  add(node.key);
@@ -26001,7 +26284,14 @@ function mangle_properties(ast, options) {
26001
26284
 
26002
26285
  // step 2: transform the tree, renaming properties
26003
26286
  return ast.transform(new TreeTransformer(function(node) {
26004
- if (node instanceof AST_ObjectKeyVal) {
26287
+ if (
26288
+ node instanceof AST_ClassPrivateProperty
26289
+ || node instanceof AST_PrivateMethod
26290
+ ) {
26291
+ node.key.name = mangle_private(node.key.name);
26292
+ } else if (node instanceof AST_DotHash) {
26293
+ node.property = mangle_private(node.property);
26294
+ } else if (node instanceof AST_ObjectKeyVal) {
26005
26295
  if (typeof node.key == "string" &&
26006
26296
  (!keep_quoted_strict || !node.quote)) {
26007
26297
  node.key = mangle(node.key);
@@ -26081,6 +26371,16 @@ function mangle_properties(ast, options) {
26081
26371
  return mangled;
26082
26372
  }
26083
26373
 
26374
+ function mangle_private(name) {
26375
+ let mangled = private_cache.get(name);
26376
+ if (!mangled) {
26377
+ mangled = base54(++cprivate);
26378
+ private_cache.set(name, mangled);
26379
+ }
26380
+
26381
+ return mangled;
26382
+ }
26383
+
26084
26384
  function mangleStrings(node) {
26085
26385
  return node.transform(new TreeTransformer(function(node) {
26086
26386
  if (node instanceof AST_Sequence) {
@@ -26156,6 +26456,7 @@ async function minify(files, options) {
26156
26456
  rename: undefined,
26157
26457
  safari10: false,
26158
26458
  sourceMap: false,
26459
+ spidermonkey: false,
26159
26460
  timings: false,
26160
26461
  toplevel: false,
26161
26462
  warnings: false,
@@ -26227,20 +26528,32 @@ async function minify(files, options) {
26227
26528
  if (files instanceof AST_Toplevel) {
26228
26529
  toplevel = files;
26229
26530
  } else {
26230
- if (typeof files == "string") {
26531
+ if (typeof files == "string" || (options.parse.spidermonkey && !Array.isArray(files))) {
26231
26532
  files = [ files ];
26232
26533
  }
26233
26534
  options.parse = options.parse || {};
26234
26535
  options.parse.toplevel = null;
26235
- for (var name in files) if (HOP(files, name)) {
26236
- options.parse.filename = name;
26237
- options.parse.toplevel = parse(files[name], options.parse);
26238
- if (options.sourceMap && options.sourceMap.content == "inline") {
26239
- if (Object.keys(files).length > 1)
26240
- throw new Error("inline source map only works with singular input");
26241
- options.sourceMap.content = read_source_map(files[name]);
26536
+
26537
+ if (options.parse.spidermonkey) {
26538
+ options.parse.toplevel = AST_Node.from_mozilla_ast(Object.keys(files).reduce(function(toplevel, name) {
26539
+ if (!toplevel) return files[name];
26540
+ toplevel.body = toplevel.body.concat(files[name].body);
26541
+ return toplevel;
26542
+ }, null));
26543
+ } else {
26544
+ delete options.parse.spidermonkey;
26545
+
26546
+ for (var name in files) if (HOP(files, name)) {
26547
+ options.parse.filename = name;
26548
+ options.parse.toplevel = parse(files[name], options.parse);
26549
+ if (options.sourceMap && options.sourceMap.content == "inline") {
26550
+ if (Object.keys(files).length > 1)
26551
+ throw new Error("inline source map only works with singular input");
26552
+ options.sourceMap.content = read_source_map(files[name]);
26553
+ }
26242
26554
  }
26243
26555
  }
26556
+
26244
26557
  toplevel = options.parse.toplevel;
26245
26558
  }
26246
26559
  if (quoted_props && options.mangle.properties.keep_quoted !== "strict") {
@@ -26276,6 +26589,9 @@ async function minify(files, options) {
26276
26589
  if (options.format.ast) {
26277
26590
  result.ast = toplevel;
26278
26591
  }
26592
+ if (options.format.spidermonkey) {
26593
+ result.ast = toplevel.to_mozilla_ast();
26594
+ }
26279
26595
  if (!HOP(options.format, "code") || options.format.code) {
26280
26596
  if (options.sourceMap) {
26281
26597
  options.format.source_map = await SourceMap({
@@ -26293,6 +26609,7 @@ async function minify(files, options) {
26293
26609
  }
26294
26610
  delete options.format.ast;
26295
26611
  delete options.format.code;
26612
+ delete options.format.spidermonkey;
26296
26613
  var stream = OutputStream(options.format);
26297
26614
  toplevel.print(stream);
26298
26615
  result.code = stream.get();
@@ -26363,7 +26680,7 @@ async function run_cli({ program, packageJson, fs, path }) {
26363
26680
  program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
26364
26681
  program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
26365
26682
  program.option("-f, --format [options]", "Format options.", parse_js());
26366
- program.option("-b, --beautify [options]", "Alias for --format beautify=true.", parse_js());
26683
+ program.option("-b, --beautify [options]", "Alias for --format.", parse_js());
26367
26684
  program.option("-o, --output <file>", "Output file (default STDOUT).");
26368
26685
  program.option("--comments [filter]", "Preserve copyright comments in the output.");
26369
26686
  program.option("--config-file <file>", "Read minify() options from JSON file.");
@@ -26414,19 +26731,9 @@ async function run_cli({ program, packageJson, fs, path }) {
26414
26731
  else
26415
26732
  options.ecma = ecma;
26416
26733
  }
26417
- if (program.beautify || program.format) {
26418
- if (program.beautify && program.format) {
26419
- fatal("Please only specify one of --beautify or --format");
26420
- }
26421
- if (program.beautify) {
26422
- options.format = typeof program.beautify == "object" ? program.beautify : {};
26423
- if (!("beautify" in options.format)) {
26424
- options.format.beautify = true;
26425
- }
26426
- }
26427
- if (program.format) {
26428
- options.format = typeof program.format == "object" ? program.format : {};
26429
- }
26734
+ if (program.format || program.beautify) {
26735
+ const chosenOption = program.format || program.beautify;
26736
+ options.format = typeof chosenOption === "object" ? chosenOption : {};
26430
26737
  }
26431
26738
  if (program.comments) {
26432
26739
  if (typeof options.format != "object") options.format = {};