terser 5.38.1 → 5.38.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v5.38.2
4
+
5
+ - internal: Flatten inheritance tree for object/class members
6
+
3
7
  ## v5.38.1
4
8
 
5
9
  - Fix inlining non-call expressions into an `optional_call?.()`
@@ -5630,6 +5630,11 @@ var AST_Object = DEFNODE("Object", "properties", function AST_Object(props) {
5630
5630
  },
5631
5631
  });
5632
5632
 
5633
+ /* -----[ OBJECT/CLASS PROPERTIES ]----- */
5634
+
5635
+ /**
5636
+ * Everything inside the curly braces of an object/class is a subclass of AST_ObjectProperty, except for AST_ClassStaticBlock.
5637
+ **/
5633
5638
  var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_ObjectProperty(props) {
5634
5639
  if (props) {
5635
5640
  this.key = props.key;
@@ -5644,7 +5649,7 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_Obj
5644
5649
  $documentation: "Base class for literal object properties",
5645
5650
  $propdoc: {
5646
5651
  key: "[string|AST_Node] property name. For ObjectKeyVal this is a string. For getters, setters and computed property this is an AST_Node.",
5647
- value: "[AST_Node] property value. For getters and setters this is an AST_Accessor."
5652
+ value: "[AST_Node] property value. For getters, setters and methods this is an AST_Accessor."
5648
5653
  },
5649
5654
  _walk: function(visitor) {
5650
5655
  return visitor._visit(this, function() {
@@ -5656,7 +5661,7 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_Obj
5656
5661
  _children_backwards(push) {
5657
5662
  push(this.value);
5658
5663
  if (this.key instanceof AST_Node) push(this.key);
5659
- }
5664
+ },
5660
5665
  });
5661
5666
 
5662
5667
  var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", function AST_ObjectKeyVal(props) {
@@ -5766,38 +5771,32 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_Obje
5766
5771
  }
5767
5772
  }, AST_ObjectProperty);
5768
5773
 
5769
- var AST_ConciseMethod = DEFNODE(
5770
- "ConciseMethod",
5771
- "quote static is_generator async",
5772
- function AST_ConciseMethod(props) {
5773
- if (props) {
5774
- this.quote = props.quote;
5775
- this.static = props.static;
5776
- this.is_generator = props.is_generator;
5777
- this.async = props.async;
5778
- this.key = props.key;
5779
- this.value = props.value;
5780
- this.start = props.start;
5781
- this.end = props.end;
5782
- this._annotations = props._annotations;
5783
- }
5774
+ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator async", function AST_ConciseMethod(props) {
5775
+ if (props) {
5776
+ this.quote = props.quote;
5777
+ this.static = props.static;
5778
+ this.is_generator = props.is_generator;
5779
+ this.async = props.async;
5780
+ this.key = props.key;
5781
+ this.value = props.value;
5782
+ this.start = props.start;
5783
+ this.end = props.end;
5784
+ this._annotations = props._annotations;
5785
+ }
5784
5786
 
5785
- this.flags = 0;
5786
- },
5787
- {
5788
- $propdoc: {
5789
- quote: "[string|undefined] the original quote character, if any",
5790
- static: "[boolean] is this method static (classes only)",
5791
- is_generator: "[boolean] is this a generator method",
5792
- async: "[boolean] is this method async",
5793
- },
5794
- $documentation: "An ES6 concise method inside an object or class",
5795
- computed_key() {
5796
- return !(this.key instanceof AST_SymbolMethod);
5797
- }
5787
+ this.flags = 0;
5788
+ }, {
5789
+ $propdoc: {
5790
+ quote: "[string|undefined] the original quote character, if any",
5791
+ static: "[boolean] is this method static (classes only)",
5792
+ is_generator: "[boolean] is this a generator method",
5793
+ async: "[boolean] is this method async",
5798
5794
  },
5799
- AST_ObjectProperty
5800
- );
5795
+ $documentation: "An ES6 concise method inside an object or class",
5796
+ computed_key() {
5797
+ return !(this.key instanceof AST_SymbolMethod);
5798
+ }
5799
+ }, AST_ObjectProperty);
5801
5800
 
5802
5801
  var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
5803
5802
  if (props) {
@@ -5814,7 +5813,10 @@ var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(
5814
5813
  this.flags = 0;
5815
5814
  }, {
5816
5815
  $documentation: "A private class method inside a class",
5817
- }, AST_ConciseMethod);
5816
+ computed_key() {
5817
+ return false;
5818
+ },
5819
+ }, AST_ObjectProperty);
5818
5820
 
