terser 5.38.1 → 5.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/bundle.min.js +184 -97
- package/lib/ast.js +64 -39
- package/lib/compress/compressor-flags.js +0 -1
- package/lib/compress/drop-side-effect-free.js +27 -15
- package/lib/compress/index.js +20 -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/size.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/bundle.min.js
CHANGED
@@ -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
|
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
|
-
|
5771
|
-
|
5772
|
-
|
5773
|
-
|
5774
|
-
|
5775
|
-
|
5776
|
-
|
5777
|
-
|
5778
|
-
|
5779
|
-
|
5780
|
-
|
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
|
-
|
5786
|
-
|
5787
|
-
{
|
5788
|
-
|
5789
|
-
|
5790
|
-
|
5791
|
-
|
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
|
-
|
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
|
-
|
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*
|
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 (
|
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 (
|
5891
|
+
if (
|
5892
|
+
prop instanceof AST_ConciseMethod
|
5893
|
+
|| prop instanceof AST_PrivateMethod
|
5894
|
+
) {
|
5887
5895
|
prop.walk(visitor);
|
5888
|
-
} else if (
|
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
|
-
|
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
|
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 =
|
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
|
|
@@ -13001,7 +13045,6 @@ const TRUTHY = 0b00000010;
|
|
13001
13045
|
const FALSY = 0b00000100;
|
13002
13046
|
const UNDEFINED = 0b00001000;
|
13003
13047
|
const INLINED = 0b00010000;
|
13004
|
-
|
13005
13048
|
// Nodes to which values are ever written. Used when keep_assign is part of the unused option string.
|
13006
13049
|
const WRITE_ONLY = 0b00100000;
|
13007
13050
|
|
@@ -13829,25 +13872,29 @@ function is_nullish(node, compressor) {
|
|
13829
13872
|
def_has_side_effects(AST_Object, function(compressor) {
|
13830
13873
|
return any(this.properties, compressor);
|
13831
13874
|
});
|
13832
|
-
def_has_side_effects(
|
13875
|
+
def_has_side_effects(AST_ObjectKeyVal, function(compressor) {
|
13833
13876
|
return (
|
13834
13877
|
this.computed_key() && this.key.has_side_effects(compressor)
|
13835
13878
|
|| this.value && this.value.has_side_effects(compressor)
|
13836
13879
|
);
|
13837
13880
|
});
|
13838
|
-
def_has_side_effects(
|
13881
|
+
def_has_side_effects([
|
13882
|
+
AST_ClassProperty,
|
13883
|
+
AST_ClassPrivateProperty,
|
13884
|
+
], function(compressor) {
|
13839
13885
|
return (
|
13840
13886
|
this.computed_key() && this.key.has_side_effects(compressor)
|
13841
13887
|
|| this.static && this.value && this.value.has_side_effects(compressor)
|
13842
13888
|
);
|
13843
13889
|
});
|
13844
|
-
def_has_side_effects(
|
13845
|
-
|
13846
|
-
|
13847
|
-
|
13848
|
-
|
13849
|
-
|
13850
|
-
|
13890
|
+
def_has_side_effects([
|
13891
|
+
AST_PrivateMethod,
|
13892
|
+
AST_PrivateGetter,
|
13893
|
+
AST_PrivateSetter,
|
13894
|
+
AST_ConciseMethod,
|
13895
|
+
AST_ObjectGetter,
|
13896
|
+
AST_ObjectSetter,
|
13897
|
+
], function(compressor) {
|
13851
13898
|
return this.computed_key() && this.key.has_side_effects(compressor);
|
13852
13899
|
});
|
13853
13900
|
def_has_side_effects(AST_Array, function(compressor) {
|
@@ -13892,8 +13939,10 @@ function is_nullish(node, compressor) {
|
|
13892
13939
|
def_has_side_effects(AST_TemplateString, function(compressor) {
|
13893
13940
|
return any(this.segments, compressor);
|
13894
13941
|
});
|
13895
|
-
})(function(
|
13896
|
-
node.
|
13942
|
+
})(function(node_or_nodes, func) {
|
13943
|
+
for (const node of [].concat(node_or_nodes)) {
|
13944
|
+
node.DEFMETHOD("has_side_effects", func);
|
13945
|
+
}
|
13897
13946
|
});
|
13898
13947
|
|
13899
13948
|
// determine if expression may throw
|
@@ -13972,25 +14021,33 @@ function is_nullish(node, compressor) {
|
|
13972
14021
|
def_may_throw(AST_Object, function(compressor) {
|
13973
14022
|
return any(this.properties, compressor);
|
13974
14023
|
});
|
13975
|
-
def_may_throw(
|
13976
|
-
|
13977
|
-
|
14024
|
+
def_may_throw(AST_ObjectKeyVal, function(compressor) {
|
14025
|
+
return (
|
14026
|
+
this.computed_key() && this.key.may_throw(compressor)
|
14027
|
+
|| this.value ? this.value.may_throw(compressor) : false
|
14028
|
+
);
|
13978
14029
|
});
|
13979
|
-
def_may_throw(
|
14030
|
+
def_may_throw([
|
14031
|
+
AST_ClassProperty,
|
14032
|
+
AST_ClassPrivateProperty,
|
14033
|
+
], function(compressor) {
|
13980
14034
|
return (
|
13981
14035
|
this.computed_key() && this.key.may_throw(compressor)
|
13982
14036
|
|| this.static && this.value && this.value.may_throw(compressor)
|
13983
14037
|
);
|
13984
14038
|
});
|
13985
|
-
def_may_throw(
|
13986
|
-
|
13987
|
-
|
13988
|
-
|
13989
|
-
|
13990
|
-
});
|
13991
|
-
def_may_throw(AST_ObjectSetter, function(compressor) {
|
14039
|
+
def_may_throw([
|
14040
|
+
AST_ConciseMethod,
|
14041
|
+
AST_ObjectGetter,
|
14042
|
+
AST_ObjectSetter,
|
14043
|
+
], function(compressor) {
|
13992
14044
|
return this.computed_key() && this.key.may_throw(compressor);
|
13993
14045
|
});
|
14046
|
+
def_may_throw([
|
14047
|
+
AST_PrivateMethod,
|
14048
|
+
AST_PrivateGetter,
|
14049
|
+
AST_PrivateSetter,
|
14050
|
+
], return_false);
|
13994
14051
|
def_may_throw(AST_Return, function(compressor) {
|
13995
14052
|
return this.value && this.value.may_throw(compressor);
|
13996
14053
|
});
|
@@ -14035,8 +14092,10 @@ function is_nullish(node, compressor) {
|
|
14035
14092
|
if (!this.value) return false;
|
14036
14093
|
return this.value.may_throw(compressor);
|
14037
14094
|
});
|
14038
|
-
})(function(
|
14039
|
-
node.
|
14095
|
+
})(function(node_or_nodes, func) {
|
14096
|
+
for (const node of [].concat(node_or_nodes)) {
|
14097
|
+
node.DEFMETHOD("may_throw", func);
|
14098
|
+
}
|
14040
14099
|
});
|
14041
14100
|
|
14042
14101
|
// determine if expression is constant
|
@@ -15031,8 +15090,10 @@ def_eval(AST_New, return_this);
|
|
15031
15090
|
// 10 -> (nothing)
|
15032
15091
|
// knownPureFunc(foo++) -> foo++
|
15033
15092
|
|
15034
|
-
function def_drop_side_effect_free(
|
15035
|
-
node.
|
15093
|
+
function def_drop_side_effect_free(node_or_nodes, func) {
|
15094
|
+
for (const node of [].concat(node_or_nodes)) {
|
15095
|
+
node.DEFMETHOD("drop_side_effect_free", func);
|
15096
|
+
}
|
15036
15097
|
}
|
15037
15098
|
|
15038
15099
|
// Drop side-effect-free elements from an array of expressions.
|
@@ -15123,7 +15184,10 @@ def_drop_side_effect_free(AST_Class, function (compressor) {
|
|
15123
15184
|
}
|
15124
15185
|
});
|
15125
15186
|
|
15126
|
-
def_drop_side_effect_free(
|
15187
|
+
def_drop_side_effect_free([
|
15188
|
+
AST_ClassProperty,
|
15189
|
+
AST_ClassPrivateProperty,
|
15190
|
+
], function (compressor) {
|
15127
15191
|
const key = this.computed_key() && this.key.drop_side_effect_free(compressor);
|
15128
15192
|
|
15129
15193
|
const value = this.static && this.value
|
@@ -15227,26 +15291,30 @@ def_drop_side_effect_free(AST_Object, function (compressor, first_in_statement)
|
|
15227
15291
|
return values && make_sequence(this, values);
|
15228
15292
|
});
|
15229
15293
|
|
15230
|
-
def_drop_side_effect_free(
|
15231
|
-
const computed_key = this
|
15294
|
+
def_drop_side_effect_free(AST_ObjectKeyVal, function (compressor, first_in_statement) {
|
15295
|
+
const computed_key = this.key instanceof AST_Node;
|
15232
15296
|
const key = computed_key && this.key.drop_side_effect_free(compressor, first_in_statement);
|
15233
|
-
const value = this.value
|
15297
|
+
const value = this.value.drop_side_effect_free(compressor, first_in_statement);
|
15234
15298
|
if (key && value) {
|
15235
15299
|
return make_sequence(this, [key, value]);
|
15236
15300
|
}
|
15237
15301
|
return key || value;
|
15238
15302
|
});
|
15239
15303
|
|
15240
|
-
def_drop_side_effect_free(
|
15241
|
-
|
15242
|
-
|
15243
|
-
|
15244
|
-
|
15304
|
+
def_drop_side_effect_free([
|
15305
|
+
AST_ConciseMethod,
|
15306
|
+
AST_ObjectGetter,
|
15307
|
+
AST_ObjectSetter,
|
15308
|
+
], function () {
|
15245
15309
|
return this.computed_key() ? this.key : null;
|
15246
15310
|
});
|
15247
15311
|
|
15248
|
-
def_drop_side_effect_free(
|
15249
|
-
|
15312
|
+
def_drop_side_effect_free([
|
15313
|
+
AST_PrivateMethod,
|
15314
|
+
AST_PrivateGetter,
|
15315
|
+
AST_PrivateSetter,
|
15316
|
+
], function () {
|
15317
|
+
return null;
|
15250
15318
|
});
|
15251
15319
|
|
15252
15320
|
def_drop_side_effect_free(AST_Array, function (compressor, first_in_statement) {
|
@@ -18960,6 +19028,7 @@ class Compressor extends TreeWalker {
|
|
18960
19028
|
}
|
18961
19029
|
}
|
18962
19030
|
|
19031
|
+
|
18963
19032
|
function def_optimize(node, optimizer) {
|
18964
19033
|
node.DEFMETHOD("optimize", function(compressor) {
|
18965
19034
|
var self = this;
|
@@ -20184,6 +20253,23 @@ def_optimize(AST_Call, function(self, compressor) {
|
|
20184
20253
|
self.args.length = last;
|
20185
20254
|
}
|
20186
20255
|
|
20256
|
+
if (
|
20257
|
+
exp instanceof AST_Dot
|
20258
|
+
&& exp.expression instanceof AST_SymbolRef
|
20259
|
+
&& exp.expression.name === "console"
|
20260
|
+
&& exp.expression.definition().undeclared
|
20261
|
+
&& exp.property === "assert"
|
20262
|
+
) {
|
20263
|
+
const condition = self.args[0];
|
20264
|
+
if (condition) {
|
20265
|
+
const value = condition.evaluate(compressor);
|
20266
|
+
|
20267
|
+
if (value === 1 || value === true) {
|
20268
|
+
return make_node(AST_Undefined, self);
|
20269
|
+
}
|
20270
|
+
}
|
20271
|
+
}
|
20272
|
+
|
20187
20273
|
if (compressor.option("unsafe") && !exp.contains_optional()) {
|
20188
20274
|
if (exp instanceof AST_Dot && exp.start.value === "Array" && exp.property === "from" && self.args.length === 1) {
|
20189
20275
|
const [argument] = self.args;
|
@@ -21951,6 +22037,7 @@ function safe_to_flatten(value, compressor) {
|
|
21951
22037
|
AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
|
21952
22038
|
if (!compressor.option("properties")) return;
|
21953
22039
|
if (key === "__proto__") return;
|
22040
|
+
if (this instanceof AST_DotHash) return;
|
21954
22041
|
|
21955
22042
|
var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 2015;
|
21956
22043
|
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
|
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) {
|
@@ -48,7 +48,6 @@ export const TRUTHY = 0b00000010;
|
|
48
48
|
export const FALSY = 0b00000100;
|
49
49
|
export const UNDEFINED = 0b00001000;
|
50
50
|
export const INLINED = 0b00010000;
|
51
|
-
|
52
51
|
// Nodes to which values are ever written. Used when keep_assign is part of the unused option string.
|
53
52
|
export const WRITE_ONLY = 0b00100000;
|
54
53
|
|
@@ -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,
|
@@ -187,7 +188,6 @@ import {
|
|
187
188
|
UNUSED,
|
188
189
|
TRUTHY,
|
189
190
|
FALSY,
|
190
|
-
|
191
191
|
has_flag,
|
192
192
|
set_flag,
|
193
193
|
clear_flag,
|
@@ -496,6 +496,7 @@ class Compressor extends TreeWalker {
|
|
496
496
|
}
|
497
497
|
}
|
498
498
|
|
499
|
+
|
499
500
|
function def_optimize(node, optimizer) {
|
500
501
|
node.DEFMETHOD("optimize", function(compressor) {
|
501
502
|
var self = this;
|
@@ -1720,6 +1721,23 @@ def_optimize(AST_Call, function(self, compressor) {
|
|
1720
1721
|
self.args.length = last;
|
1721
1722
|
}
|
1722
1723
|
|
1724
|
+
if (
|
1725
|
+
exp instanceof AST_Dot
|
1726
|
+
&& exp.expression instanceof AST_SymbolRef
|
1727
|
+
&& exp.expression.name === "console"
|
1728
|
+
&& exp.expression.definition().undeclared
|
1729
|
+
&& exp.property === "assert"
|
1730
|
+
) {
|
1731
|
+
const condition = self.args[0];
|
1732
|
+
if (condition) {
|
1733
|
+
const value = condition.evaluate(compressor);
|
1734
|
+
|
1735
|
+
if (value === 1 || value === true) {
|
1736
|
+
return make_node(AST_Undefined, self);
|
1737
|
+
}
|
1738
|
+
}
|
1739
|
+
}
|
1740
|
+
|
1723
1741
|
if (compressor.option("unsafe") && !exp.contains_optional()) {
|
1724
1742
|
if (exp instanceof AST_Dot && exp.start.value === "Array" && exp.property === "from" && self.args.length === 1) {
|
1725
1743
|
const [argument] = self.args;
|
@@ -3487,6 +3505,7 @@ function safe_to_flatten(value, compressor) {
|
|
3487
3505
|
AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
|
3488
3506
|
if (!compressor.option("properties")) return;
|
3489
3507
|
if (key === "__proto__") return;
|
3508
|
+
if (this instanceof AST_DotHash) return;
|
3490
3509
|
|
3491
3510
|
var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 2015;
|
3492
3511
|
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(
|
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/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
|
|