terser 5.14.2 → 5.15.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 +5 -0
- package/bin/terser.mjs +21 -0
- package/dist/bundle.min.js +123 -13
- package/lib/ast.js +23 -0
- package/lib/cli.js +3 -1
- package/lib/compress/drop-side-effect-free.js +9 -0
- package/lib/compress/index.js +12 -11
- package/lib/compress/inference.js +21 -1
- package/lib/compress/inline.js +1 -0
- package/lib/compress/reduce-vars.js +5 -0
- package/lib/mozilla-ast.js +16 -0
- package/lib/output.js +6 -0
- package/lib/parse.js +24 -0
- package/lib/size.js +6 -0
- package/lib/transform.js +5 -0
- package/package.json +1 -1
- package/tools/domprops.js +3 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.15.0
|
4
|
+
- Basic support for ES2022 class static initializer blocks.
|
5
|
+
- Add `AudioWorkletNode` constructor options to domprops list (#1230)
|
6
|
+
- Make identity function inliner not inline `id(...expandedArgs)`
|
7
|
+
|
3
8
|
## v5.14.2
|
4
9
|
|
5
10
|
- Security fix for RegExps that should not be evaluated (regexp DDOS)
|
package/bin/terser.mjs
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
"use strict";
|
4
|
+
|
5
|
+
import "../tools/exit.cjs";
|
6
|
+
|
7
|
+
import fs from "fs"
|
8
|
+
import path from "path"
|
9
|
+
import program from "commander"
|
10
|
+
|
11
|
+
import { run_cli } from "../lib/cli.js"
|
12
|
+
|
13
|
+
const packageJson = {
|
14
|
+
name: "terser",
|
15
|
+
version: "experimental module CLI"
|
16
|
+
}
|
17
|
+
|
18
|
+
run_cli({ program, packageJson, fs, path }).catch((error) => {
|
19
|
+
console.error(error);
|
20
|
+
process.exitCode = 1;
|
21
|
+
});
|
package/dist/bundle.min.js
CHANGED
@@ -2731,6 +2731,10 @@ function parse($TEXT, options) {
|
|
2731
2731
|
var accessor_type = null;
|
2732
2732
|
|
2733
2733
|
if (is_class && name === "static" && is_not_method_start()) {
|
2734
|
+
const static_block = class_static_block();
|
2735
|
+
if (static_block != null) {
|
2736
|
+
return static_block;
|
2737
|
+
}
|
2734
2738
|
is_static = true;
|
2735
2739
|
name = as_property_name();
|
2736
2740
|
}
|
@@ -2837,6 +2841,25 @@ function parse($TEXT, options) {
|
|
2837
2841
|
}
|
2838
2842
|
}
|
2839
2843
|
|
2844
|
+
function class_static_block() {
|
2845
|
+
if (!is("punc", "{")) {
|
2846
|
+
return null;
|
2847
|
+
}
|
2848
|
+
|
2849
|
+
const start = S.token;
|
2850
|
+
const body = [];
|
2851
|
+
|
2852
|
+
next();
|
2853
|
+
|
2854
|
+
while (!is("punc", "}")) {
|
2855
|
+
body.push(statement());
|
2856
|
+
}
|
2857
|
+
|
2858
|
+
next();
|
2859
|
+
|
2860
|
+
return new AST_ClassStaticBlock({ start, body, end: prev() });
|
2861
|
+
}
|
2862
|
+
|
2840
2863
|
function maybe_import_assertion() {
|
2841
2864
|
if (is("name", "assert") && !has_newline_before(S.token)) {
|
2842
2865
|
next();
|
@@ -5784,6 +5807,28 @@ var AST_DefClass = DEFNODE("DefClass", null, function AST_DefClass(props) {
|
|
5784
5807
|
$documentation: "A class definition",
|
5785
5808
|
}, AST_Class);
|
5786
5809
|
|
5810
|
+
var AST_ClassStaticBlock = DEFNODE("ClassStaticBlock", "body block_scope", function AST_ClassStaticBlock (props) {
|
5811
|
+
this.body = props.body;
|
5812
|
+
this.block_scope = props.block_scope;
|
5813
|
+
this.start = props.start;
|
5814
|
+
this.end = props.end;
|
5815
|
+
}, {
|
5816
|
+
$documentation: "A block containing statements to be executed in the context of the class",
|
5817
|
+
$propdoc: {
|
5818
|
+
body: "[AST_Statement*] an array of statements",
|
5819
|
+
},
|
5820
|
+
_walk: function(visitor) {
|
5821
|
+
return visitor._visit(this, function() {
|
5822
|
+
walk_body(this, visitor);
|
5823
|
+
});
|
5824
|
+
},
|
5825
|
+
_children_backwards(push) {
|
5826
|
+
let i = this.body.length;
|
5827
|
+
while (i--) push(this.body[i]);
|
5828
|
+
},
|
5829
|
+
clone: clone_block_scope,
|
5830
|
+
}, AST_Scope);
|
5831
|
+
|
5787
5832
|
var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExpression(props) {
|
5788
5833
|
if (props) {
|
5789
5834
|
this.name = props.name;
|
@@ -6800,6 +6845,10 @@ def_transform(AST_Class, function(self, tw) {
|
|
6800
6845
|
self.properties = do_list(self.properties, tw);
|
6801
6846
|
});
|
6802
6847
|
|
6848
|
+
def_transform(AST_ClassStaticBlock, function(self, tw) {
|
6849
|
+
self.body = do_list(self.body, tw);
|
6850
|
+
});
|
6851
|
+
|
6803
6852
|
def_transform(AST_Expansion, function(self, tw) {
|
6804
6853
|
self.expression = self.expression.transform(tw);
|
6805
6854
|
});
|
@@ -7159,6 +7208,14 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7159
7208
|
});
|
7160
7209
|
},
|
7161
7210
|
|
7211
|
+
StaticBlock: function(M) {
|
7212
|
+
return new AST_ClassStaticBlock({
|
7213
|
+
start : my_start_token(M),
|
7214
|
+
end : my_end_token(M),
|
7215
|
+
body : M.body.map(from_moz),
|
7216
|
+
});
|
7217
|
+
},
|
7218
|
+
|
7162
7219
|
ArrayExpression: function(M) {
|
7163
7220
|
return new AST_Array({
|
7164
7221
|
start : my_start_token(M),
|
@@ -8298,6 +8355,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8298
8355
|
};
|
8299
8356
|
});
|
8300
8357
|
|
8358
|
+
def_to_moz(AST_ClassStaticBlock, function To_Moz_StaticBlock(M) {
|
8359
|
+
return {
|
8360
|
+
type: "StaticBlock",
|
8361
|
+
body: M.body.map(to_moz),
|
8362
|
+
};
|
8363
|
+
});
|
8364
|
+
|
8301
8365
|
def_to_moz(AST_NewTarget, function To_Moz_MetaProperty() {
|
8302
8366
|
return {
|
8303
8367
|
type: "MetaProperty",
|
@@ -10595,6 +10659,11 @@ function OutputStream(options) {
|
|
10595
10659
|
}
|
10596
10660
|
self._print_getter_setter(type, false, output);
|
10597
10661
|
});
|
10662
|
+
DEFPRINT(AST_ClassStaticBlock, function (self, output) {
|
10663
|
+
output.print("static");
|
10664
|
+
output.space();
|
10665
|
+
print_braced(self, output);
|
10666
|
+
});
|
10598
10667
|
AST_Symbol.DEFMETHOD("_do_print", function(output) {
|
10599
10668
|
var def = this.definition();
|
10600
10669
|
output.print_name(def ? def.mangled_name || def.name : this.name);
|
@@ -12268,6 +12337,11 @@ AST_Class.prototype._size = function () {
|
|
12268
12337
|
);
|
12269
12338
|
};
|
12270
12339
|
|
12340
|
+
AST_ClassStaticBlock.prototype._size = function () {
|
12341
|
+
// "class{}" + semicolons
|
12342
|
+
return 7 + list_overhead(this.body);
|
12343
|
+
};
|
12344
|
+
|
12271
12345
|
AST_ClassProperty.prototype._size = function () {
|
12272
12346
|
return (
|
12273
12347
|
static_size(this.static)
|
@@ -13138,6 +13212,9 @@ function is_nullish(node, compressor) {
|
|
13138
13212
|
}
|
13139
13213
|
return any(this.properties, compressor);
|
13140
13214
|
});
|
13215
|
+
def_has_side_effects(AST_ClassStaticBlock, function(compressor) {
|
13216
|
+
return any(this.body, compressor);
|
13217
|
+
});
|
13141
13218
|
def_has_side_effects(AST_Binary, function(compressor) {
|
13142
13219
|
return this.left.has_side_effects(compressor)
|
13143
13220
|
|| this.right.has_side_effects(compressor);
|
@@ -13237,6 +13314,9 @@ function is_nullish(node, compressor) {
|
|
13237
13314
|
if (this.extends && this.extends.may_throw(compressor)) return true;
|
13238
13315
|
return any(this.properties, compressor);
|
13239
13316
|
});
|
13317
|
+
def_may_throw(AST_ClassStaticBlock, function (compressor) {
|
13318
|
+
return any(this.body, compressor);
|
13319
|
+
});
|
13240
13320
|
|
13241
13321
|
def_may_throw(AST_Array, function(compressor) {
|
13242
13322
|
return any(this.elements, compressor);
|
@@ -13405,6 +13485,9 @@ function is_nullish(node, compressor) {
|
|
13405
13485
|
if (prop.static && prop.value && !prop.value.is_constant_expression(scope)) {
|
13406
13486
|
return false;
|
13407
13487
|
}
|
13488
|
+
if (prop instanceof AST_ClassStaticBlock) {
|
13489
|
+
return false;
|
13490
|
+
}
|
13408
13491
|
}
|
13409
13492
|
|
13410
13493
|
return all_refs_local.call(this, scope);
|
@@ -13728,9 +13811,18 @@ const aborts = (thing) => thing && thing.aborts();
|
|
13728
13811
|
}
|
13729
13812
|
return null;
|
13730
13813
|
}
|
13731
|
-
def_aborts(AST_Import,
|
13814
|
+
def_aborts(AST_Import, return_null);
|
13732
13815
|
def_aborts(AST_BlockStatement, block_aborts);
|
13733
13816
|
def_aborts(AST_SwitchBranch, block_aborts);
|
13817
|
+
def_aborts(AST_DefClass, function () {
|
13818
|
+
for (const prop of this.properties) {
|
13819
|
+
if (prop instanceof AST_ClassStaticBlock) {
|
13820
|
+
if (prop.aborts()) return prop;
|
13821
|
+
}
|
13822
|
+
}
|
13823
|
+
return null;
|
13824
|
+
});
|
13825
|
+
def_aborts(AST_ClassStaticBlock, block_aborts);
|
13734
13826
|
def_aborts(AST_If, function() {
|
13735
13827
|
return this.alternative && aborts(this.body) && aborts(this.alternative) && this;
|
13736
13828
|
});
|
@@ -14309,6 +14401,14 @@ def_drop_side_effect_free(AST_Class, function (compressor) {
|
|
14309
14401
|
if (trimmed_extends)
|
14310
14402
|
with_effects.push(trimmed_extends);
|
14311
14403
|
for (const prop of this.properties) {
|
14404
|
+
if (prop instanceof AST_ClassStaticBlock) {
|
14405
|
+
if (prop.body.some(stat => stat.has_side_effects(compressor))) {
|
14406
|
+
return this;
|
14407
|
+
} else {
|
14408
|
+
continue;
|
14409
|
+
}
|
14410
|
+
}
|
14411
|
+
|
14312
14412
|
const trimmed_prop = prop.drop_side_effect_free(compressor);
|
14313
14413
|
if (trimmed_prop)
|
14314
14414
|
with_effects.push(trimmed_prop);
|
@@ -14820,6 +14920,10 @@ def_reduce_vars(AST_Class, function(tw, descend) {
|
|
14820
14920
|
return true;
|
14821
14921
|
});
|
14822
14922
|
|
14923
|
+
def_reduce_vars(AST_ClassStaticBlock, function(tw, descend, compressor) {
|
14924
|
+
reset_block_variables(compressor, this);
|
14925
|
+
});
|
14926
|
+
|
14823
14927
|
def_reduce_vars(AST_Conditional, function(tw) {
|
14824
14928
|
this.condition.walk(tw);
|
14825
14929
|
push(tw);
|
@@ -16734,6 +16838,7 @@ function inline_into_call(self, fn, compressor) {
|
|
16734
16838
|
fn.argnames.length === 1
|
16735
16839
|
&& (fn.argnames[0] instanceof AST_SymbolFunarg)
|
16736
16840
|
&& self.args.length < 2
|
16841
|
+
&& !(self.args[0] instanceof AST_Expansion)
|
16737
16842
|
&& returned instanceof AST_SymbolRef
|
16738
16843
|
&& returned.name === fn.argnames[0].name
|
16739
16844
|
) {
|
@@ -17693,18 +17798,13 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
17693
17798
|
}
|
17694
17799
|
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
17695
17800
|
const def = node.name.definition();
|
17696
|
-
|
17697
|
-
|
17801
|
+
const keep = def.global && !drop_funcs || in_use_ids.has(def.id);
|
17802
|
+
// Class "extends" and static blocks may have side effects
|
17803
|
+
const has_side_effects = !keep
|
17804
|
+
&& node instanceof AST_Class
|
17805
|
+
&& node.has_side_effects(compressor);
|
17806
|
+
if (!keep && !has_side_effects) {
|
17698
17807
|
def.eliminated++;
|
17699
|
-
if (node instanceof AST_DefClass) {
|
17700
|
-
// Classes might have extends with side effects
|
17701
|
-
const side_effects = node.drop_side_effect_free(compressor);
|
17702
|
-
if (side_effects) {
|
17703
|
-
return make_node(AST_SimpleStatement, node, {
|
17704
|
-
body: side_effects
|
17705
|
-
});
|
17706
|
-
}
|
17707
|
-
}
|
17708
17808
|
return in_list ? MAP.skip : make_node(AST_EmptyStatement, node);
|
17709
17809
|
}
|
17710
17810
|
}
|
@@ -20783,6 +20883,11 @@ def_optimize(AST_Class, function(self) {
|
|
20783
20883
|
return self;
|
20784
20884
|
});
|
20785
20885
|
|
20886
|
+
def_optimize(AST_ClassStaticBlock, function(self, compressor) {
|
20887
|
+
tighten_body(self.body, compressor);
|
20888
|
+
return self;
|
20889
|
+
});
|
20890
|
+
|
20786
20891
|
def_optimize(AST_Yield, function(self, compressor) {
|
20787
20892
|
if (self.expression && !self.is_star && is_undefined(self.expression, compressor)) {
|
20788
20893
|
self.expression = null;
|
@@ -27170,6 +27275,7 @@ var domprops = [
|
|
27170
27275
|
"outlineStyle",
|
27171
27276
|
"outlineWidth",
|
27172
27277
|
"outputBuffer",
|
27278
|
+
"outputChannelCount",
|
27173
27279
|
"outputLatency",
|
27174
27280
|
"outputs",
|
27175
27281
|
"overflow",
|
@@ -27257,6 +27363,7 @@ var domprops = [
|
|
27257
27363
|
"palette",
|
27258
27364
|
"pan",
|
27259
27365
|
"panningModel",
|
27366
|
+
"parameterData",
|
27260
27367
|
"parameters",
|
27261
27368
|
"parent",
|
27262
27369
|
"parentElement",
|
@@ -27432,6 +27539,7 @@ var domprops = [
|
|
27432
27539
|
"processIceMessage",
|
27433
27540
|
"processingEnd",
|
27434
27541
|
"processingStart",
|
27542
|
+
"processorOptions",
|
27435
27543
|
"product",
|
27436
27544
|
"productId",
|
27437
27545
|
"productName",
|
@@ -29872,7 +29980,9 @@ async function run_cli({ program, packageJson, fs, path }) {
|
|
29872
29980
|
result.enclosed = value.block_scope.enclosed;
|
29873
29981
|
}
|
29874
29982
|
value.CTOR.PROPS.forEach(function(prop) {
|
29875
|
-
|
29983
|
+
if (prop !== "block_scope") {
|
29984
|
+
result[prop] = value[prop];
|
29985
|
+
}
|
29876
29986
|
});
|
29877
29987
|
return result;
|
29878
29988
|
}
|
package/lib/ast.js
CHANGED
@@ -2272,6 +2272,28 @@ var AST_DefClass = DEFNODE("DefClass", null, function AST_DefClass(props) {
|
|
2272
2272
|
$documentation: "A class definition",
|
2273
2273
|
}, AST_Class);
|
2274
2274
|
|
2275
|
+
var AST_ClassStaticBlock = DEFNODE("ClassStaticBlock", "body block_scope", function AST_ClassStaticBlock (props) {
|
2276
|
+
this.body = props.body;
|
2277
|
+
this.block_scope = props.block_scope;
|
2278
|
+
this.start = props.start;
|
2279
|
+
this.end = props.end;
|
2280
|
+
}, {
|
2281
|
+
$documentation: "A block containing statements to be executed in the context of the class",
|
2282
|
+
$propdoc: {
|
2283
|
+
body: "[AST_Statement*] an array of statements",
|
2284
|
+
},
|
2285
|
+
_walk: function(visitor) {
|
2286
|
+
return visitor._visit(this, function() {
|
2287
|
+
walk_body(this, visitor);
|
2288
|
+
});
|
2289
|
+
},
|
2290
|
+
_children_backwards(push) {
|
2291
|
+
let i = this.body.length;
|
2292
|
+
while (i--) push(this.body[i]);
|
2293
|
+
},
|
2294
|
+
clone: clone_block_scope,
|
2295
|
+
}, AST_Scope);
|
2296
|
+
|
2275
2297
|
var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExpression(props) {
|
2276
2298
|
if (props) {
|
2277
2299
|
this.name = props.name;
|
@@ -3072,6 +3094,7 @@ export {
|
|
3072
3094
|
AST_ClassExpression,
|
3073
3095
|
AST_ClassPrivateProperty,
|
3074
3096
|
AST_ClassProperty,
|
3097
|
+
AST_ClassStaticBlock,
|
3075
3098
|
AST_ConciseMethod,
|
3076
3099
|
AST_Conditional,
|
3077
3100
|
AST_Const,
|
package/lib/cli.js
CHANGED
@@ -279,7 +279,9 @@ export async function run_cli({ program, packageJson, fs, path }) {
|
|
279
279
|
result.enclosed = value.block_scope.enclosed;
|
280
280
|
}
|
281
281
|
value.CTOR.PROPS.forEach(function(prop) {
|
282
|
-
|
282
|
+
if (prop !== "block_scope") {
|
283
|
+
result[prop] = value[prop];
|
284
|
+
}
|
283
285
|
});
|
284
286
|
return result;
|
285
287
|
}
|
@@ -50,6 +50,7 @@ import {
|
|
50
50
|
AST_Call,
|
51
51
|
AST_Chain,
|
52
52
|
AST_Class,
|
53
|
+
AST_ClassStaticBlock,
|
53
54
|
AST_ClassProperty,
|
54
55
|
AST_ConciseMethod,
|
55
56
|
AST_Conditional,
|
@@ -156,6 +157,14 @@ def_drop_side_effect_free(AST_Class, function (compressor) {
|
|
156
157
|
if (trimmed_extends)
|
157
158
|
with_effects.push(trimmed_extends);
|
158
159
|
for (const prop of this.properties) {
|
160
|
+
if (prop instanceof AST_ClassStaticBlock) {
|
161
|
+
if (prop.body.some(stat => stat.has_side_effects(compressor))) {
|
162
|
+
return this;
|
163
|
+
} else {
|
164
|
+
continue;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
159
168
|
const trimmed_prop = prop.drop_side_effect_free(compressor);
|
160
169
|
if (trimmed_prop)
|
161
170
|
with_effects.push(trimmed_prop);
|
package/lib/compress/index.js
CHANGED
@@ -58,6 +58,7 @@ import {
|
|
58
58
|
AST_Class,
|
59
59
|
AST_ClassExpression,
|
60
60
|
AST_ClassProperty,
|
61
|
+
AST_ClassStaticBlock,
|
61
62
|
AST_ConciseMethod,
|
62
63
|
AST_Conditional,
|
63
64
|
AST_Const,
|
@@ -833,18 +834,13 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
833
834
|
}
|
834
835
|
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
835
836
|
const def = node.name.definition();
|
836
|
-
|
837
|
-
|
837
|
+
const keep = def.global && !drop_funcs || in_use_ids.has(def.id);
|
838
|
+
// Class "extends" and static blocks may have side effects
|
839
|
+
const has_side_effects = !keep
|
840
|
+
&& node instanceof AST_Class
|
841
|
+
&& node.has_side_effects(compressor);
|
842
|
+
if (!keep && !has_side_effects) {
|
838
843
|
def.eliminated++;
|
839
|
-
if (node instanceof AST_DefClass) {
|
840
|
-
// Classes might have extends with side effects
|
841
|
-
const side_effects = node.drop_side_effect_free(compressor);
|
842
|
-
if (side_effects) {
|
843
|
-
return make_node(AST_SimpleStatement, node, {
|
844
|
-
body: side_effects
|
845
|
-
});
|
846
|
-
}
|
847
|
-
}
|
848
844
|
return in_list ? MAP.skip : make_node(AST_EmptyStatement, node);
|
849
845
|
}
|
850
846
|
}
|
@@ -3923,6 +3919,11 @@ def_optimize(AST_Class, function(self) {
|
|
3923
3919
|
return self;
|
3924
3920
|
});
|
3925
3921
|
|
3922
|
+
def_optimize(AST_ClassStaticBlock, function(self, compressor) {
|
3923
|
+
tighten_body(self.body, compressor);
|
3924
|
+
return self;
|
3925
|
+
});
|
3926
|
+
|
3926
3927
|
def_optimize(AST_Yield, function(self, compressor) {
|
3927
3928
|
if (self.expression && !self.is_star && is_undefined(self.expression, compressor)) {
|
3928
3929
|
self.expression = null;
|
@@ -52,6 +52,8 @@ import {
|
|
52
52
|
AST_Case,
|
53
53
|
AST_Chain,
|
54
54
|
AST_Class,
|
55
|
+
AST_DefClass,
|
56
|
+
AST_ClassStaticBlock,
|
55
57
|
AST_ClassProperty,
|
56
58
|
AST_ConciseMethod,
|
57
59
|
AST_Conditional,
|
@@ -320,6 +322,9 @@ export function is_nullish(node, compressor) {
|
|
320
322
|
}
|
321
323
|
return any(this.properties, compressor);
|
322
324
|
});
|
325
|
+
def_has_side_effects(AST_ClassStaticBlock, function(compressor) {
|
326
|
+
return any(this.body, compressor);
|
327
|
+
});
|
323
328
|
def_has_side_effects(AST_Binary, function(compressor) {
|
324
329
|
return this.left.has_side_effects(compressor)
|
325
330
|
|| this.right.has_side_effects(compressor);
|
@@ -419,6 +424,9 @@ export function is_nullish(node, compressor) {
|
|
419
424
|
if (this.extends && this.extends.may_throw(compressor)) return true;
|
420
425
|
return any(this.properties, compressor);
|
421
426
|
});
|
427
|
+
def_may_throw(AST_ClassStaticBlock, function (compressor) {
|
428
|
+
return any(this.body, compressor);
|
429
|
+
});
|
422
430
|
|
423
431
|
def_may_throw(AST_Array, function(compressor) {
|
424
432
|
return any(this.elements, compressor);
|
@@ -587,6 +595,9 @@ export function is_nullish(node, compressor) {
|
|
587
595
|
if (prop.static && prop.value && !prop.value.is_constant_expression(scope)) {
|
588
596
|
return false;
|
589
597
|
}
|
598
|
+
if (prop instanceof AST_ClassStaticBlock) {
|
599
|
+
return false;
|
600
|
+
}
|
590
601
|
}
|
591
602
|
|
592
603
|
return all_refs_local.call(this, scope);
|
@@ -910,9 +921,18 @@ export const aborts = (thing) => thing && thing.aborts();
|
|
910
921
|
}
|
911
922
|
return null;
|
912
923
|
}
|
913
|
-
def_aborts(AST_Import,
|
924
|
+
def_aborts(AST_Import, return_null);
|
914
925
|
def_aborts(AST_BlockStatement, block_aborts);
|
915
926
|
def_aborts(AST_SwitchBranch, block_aborts);
|
927
|
+
def_aborts(AST_DefClass, function () {
|
928
|
+
for (const prop of this.properties) {
|
929
|
+
if (prop instanceof AST_ClassStaticBlock) {
|
930
|
+
if (prop.aborts()) return prop;
|
931
|
+
}
|
932
|
+
}
|
933
|
+
return null;
|
934
|
+
});
|
935
|
+
def_aborts(AST_ClassStaticBlock, block_aborts);
|
916
936
|
def_aborts(AST_If, function() {
|
917
937
|
return this.alternative && aborts(this.body) && aborts(this.alternative) && this;
|
918
938
|
});
|
package/lib/compress/inline.js
CHANGED
@@ -335,6 +335,7 @@ export function inline_into_call(self, fn, compressor) {
|
|
335
335
|
fn.argnames.length === 1
|
336
336
|
&& (fn.argnames[0] instanceof AST_SymbolFunarg)
|
337
337
|
&& self.args.length < 2
|
338
|
+
&& !(self.args[0] instanceof AST_Expansion)
|
338
339
|
&& returned instanceof AST_SymbolRef
|
339
340
|
&& returned.name === fn.argnames[0].name
|
340
341
|
) {
|
@@ -52,6 +52,7 @@ import {
|
|
52
52
|
AST_Case,
|
53
53
|
AST_Chain,
|
54
54
|
AST_Class,
|
55
|
+
AST_ClassStaticBlock,
|
55
56
|
AST_ClassExpression,
|
56
57
|
AST_Conditional,
|
57
58
|
AST_Default,
|
@@ -377,6 +378,10 @@ def_reduce_vars(AST_Class, function(tw, descend) {
|
|
377
378
|
return true;
|
378
379
|
});
|
379
380
|
|
381
|
+
def_reduce_vars(AST_ClassStaticBlock, function(tw, descend, compressor) {
|
382
|
+
reset_block_variables(compressor, this);
|
383
|
+
});
|
384
|
+
|
380
385
|
def_reduce_vars(AST_Conditional, function(tw) {
|
381
386
|
this.condition.walk(tw);
|
382
387
|
push(tw);
|
package/lib/mozilla-ast.js
CHANGED
@@ -60,6 +60,7 @@ import {
|
|
60
60
|
AST_Catch,
|
61
61
|
AST_Chain,
|
62
62
|
AST_Class,
|
63
|
+
AST_ClassStaticBlock,
|
63
64
|
AST_ClassExpression,
|
64
65
|
AST_ClassProperty,
|
65
66
|
AST_ClassPrivateProperty,
|
@@ -444,6 +445,14 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
444
445
|
});
|
445
446
|
},
|
446
447
|
|
448
|
+
StaticBlock: function(M) {
|
449
|
+
return new AST_ClassStaticBlock({
|
450
|
+
start : my_start_token(M),
|
451
|
+
end : my_end_token(M),
|
452
|
+
body : M.body.map(from_moz),
|
453
|
+
});
|
454
|
+
},
|
455
|
+
|
447
456
|
ArrayExpression: function(M) {
|
448
457
|
return new AST_Array({
|
449
458
|
start : my_start_token(M),
|
@@ -1583,6 +1592,13 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1583
1592
|
};
|
1584
1593
|
});
|
1585
1594
|
|
1595
|
+
def_to_moz(AST_ClassStaticBlock, function To_Moz_StaticBlock(M) {
|
1596
|
+
return {
|
1597
|
+
type: "StaticBlock",
|
1598
|
+
body: M.body.map(to_moz),
|
1599
|
+
};
|
1600
|
+
});
|
1601
|
+
|
1586
1602
|
def_to_moz(AST_NewTarget, function To_Moz_MetaProperty() {
|
1587
1603
|
return {
|
1588
1604
|
type: "MetaProperty",
|
package/lib/output.js
CHANGED
@@ -70,6 +70,7 @@ import {
|
|
70
70
|
AST_ClassExpression,
|
71
71
|
AST_ClassPrivateProperty,
|
72
72
|
AST_ClassProperty,
|
73
|
+
AST_ClassStaticBlock,
|
73
74
|
AST_ConciseMethod,
|
74
75
|
AST_PrivateGetter,
|
75
76
|
AST_PrivateMethod,
|
@@ -2194,6 +2195,11 @@ function OutputStream(options) {
|
|
2194
2195
|
}
|
2195
2196
|
self._print_getter_setter(type, false, output);
|
2196
2197
|
});
|
2198
|
+
DEFPRINT(AST_ClassStaticBlock, function (self, output) {
|
2199
|
+
output.print("static");
|
2200
|
+
output.space();
|
2201
|
+
print_braced(self, output);
|
2202
|
+
});
|
2197
2203
|
AST_Symbol.DEFMETHOD("_do_print", function(output) {
|
2198
2204
|
var def = this.definition();
|
2199
2205
|
output.print_name(def ? def.mangled_name || def.name : this.name);
|
package/lib/parse.js
CHANGED
@@ -67,6 +67,7 @@ import {
|
|
67
67
|
AST_ClassExpression,
|
68
68
|
AST_ClassPrivateProperty,
|
69
69
|
AST_ClassProperty,
|
70
|
+
AST_ClassStaticBlock,
|
70
71
|
AST_ConciseMethod,
|
71
72
|
AST_PrivateGetter,
|
72
73
|
AST_PrivateMethod,
|
@@ -2562,6 +2563,10 @@ function parse($TEXT, options) {
|
|
2562
2563
|
var accessor_type = null;
|
2563
2564
|
|
2564
2565
|
if (is_class && name === "static" && is_not_method_start()) {
|
2566
|
+
const static_block = class_static_block();
|
2567
|
+
if (static_block != null) {
|
2568
|
+
return static_block;
|
2569
|
+
}
|
2565
2570
|
is_static = true;
|
2566
2571
|
name = as_property_name();
|
2567
2572
|
}
|
@@ -2668,6 +2673,25 @@ function parse($TEXT, options) {
|
|
2668
2673
|
}
|
2669
2674
|
}
|
2670
2675
|
|
2676
|
+
function class_static_block() {
|
2677
|
+
if (!is("punc", "{")) {
|
2678
|
+
return null;
|
2679
|
+
}
|
2680
|
+
|
2681
|
+
const start = S.token;
|
2682
|
+
const body = [];
|
2683
|
+
|
2684
|
+
next();
|
2685
|
+
|
2686
|
+
while (!is("punc", "}")) {
|
2687
|
+
body.push(statement());
|
2688
|
+
}
|
2689
|
+
|
2690
|
+
next();
|
2691
|
+
|
2692
|
+
return new AST_ClassStaticBlock({ start, body, end: prev() });
|
2693
|
+
}
|
2694
|
+
|
2671
2695
|
function maybe_import_assertion() {
|
2672
2696
|
if (is("name", "assert") && !has_newline_before(S.token)) {
|
2673
2697
|
next();
|
package/lib/size.js
CHANGED
@@ -10,6 +10,7 @@ import {
|
|
10
10
|
AST_Call,
|
11
11
|
AST_Case,
|
12
12
|
AST_Class,
|
13
|
+
AST_ClassStaticBlock,
|
13
14
|
AST_ClassPrivateProperty,
|
14
15
|
AST_ClassProperty,
|
15
16
|
AST_ConciseMethod,
|
@@ -401,6 +402,11 @@ AST_Class.prototype._size = function () {
|
|
401
402
|
);
|
402
403
|
};
|
403
404
|
|
405
|
+
AST_ClassStaticBlock.prototype._size = function () {
|
406
|
+
// "class{}" + semicolons
|
407
|
+
return 7 + list_overhead(this.body);
|
408
|
+
};
|
409
|
+
|
404
410
|
AST_ClassProperty.prototype._size = function () {
|
405
411
|
return (
|
406
412
|
static_size(this.static)
|
package/lib/transform.js
CHANGED
@@ -53,6 +53,7 @@ import {
|
|
53
53
|
AST_Catch,
|
54
54
|
AST_Chain,
|
55
55
|
AST_Class,
|
56
|
+
AST_ClassStaticBlock,
|
56
57
|
AST_Conditional,
|
57
58
|
AST_Definitions,
|
58
59
|
AST_Destructuring,
|
@@ -285,6 +286,10 @@ def_transform(AST_Class, function(self, tw) {
|
|
285
286
|
self.properties = do_list(self.properties, tw);
|
286
287
|
});
|
287
288
|
|
289
|
+
def_transform(AST_ClassStaticBlock, function(self, tw) {
|
290
|
+
self.body = do_list(self.body, tw);
|
291
|
+
});
|
292
|
+
|
288
293
|
def_transform(AST_Expansion, function(self, tw) {
|
289
294
|
self.expression = self.expression.transform(tw);
|
290
295
|
});
|
package/package.json
CHANGED
package/tools/domprops.js
CHANGED
@@ -6021,6 +6021,7 @@ export var domprops = [
|
|
6021
6021
|
"outlineStyle",
|
6022
6022
|
"outlineWidth",
|
6023
6023
|
"outputBuffer",
|
6024
|
+
"outputChannelCount",
|
6024
6025
|
"outputLatency",
|
6025
6026
|
"outputs",
|
6026
6027
|
"overflow",
|
@@ -6108,6 +6109,7 @@ export var domprops = [
|
|
6108
6109
|
"palette",
|
6109
6110
|
"pan",
|
6110
6111
|
"panningModel",
|
6112
|
+
"parameterData",
|
6111
6113
|
"parameters",
|
6112
6114
|
"parent",
|
6113
6115
|
"parentElement",
|
@@ -6283,6 +6285,7 @@ export var domprops = [
|
|
6283
6285
|
"processIceMessage",
|
6284
6286
|
"processingEnd",
|
6285
6287
|
"processingStart",
|
6288
|
+
"processorOptions",
|
6286
6289
|
"product",
|
6287
6290
|
"productId",
|
6288
6291
|
"productName",
|