5819
5821
  var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(props) {
5820
5822
  if (props) {
@@ -5838,7 +5840,7 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
5838
5840
  $propdoc: {
5839
5841
  name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",
5840
5842
  extends: "[AST_Node]? optional parent class",
5841
- properties: "[AST_ObjectProperty*] array of properties"
5843
+ properties: "[AST_ObjectProperty|AST_ClassStaticBlock]* array of properties or static blocks"
5842
5844
  },
5843
5845
  $documentation: "An ES6 class",
5844
5846
  _walk: function(visitor) {
@@ -5873,7 +5875,10 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
5873
5875
  prop.key._walk(visitor);
5874
5876
  visitor.pop();
5875
5877
  }
5876
- if ((prop instanceof AST_ClassPrivateProperty || prop instanceof AST_ClassProperty) && prop.static && prop.value) {
5878
+ if (
5879
+ prop instanceof AST_ClassPrivateProperty && prop.static && prop.value
5880
+ || prop instanceof AST_ClassProperty && prop.static && prop.value
5881
+ ) {
5877
5882
  visitor.push(prop);
5878
5883
  prop.value._walk(visitor);
5879
5884
  visitor.pop();
@@ -5883,9 +5888,15 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
5883
5888
  /** go through the bits that are executed later, when the class is `new`'d or a static method is called */
5884
5889
  visit_deferred_class_parts(visitor) {
5885
5890
  this.properties.forEach((prop) => {
5886
- if (prop instanceof AST_ConciseMethod) {
5891
+ if (
5892
+ prop instanceof AST_ConciseMethod
5893
+ || prop instanceof AST_PrivateMethod
5894
+ ) {
5887
5895
  prop.walk(visitor);
5888
- } else if (prop instanceof AST_ClassProperty && !prop.static && prop.value) {
5896
+ } else if (
5897
+ prop instanceof AST_ClassProperty && !prop.static && prop.value
5898
+ || prop instanceof AST_ClassPrivateProperty && !prop.static && prop.value
5899
+ ) {
5889
5900
  visitor.push(prop);
5890
5901
  prop.value._walk(visitor);
5891
5902
  visitor.pop();
@@ -5960,7 +5971,19 @@ var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_
5960
5971
  this.flags = 0;
5961
5972
  }, {
5962
5973
  $documentation: "A class property for a private property",
5963
- }, AST_ClassProperty);
5974
+ _walk: function(visitor) {
5975
+ return visitor._visit(this, function() {
5976
+ if (this.value instanceof AST_Node)
5977
+ this.value._walk(visitor);
5978
+ });
5979
+ },
5980
+ _children_backwards(push) {
5981
+ if (this.value instanceof AST_Node) push(this.value);
5982
+ },
5983
+ computed_key() {
5984
+ return false;
5985
+ },
5986
+ }, AST_ObjectProperty);
5964
5987
 
5965
5988
  var AST_PrivateIn = DEFNODE("PrivateIn", "key value", function AST_PrivateIn(props) {
5966
5989
  if (props) {
@@ -6027,7 +6050,9 @@ var AST_ClassStaticBlock = DEFNODE("ClassStaticBlock", "body block_scope", funct
6027
6050
  while (i--) push(this.body[i]);
6028
6051
  },
6029
6052
  clone: clone_block_scope,
6030
- computed_key: () => false
6053
+ computed_key() {
6054
+ return false;
6055
+ },
6031
6056
  }, AST_Scope);
6032
6057
 
6033
6058
  var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExpression(props) {
@@ -8658,23 +8683,27 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
8658
8683
  };
8659
8684
  }
8660
8685
 
8661
- const key = M instanceof AST_PrivateMethod
8662
- ? {
8663
- type: "PrivateIdentifier",
8664
- name: M.key.name
8665
- }
8666
- : to_moz(M.key);
8667
-
8668
8686
  return {
8669
8687
  type: "MethodDefinition",
8670
8688
  kind: M.key === "constructor" ? "constructor" : "method",
8671
- key,
8689
+ key: to_moz(M.key),
8672
8690
  value: to_moz(M.value),
8673
8691
  computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
8674
8692
  static: M.static,
8675
8693
  };
8676
8694
  });
8677
8695
 
8696
+ def_to_moz(AST_PrivateMethod, function To_Moz_MethodDefinition(M) {
8697
+ return {
8698
+ type: "MethodDefinition",
8699
+ kind: "method",
8700
+ key: { type: "PrivateIdentifier", name: M.key.name },
8701
+ value: to_moz(M.value),
8702
+ computed: false,
8703
+ static: M.static,
8704
+ };
8705
+ });
8706
+
8678
8707
  def_to_moz(AST_Class, function To_Moz_Class(M) {
8679
8708
  var type = M instanceof AST_ClassExpression ? "ClassExpression" : "ClassDeclaration";
8680
8709
  return {
@@ -11104,6 +11133,17 @@ function OutputStream(options) {
11104
11133
  DEFPRINT(AST_PrivateGetter, function(self, output) {
11105
11134
  self._print_getter_setter("get", true, output);
11106
11135
  });
11136
+ DEFPRINT(AST_ConciseMethod, function(self, output) {
11137
+ var type;
11138
+ if (self.is_generator && self.async) {
11139
+ type = "async*";
11140
+ } else if (self.is_generator) {
11141
+ type = "*";
11142
+ } else if (self.async) {
11143
+ type = "async";
11144
+ }
11145
+ self._print_getter_setter(type, false, output);
11146
+ });
11107
11147
  DEFPRINT(AST_PrivateMethod, function(self, output) {
11108
11148
  var type;
11109
11149
  if (self.is_generator && self.async) {
@@ -11125,17 +11165,6 @@ function OutputStream(options) {
11125
11165
  DEFPRINT(AST_SymbolPrivateProperty, function(self, output) {
11126
11166
  output.print("#" + self.name);
11127
11167
  });
11128
- DEFPRINT(AST_ConciseMethod, function(self, output) {
11129
- var type;
11130
- if (self.is_generator && self.async) {
11131
- type = "async*";
11132
- } else if (self.is_generator) {
11133
- type = "*";
11134
- } else if (self.async) {
11135
- type = "async";
11136
- }
11137
- self._print_getter_setter(type, false, output);
11138
- });
11139
11168
  DEFPRINT(AST_ClassStaticBlock, function (self, output) {
11140
11169
  output.print("static");
11141
11170
  output.space();
@@ -11514,11 +11543,22 @@ AST_ConciseMethod.prototype.shallow_cmp = function(other) {
11514
11543
  return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async;
11515
11544
  };
11516
11545
 
11546
+ AST_PrivateMethod.prototype.shallow_cmp = function(other) {
11547
+ return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async;
11548
+ };
11549
+
11517
11550
  AST_Class.prototype.shallow_cmp = function(other) {
11518
11551
  return (this.name == null ? other.name == null : this.name === other.name) && (this.extends == null ? other.extends == null : this.extends === other.extends);
11519
11552
  };
11520
11553
 
11521
11554
  AST_ClassProperty.prototype.shallow_cmp = function(other) {
11555
+ return this.static === other.static
11556
+ && (typeof this.key === "string"
11557
+ ? this.key === other.key
11558
+ : true /* AST_Node handled elsewhere */);
11559
+ };
11560
+
11561
+ AST_ClassPrivateProperty.prototype.shallow_cmp = function(other) {
11522
11562
  return this.static === other.static;
11523
11563
  };
11524
11564
 
@@ -12847,7 +12887,11 @@ AST_PrivateMethod.prototype._size = function () {
12847
12887
  return AST_ConciseMethod.prototype._size.call(this) + 1;
12848
12888
  };
12849
12889
 
12850
- AST_PrivateGetter.prototype._size = AST_PrivateSetter.prototype._size = function () {
12890
+ AST_PrivateGetter.prototype._size = function () {
12891
+ return AST_ConciseMethod.prototype._size.call(this) + 4;
12892
+ };
12893
+
12894
+ AST_PrivateSetter.prototype._size = function () {
12851
12895
  return AST_ConciseMethod.prototype._size.call(this) + 4;
12852
12896
  };
12853
12897
 
@@ -13829,25 +13873,29 @@ function is_nullish(node, compressor) {
13829
13873
  def_has_side_effects(AST_Object, function(compressor) {
13830
13874
  return any(this.properties, compressor);
13831
13875
  });
13832
- def_has_side_effects(AST_ObjectProperty, function(compressor) {
13876
+ def_has_side_effects(AST_ObjectKeyVal, function(compressor) {
13833
13877
  return (
13834
13878
  this.computed_key() && this.key.has_side_effects(compressor)
13835
13879
  || this.value && this.value.has_side_effects(compressor)
13836
13880
  );
13837
13881
  });
13838
- def_has_side_effects(AST_ClassProperty, function(compressor) {
13882
+ def_has_side_effects([
13883
+ AST_ClassProperty,
13884
+ AST_ClassPrivateProperty,
13885
+ ], function(compressor) {
13839
13886
  return (
13840
13887
  this.computed_key() && this.key.has_side_effects(compressor)
13841
13888
  || this.static && this.value && this.value.has_side_effects(compressor)
13842
13889
  );
13843
13890
  });
13844
- def_has_side_effects(AST_ConciseMethod, function(compressor) {
13845
- return this.computed_key() && this.key.has_side_effects(compressor);
13846
- });
13847
- def_has_side_effects(AST_ObjectGetter, function(compressor) {
13848
- return this.computed_key() && this.key.has_side_effects(compressor);
13849
- });
13850
- def_has_side_effects(AST_ObjectSetter, function(compressor) {
13891
+ def_has_side_effects([
13892
+ AST_PrivateMethod,
13893
+ AST_PrivateGetter,
13894
+ AST_PrivateSetter,
13895
+ AST_ConciseMethod,
13896
+ AST_ObjectGetter,
13897
+ AST_ObjectSetter,
13898
+ ], function(compressor) {
13851
13899
  return this.computed_key() && this.key.has_side_effects(compressor);
13852
13900
  });
13853
13901
  def_has_side_effects(AST_Array, function(compressor) {
@@ -13892,8 +13940,10 @@ function is_nullish(node, compressor) {
13892
13940
  def_has_side_effects(AST_TemplateString, function(compressor) {
13893
13941
  return any(this.segments, compressor);
13894
13942
  });
13895
- })(function(node, func) {
13896
- node.DEFMETHOD("has_side_effects", func);
13943
+ })(function(node_or_nodes, func) {
13944
+ for (const node of [].concat(node_or_nodes)) {
13945
+ node.DEFMETHOD("has_side_effects", func);
13946
+ }
13897
13947
  });
13898
13948
 
13899
13949
  // determine if expression may throw
@@ -13972,25 +14022,33 @@ function is_nullish(node, compressor) {
13972
14022
  def_may_throw(AST_Object, function(compressor) {
13973
14023
  return any(this.properties, compressor);
13974
14024
  });
13975
- def_may_throw(AST_ObjectProperty, function(compressor) {
13976
- // TODO key may throw too
13977
- return this.value ? this.value.may_throw(compressor) : false;
14025
+ def_may_throw(AST_ObjectKeyVal, function(compressor) {
14026
+ return (
14027
+ this.computed_key() && this.key.may_throw(compressor)
14028
+ || this.value ? this.value.may_throw(compressor) : false
14029
+ );
13978
14030
  });
13979
- def_may_throw(AST_ClassProperty, function(compressor) {
14031
+ def_may_throw([
14032
+ AST_ClassProperty,
14033
+ AST_ClassPrivateProperty,
14034
+ ], function(compressor) {
13980
14035
  return (
13981
14036
  this.computed_key() && this.key.may_throw(compressor)
13982
14037
  || this.static && this.value && this.value.may_throw(compressor)
13983
14038
  );
13984
14039
  });
13985
- def_may_throw(AST_ConciseMethod, function(compressor) {
13986
- return this.computed_key() && this.key.may_throw(compressor);
13987
- });
13988
- def_may_throw(AST_ObjectGetter, function(compressor) {
13989
- return this.computed_key() && this.key.may_throw(compressor);
13990
- });
13991
- def_may_throw(AST_ObjectSetter, function(compressor) {
14040
+ def_may_throw([
14041
+ AST_ConciseMethod,
14042
+ AST_ObjectGetter,
14043
+ AST_ObjectSetter,
14044
+ ], function(compressor) {
13992
14045
  return this.computed_key() && this.key.may_throw(compressor);
13993
14046
  });
14047
+ def_may_throw([
14048
+ AST_PrivateMethod,
14049
+ AST_PrivateGetter,
14050
+ AST_PrivateSetter,
14051
+ ], return_false);
13994
14052
  def_may_throw(AST_Return, function(compressor) {
13995
14053
  return this.value && this.value.may_throw(compressor);
13996
14054
  });
@@ -14035,8 +14093,10 @@ function is_nullish(node, compressor) {
14035
14093
  if (!this.value) return false;
14036
14094
  return this.value.may_throw(compressor);
14037
14095
  });
14038
- })(function(node, func) {
14039
- node.DEFMETHOD("may_throw", func);
14096
+ })(function(node_or_nodes, func) {
14097
+ for (const node of [].concat(node_or_nodes)) {
14098
+ node.DEFMETHOD("may_throw", func);
14099
+ }
14040
14100
  });
14041
14101
 
14042
14102
  // determine if expression is constant
@@ -15031,8 +15091,10 @@ def_eval(AST_New, return_this);
15031
15091
  // 10 -> (nothing)
15032
15092
  // knownPureFunc(foo++) -> foo++
15033
15093
 
15034
- function def_drop_side_effect_free(node, func) {
15035
- node.DEFMETHOD("drop_side_effect_free", func);
15094
+ function def_drop_side_effect_free(node_or_nodes, func) {
15095
+ for (const node of [].concat(node_or_nodes)) {
15096
+ node.DEFMETHOD("drop_side_effect_free", func);
15097
+ }
15036
15098
  }
15037
15099
 
15038
15100
  // Drop side-effect-free elements from an array of expressions.
@@ -15123,7 +15185,10 @@ def_drop_side_effect_free(AST_Class, function (compressor) {
15123
15185
  }
15124
15186
  });
15125
15187
 
15126
- def_drop_side_effect_free(AST_ClassProperty, function (compressor) {
15188
+ def_drop_side_effect_free([
15189
+ AST_ClassProperty,
15190
+ AST_ClassPrivateProperty,
15191
+ ], function (compressor) {
15127
15192
  const key = this.computed_key() && this.key.drop_side_effect_free(compressor);
15128
15193
 
15129
15194
  const value = this.static && this.value
@@ -15227,26 +15292,30 @@ def_drop_side_effect_free(AST_Object, function (compressor, first_in_statement)
15227
15292
  return values && make_sequence(this, values);
15228
15293
  });
15229
15294
 
15230
- def_drop_side_effect_free(AST_ObjectProperty, function (compressor, first_in_statement) {
15231
- const computed_key = this instanceof AST_ObjectKeyVal && this.key instanceof AST_Node;
15295
+ def_drop_side_effect_free(AST_ObjectKeyVal, function (compressor, first_in_statement) {
15296
+ const computed_key = this.key instanceof AST_Node;
15232
15297
  const key = computed_key && this.key.drop_side_effect_free(compressor, first_in_statement);
15233
- const value = this.value && this.value.drop_side_effect_free(compressor, first_in_statement);
15298
+ const value = this.value.drop_side_effect_free(compressor, first_in_statement);
15234
15299
  if (key && value) {
15235
15300
  return make_sequence(this, [key, value]);
15236
15301
  }
15237
15302
  return key || value;
15238
15303
  });
15239
15304
 
15240
- def_drop_side_effect_free(AST_ConciseMethod, function () {
15305
+ def_drop_side_effect_free([
15306
+ AST_ConciseMethod,
15307
+ AST_ObjectGetter,
15308
+ AST_ObjectSetter,
15309
+ ], function () {
15241
15310
  return this.computed_key() ? this.key : null;
15242
15311
  });
15243
15312
 
15244
- def_drop_side_effect_free(AST_ObjectGetter, function () {
15245
- return this.computed_key() ? this.key : null;
15246
- });
15247
-
15248
- def_drop_side_effect_free(AST_ObjectSetter, function () {
15249
- return this.computed_key() ? this.key : null;
15313
+ def_drop_side_effect_free([
15314
+ AST_PrivateMethod,
15315
+ AST_PrivateGetter,
15316
+ AST_PrivateSetter,
15317
+ ], function () {
15318
+ return null;
15250
15319
  });
15251
15320
 
15252
15321
  def_drop_side_effect_free(AST_Array, function (compressor, first_in_statement) {
@@ -21951,6 +22020,7 @@ function safe_to_flatten(value, compressor) {
21951
22020
  AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
21952
22021
  if (!compressor.option("properties")) return;
21953
22022
  if (key === "__proto__") return;
22023
+ if (this instanceof AST_DotHash) return;
21954
22024
 
21955
22025
  var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 2015;
21956
22026
  var expr = this.expression;
package/lib/ast.js CHANGED
@@ -2009,6 +2009,11 @@ var AST_Object = DEFNODE("Object", "properties", function AST_Object(props) {
2009
2009
  },
2010
2010
  });
2011
2011
 
2012
+ /* -----[ OBJECT/CLASS PROPERTIES ]----- */
2013
+
2014
+ /**
2015
+ * Everything inside the curly braces of an object/class is a subclass of AST_ObjectProperty, except for AST_ClassStaticBlock.
2016
+ **/
2012
2017
  var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_ObjectProperty(props) {
2013
2018
  if (props) {
2014
2019
  this.key = props.key;
@@ -2023,7 +2028,7 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_Obj
2023
2028
  $documentation: "Base class for literal object properties",
2024
2029
  $propdoc: {
2025
2030
  key: "[string|AST_Node] property name. For ObjectKeyVal this is a string. For getters, setters and computed property this is an AST_Node.",
2026
- value: "[AST_Node] property value. For getters and setters this is an AST_Accessor."
2031
+ value: "[AST_Node] property value. For getters, setters and methods this is an AST_Accessor."
2027
2032
  },
2028
2033
  _walk: function(visitor) {
2029
2034
  return visitor._visit(this, function() {
@@ -2035,7 +2040,7 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_Obj
2035
2040
  _children_backwards(push) {
2036
2041
  push(this.value);
2037
2042
  if (this.key instanceof AST_Node) push(this.key);
2038
- }
2043
+ },
2039
2044
  });
2040
2045
 
2041
2046
  var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", function AST_ObjectKeyVal(props) {
@@ -2145,38 +2150,32 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_Obje
2145
2150
  }
2146
2151
  }, AST_ObjectProperty);
2147
2152
 
2148
- var AST_ConciseMethod = DEFNODE(
2149
- "ConciseMethod",
2150
- "quote static is_generator async",
2151
- function AST_ConciseMethod(props) {
2152
- if (props) {
2153
- this.quote = props.quote;
2154
- this.static = props.static;
2155
- this.is_generator = props.is_generator;
2156
- this.async = props.async;
2157
- this.key = props.key;
2158
- this.value = props.value;
2159
- this.start = props.start;
2160
- this.end = props.end;
2161
- this._annotations = props._annotations;
2162
- }
2153
+ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator async", function AST_ConciseMethod(props) {
2154
+ if (props) {
2155
+ this.quote = props.quote;
2156
+ this.static = props.static;
2157
+ this.is_generator = props.is_generator;
2158
+ this.async = props.async;
2159
+ this.key = props.key;
2160
+ this.value = props.value;
2161
+ this.start = props.start;
2162
+ this.end = props.end;
2163
+ this._annotations = props._annotations;
2164
+ }
2163
2165
 
2164
- this.flags = 0;
2165
- },
2166
- {
2167
- $propdoc: {
2168
- quote: "[string|undefined] the original quote character, if any",
2169
- static: "[boolean] is this method static (classes only)",
2170
- is_generator: "[boolean] is this a generator method",
2171
- async: "[boolean] is this method async",
2172
- },
2173
- $documentation: "An ES6 concise method inside an object or class",
2174
- computed_key() {
2175
- return !(this.key instanceof AST_SymbolMethod);
2176
- }
2166
+ this.flags = 0;
2167
+ }, {
2168
+ $propdoc: {
2169
+ quote: "[string|undefined] the original quote character, if any",
2170
+ static: "[boolean] is this method static (classes only)",
2171
+ is_generator: "[boolean] is this a generator method",
2172
+ async: "[boolean] is this method async",
2177
2173
  },
2178
- AST_ObjectProperty
2179
- );
2174
+ $documentation: "An ES6 concise method inside an object or class",
2175
+ computed_key() {
2176
+ return !(this.key instanceof AST_SymbolMethod);
2177
+ }
2178
+ }, AST_ObjectProperty);
2180
2179
 
2181
2180
  var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
2182
2181
  if (props) {
@@ -2193,7 +2192,10 @@ var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(
2193
2192
  this.flags = 0;
2194
2193
  }, {
2195
2194
  $documentation: "A private class method inside a class",
2196
- }, AST_ConciseMethod);
2195
+ computed_key() {
2196
+ return false;
2197
+ },
2198
+ }, AST_ObjectProperty);
2197
2199
 
2198
2200
  var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(props) {
2199
2201
  if (props) {
@@ -2217,7 +2219,7 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
2217
2219
  $propdoc: {
2218
2220
  name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",
2219
2221
  extends: "[AST_Node]? optional parent class",
2220
- properties: "[AST_ObjectProperty*] array of properties"
2222
+ properties: "[AST_ObjectProperty|AST_ClassStaticBlock]* array of properties or static blocks"
2221
2223
  },
2222
2224
  $documentation: "An ES6 class",
2223
2225
  _walk: function(visitor) {
@@ -2252,7 +2254,10 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
2252
2254
  prop.key._walk(visitor);
2253
2255
  visitor.pop();
2254
2256
  }
2255
- if ((prop instanceof AST_ClassPrivateProperty || prop instanceof AST_ClassProperty) && prop.static && prop.value) {
2257
+ if (
2258
+ prop instanceof AST_ClassPrivateProperty && prop.static && prop.value
2259
+ || prop instanceof AST_ClassProperty && prop.static && prop.value
2260
+ ) {
2256
2261
  visitor.push(prop);
2257
2262
  prop.value._walk(visitor);
2258
2263
  visitor.pop();
@@ -2262,9 +2267,15 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
2262
2267
  /** go through the bits that are executed later, when the class is `new`'d or a static method is called */
2263
2268
  visit_deferred_class_parts(visitor) {
2264
2269
  this.properties.forEach((prop) => {
2265
- if (prop instanceof AST_ConciseMethod) {
2270
+ if (
2271
+ prop instanceof AST_ConciseMethod
2272
+ || prop instanceof AST_PrivateMethod
2273
+ ) {
2266
2274
  prop.walk(visitor);
2267
- } else if (prop instanceof AST_ClassProperty && !prop.static && prop.value) {
2275
+ } else if (
2276
+ prop instanceof AST_ClassProperty && !prop.static && prop.value
2277
+ || prop instanceof AST_ClassPrivateProperty && !prop.static && prop.value
2278
+ ) {
2268
2279
  visitor.push(prop);
2269
2280
  prop.value._walk(visitor);
2270
2281
  visitor.pop();
@@ -2339,7 +2350,19 @@ var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_
2339
2350
  this.flags = 0;
2340
2351
  }, {
2341
2352
  $documentation: "A class property for a private property",
2342
- }, AST_ClassProperty);
2353
+ _walk: function(visitor) {
2354
+ return visitor._visit(this, function() {
2355
+ if (this.value instanceof AST_Node)
2356
+ this.value._walk(visitor);
2357
+ });
2358
+ },
2359
+ _children_backwards(push) {
2360
+ if (this.value instanceof AST_Node) push(this.value);
2361
+ },
2362
+ computed_key() {
2363
+ return false;
2364
+ },
2365
+ }, AST_ObjectProperty);
2343
2366
 
2344
2367
  var AST_PrivateIn = DEFNODE("PrivateIn", "key value", function AST_PrivateIn(props) {
2345
2368
  if (props) {
@@ -2406,7 +2429,9 @@ var AST_ClassStaticBlock = DEFNODE("ClassStaticBlock", "body block_scope", funct
2406
2429
  while (i--) push(this.body[i]);
2407
2430
  },
2408
2431
  clone: clone_block_scope,
2409
- computed_key: () => false
2432
+ computed_key() {
2433
+ return false;
2434
+ },
2410
2435
  }, AST_Scope);
2411
2436
 
2412
2437
  var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExpression(props) {
@@ -50,8 +50,9 @@ import {
50
50
  AST_Call,
51
51
  AST_Chain,
52
52
  AST_Class,
53
- AST_ClassStaticBlock,
53
+ AST_ClassPrivateProperty,
54
54
  AST_ClassProperty,
55
+ AST_ClassStaticBlock,
55
56
  AST_ConciseMethod,
56
57
  AST_Conditional,
57
58
  AST_Constant,
@@ -64,8 +65,10 @@ import {
64
65
  AST_Object,
65
66
  AST_ObjectGetter,
66
67
  AST_ObjectKeyVal,
67
- AST_ObjectProperty,
68
68
  AST_ObjectSetter,
69
+ AST_PrivateGetter,
70
+ AST_PrivateSetter,
71
+ AST_PrivateMethod,
69
72
  AST_PropAccess,
70
73
  AST_Scope,
71
74
  AST_Sequence,
@@ -94,8 +97,10 @@ import { make_sequence, is_func_expr, is_iife_call } from "./common.js";
94
97
  // 10 -> (nothing)
95
98
  // knownPureFunc(foo++) -> foo++
96
99
 
97
- function def_drop_side_effect_free(node, func) {
98
- node.DEFMETHOD("drop_side_effect_free", func);
100
+ function def_drop_side_effect_free(node_or_nodes, func) {
101
+ for (const node of [].concat(node_or_nodes)) {
102
+ node.DEFMETHOD("drop_side_effect_free", func);
103
+ }
99
104
  }
100
105
 
101
106
  // Drop side-effect-free elements from an array of expressions.
@@ -186,7 +191,10 @@ def_drop_side_effect_free(AST_Class, function (compressor) {
186
191
  }
187
192
  });
188
193
 
189
- def_drop_side_effect_free(AST_ClassProperty, function (compressor) {
194
+ def_drop_side_effect_free([
195
+ AST_ClassProperty,
196
+ AST_ClassPrivateProperty,
197
+ ], function (compressor) {
190
198
  const key = this.computed_key() && this.key.drop_side_effect_free(compressor);
191
199
 
192
200
  const value = this.static && this.value
@@ -290,26 +298,30 @@ def_drop_side_effect_free(AST_Object, function (compressor, first_in_statement)
290
298
  return values && make_sequence(this, values);
291
299
  });
292
300
 
293
- def_drop_side_effect_free(AST_ObjectProperty, function (compressor, first_in_statement) {
294
- const computed_key = this instanceof AST_ObjectKeyVal && this.key instanceof AST_Node;
301
+ def_drop_side_effect_free(AST_ObjectKeyVal, function (compressor, first_in_statement) {
302
+ const computed_key = this.key instanceof AST_Node;
295
303
  const key = computed_key && this.key.drop_side_effect_free(compressor, first_in_statement);
296
- const value = this.value && this.value.drop_side_effect_free(compressor, first_in_statement);
304
+ const value = this.value.drop_side_effect_free(compressor, first_in_statement);
297
305
  if (key && value) {
298
306
  return make_sequence(this, [key, value]);
299
307
  }
300
308
  return key || value;
301
309
  });
302
310
 
303
- def_drop_side_effect_free(AST_ConciseMethod, function () {
304
- return this.computed_key() ? this.key : null;
305
- });
306
-
307
- def_drop_side_effect_free(AST_ObjectGetter, function () {
311
+ def_drop_side_effect_free([
312
+ AST_ConciseMethod,
313
+ AST_ObjectGetter,
314
+ AST_ObjectSetter,
315
+ ], function () {
308
316
  return this.computed_key() ? this.key : null;
309
317
  });
310
318
 
311
- def_drop_side_effect_free(AST_ObjectSetter, function () {
312
- return this.computed_key() ? this.key : null;
319
+ def_drop_side_effect_free([
320
+ AST_PrivateMethod,
321
+ AST_PrivateGetter,
322
+ AST_PrivateSetter,
323
+ ], function () {
324
+ return null;
313
325
  });
314
326
 
315
327
  def_drop_side_effect_free(AST_Array, function (compressor, first_in_statement) {
@@ -71,6 +71,7 @@ import {
71
71
  AST_Directive,
72
72
  AST_Do,
73
73
  AST_Dot,
74
+ AST_DotHash,
74
75
  AST_DWLoop,
75
76
  AST_EmptyStatement,
76
77
  AST_Exit,
@@ -3487,6 +3488,7 @@ function safe_to_flatten(value, compressor) {
3487
3488
  AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
3488
3489
  if (!compressor.option("properties")) return;
3489
3490
  if (key === "__proto__") return;
3491
+ if (this instanceof AST_DotHash) return;
3490
3492
 
3491
3493
  var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 2015;
3492
3494
  var expr = this.expression;
@@ -55,6 +55,7 @@ import {
55
55
  AST_Class,
56
56
  AST_DefClass,
57
57
  AST_ClassStaticBlock,
58
+ AST_ClassPrivateProperty,
58
59
  AST_ClassProperty,
59
60
  AST_ConciseMethod,
60
61
  AST_Conditional,
@@ -81,6 +82,9 @@ import {
81
82
  AST_ObjectKeyVal,
82
83
  AST_ObjectProperty,
83
84
  AST_ObjectSetter,
85
+ AST_PrivateGetter,
86
+ AST_PrivateMethod,
87
+ AST_PrivateSetter,
84
88
  AST_PropAccess,
85
89
  AST_RegExp,
86
90
  AST_Return,
@@ -367,25 +371,29 @@ export function is_nullish(node, compressor) {
367
371
  def_has_side_effects(AST_Object, function(compressor) {
368
372
  return any(this.properties, compressor);
369
373
  });
370
- def_has_side_effects(AST_ObjectProperty, function(compressor) {
374
+ def_has_side_effects(AST_ObjectKeyVal, function(compressor) {
371
375
  return (
372
376
  this.computed_key() && this.key.has_side_effects(compressor)
373
377
  || this.value && this.value.has_side_effects(compressor)
374
378
  );
375
379
  });
376
- def_has_side_effects(AST_ClassProperty, function(compressor) {
380
+ def_has_side_effects([
381
+ AST_ClassProperty,
382
+ AST_ClassPrivateProperty,
383
+ ], function(compressor) {
377
384
  return (
378
385
  this.computed_key() && this.key.has_side_effects(compressor)
379
386
  || this.static && this.value && this.value.has_side_effects(compressor)
380
387
  );
381
388
  });
382
- def_has_side_effects(AST_ConciseMethod, function(compressor) {
383
- return this.computed_key() && this.key.has_side_effects(compressor);
384
- });
385
- def_has_side_effects(AST_ObjectGetter, function(compressor) {
386
- return this.computed_key() && this.key.has_side_effects(compressor);
387
- });
388
- def_has_side_effects(AST_ObjectSetter, function(compressor) {
389
+ def_has_side_effects([
390
+ AST_PrivateMethod,
391
+ AST_PrivateGetter,
392
+ AST_PrivateSetter,
393
+ AST_ConciseMethod,
394
+ AST_ObjectGetter,
395
+ AST_ObjectSetter,
396
+ ], function(compressor) {
389
397
  return this.computed_key() && this.key.has_side_effects(compressor);
390
398
  });
391
399
  def_has_side_effects(AST_Array, function(compressor) {
@@ -430,8 +438,10 @@ export function is_nullish(node, compressor) {
430
438
  def_has_side_effects(AST_TemplateString, function(compressor) {
431
439
  return any(this.segments, compressor);
432
440
  });
433
- })(function(node, func) {
434
- node.DEFMETHOD("has_side_effects", func);
441
+ })(function(node_or_nodes, func) {
442
+ for (const node of [].concat(node_or_nodes)) {
443
+ node.DEFMETHOD("has_side_effects", func);
444
+ }
435
445
  });
436
446
 
437
447
  // determine if expression may throw
@@ -510,25 +520,33 @@ export function is_nullish(node, compressor) {
510
520
  def_may_throw(AST_Object, function(compressor) {
511
521
  return any(this.properties, compressor);
512
522
  });
513
- def_may_throw(AST_ObjectProperty, function(compressor) {
514
- // TODO key may throw too
515
- return this.value ? this.value.may_throw(compressor) : false;
523
+ def_may_throw(AST_ObjectKeyVal, function(compressor) {
524
+ return (
525
+ this.computed_key() && this.key.may_throw(compressor)
526
+ || this.value ? this.value.may_throw(compressor) : false
527
+ );
516
528
  });
517
- def_may_throw(AST_ClassProperty, function(compressor) {
529
+ def_may_throw([
530
+ AST_ClassProperty,
531
+ AST_ClassPrivateProperty,
532
+ ], function(compressor) {
518
533
  return (
519
534
  this.computed_key() && this.key.may_throw(compressor)
520
535
  || this.static && this.value && this.value.may_throw(compressor)
521
536
  );
522
537
  });
523
- def_may_throw(AST_ConciseMethod, function(compressor) {
524
- return this.computed_key() && this.key.may_throw(compressor);
525
- });
526
- def_may_throw(AST_ObjectGetter, function(compressor) {
527
- return this.computed_key() && this.key.may_throw(compressor);
528
- });
529
- def_may_throw(AST_ObjectSetter, function(compressor) {
538
+ def_may_throw([
539
+ AST_ConciseMethod,
540
+ AST_ObjectGetter,
541
+ AST_ObjectSetter,
542
+ ], function(compressor) {
530
543
  return this.computed_key() && this.key.may_throw(compressor);
531
544
  });
545
+ def_may_throw([
546
+ AST_PrivateMethod,
547
+ AST_PrivateGetter,
548
+ AST_PrivateSetter,
549
+ ], return_false);
532
550
  def_may_throw(AST_Return, function(compressor) {
533
551
  return this.value && this.value.may_throw(compressor);
534
552
  });
@@ -573,8 +591,10 @@ export function is_nullish(node, compressor) {
573
591
  if (!this.value) return false;
574
592
  return this.value.may_throw(compressor);
575
593
  });
576
- })(function(node, func) {
577
- node.DEFMETHOD("may_throw", func);
594
+ })(function(node_or_nodes, func) {
595
+ for (const node of [].concat(node_or_nodes)) {
596
+ node.DEFMETHOD("may_throw", func);
597
+ }
578
598
  });
579
599
 
580
600
  // determine if expression is constant
@@ -10,6 +10,7 @@ import {
10
10
  AST_Chain,
11
11
  AST_Class,
12
12
  AST_ClassProperty,
13
+ AST_ClassPrivateProperty,
13
14
  AST_ConciseMethod,
14
15
  AST_Conditional,
15
16
  AST_Debugger,
@@ -43,6 +44,7 @@ import {
43
44
  AST_ObjectProperty,
44
45
  AST_ObjectSetter,
45
46
  AST_PrefixedTemplateString,
47
+ AST_PrivateMethod,
46
48
  AST_PropAccess,
47
49
  AST_RegExp,
48
50
  AST_Sequence,
@@ -247,11 +249,22 @@ AST_ConciseMethod.prototype.shallow_cmp = function(other) {
247
249
  return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async;
248
250
  };
249
251
 
252
+ AST_PrivateMethod.prototype.shallow_cmp = function(other) {
253
+ return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async;
254
+ };
255
+
250
256
  AST_Class.prototype.shallow_cmp = function(other) {
251
257
  return (this.name == null ? other.name == null : this.name === other.name) && (this.extends == null ? other.extends == null : this.extends === other.extends);
252
258
  };
253
259
 
254
260
  AST_ClassProperty.prototype.shallow_cmp = function(other) {
261
+ return this.static === other.static
262
+ && (typeof this.key === "string"
263
+ ? this.key === other.key
264
+ : true /* AST_Node handled elsewhere */);
265
+ };
266
+
267
+ AST_ClassPrivateProperty.prototype.shallow_cmp = function(other) {
255
268
  return this.static === other.static;
256
269
  };
257
270
 
@@ -1677,23 +1677,27 @@ import { is_basic_identifier_string } from "./parse.js";
1677
1677
  };
1678
1678
  }
1679
1679
 
1680
- const key = M instanceof AST_PrivateMethod
1681
- ? {
1682
- type: "PrivateIdentifier",
1683
- name: M.key.name
1684
- }
1685
- : to_moz(M.key);
1686
-
1687
1680
  return {
1688
1681
  type: "MethodDefinition",
1689
1682
  kind: M.key === "constructor" ? "constructor" : "method",
1690
- key,
1683
+ key: to_moz(M.key),
1691
1684
  value: to_moz(M.value),
1692
1685
  computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
1693
1686
  static: M.static,
1694
1687
  };
1695
1688
  });
1696
1689
 
1690
+ def_to_moz(AST_PrivateMethod, function To_Moz_MethodDefinition(M) {
1691
+ return {
1692
+ type: "MethodDefinition",
1693
+ kind: "method",
1694
+ key: { type: "PrivateIdentifier", name: M.key.name },
1695
+ value: to_moz(M.value),
1696
+ computed: false,
1697
+ static: M.static,
1698
+ };
1699
+ });
1700
+
1697
1701
  def_to_moz(AST_Class, function To_Moz_Class(M) {
1698
1702
  var type = M instanceof AST_ClassExpression ? "ClassExpression" : "ClassDeclaration";
1699
1703
  return {
package/lib/output.js CHANGED
@@ -2296,6 +2296,17 @@ function OutputStream(options) {
2296
2296
  DEFPRINT(AST_PrivateGetter, function(self, output) {
2297
2297
  self._print_getter_setter("get", true, output);
2298
2298
  });
2299
+ DEFPRINT(AST_ConciseMethod, function(self, output) {
2300
+ var type;
2301
+ if (self.is_generator && self.async) {
2302
+ type = "async*";
2303
+ } else if (self.is_generator) {
2304
+ type = "*";
2305
+ } else if (self.async) {
2306
+ type = "async";
2307
+ }
2308
+ self._print_getter_setter(type, false, output);
2309
+ });
2299
2310
  DEFPRINT(AST_PrivateMethod, function(self, output) {
2300
2311
  var type;
2301
2312
  if (self.is_generator && self.async) {
@@ -2317,17 +2328,6 @@ function OutputStream(options) {
2317
2328
  DEFPRINT(AST_SymbolPrivateProperty, function(self, output) {
2318
2329
  output.print("#" + self.name);
2319
2330
  });
2320
- DEFPRINT(AST_ConciseMethod, function(self, output) {
2321
- var type;
2322
- if (self.is_generator && self.async) {
2323
- type = "async*";
2324
- } else if (self.is_generator) {
2325
- type = "*";
2326
- } else if (self.async) {
2327
- type = "async";
2328
- }
2329
- self._print_getter_setter(type, false, output);
2330
- });
2331
2331
  DEFPRINT(AST_ClassStaticBlock, function (self, output) {
2332
2332
  output.print("static");
2333
2333
  output.space();
package/lib/size.js CHANGED
@@ -390,7 +390,11 @@ AST_PrivateMethod.prototype._size = function () {
390
390
  return AST_ConciseMethod.prototype._size.call(this) + 1;
391
391
  };
392
392
 
393
- AST_PrivateGetter.prototype._size = AST_PrivateSetter.prototype._size = function () {
393
+ AST_PrivateGetter.prototype._size = function () {
394
+ return AST_ConciseMethod.prototype._size.call(this) + 4;
395
+ };
396
+
397
+ AST_PrivateSetter.prototype._size = function () {
394
398
  return AST_ConciseMethod.prototype._size.call(this) + 4;
395
399
  };
396
400
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "homepage": "https://terser.org",
5
5
  "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
6
6
  "license": "BSD-2-Clause",
7
- "version": "5.38.1",
7
+ "version": "5.38.2",
8
8
  "engines": {
9
9
  "node": ">=10"
10
10
  },