terser 5.38.0 → 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 +8 -0
- package/dist/bundle.min.js +176 -97
- package/lib/ast.js +64 -39
- package/lib/compress/drop-side-effect-free.js +27 -15
- package/lib/compress/index.js +11 -1
- package/lib/compress/inference.js +44 -24
- package/lib/equivalent-to.js +13 -0
- package/lib/mozilla-ast.js +12 -8
- package/lib/output.js +11 -11
- package/lib/parse.js +1 -0
- package/lib/size.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.38.2
|
4
|
+
|
5
|
+
- internal: Flatten inheritance tree for object/class members
|
6
|
+
|
7
|
+
## v5.38.1
|
8
|
+
|
9
|
+
- Fix inlining non-call expressions into an `optional_call?.()`
|
10
|
+
|
3
11
|
## v5.38.0
|
4
12
|
|
5
13
|
- Remove `console` method-of-method calls (eg `console.log.apply()`) when `drop_console` option is used (#1585)
|
package/dist/bundle.min.js
CHANGED
@@ -3286,6 +3286,7 @@ function parse($TEXT, options) {
|
|
3286
3286
|
return subscripts(call, true, is_chain);
|
3287
3287
|
}
|
3288
3288
|
|
3289
|
+
// Optional chain
|
3289
3290
|
if (is("punc", "?.")) {
|
3290
3291
|
next();
|
3291
3292
|
|
@@ -5629,6 +5630,11 @@ var AST_Object = DEFNODE("Object", "properties", function AST_Object(props) {
|
|
5629
5630
|
},
|
5630
5631
|
});
|
5631
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
|
+
**/
|
5632
5638
|
var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_ObjectProperty(props) {
|
5633
5639
|
if (props) {
|
5634
5640
|
this.key = props.key;
|
@@ -5643,7 +5649,7 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_Obj
|
|
5643
5649
|
$documentation: "Base class for literal object properties",
|
5644
5650
|
$propdoc: {
|
5645
5651
|
key: "[string|AST_Node] property name. For ObjectKeyVal this is a string. For getters, setters and computed property this is an AST_Node.",
|
5646
|
-
value: "[AST_Node] property value. For getters and
|
5652
|
+
value: "[AST_Node] property value. For getters, setters and methods this is an AST_Accessor."
|
5647
5653
|
},
|
5648
5654
|
_walk: function(visitor) {
|
5649
5655
|
return visitor._visit(this, function() {
|
@@ -5655,7 +5661,7 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_Obj
|
|
5655
5661
|
_children_backwards(push) {
|
5656
5662
|
push(this.value);
|
5657
5663
|
if (this.key instanceof AST_Node) push(this.key);
|
5658
|
-
}
|
5664
|
+
},
|
5659
5665
|
});
|
5660
5666
|
|
5661
5667
|
var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", function AST_ObjectKeyVal(props) {
|
@@ -5765,38 +5771,32 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_Obje
|
|
5765
5771
|
}
|
5766
5772
|
}, AST_ObjectProperty);
|
5767
5773
|
|
5768
|
-
var AST_ConciseMethod = DEFNODE(
|
5769
|
-
|
5770
|
-
|
5771
|
-
|
5772
|
-
|
5773
|
-
|
5774
|
-
|
5775
|
-
|
5776
|
-
|
5777
|
-
|
5778
|
-
|
5779
|
-
|
5780
|
-
this.end = props.end;
|
5781
|
-
this._annotations = props._annotations;
|
5782
|
-
}
|
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
|
+
}
|
5783
5786
|
|
5784
|
-
|
5785
|
-
|
5786
|
-
{
|
5787
|
-
|
5788
|
-
|
5789
|
-
|
5790
|
-
|
5791
|
-
async: "[boolean] is this method async",
|
5792
|
-
},
|
5793
|
-
$documentation: "An ES6 concise method inside an object or class",
|
5794
|
-
computed_key() {
|
5795
|
-
return !(this.key instanceof AST_SymbolMethod);
|
5796
|
-
}
|
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",
|
5797
5794
|
},
|
5798
|
-
|
5799
|
-
)
|
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);
|
5800
5800
|
|
5801
5801
|
var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
|
5802
5802
|
if (props) {
|
@@ -5813,7 +5813,10 @@ var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(
|
|
5813
5813
|
this.flags = 0;
|
5814
5814
|
}, {
|
5815
5815
|
$documentation: "A private class method inside a class",
|
5816
|
-
|
5816
|
+
computed_key() {
|
5817
|
+
return false;
|
5818
|
+
},
|
5819
|
+
}, AST_ObjectProperty);
|
5817
5820
|
|
5818
5821
|
var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(props) {
|
5819
5822
|
if (props) {
|
@@ -5837,7 +5840,7 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
|
|
5837
5840
|
$propdoc: {
|
5838
5841
|
name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",
|
5839
5842
|
extends: "[AST_Node]? optional parent class",
|
5840
|
-
properties: "[AST_ObjectProperty*
|
5843
|
+
properties: "[AST_ObjectProperty|AST_ClassStaticBlock]* array of properties or static blocks"
|
5841
5844
|
},
|
5842
5845
|
$documentation: "An ES6 class",
|
5843
5846
|
_walk: function(visitor) {
|
@@ -5872,7 +5875,10 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
|
|
5872
5875
|
prop.key._walk(visitor);
|
5873
5876
|
visitor.pop();
|
5874
5877
|
}
|
5875
|
-
if (
|
5878
|
+
if (
|
5879
|
+
prop instanceof AST_ClassPrivateProperty && prop.static && prop.value
|
5880
|
+
|| prop instanceof AST_ClassProperty && prop.static && prop.value
|
5881
|
+
) {
|
5876
5882
|
visitor.push(prop);
|
5877
5883
|
prop.value._walk(visitor);
|
5878
5884
|
visitor.pop();
|
@@ -5882,9 +5888,15 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
|
|
5882
5888
|
/** go through the bits that are executed later, when the class is `new`'d or a static method is called */
|
5883
5889
|
visit_deferred_class_parts(visitor) {
|
5884
5890
|
this.properties.forEach((prop) => {
|
5885
|
-
if (
|
5891
|
+
if (
|
5892
|
+
prop instanceof AST_ConciseMethod
|
5893
|
+
|| prop instanceof AST_PrivateMethod
|
5894
|
+
) {
|
5886
5895
|
prop.walk(visitor);
|
5887
|
-
} else if (
|
5896
|
+
} else if (
|
5897
|
+
prop instanceof AST_ClassProperty && !prop.static && prop.value
|
5898
|
+
|| prop instanceof AST_ClassPrivateProperty && !prop.static && prop.value
|
5899
|
+
) {
|
5888
5900
|
visitor.push(prop);
|
5889
5901
|
prop.value._walk(visitor);
|
5890
5902
|
visitor.pop();
|
@@ -5959,7 +5971,19 @@ var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_
|
|
5959
5971
|
this.flags = 0;
|
5960
5972
|
}, {
|
5961
5973
|
$documentation: "A class property for a private property",
|
5962
|
-
|
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);
|
5963
5987
|
|
5964
5988
|
var AST_PrivateIn = DEFNODE("PrivateIn", "key value", function AST_PrivateIn(props) {
|
5965
5989
|
if (props) {
|
@@ -6026,7 +6050,9 @@ var AST_ClassStaticBlock = DEFNODE("ClassStaticBlock", "body block_scope", funct
|
|
6026
6050
|
while (i--) push(this.body[i]);
|
6027
6051
|
},
|
6028
6052
|
clone: clone_block_scope,
|
6029
|
-
computed_key
|
6053
|
+
computed_key() {
|
6054
|
+
return false;
|
6055
|
+
},
|
6030
6056
|
}, AST_Scope);
|
6031
6057
|
|
6032
6058
|
var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExpression(props) {
|
@@ -8657,23 +8683,27 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8657
8683
|
};
|
8658
8684
|
}
|
8659
8685
|
|
8660
|
-
const key = M instanceof AST_PrivateMethod
|
8661
|
-
? {
|
8662
|
-
type: "PrivateIdentifier",
|
8663
|
-
name: M.key.name
|
8664
|
-
}
|
8665
|
-
: to_moz(M.key);
|
8666
|
-
|
8667
8686
|
return {
|
8668
8687
|
type: "MethodDefinition",
|
8669
8688
|
kind: M.key === "constructor" ? "constructor" : "method",
|
8670
|
-
key,
|
8689
|
+
key: to_moz(M.key),
|
8671
8690
|
value: to_moz(M.value),
|
8672
8691
|
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
|
8673
8692
|
static: M.static,
|
8674
8693
|
};
|
8675
8694
|
});
|
8676
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
|
+
|
8677
8707
|
def_to_moz(AST_Class, function To_Moz_Class(M) {
|
8678
8708
|
var type = M instanceof AST_ClassExpression ? "ClassExpression" : "ClassDeclaration";
|
8679
8709
|
return {
|
@@ -11103,6 +11133,17 @@ function OutputStream(options) {
|
|
11103
11133
|
DEFPRINT(AST_PrivateGetter, function(self, output) {
|
11104
11134
|
self._print_getter_setter("get", true, output);
|
11105
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
|
+
});
|
11106
11147
|
DEFPRINT(AST_PrivateMethod, function(self, output) {
|
11107
11148
|
var type;
|
11108
11149
|
if (self.is_generator && self.async) {
|
@@ -11124,17 +11165,6 @@ function OutputStream(options) {
|
|
11124
11165
|
DEFPRINT(AST_SymbolPrivateProperty, function(self, output) {
|
11125
11166
|
output.print("#" + self.name);
|
11126
11167
|
});
|
11127
|
-
DEFPRINT(AST_ConciseMethod, function(self, output) {
|
11128
|
-
var type;
|
11129
|
-
if (self.is_generator && self.async) {
|
11130
|
-
type = "async*";
|
11131
|
-
} else if (self.is_generator) {
|
11132
|
-
type = "*";
|
11133
|
-
} else if (self.async) {
|
11134
|
-
type = "async";
|
11135
|
-
}
|
11136
|
-
self._print_getter_setter(type, false, output);
|
11137
|
-
});
|
11138
11168
|
DEFPRINT(AST_ClassStaticBlock, function (self, output) {
|
11139
11169
|
output.print("static");
|
11140
11170
|
output.space();
|
@@ -11513,11 +11543,22 @@ AST_ConciseMethod.prototype.shallow_cmp = function(other) {
|
|
11513
11543
|
return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async;
|
11514
11544
|
};
|
11515
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
|
+
|
11516
11550
|
AST_Class.prototype.shallow_cmp = function(other) {
|
11517
11551
|
return (this.name == null ? other.name == null : this.name === other.name) && (this.extends == null ? other.extends == null : this.extends === other.extends);
|
11518
11552
|
};
|
11519
11553
|
|
11520
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) {
|
11521
11562
|
return this.static === other.static;
|
11522
11563
|
};
|
11523
11564
|
|
@@ -12846,7 +12887,11 @@ AST_PrivateMethod.prototype._size = function () {
|
|
12846
12887
|
return AST_ConciseMethod.prototype._size.call(this) + 1;
|
12847
12888
|
};
|
12848
12889
|
|
12849
|
-
AST_PrivateGetter.prototype._size =
|
12890
|
+
AST_PrivateGetter.prototype._size = function () {
|
12891
|
+
return AST_ConciseMethod.prototype._size.call(this) + 4;
|
12892
|
+
};
|
12893
|
+
|
12894
|
+
AST_PrivateSetter.prototype._size = function () {
|
12850
12895
|
return AST_ConciseMethod.prototype._size.call(this) + 4;
|
12851
12896
|
};
|
12852
12897
|
|
@@ -13828,25 +13873,29 @@ function is_nullish(node, compressor) {
|
|
13828
13873
|
def_has_side_effects(AST_Object, function(compressor) {
|
13829
13874
|
return any(this.properties, compressor);
|
13830
13875
|
});
|
13831
|
-
def_has_side_effects(
|
13876
|
+
def_has_side_effects(AST_ObjectKeyVal, function(compressor) {
|
13832
13877
|
return (
|
13833
13878
|
this.computed_key() && this.key.has_side_effects(compressor)
|
13834
13879
|
|| this.value && this.value.has_side_effects(compressor)
|
13835
13880
|
);
|
13836
13881
|
});
|
13837
|
-
def_has_side_effects(
|
13882
|
+
def_has_side_effects([
|
13883
|
+
AST_ClassProperty,
|
13884
|
+
AST_ClassPrivateProperty,
|
13885
|
+
], function(compressor) {
|
13838
13886
|
return (
|
13839
13887
|
this.computed_key() && this.key.has_side_effects(compressor)
|
13840
13888
|
|| this.static && this.value && this.value.has_side_effects(compressor)
|
13841
13889
|
);
|
13842
13890
|
});
|
13843
|
-
def_has_side_effects(
|
13844
|
-
|
13845
|
-
|
13846
|
-
|
13847
|
-
|
13848
|
-
|
13849
|
-
|
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) {
|
13850
13899
|
return this.computed_key() && this.key.has_side_effects(compressor);
|
13851
13900
|
});
|
13852
13901
|
def_has_side_effects(AST_Array, function(compressor) {
|
@@ -13891,8 +13940,10 @@ function is_nullish(node, compressor) {
|
|
13891
13940
|
def_has_side_effects(AST_TemplateString, function(compressor) {
|
13892
13941
|
return any(this.segments, compressor);
|
13893
13942
|
});
|
13894
|
-
})(function(
|
13895
|
-
node.
|
13943
|
+
})(function(node_or_nodes, func) {
|
13944
|
+
for (const node of [].concat(node_or_nodes)) {
|
13945
|
+
node.DEFMETHOD("has_side_effects", func);
|
13946
|
+
}
|
13896
13947
|
});
|
13897
13948
|
|
13898
13949
|
// determine if expression may throw
|
@@ -13971,25 +14022,33 @@ function is_nullish(node, compressor) {
|
|
13971
14022
|
def_may_throw(AST_Object, function(compressor) {
|
13972
14023
|
return any(this.properties, compressor);
|
13973
14024
|
});
|
13974
|
-
def_may_throw(
|
13975
|
-
|
13976
|
-
|
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
|
+
);
|
13977
14030
|
});
|
13978
|
-
def_may_throw(
|
14031
|
+
def_may_throw([
|
14032
|
+
AST_ClassProperty,
|
14033
|
+
AST_ClassPrivateProperty,
|
14034
|
+
], function(compressor) {
|
13979
14035
|
return (
|
13980
14036
|
this.computed_key() && this.key.may_throw(compressor)
|
13981
14037
|
|| this.static && this.value && this.value.may_throw(compressor)
|
13982
14038
|
);
|
13983
14039
|
});
|
13984
|
-
def_may_throw(
|
13985
|
-
|
13986
|
-
|
13987
|
-
|
13988
|
-
|
13989
|
-
});
|
13990
|
-
def_may_throw(AST_ObjectSetter, function(compressor) {
|
14040
|
+
def_may_throw([
|
14041
|
+
AST_ConciseMethod,
|
14042
|
+
AST_ObjectGetter,
|
14043
|
+
AST_ObjectSetter,
|
14044
|
+
], function(compressor) {
|
13991
14045
|
return this.computed_key() && this.key.may_throw(compressor);
|
13992
14046
|
});
|
14047
|
+
def_may_throw([
|
14048
|
+
AST_PrivateMethod,
|
14049
|
+
AST_PrivateGetter,
|
14050
|
+
AST_PrivateSetter,
|
14051
|
+
], return_false);
|
13993
14052
|
def_may_throw(AST_Return, function(compressor) {
|
13994
14053
|
return this.value && this.value.may_throw(compressor);
|
13995
14054
|
});
|
@@ -14034,8 +14093,10 @@ function is_nullish(node, compressor) {
|
|
14034
14093
|
if (!this.value) return false;
|
14035
14094
|
return this.value.may_throw(compressor);
|
14036
14095
|
});
|
14037
|
-
})(function(
|
14038
|
-
node.
|
14096
|
+
})(function(node_or_nodes, func) {
|
14097
|
+
for (const node of [].concat(node_or_nodes)) {
|
14098
|
+
node.DEFMETHOD("may_throw", func);
|
14099
|
+
}
|
14039
14100
|
});
|
14040
14101
|
|
14041
14102
|
// determine if expression is constant
|
@@ -15030,8 +15091,10 @@ def_eval(AST_New, return_this);
|
|
15030
15091
|
// 10 -> (nothing)
|
15031
15092
|
// knownPureFunc(foo++) -> foo++
|
15032
15093
|
|
15033
|
-
function def_drop_side_effect_free(
|
15034
|
-
node.
|
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
|
+
}
|
15035
15098
|
}
|
15036
15099
|
|
15037
15100
|
// Drop side-effect-free elements from an array of expressions.
|
@@ -15122,7 +15185,10 @@ def_drop_side_effect_free(AST_Class, function (compressor) {
|
|
15122
15185
|
}
|
15123
15186
|
});
|
15124
15187
|
|
15125
|
-
def_drop_side_effect_free(
|
15188
|
+
def_drop_side_effect_free([
|
15189
|
+
AST_ClassProperty,
|
15190
|
+
AST_ClassPrivateProperty,
|
15191
|
+
], function (compressor) {
|
15126
15192
|
const key = this.computed_key() && this.key.drop_side_effect_free(compressor);
|
15127
15193
|
|
15128
15194
|
const value = this.static && this.value
|
@@ -15226,26 +15292,30 @@ def_drop_side_effect_free(AST_Object, function (compressor, first_in_statement)
|
|
15226
15292
|
return values && make_sequence(this, values);
|
15227
15293
|
});
|
15228
15294
|
|
15229
|
-
def_drop_side_effect_free(
|
15230
|
-
const computed_key = this
|
15295
|
+
def_drop_side_effect_free(AST_ObjectKeyVal, function (compressor, first_in_statement) {
|
15296
|
+
const computed_key = this.key instanceof AST_Node;
|
15231
15297
|
const key = computed_key && this.key.drop_side_effect_free(compressor, first_in_statement);
|
15232
|
-
const value = this.value
|
15298
|
+
const value = this.value.drop_side_effect_free(compressor, first_in_statement);
|
15233
15299
|
if (key && value) {
|
15234
15300
|
return make_sequence(this, [key, value]);
|
15235
15301
|
}
|
15236
15302
|
return key || value;
|
15237
15303
|
});
|
15238
15304
|
|
15239
|
-
def_drop_side_effect_free(
|
15240
|
-
|
15241
|
-
|
15242
|
-
|
15243
|
-
|
15305
|
+
def_drop_side_effect_free([
|
15306
|
+
AST_ConciseMethod,
|
15307
|
+
AST_ObjectGetter,
|
15308
|
+
AST_ObjectSetter,
|
15309
|
+
], function () {
|
15244
15310
|
return this.computed_key() ? this.key : null;
|
15245
15311
|
});
|
15246
15312
|
|
15247
|
-
def_drop_side_effect_free(
|
15248
|
-
|
15313
|
+
def_drop_side_effect_free([
|
15314
|
+
AST_PrivateMethod,
|
15315
|
+
AST_PrivateGetter,
|
15316
|
+
AST_PrivateSetter,
|
15317
|
+
], function () {
|
15318
|
+
return null;
|
15249
15319
|
});
|
15250
15320
|
|
15251
15321
|
def_drop_side_effect_free(AST_Array, function (compressor, first_in_statement) {
|
@@ -21950,6 +22020,7 @@ function safe_to_flatten(value, compressor) {
|
|
21950
22020
|
AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
|
21951
22021
|
if (!compressor.option("properties")) return;
|
21952
22022
|
if (key === "__proto__") return;
|
22023
|
+
if (this instanceof AST_DotHash) return;
|
21953
22024
|
|
21954
22025
|
var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 2015;
|
21955
22026
|
var expr = this.expression;
|
@@ -22137,7 +22208,15 @@ def_optimize(AST_Chain, function (self, compressor) {
|
|
22137
22208
|
}
|
22138
22209
|
return make_node(AST_Undefined, self);
|
22139
22210
|
}
|
22140
|
-
|
22211
|
+
if (
|
22212
|
+
self.expression instanceof AST_PropAccess
|
22213
|
+
|| self.expression instanceof AST_Call
|
22214
|
+
) {
|
22215
|
+
return self;
|
22216
|
+
} else {
|
22217
|
+
// Keep the AST valid, in case the child swapped itself
|
22218
|
+
return self.expression;
|
22219
|
+
}
|
22141
22220
|
});
|
22142
22221
|
|
22143
22222
|
def_optimize(AST_Dot, function(self, compressor) {
|
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
|
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
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
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
|
-
|
2165
|
-
|
2166
|
-
{
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
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
|
-
|
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
|
-
|
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*
|
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 (
|
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 (
|
2270
|
+
if (
|
2271
|
+
prop instanceof AST_ConciseMethod
|
2272
|
+
|| prop instanceof AST_PrivateMethod
|
2273
|
+
) {
|
2266
2274
|
prop.walk(visitor);
|
2267
|
-
} else if (
|
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
|
-
|
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
|
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
|
-
|
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(
|
98
|
-
node.
|
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(
|
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(
|
294
|
-
const computed_key = this
|
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
|
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(
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
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(
|
312
|
-
|
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) {
|
package/lib/compress/index.js
CHANGED
@@ -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;
|
@@ -3674,7 +3676,15 @@ def_optimize(AST_Chain, function (self, compressor) {
|
|
3674
3676
|
}
|
3675
3677
|
return make_node(AST_Undefined, self);
|
3676
3678
|
}
|
3677
|
-
|
3679
|
+
if (
|
3680
|
+
self.expression instanceof AST_PropAccess
|
3681
|
+
|| self.expression instanceof AST_Call
|
3682
|
+
) {
|
3683
|
+
return self;
|
3684
|
+
} else {
|
3685
|
+
// Keep the AST valid, in case the child swapped itself
|
3686
|
+
return self.expression;
|
3687
|
+
}
|
3678
3688
|
});
|
3679
3689
|
|
3680
3690
|
def_optimize(AST_Dot, function(self, compressor) {
|
@@ -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(
|
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(
|
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(
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
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(
|
434
|
-
node.
|
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(
|
514
|
-
|
515
|
-
|
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(
|
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(
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
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(
|
577
|
-
node.
|
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
|
package/lib/equivalent-to.js
CHANGED
@@ -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
|
|
package/lib/mozilla-ast.js
CHANGED
@@ -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/parse.js
CHANGED
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 =
|
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
|
|