terser 5.41.0 → 5.43.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 +10 -0
- package/README.md +1 -1
- package/dist/bundle.min.js +437 -239
- package/lib/ast.js +27 -8
- package/lib/compress/index.js +4 -6
- package/lib/compress/inline.js +15 -0
- package/lib/equivalent-to.js +2 -2
- package/lib/mozilla-ast.js +351 -200
- package/lib/output.js +7 -7
- package/lib/parse.js +30 -15
- package/lib/size.js +1 -1
- package/package.json +1 -1
package/dist/bundle.min.js
CHANGED
@@ -329,7 +329,6 @@ ALL_RESERVED_WORDS = makePredicate(ALL_RESERVED_WORDS);
|
|
329
329
|
|
330
330
|
var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));
|
331
331
|
|
332
|
-
var RE_NUM_LITERAL = /[0-9a-f]/i;
|
333
332
|
var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
|
334
333
|
var RE_OCT_NUMBER = /^0[0-7]+$/;
|
335
334
|
var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;
|
@@ -694,15 +693,16 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|
694
693
|
return after_e;
|
695
694
|
case (after_e = false, 46): // .
|
696
695
|
return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;
|
697
|
-
|
698
|
-
|
699
|
-
if (ch === "n") {
|
696
|
+
case 110: // n
|
700
697
|
is_big_int = true;
|
701
|
-
|
702
698
|
return true;
|
703
699
|
}
|
704
700
|
|
705
|
-
return
|
701
|
+
return (
|
702
|
+
code >= 48 && code <= 57 // 0-9
|
703
|
+
|| code >= 97 && code <= 102 // a-f
|
704
|
+
|| code >= 65 && code <= 70 // A-F
|
705
|
+
);
|
706
706
|
});
|
707
707
|
if (prefix) num = prefix + num;
|
708
708
|
|
@@ -719,7 +719,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|
719
719
|
}
|
720
720
|
num = num.replace(/_/g, "");
|
721
721
|
}
|
722
|
-
if (
|
722
|
+
if (is_big_int) {
|
723
723
|
const without_n = num.slice(0, -1);
|
724
724
|
const allow_e = RE_HEX_NUMBER.test(without_n);
|
725
725
|
const valid = parse_js_number(without_n, allow_e);
|
@@ -894,7 +894,24 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|
894
894
|
return next_token;
|
895
895
|
});
|
896
896
|
|
897
|
-
var read_name =
|
897
|
+
var read_name = function () {
|
898
|
+
let start = S.pos, end = start - 1, ch = "c";
|
899
|
+
|
900
|
+
while (
|
901
|
+
(ch = S.text.charAt(++end))
|
902
|
+
&& (ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z")
|
903
|
+
);
|
904
|
+
|
905
|
+
if (end > start + 1 && ch && ch !== "\\" && !is_identifier_char(ch)) {
|
906
|
+
S.pos += end - start;
|
907
|
+
S.col += end - start;
|
908
|
+
return S.text.slice(start, S.pos);
|
909
|
+
}
|
910
|
+
|
911
|
+
return read_name_hard();
|
912
|
+
};
|
913
|
+
|
914
|
+
var read_name_hard = with_eof_error("Unterminated identifier name", function() {
|
898
915
|
var name = [], ch, escaped = false;
|
899
916
|
var read_escaped_identifier_char = function() {
|
900
917
|
escaped = true;
|
@@ -1694,10 +1711,10 @@ function parse($TEXT, options) {
|
|
1694
1711
|
});
|
1695
1712
|
};
|
1696
1713
|
|
1697
|
-
var function_ = function(ctor,
|
1714
|
+
var function_ = function(ctor, is_generator, is_async, is_export_default) {
|
1698
1715
|
var in_statement = ctor === AST_Defun;
|
1699
|
-
|
1700
|
-
|
1716
|
+
if (is("operator", "*")) {
|
1717
|
+
is_generator = true;
|
1701
1718
|
next();
|
1702
1719
|
}
|
1703
1720
|
|
@@ -1714,11 +1731,11 @@ function parse($TEXT, options) {
|
|
1714
1731
|
unexpected(prev());
|
1715
1732
|
|
1716
1733
|
var args = [];
|
1717
|
-
var body = _function_body(true, is_generator
|
1734
|
+
var body = _function_body(true, is_generator, is_async, name, args);
|
1718
1735
|
return new ctor({
|
1719
1736
|
start : args.start,
|
1720
1737
|
end : body.end,
|
1721
|
-
is_generator: is_generator
|
1738
|
+
is_generator: is_generator,
|
1722
1739
|
async : is_async,
|
1723
1740
|
name : name,
|
1724
1741
|
argnames: args,
|
@@ -2794,8 +2811,6 @@ function parse($TEXT, options) {
|
|
2794
2811
|
var node = new AST_MethodVariant({
|
2795
2812
|
start : start,
|
2796
2813
|
static : is_static,
|
2797
|
-
is_generator: is_generator,
|
2798
|
-
async : is_async,
|
2799
2814
|
key : name,
|
2800
2815
|
quote : name instanceof AST_SymbolMethod ?
|
2801
2816
|
property_token.quote : undefined,
|
@@ -5775,12 +5790,10 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_Obje
|
|
5775
5790
|
}
|
5776
5791
|
}, AST_ObjectProperty);
|
5777
5792
|
|
5778
|
-
var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static
|
5793
|
+
var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static", function AST_ConciseMethod(props) {
|
5779
5794
|
if (props) {
|
5780
5795
|
this.quote = props.quote;
|
5781
5796
|
this.static = props.static;
|
5782
|
-
this.is_generator = props.is_generator;
|
5783
|
-
this.async = props.async;
|
5784
5797
|
this.key = props.key;
|
5785
5798
|
this.value = props.value;
|
5786
5799
|
this.start = props.start;
|
@@ -5793,8 +5806,6 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
|
|
5793
5806
|
$propdoc: {
|
5794
5807
|
quote: "[string|undefined] the original quote character, if any",
|
5795
5808
|
static: "[boolean] is this method static (classes only)",
|
5796
|
-
is_generator: "[boolean] is this a generator method",
|
5797
|
-
async: "[boolean] is this method async",
|
5798
5809
|
},
|
5799
5810
|
$documentation: "An ES6 concise method inside an object or class",
|
5800
5811
|
computed_key() {
|
@@ -5802,11 +5813,9 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
|
|
5802
5813
|
}
|
5803
5814
|
}, AST_ObjectProperty);
|
5804
5815
|
|
5805
|
-
var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
|
5816
|
+
var AST_PrivateMethod = DEFNODE("PrivateMethod", "static", function AST_PrivateMethod(props) {
|
5806
5817
|
if (props) {
|
5807
5818
|
this.static = props.static;
|
5808
|
-
this.is_generator = props.is_generator;
|
5809
|
-
this.async = props.async;
|
5810
5819
|
this.key = props.key;
|
5811
5820
|
this.value = props.value;
|
5812
5821
|
this.start = props.start;
|
@@ -5816,6 +5825,9 @@ var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(
|
|
5816
5825
|
this.flags = 0;
|
5817
5826
|
}, {
|
5818
5827
|
$documentation: "A private class method inside a class",
|
5828
|
+
$propdoc: {
|
5829
|
+
static: "[boolean] is this a static private method",
|
5830
|
+
},
|
5819
5831
|
computed_key() {
|
5820
5832
|
return false;
|
5821
5833
|
},
|
@@ -6806,6 +6818,28 @@ class TreeWalker {
|
|
6806
6818
|
}
|
6807
6819
|
}
|
6808
6820
|
|
6821
|
+
is_within_loop() {
|
6822
|
+
let i = this.stack.length - 1;
|
6823
|
+
let child = this.stack[i];
|
6824
|
+
while (i--) {
|
6825
|
+
const node = this.stack[i];
|
6826
|
+
|
6827
|
+
if (node instanceof AST_Lambda) return false;
|
6828
|
+
if (
|
6829
|
+
node instanceof AST_IterationStatement
|
6830
|
+
// exclude for-loop bits that only run once
|
6831
|
+
&& !((node instanceof AST_For) && child === node.init)
|
6832
|
+
&& !((node instanceof AST_ForIn || node instanceof AST_ForOf) && child === node.object)
|
6833
|
+
) {
|
6834
|
+
return true;
|
6835
|
+
}
|
6836
|
+
|
6837
|
+
child = node;
|
6838
|
+
}
|
6839
|
+
|
6840
|
+
return false;
|
6841
|
+
}
|
6842
|
+
|
6809
6843
|
find_scope() {
|
6810
6844
|
var stack = this.stack;
|
6811
6845
|
for (var i = stack.length; --i >= 0;) {
|
@@ -7181,6 +7215,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7181
7215
|
body[i] = new AST_Directive({
|
7182
7216
|
start: body[i].start,
|
7183
7217
|
end: body[i].end,
|
7218
|
+
quote: '"',
|
7184
7219
|
value: body[i].body.value
|
7185
7220
|
});
|
7186
7221
|
} else {
|
@@ -7304,8 +7339,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7304
7339
|
return new AST_Defun({
|
7305
7340
|
start: my_start_token(M),
|
7306
7341
|
end: my_end_token(M),
|
7307
|
-
name:
|
7308
|
-
argnames: M.params.map(
|
7342
|
+
name: M.id && from_moz_symbol(AST_SymbolDefun, M.id),
|
7343
|
+
argnames: M.params.map(M => from_moz_pattern(M, AST_SymbolFunarg)),
|
7309
7344
|
is_generator: M.generator,
|
7310
7345
|
async: M.async,
|
7311
7346
|
body: normalize_directives(from_moz(M.body).body)
|
@@ -7313,15 +7348,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7313
7348
|
},
|
7314
7349
|
|
7315
7350
|
FunctionExpression: function(M) {
|
7316
|
-
return
|
7317
|
-
start: my_start_token(M),
|
7318
|
-
end: my_end_token(M),
|
7319
|
-
name: from_moz(M.id),
|
7320
|
-
argnames: M.params.map(from_moz),
|
7321
|
-
is_generator: M.generator,
|
7322
|
-
async: M.async,
|
7323
|
-
body: normalize_directives(from_moz(M.body).body)
|
7324
|
-
});
|
7351
|
+
return from_moz_lambda(M, /*is_method=*/false);
|
7325
7352
|
},
|
7326
7353
|
|
7327
7354
|
ArrowFunctionExpression: function(M) {
|
@@ -7331,7 +7358,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7331
7358
|
return new AST_Arrow({
|
7332
7359
|
start: my_start_token(M),
|
7333
7360
|
end: my_end_token(M),
|
7334
|
-
argnames: M.params.map(
|
7361
|
+
argnames: M.params.map(p => from_moz_pattern(p, AST_SymbolFunarg)),
|
7335
7362
|
body,
|
7336
7363
|
async: M.async,
|
7337
7364
|
});
|
@@ -7360,59 +7387,48 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7360
7387
|
},
|
7361
7388
|
|
7362
7389
|
Property: function(M) {
|
7363
|
-
|
7364
|
-
|
7365
|
-
|
7366
|
-
|
7367
|
-
|
7368
|
-
|
7369
|
-
|
7370
|
-
|
7371
|
-
|
7372
|
-
|
7373
|
-
|
7374
|
-
|
7375
|
-
}
|
7376
|
-
if (M.method) {
|
7377
|
-
args.is_generator = M.value.generator;
|
7378
|
-
args.async = M.value.async;
|
7379
|
-
if (!M.computed) {
|
7380
|
-
args.key = new AST_SymbolMethod({ name: args.key });
|
7381
|
-
} else {
|
7382
|
-
args.key = from_moz(M.key);
|
7383
|
-
}
|
7384
|
-
return new AST_ConciseMethod(args);
|
7385
|
-
}
|
7386
|
-
if (M.kind == "init") {
|
7387
|
-
if (key.type != "Identifier" && key.type != "Literal") {
|
7388
|
-
args.key = from_moz(key);
|
7389
|
-
}
|
7390
|
+
if (M.kind == "init" && !M.method) {
|
7391
|
+
var args = {
|
7392
|
+
start : my_start_token(M.key || M.value),
|
7393
|
+
end : my_end_token(M.value),
|
7394
|
+
key : M.computed
|
7395
|
+
? from_moz(M.key)
|
7396
|
+
: M.key.name || String(M.key.value),
|
7397
|
+
quote : from_moz_quote(M.key, M.computed),
|
7398
|
+
static : false, // always an object
|
7399
|
+
value : from_moz(M.value)
|
7400
|
+
};
|
7401
|
+
|
7390
7402
|
return new AST_ObjectKeyVal(args);
|
7391
|
-
}
|
7392
|
-
|
7393
|
-
args
|
7394
|
-
|
7395
|
-
|
7396
|
-
|
7397
|
-
|
7398
|
-
|
7399
|
-
|
7400
|
-
|
7401
|
-
|
7402
|
-
|
7403
|
-
|
7403
|
+
} else {
|
7404
|
+
var value = from_moz_lambda(M.value, /*is_method=*/true);
|
7405
|
+
var args = {
|
7406
|
+
start : my_start_token(M.key || M.value),
|
7407
|
+
end : my_end_token(M.value),
|
7408
|
+
key : M.computed
|
7409
|
+
? from_moz(M.key)
|
7410
|
+
: from_moz_symbol(AST_SymbolMethod, M.key),
|
7411
|
+
quote : from_moz_quote(M.key, M.computed),
|
7412
|
+
static : false, // always an object
|
7413
|
+
value,
|
7414
|
+
};
|
7415
|
+
|
7416
|
+
if (M.kind == "get") return new AST_ObjectGetter(args);
|
7417
|
+
if (M.kind == "set") return new AST_ObjectSetter(args);
|
7418
|
+
if (M.method) return new AST_ConciseMethod(args);
|
7404
7419
|
}
|
7405
7420
|
},
|
7406
7421
|
|
7407
7422
|
MethodDefinition: function(M) {
|
7408
7423
|
const is_private = M.key.type === "PrivateIdentifier";
|
7409
|
-
const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value });
|
7424
|
+
const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || String(M.key.value) });
|
7410
7425
|
|
7411
7426
|
var args = {
|
7412
7427
|
start : my_start_token(M),
|
7413
7428
|
end : my_end_token(M),
|
7414
7429
|
key,
|
7415
|
-
|
7430
|
+
quote : from_moz_quote(M.key, M.computed),
|
7431
|
+
value : from_moz_lambda(M.value, /*is_method=*/true),
|
7416
7432
|
static : M.static,
|
7417
7433
|
};
|
7418
7434
|
if (M.kind == "get") {
|
@@ -7421,8 +7437,6 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7421
7437
|
if (M.kind == "set") {
|
7422
7438
|
return new (is_private ? AST_PrivateSetter : AST_ObjectSetter)(args);
|
7423
7439
|
}
|
7424
|
-
args.is_generator = M.value.generator;
|
7425
|
-
args.async = M.value.async;
|
7426
7440
|
return new (is_private ? AST_PrivateMethod : AST_ConciseMethod)(args);
|
7427
7441
|
},
|
7428
7442
|
|
@@ -7437,6 +7451,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7437
7451
|
return new AST_ClassProperty({
|
7438
7452
|
start : my_start_token(M),
|
7439
7453
|
end : my_end_token(M),
|
7454
|
+
quote : from_moz_quote(M.key, M.computed),
|
7440
7455
|
key,
|
7441
7456
|
value : from_moz(M.value),
|
7442
7457
|
static : M.static,
|
@@ -7456,15 +7471,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7456
7471
|
static : M.static,
|
7457
7472
|
});
|
7458
7473
|
} else {
|
7459
|
-
|
7460
|
-
throw new Error("Non-Identifier key in PropertyDefinition");
|
7461
|
-
}
|
7462
|
-
key = from_moz(M.key);
|
7474
|
+
key = from_moz_symbol(AST_SymbolClassProperty, M.key);
|
7463
7475
|
}
|
7464
7476
|
|
7465
7477
|
return new AST_ClassProperty({
|
7466
7478
|
start : my_start_token(M),
|
7467
7479
|
end : my_end_token(M),
|
7480
|
+
quote : from_moz_quote(M.key, M.computed),
|
7468
7481
|
key,
|
7469
7482
|
value : from_moz(M.value),
|
7470
7483
|
static : M.static,
|
@@ -7556,11 +7569,30 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7556
7569
|
},
|
7557
7570
|
|
7558
7571
|
VariableDeclaration: function(M) {
|
7559
|
-
|
7560
|
-
|
7572
|
+
let decl_type;
|
7573
|
+
let sym_type;
|
7574
|
+
if (M.kind === "const") {
|
7575
|
+
decl_type = AST_Const;
|
7576
|
+
sym_type = AST_SymbolConst;
|
7577
|
+
} else if (M.kind === "let") {
|
7578
|
+
decl_type = AST_Let;
|
7579
|
+
sym_type = AST_SymbolLet;
|
7580
|
+
} else {
|
7581
|
+
decl_type = AST_Var;
|
7582
|
+
sym_type = AST_SymbolVar;
|
7583
|
+
}
|
7584
|
+
const definitions = M.declarations.map(M => {
|
7585
|
+
return new AST_VarDef({
|
7586
|
+
start: my_start_token(M),
|
7587
|
+
end: my_end_token(M),
|
7588
|
+
name: from_moz_pattern(M.id, sym_type),
|
7589
|
+
value: from_moz(M.init),
|
7590
|
+
});
|
7591
|
+
});
|
7592
|
+
return new decl_type({
|
7561
7593
|
start : my_start_token(M),
|
7562
7594
|
end : my_end_token(M),
|
7563
|
-
definitions :
|
7595
|
+
definitions : definitions,
|
7564
7596
|
});
|
7565
7597
|
},
|
7566
7598
|
|
@@ -7589,13 +7621,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7589
7621
|
return new AST_NameMapping({
|
7590
7622
|
start: my_start_token(M),
|
7591
7623
|
end: my_end_token(M),
|
7592
|
-
foreign_name:
|
7593
|
-
name:
|
7624
|
+
foreign_name: from_moz_symbol(AST_SymbolImportForeign, M.imported, M.imported.type === "Literal"),
|
7625
|
+
name: from_moz_symbol(AST_SymbolImport, M.local)
|
7594
7626
|
});
|
7595
7627
|
},
|
7596
7628
|
|
7597
7629
|
ImportDefaultSpecifier: function(M) {
|
7598
|
-
return
|
7630
|
+
return from_moz_symbol(AST_SymbolImport, M.local);
|
7599
7631
|
},
|
7600
7632
|
|
7601
7633
|
ImportNamespaceSpecifier: function(M) {
|
@@ -7603,7 +7635,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7603
7635
|
start: my_start_token(M),
|
7604
7636
|
end: my_end_token(M),
|
7605
7637
|
foreign_name: new AST_SymbolImportForeign({ name: "*" }),
|
7606
|
-
name:
|
7638
|
+
name: from_moz_symbol(AST_SymbolImport, M.local)
|
7607
7639
|
});
|
7608
7640
|
},
|
7609
7641
|
|
@@ -7625,15 +7657,17 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7625
7657
|
},
|
7626
7658
|
|
7627
7659
|
ExportAllDeclaration: function(M) {
|
7628
|
-
var foreign_name = M.exported == null ?
|
7660
|
+
var foreign_name = M.exported == null ?
|
7629
7661
|
new AST_SymbolExportForeign({ name: "*" }) :
|
7630
|
-
|
7662
|
+
from_moz_symbol(AST_SymbolExportForeign, M.exported, M.exported.type === "Literal");
|
7631
7663
|
return new AST_Export({
|
7632
7664
|
start: my_start_token(M),
|
7633
7665
|
end: my_end_token(M),
|
7634
7666
|
exported_names: [
|
7635
7667
|
new AST_NameMapping({
|
7636
|
-
|
7668
|
+
start: my_start_token(M),
|
7669
|
+
end: my_end_token(M),
|
7670
|
+
name: new AST_SymbolExport({ name: "*" }),
|
7637
7671
|
foreign_name: foreign_name
|
7638
7672
|
})
|
7639
7673
|
],
|
@@ -7676,8 +7710,10 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7676
7710
|
|
7677
7711
|
ExportSpecifier: function(M) {
|
7678
7712
|
return new AST_NameMapping({
|
7679
|
-
|
7680
|
-
|
7713
|
+
start: my_start_token(M),
|
7714
|
+
end: my_end_token(M),
|
7715
|
+
foreign_name: from_moz_symbol(AST_SymbolExportForeign, M.exported, M.exported.type === "Literal"),
|
7716
|
+
name: from_moz_symbol(AST_SymbolExport, M.local, M.local.type === "Literal"),
|
7681
7717
|
});
|
7682
7718
|
},
|
7683
7719
|
|
@@ -7706,27 +7742,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7706
7742
|
const bi = typeof M.value === "bigint" ? M.value.toString() : M.bigint;
|
7707
7743
|
if (typeof bi === "string") {
|
7708
7744
|
args.value = bi;
|
7745
|
+
args.raw = M.raw;
|
7709
7746
|
return new AST_BigInt(args);
|
7710
7747
|
}
|
7711
7748
|
if (val === null) return new AST_Null(args);
|
7712
7749
|
switch (typeof val) {
|
7713
7750
|
case "string":
|
7714
7751
|
args.quote = "\"";
|
7715
|
-
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
7716
|
-
if (p.type == "ImportSpecifier") {
|
7717
|
-
args.name = val;
|
7718
|
-
return new AST_SymbolImportForeign(args);
|
7719
|
-
} else if (p.type == "ExportSpecifier") {
|
7720
|
-
args.name = val;
|
7721
|
-
if (M == p.exported) {
|
7722
|
-
return new AST_SymbolExportForeign(args);
|
7723
|
-
} else {
|
7724
|
-
return new AST_SymbolExport(args);
|
7725
|
-
}
|
7726
|
-
} else if (p.type == "ExportAllDeclaration" && M == p.exported) {
|
7727
|
-
args.name = val;
|
7728
|
-
return new AST_SymbolExportForeign(args);
|
7729
|
-
}
|
7730
7752
|
args.value = val;
|
7731
7753
|
return new AST_String(args);
|
7732
7754
|
case "number":
|
@@ -7753,27 +7775,11 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7753
7775
|
},
|
7754
7776
|
|
7755
7777
|
Identifier: function(M) {
|
7756
|
-
|
7757
|
-
|
7758
|
-
|
7759
|
-
|
7760
|
-
|
7761
|
-
: p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign)
|
7762
|
-
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
7763
|
-
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
7764
|
-
: p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef
|
7765
|
-
: p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
|
7766
|
-
: p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)
|
7767
|
-
: p.type == "PropertyDefinition" || p.type === "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty)
|
7768
|
-
: p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
|
7769
|
-
: p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
|
7770
|
-
: p.type == "CatchClause" ? AST_SymbolCatch
|
7771
|
-
: p.type == "BreakStatement" || p.type == "ContinueStatement" ? AST_LabelRef
|
7772
|
-
: AST_SymbolRef)({
|
7773
|
-
start : my_start_token(M),
|
7774
|
-
end : my_end_token(M),
|
7775
|
-
name : M.name
|
7776
|
-
});
|
7778
|
+
return new AST_SymbolRef({
|
7779
|
+
start : my_start_token(M),
|
7780
|
+
end : my_end_token(M),
|
7781
|
+
name : M.name
|
7782
|
+
});
|
7777
7783
|
},
|
7778
7784
|
|
7779
7785
|
EmptyStatement: function(M) {
|
@@ -7802,19 +7808,28 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7802
7808
|
},
|
7803
7809
|
|
7804
7810
|
LabeledStatement: function(M) {
|
7805
|
-
|
7806
|
-
|
7807
|
-
|
7808
|
-
|
7809
|
-
|
7810
|
-
|
7811
|
+
try {
|
7812
|
+
const label = from_moz_symbol(AST_Label, M.label);
|
7813
|
+
FROM_MOZ_LABELS.push(label);
|
7814
|
+
|
7815
|
+
const stat = new AST_LabeledStatement({
|
7816
|
+
start: my_start_token(M),
|
7817
|
+
end: my_end_token(M),
|
7818
|
+
label,
|
7819
|
+
body: from_moz(M.body)
|
7820
|
+
});
|
7821
|
+
|
7822
|
+
return stat;
|
7823
|
+
} finally {
|
7824
|
+
FROM_MOZ_LABELS.pop();
|
7825
|
+
}
|
7811
7826
|
},
|
7812
7827
|
|
7813
7828
|
BreakStatement: function(M) {
|
7814
7829
|
return new AST_Break({
|
7815
7830
|
start: my_start_token(M),
|
7816
7831
|
end: my_end_token(M),
|
7817
|
-
label:
|
7832
|
+
label: from_moz_label_ref(M.label),
|
7818
7833
|
});
|
7819
7834
|
},
|
7820
7835
|
|
@@ -7822,7 +7837,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7822
7837
|
return new AST_Continue({
|
7823
7838
|
start: my_start_token(M),
|
7824
7839
|
end: my_end_token(M),
|
7825
|
-
label:
|
7840
|
+
label: from_moz_label_ref(M.label),
|
7826
7841
|
});
|
7827
7842
|
},
|
7828
7843
|
|
@@ -7934,20 +7949,11 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7934
7949
|
});
|
7935
7950
|
},
|
7936
7951
|
|
7937
|
-
VariableDeclarator: function(M) {
|
7938
|
-
return new AST_VarDef({
|
7939
|
-
start: my_start_token(M),
|
7940
|
-
end: my_end_token(M),
|
7941
|
-
name: from_moz(M.id),
|
7942
|
-
value: from_moz(M.init)
|
7943
|
-
});
|
7944
|
-
},
|
7945
|
-
|
7946
7952
|
CatchClause: function(M) {
|
7947
7953
|
return new AST_Catch({
|
7948
7954
|
start: my_start_token(M),
|
7949
7955
|
end: my_end_token(M),
|
7950
|
-
argname:
|
7956
|
+
argname: M.param ? from_moz_pattern(M.param, AST_SymbolCatch) : null,
|
7951
7957
|
body: from_moz(M.body).body
|
7952
7958
|
});
|
7953
7959
|
},
|
@@ -7955,6 +7961,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7955
7961
|
ThisExpression: function(M) {
|
7956
7962
|
return new AST_This({
|
7957
7963
|
start: my_start_token(M),
|
7964
|
+
name: "this",
|
7958
7965
|
end: my_end_token(M)
|
7959
7966
|
});
|
7960
7967
|
},
|
@@ -7962,7 +7969,8 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7962
7969
|
Super: function(M) {
|
7963
7970
|
return new AST_Super({
|
7964
7971
|
start: my_start_token(M),
|
7965
|
-
end: my_end_token(M)
|
7972
|
+
end: my_end_token(M),
|
7973
|
+
name: "super",
|
7966
7974
|
});
|
7967
7975
|
},
|
7968
7976
|
|
@@ -8003,6 +8011,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8003
8011
|
start: my_start_token(M),
|
8004
8012
|
end: my_end_token(M),
|
8005
8013
|
operator: M.operator,
|
8014
|
+
logical: M.operator === "??=" || M.operator === "&&=" || M.operator === "||=",
|
8006
8015
|
left: from_moz(M.left),
|
8007
8016
|
right: from_moz(M.right)
|
8008
8017
|
});
|
@@ -8055,7 +8064,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8055
8064
|
return new (M.type === "ClassDeclaration" ? AST_DefClass : AST_ClassExpression)({
|
8056
8065
|
start : my_start_token(M),
|
8057
8066
|
end : my_end_token(M),
|
8058
|
-
name :
|
8067
|
+
name : M.id && from_moz_symbol(M.type === "ClassDeclaration" ? AST_SymbolDefClass : AST_SymbolClass, M.id),
|
8059
8068
|
extends : from_moz(M.superClass),
|
8060
8069
|
properties: M.body.body.map(from_moz)
|
8061
8070
|
});
|
@@ -8190,13 +8199,6 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8190
8199
|
init: to_moz(M.value)
|
8191
8200
|
};
|
8192
8201
|
});
|
8193
|
-
def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {
|
8194
|
-
return {
|
8195
|
-
type: "CatchClause",
|
8196
|
-
param: to_moz(M.argname),
|
8197
|
-
body: to_moz_block(M)
|
8198
|
-
};
|
8199
|
-
});
|
8200
8202
|
|
8201
8203
|
def_to_moz(AST_This, function To_Moz_ThisExpression() {
|
8202
8204
|
return {
|
@@ -8229,7 +8231,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8229
8231
|
return {
|
8230
8232
|
type: "ImportExpression",
|
8231
8233
|
source,
|
8232
|
-
options
|
8234
|
+
options: options || null
|
8233
8235
|
};
|
8234
8236
|
}
|
8235
8237
|
|
@@ -8288,36 +8290,36 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8288
8290
|
return {
|
8289
8291
|
type: "FunctionDeclaration",
|
8290
8292
|
id: to_moz(M.name),
|
8291
|
-
params: M.argnames.map(
|
8293
|
+
params: M.argnames.map(to_moz_pattern),
|
8292
8294
|
generator: M.is_generator,
|
8293
8295
|
async: M.async,
|
8294
8296
|
body: to_moz_scope("BlockStatement", M)
|
8295
8297
|
};
|
8296
8298
|
});
|
8297
8299
|
|
8298
|
-
def_to_moz(AST_Function, function To_Moz_FunctionExpression(M
|
8299
|
-
var is_generator = parent.is_generator !== undefined ?
|
8300
|
-
parent.is_generator : M.is_generator;
|
8300
|
+
def_to_moz(AST_Function, function To_Moz_FunctionExpression(M) {
|
8301
8301
|
return {
|
8302
8302
|
type: "FunctionExpression",
|
8303
8303
|
id: to_moz(M.name),
|
8304
|
-
params: M.argnames.map(
|
8305
|
-
generator: is_generator,
|
8306
|
-
async: M.async,
|
8304
|
+
params: M.argnames.map(to_moz_pattern),
|
8305
|
+
generator: M.is_generator || false,
|
8306
|
+
async: M.async || false,
|
8307
8307
|
body: to_moz_scope("BlockStatement", M)
|
8308
8308
|
};
|
8309
8309
|
});
|
8310
8310
|
|
8311
8311
|
def_to_moz(AST_Arrow, function To_Moz_ArrowFunctionExpression(M) {
|
8312
|
-
var body =
|
8313
|
-
|
8314
|
-
|
8315
|
-
|
8312
|
+
var body = M.body.length === 1 && M.body[0] instanceof AST_Return && M.body[0].value
|
8313
|
+
? to_moz(M.body[0].value)
|
8314
|
+
: {
|
8315
|
+
type: "BlockStatement",
|
8316
|
+
body: M.body.map(to_moz)
|
8317
|
+
};
|
8316
8318
|
return {
|
8317
8319
|
type: "ArrowFunctionExpression",
|
8318
|
-
params: M.argnames.map(
|
8320
|
+
params: M.argnames.map(to_moz_pattern),
|
8319
8321
|
async: M.async,
|
8320
|
-
body: body
|
8322
|
+
body: body,
|
8321
8323
|
};
|
8322
8324
|
});
|
8323
8325
|
|
@@ -8325,19 +8327,38 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8325
8327
|
if (M.is_array) {
|
8326
8328
|
return {
|
8327
8329
|
type: "ArrayPattern",
|
8328
|
-
elements: M.names.map(
|
8330
|
+
elements: M.names.map(
|
8331
|
+
M => M instanceof AST_Hole ? null : to_moz_pattern(M)
|
8332
|
+
),
|
8329
8333
|
};
|
8330
8334
|
}
|
8331
8335
|
return {
|
8332
8336
|
type: "ObjectPattern",
|
8333
|
-
properties: M.names.map(
|
8337
|
+
properties: M.names.map(M => {
|
8338
|
+
if (M instanceof AST_ObjectKeyVal) {
|
8339
|
+
var computed = M.computed_key();
|
8340
|
+
const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
|
8341
|
+
|
8342
|
+
return {
|
8343
|
+
type: "Property",
|
8344
|
+
computed,
|
8345
|
+
kind: "init",
|
8346
|
+
key: key,
|
8347
|
+
method: false,
|
8348
|
+
shorthand,
|
8349
|
+
value: to_moz_pattern(M.value)
|
8350
|
+
};
|
8351
|
+
} else {
|
8352
|
+
return to_moz_pattern(M);
|
8353
|
+
}
|
8354
|
+
}),
|
8334
8355
|
};
|
8335
8356
|
});
|
8336
8357
|
|
8337
8358
|
def_to_moz(AST_DefaultAssign, function To_Moz_AssignmentExpression(M) {
|
8338
8359
|
return {
|
8339
8360
|
type: "AssignmentPattern",
|
8340
|
-
left:
|
8361
|
+
left: to_moz_pattern(M.left),
|
8341
8362
|
right: to_moz(M.right),
|
8342
8363
|
};
|
8343
8364
|
});
|
@@ -8382,8 +8403,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8382
8403
|
def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {
|
8383
8404
|
return {
|
8384
8405
|
type: "CatchClause",
|
8385
|
-
param:
|
8386
|
-
guard: null,
|
8406
|
+
param: M.argname != null ? to_moz_pattern(M.argname) : null,
|
8387
8407
|
body: to_moz_block(M)
|
8388
8408
|
};
|
8389
8409
|
});
|
@@ -8444,10 +8464,20 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8444
8464
|
attributes: import_attributes_to_moz(M.attributes)
|
8445
8465
|
};
|
8446
8466
|
}
|
8447
|
-
|
8448
|
-
|
8449
|
-
|
8450
|
-
|
8467
|
+
|
8468
|
+
if (M.is_default) {
|
8469
|
+
return {
|
8470
|
+
type: "ExportDefaultDeclaration",
|
8471
|
+
declaration: to_moz(M.exported_value || M.exported_definition),
|
8472
|
+
};
|
8473
|
+
} else {
|
8474
|
+
return {
|
8475
|
+
type: "ExportNamedDeclaration",
|
8476
|
+
declaration: to_moz(M.exported_value || M.exported_definition),
|
8477
|
+
specifiers: [],
|
8478
|
+
source: null,
|
8479
|
+
};
|
8480
|
+
}
|
8451
8481
|
});
|
8452
8482
|
|
8453
8483
|
def_to_moz(AST_Import, function To_Moz_ImportDeclaration(M) {
|
@@ -8598,35 +8628,10 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8598
8628
|
});
|
8599
8629
|
|
8600
8630
|
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) {
|
8601
|
-
var
|
8602
|
-
|
8603
|
-
|
8604
|
-
};
|
8605
|
-
if (typeof M.key === "number") {
|
8606
|
-
key = {
|
8607
|
-
type: "Literal",
|
8608
|
-
value: Number(M.key)
|
8609
|
-
};
|
8610
|
-
}
|
8611
|
-
if (typeof M.key === "string") {
|
8612
|
-
key = M.quote
|
8613
|
-
? {
|
8614
|
-
type: "Literal",
|
8615
|
-
value: M.key,
|
8616
|
-
raw: JSON.stringify(M.key),
|
8617
|
-
}
|
8618
|
-
: {
|
8619
|
-
type: "Identifier",
|
8620
|
-
name: M.key,
|
8621
|
-
};
|
8622
|
-
}
|
8631
|
+
var computed = M.computed_key();
|
8632
|
+
const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
|
8633
|
+
|
8623
8634
|
var kind;
|
8624
|
-
var string_or_num = typeof M.key === "string" || typeof M.key === "number";
|
8625
|
-
var computed = string_or_num ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef;
|
8626
|
-
if (M instanceof AST_ObjectKeyVal) {
|
8627
|
-
kind = "init";
|
8628
|
-
computed = !string_or_num;
|
8629
|
-
} else
|
8630
8635
|
if (M instanceof AST_ObjectGetter) {
|
8631
8636
|
kind = "get";
|
8632
8637
|
} else
|
@@ -8681,31 +8686,51 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8681
8686
|
return {
|
8682
8687
|
type: "Property",
|
8683
8688
|
computed: computed,
|
8689
|
+
method: false,
|
8690
|
+
shorthand,
|
8684
8691
|
kind: kind,
|
8685
8692
|
key: key,
|
8686
8693
|
value: to_moz(M.value)
|
8687
8694
|
};
|
8688
8695
|
});
|
8689
8696
|
|
8697
|
+
def_to_moz(AST_ObjectKeyVal, function To_Moz_Property(M) {
|
8698
|
+
var computed = M.computed_key();
|
8699
|
+
const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
|
8700
|
+
|
8701
|
+
return {
|
8702
|
+
type: "Property",
|
8703
|
+
computed: computed,
|
8704
|
+
shorthand: shorthand,
|
8705
|
+
method: false,
|
8706
|
+
kind: "init",
|
8707
|
+
key: key,
|
8708
|
+
value: to_moz(M.value)
|
8709
|
+
};
|
8710
|
+
});
|
8711
|
+
|
8690
8712
|
def_to_moz(AST_ConciseMethod, function To_Moz_MethodDefinition(M, parent) {
|
8713
|
+
const computed = M.computed_key();
|
8714
|
+
const [_always_false, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
|
8715
|
+
|
8691
8716
|
if (parent instanceof AST_Object) {
|
8692
8717
|
return {
|
8693
8718
|
type: "Property",
|
8694
|
-
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
|
8695
8719
|
kind: "init",
|
8720
|
+
computed,
|
8696
8721
|
method: true,
|
8697
8722
|
shorthand: false,
|
8698
|
-
key
|
8699
|
-
value: to_moz(M.value)
|
8723
|
+
key,
|
8724
|
+
value: to_moz(M.value),
|
8700
8725
|
};
|
8701
8726
|
}
|
8702
8727
|
|
8703
8728
|
return {
|
8704
8729
|
type: "MethodDefinition",
|
8705
|
-
kind: M.key === "constructor" ? "constructor" : "method",
|
8706
|
-
|
8730
|
+
kind: !computed && M.key.name === "constructor" ? "constructor" : "method",
|
8731
|
+
computed,
|
8732
|
+
key,
|
8707
8733
|
value: to_moz(M.value),
|
8708
|
-
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
|
8709
8734
|
static: M.static,
|
8710
8735
|
};
|
8711
8736
|
});
|
@@ -8811,6 +8836,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8811
8836
|
// `M.value` is a string that may be a hex number representation.
|
8812
8837
|
// but "bigint" property should have only decimal digits
|
8813
8838
|
bigint: typeof BigInt === "function" ? BigInt(M.value).toString() : M.value,
|
8839
|
+
raw: M.raw,
|
8814
8840
|
}));
|
8815
8841
|
|
8816
8842
|
AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
|
@@ -8854,20 +8880,133 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8854
8880
|
);
|
8855
8881
|
}
|
8856
8882
|
|
8857
|
-
var
|
8883
|
+
var FROM_MOZ_LABELS = null;
|
8858
8884
|
|
8859
8885
|
function from_moz(node) {
|
8860
|
-
|
8861
|
-
|
8862
|
-
|
8863
|
-
|
8886
|
+
if (node == null) return null;
|
8887
|
+
return MOZ_TO_ME[node.type](node);
|
8888
|
+
}
|
8889
|
+
|
8890
|
+
function from_moz_quote(moz_key, computed) {
|
8891
|
+
if (!computed && moz_key.type === "Literal" && typeof moz_key.value === "string") {
|
8892
|
+
return '"';
|
8893
|
+
} else {
|
8894
|
+
return "";
|
8895
|
+
}
|
8896
|
+
}
|
8897
|
+
|
8898
|
+
function from_moz_symbol(symbol_type, M, has_quote) {
|
8899
|
+
return new symbol_type({
|
8900
|
+
start: my_start_token(M),
|
8901
|
+
quote: has_quote ? '"' : undefined,
|
8902
|
+
name: M.type === "Identifier" ? M.name : String(M.value),
|
8903
|
+
end: my_end_token(M),
|
8904
|
+
});
|
8905
|
+
}
|
8906
|
+
|
8907
|
+
function from_moz_lambda(M, is_method) {
|
8908
|
+
return new (is_method ? AST_Accessor : AST_Function)({
|
8909
|
+
start: my_start_token(M),
|
8910
|
+
end: my_end_token(M),
|
8911
|
+
name: M.id && from_moz_symbol(is_method ? AST_SymbolMethod : AST_SymbolLambda, M.id),
|
8912
|
+
argnames: M.params.map(M => from_moz_pattern(M, AST_SymbolFunarg)),
|
8913
|
+
is_generator: M.generator,
|
8914
|
+
async: M.async,
|
8915
|
+
body: normalize_directives(from_moz(M.body).body)
|
8916
|
+
});
|
8917
|
+
}
|
8918
|
+
|
8919
|
+
function from_moz_pattern(M, sym_type) {
|
8920
|
+
switch (M.type) {
|
8921
|
+
case "ObjectPattern":
|
8922
|
+
return new AST_Destructuring({
|
8923
|
+
start: my_start_token(M),
|
8924
|
+
end: my_end_token(M),
|
8925
|
+
names: M.properties.map(p => from_moz_pattern(p, sym_type)),
|
8926
|
+
is_array: false
|
8927
|
+
});
|
8928
|
+
|
8929
|
+
case "Property":
|
8930
|
+
var key = M.key;
|
8931
|
+
var args = {
|
8932
|
+
start : my_start_token(key || M.value),
|
8933
|
+
end : my_end_token(M.value),
|
8934
|
+
key : key.type == "Identifier" ? key.name : String(key.value),
|
8935
|
+
quote : !M.computed && key.type === "Literal" && typeof key.value === "string"
|
8936
|
+
? '"'
|
8937
|
+
: "",
|
8938
|
+
value : from_moz_pattern(M.value, sym_type)
|
8939
|
+
};
|
8940
|
+
if (M.computed) {
|
8941
|
+
args.key = from_moz(M.key);
|
8942
|
+
}
|
8943
|
+
return new AST_ObjectKeyVal(args);
|
8944
|
+
|
8945
|
+
case "ArrayPattern":
|
8946
|
+
return new AST_Destructuring({
|
8947
|
+
start: my_start_token(M),
|
8948
|
+
end: my_end_token(M),
|
8949
|
+
names: M.elements.map(function(elm) {
|
8950
|
+
if (elm === null) {
|
8951
|
+
return new AST_Hole();
|
8952
|
+
}
|
8953
|
+
return from_moz_pattern(elm, sym_type);
|
8954
|
+
}),
|
8955
|
+
is_array: true
|
8956
|
+
});
|
8957
|
+
|
8958
|
+
case "SpreadElement":
|
8959
|
+
case "RestElement":
|
8960
|
+
return new AST_Expansion({
|
8961
|
+
start: my_start_token(M),
|
8962
|
+
end: my_end_token(M),
|
8963
|
+
expression: from_moz_pattern(M.argument, sym_type),
|
8964
|
+
});
|
8965
|
+
|
8966
|
+
case "AssignmentPattern":
|
8967
|
+
return new AST_DefaultAssign({
|
8968
|
+
start : my_start_token(M),
|
8969
|
+
end : my_end_token(M),
|
8970
|
+
left : from_moz_pattern(M.left, sym_type),
|
8971
|
+
operator: "=",
|
8972
|
+
right : from_moz(M.right),
|
8973
|
+
});
|
8974
|
+
|
8975
|
+
case "Identifier":
|
8976
|
+
return new sym_type({
|
8977
|
+
start : my_start_token(M),
|
8978
|
+
end : my_end_token(M),
|
8979
|
+
name : M.name,
|
8980
|
+
});
|
8981
|
+
|
8982
|
+
default:
|
8983
|
+
throw new Error("Invalid node type for destructuring: " + M.type);
|
8984
|
+
}
|
8985
|
+
}
|
8986
|
+
|
8987
|
+
function from_moz_label_ref(m_label) {
|
8988
|
+
if (!m_label) return null;
|
8989
|
+
|
8990
|
+
const label = from_moz_symbol(AST_LabelRef, m_label);
|
8991
|
+
|
8992
|
+
let i = FROM_MOZ_LABELS.length;
|
8993
|
+
while (i--) {
|
8994
|
+
const label_origin = FROM_MOZ_LABELS[i];
|
8995
|
+
|
8996
|
+
if (label.name === label_origin.name) {
|
8997
|
+
label.thedef = label_origin;
|
8998
|
+
break;
|
8999
|
+
}
|
9000
|
+
}
|
9001
|
+
|
9002
|
+
return label;
|
8864
9003
|
}
|
8865
9004
|
|
8866
9005
|
AST_Node.from_mozilla_ast = function(node) {
|
8867
|
-
var
|
8868
|
-
|
9006
|
+
var save_labels = FROM_MOZ_LABELS;
|
9007
|
+
FROM_MOZ_LABELS = [];
|
8869
9008
|
var ast = from_moz(node);
|
8870
|
-
|
9009
|
+
FROM_MOZ_LABELS = save_labels;
|
8871
9010
|
return ast;
|
8872
9011
|
};
|
8873
9012
|
|
@@ -8909,6 +9048,52 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8909
9048
|
return ast;
|
8910
9049
|
}
|
8911
9050
|
|
9051
|
+
/** Object property keys can be number literals, string literals, or raw names. Additionally they can be shorthand. We decide that here. */
|
9052
|
+
function to_moz_property_key(key, computed = false, quote = false, value = null) {
|
9053
|
+
if (computed) {
|
9054
|
+
return [false, to_moz(key)];
|
9055
|
+
}
|
9056
|
+
|
9057
|
+
const key_name = typeof key === "string" ? key : key.name;
|
9058
|
+
let moz_key;
|
9059
|
+
if (quote) {
|
9060
|
+
moz_key = { type: "Literal", value: key_name, raw: JSON.stringify(key_name) };
|
9061
|
+
} else if ("" + +key_name === key_name && +key_name >= 0) {
|
9062
|
+
// representable as a number
|
9063
|
+
moz_key = { type: "Literal", value: +key_name, raw: JSON.stringify(+key_name) };
|
9064
|
+
} else {
|
9065
|
+
moz_key = { type: "Identifier", name: key_name };
|
9066
|
+
}
|
9067
|
+
|
9068
|
+
const shorthand =
|
9069
|
+
moz_key.type === "Identifier"
|
9070
|
+
&& moz_key.name === key_name
|
9071
|
+
&& (value instanceof AST_Symbol && value.name === key_name
|
9072
|
+
|| value instanceof AST_DefaultAssign && value.left.name === key_name);
|
9073
|
+
return [shorthand, moz_key];
|
9074
|
+
}
|
9075
|
+
|
9076
|
+
function to_moz_pattern(node) {
|
9077
|
+
if (node instanceof AST_Expansion) {
|
9078
|
+
return {
|
9079
|
+
type: "RestElement",
|
9080
|
+
argument: to_moz_pattern(node.expression),
|
9081
|
+
};
|
9082
|
+
}
|
9083
|
+
|
9084
|
+
if ((
|
9085
|
+
node instanceof AST_Symbol
|
9086
|
+
|| node instanceof AST_Destructuring
|
9087
|
+
|| node instanceof AST_DefaultAssign
|
9088
|
+
|| node instanceof AST_PropAccess
|
9089
|
+
)) {
|
9090
|
+
// Plain translation
|
9091
|
+
return to_moz(node);
|
9092
|
+
}
|
9093
|
+
|
9094
|
+
throw new Error(node.TYPE);
|
9095
|
+
}
|
9096
|
+
|
8912
9097
|
function to_moz_in_destructuring() {
|
8913
9098
|
var i = TO_MOZ_STACK.length;
|
8914
9099
|
while (i--) {
|
@@ -9141,7 +9326,7 @@ function OutputStream(options) {
|
|
9141
9326
|
webkit : false,
|
9142
9327
|
width : 80,
|
9143
9328
|
wrap_iife : false,
|
9144
|
-
wrap_func_args :
|
9329
|
+
wrap_func_args : false,
|
9145
9330
|
|
9146
9331
|
_destroy_ast : false
|
9147
9332
|
}, true);
|
@@ -11152,22 +11337,22 @@ function OutputStream(options) {
|
|
11152
11337
|
});
|
11153
11338
|
DEFPRINT(AST_ConciseMethod, function(self, output) {
|
11154
11339
|
var type;
|
11155
|
-
if (self.is_generator && self.async) {
|
11340
|
+
if (self.value.is_generator && self.value.async) {
|
11156
11341
|
type = "async*";
|
11157
|
-
} else if (self.is_generator) {
|
11342
|
+
} else if (self.value.is_generator) {
|
11158
11343
|
type = "*";
|
11159
|
-
} else if (self.async) {
|
11344
|
+
} else if (self.value.async) {
|
11160
11345
|
type = "async";
|
11161
11346
|
}
|
11162
11347
|
self._print_getter_setter(type, false, output);
|
11163
11348
|
});
|
11164
11349
|
DEFPRINT(AST_PrivateMethod, function(self, output) {
|
11165
11350
|
var type;
|
11166
|
-
if (self.is_generator && self.async) {
|
11351
|
+
if (self.value.is_generator && self.value.async) {
|
11167
11352
|
type = "async*";
|
11168
|
-
} else if (self.is_generator) {
|
11353
|
+
} else if (self.value.is_generator) {
|
11169
11354
|
type = "*";
|
11170
|
-
} else if (self.async) {
|
11355
|
+
} else if (self.value.async) {
|
11171
11356
|
type = "async";
|
11172
11357
|
}
|
11173
11358
|
self._print_getter_setter(type, true, output);
|
@@ -11563,11 +11748,11 @@ AST_ObjectGetter.prototype.shallow_cmp = function(other) {
|
|
11563
11748
|
};
|
11564
11749
|
|
11565
11750
|
AST_ConciseMethod.prototype.shallow_cmp = function(other) {
|
11566
|
-
return this.static === other.static
|
11751
|
+
return this.static === other.static;
|
11567
11752
|
};
|
11568
11753
|
|
11569
11754
|
AST_PrivateMethod.prototype.shallow_cmp = function(other) {
|
11570
|
-
return this.static === other.static
|
11755
|
+
return this.static === other.static;
|
11571
11756
|
};
|
11572
11757
|
|
11573
11758
|
AST_Class.prototype.shallow_cmp = function(other) {
|
@@ -12903,7 +13088,7 @@ AST_ObjectSetter.prototype._size = function () {
|
|
12903
13088
|
};
|
12904
13089
|
|
12905
13090
|
AST_ConciseMethod.prototype._size = function () {
|
12906
|
-
return static_size(this.static) + key_size(this.key)
|
13091
|
+
return static_size(this.static) + key_size(this.key);
|
12907
13092
|
};
|
12908
13093
|
|
12909
13094
|
AST_PrivateMethod.prototype._size = function () {
|
@@ -18246,6 +18431,8 @@ function inline_into_symbolref(self, compressor) {
|
|
18246
18431
|
return self;
|
18247
18432
|
}
|
18248
18433
|
|
18434
|
+
if (dont_inline_lambda_in_loop(compressor, fixed)) return self;
|
18435
|
+
|
18249
18436
|
let single_use = def.single_use
|
18250
18437
|
&& !(parent instanceof AST_Call
|
18251
18438
|
&& (parent.is_callee_pure(compressor))
|
@@ -18399,6 +18586,11 @@ function inline_into_call(self, compressor) {
|
|
18399
18586
|
fn = fixed;
|
18400
18587
|
}
|
18401
18588
|
|
18589
|
+
if (
|
18590
|
+
dont_inline_lambda_in_loop(compressor, fn)
|
18591
|
+
&& !has_annotation(self, _INLINE)
|
18592
|
+
) return self;
|
18593
|
+
|
18402
18594
|
var is_func = fn instanceof AST_Lambda;
|
18403
18595
|
|
18404
18596
|
var stat = is_func && fn.body[0];
|
@@ -18727,6 +18919,14 @@ function inline_into_call(self, compressor) {
|
|
18727
18919
|
}
|
18728
18920
|
}
|
18729
18921
|
|
18922
|
+
/** prevent inlining functions into loops, for performance reasons */
|
18923
|
+
function dont_inline_lambda_in_loop(compressor, maybe_lambda) {
|
18924
|
+
return (
|
18925
|
+
(maybe_lambda instanceof AST_Lambda || maybe_lambda instanceof AST_Class)
|
18926
|
+
&& !!compressor.is_within_loop()
|
18927
|
+
);
|
18928
|
+
}
|
18929
|
+
|
18730
18930
|
(function(def_find_defs) {
|
18731
18931
|
function to_node(value, orig) {
|
18732
18932
|
if (value instanceof AST_Node) {
|
@@ -22153,7 +22353,7 @@ AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
|
|
22153
22353
|
if ("" + (prop instanceof AST_ConciseMethod ? prop.key.name : prop.key) == key) {
|
22154
22354
|
const all_props_flattenable = props.every((p) =>
|
22155
22355
|
(p instanceof AST_ObjectKeyVal
|
22156
|
-
|| arrows && p instanceof AST_ConciseMethod && !p.is_generator
|
22356
|
+
|| arrows && p instanceof AST_ConciseMethod && !p.value.is_generator
|
22157
22357
|
)
|
22158
22358
|
&& !p.computed_key()
|
22159
22359
|
);
|
@@ -22639,7 +22839,7 @@ def_optimize(AST_ConciseMethod, function(self, compressor) {
|
|
22639
22839
|
// p(){return x;} ---> p:()=>x
|
22640
22840
|
if (compressor.option("arrows")
|
22641
22841
|
&& compressor.parent() instanceof AST_Object
|
22642
|
-
&& !self.is_generator
|
22842
|
+
&& !self.value.is_generator
|
22643
22843
|
&& !self.value.uses_arguments
|
22644
22844
|
&& !self.value.pinned()
|
22645
22845
|
&& self.value.body.length == 1
|
@@ -22647,8 +22847,8 @@ def_optimize(AST_ConciseMethod, function(self, compressor) {
|
|
22647
22847
|
&& self.value.body[0].value
|
22648
22848
|
&& !self.value.contains_this()) {
|
22649
22849
|
var arrow = make_node(AST_Arrow, self.value, self.value);
|
22650
|
-
arrow.async = self.async;
|
22651
|
-
arrow.is_generator = self.is_generator;
|
22850
|
+
arrow.async = self.value.async;
|
22851
|
+
arrow.is_generator = self.value.is_generator;
|
22652
22852
|
return make_node(AST_ObjectKeyVal, self, {
|
22653
22853
|
key: self.key instanceof AST_SymbolMethod ? self.key.name : self.key,
|
22654
22854
|
value: arrow,
|
@@ -22676,8 +22876,6 @@ def_optimize(AST_ObjectKeyVal, function(self, compressor) {
|
|
22676
22876
|
&& !value.contains_this();
|
22677
22877
|
if ((is_arrow_with_block || value instanceof AST_Function) && !value.name) {
|
22678
22878
|
return make_node(AST_ConciseMethod, self, {
|
22679
|
-
async: value.async,
|
22680
|
-
is_generator: value.is_generator,
|
22681
22879
|
key: key instanceof AST_Node ? key : make_node(AST_SymbolMethod, self, {
|
22682
22880
|
name: key,
|
22683
22881
|
}),
|