html-minifier-next 1.1.5 → 1.2.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/README.md +18 -16
- package/cli.js +1 -0
- package/dist/htmlminifier.cjs +9 -10
- package/dist/htmlminifier.esm.bundle.js +559 -329
- package/dist/htmlminifier.umd.bundle.js +559 -329
- package/dist/htmlminifier.umd.bundle.min.js +3 -3
- package/package.json +9 -12
- package/src/htmlminifier.js +11 -7
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
var f = n.default;
|
|
16
16
|
if (typeof f == "function") {
|
|
17
17
|
var a = function a () {
|
|
18
|
-
|
|
18
|
+
var isInstance = false;
|
|
19
|
+
try {
|
|
20
|
+
isInstance = this instanceof a;
|
|
21
|
+
} catch {}
|
|
22
|
+
if (isInstance) {
|
|
19
23
|
return Reflect.construct(f, arguments, this.constructor);
|
|
20
24
|
}
|
|
21
25
|
return f.apply(this, arguments);
|
|
@@ -26515,7 +26519,6 @@
|
|
|
26515
26519
|
|
|
26516
26520
|
var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));
|
|
26517
26521
|
|
|
26518
|
-
var RE_NUM_LITERAL = /[0-9a-f]/i;
|
|
26519
26522
|
var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
|
|
26520
26523
|
var RE_OCT_NUMBER = /^0[0-7]+$/;
|
|
26521
26524
|
var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;
|
|
@@ -26880,15 +26883,16 @@
|
|
|
26880
26883
|
return after_e;
|
|
26881
26884
|
case (after_e = false, 46): // .
|
|
26882
26885
|
return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;
|
|
26883
|
-
|
|
26884
|
-
|
|
26885
|
-
if (ch === "n") {
|
|
26886
|
+
case 110: // n
|
|
26886
26887
|
is_big_int = true;
|
|
26887
|
-
|
|
26888
26888
|
return true;
|
|
26889
26889
|
}
|
|
26890
26890
|
|
|
26891
|
-
return
|
|
26891
|
+
return (
|
|
26892
|
+
code >= 48 && code <= 57 // 0-9
|
|
26893
|
+
|| code >= 97 && code <= 102 // a-f
|
|
26894
|
+
|| code >= 65 && code <= 70 // A-F
|
|
26895
|
+
);
|
|
26892
26896
|
});
|
|
26893
26897
|
if (prefix) num = prefix + num;
|
|
26894
26898
|
|
|
@@ -26905,7 +26909,7 @@
|
|
|
26905
26909
|
}
|
|
26906
26910
|
num = num.replace(/_/g, "");
|
|
26907
26911
|
}
|
|
26908
|
-
if (
|
|
26912
|
+
if (is_big_int) {
|
|
26909
26913
|
const without_n = num.slice(0, -1);
|
|
26910
26914
|
const allow_e = RE_HEX_NUMBER.test(without_n);
|
|
26911
26915
|
const valid = parse_js_number(without_n, allow_e);
|
|
@@ -27080,7 +27084,24 @@
|
|
|
27080
27084
|
return next_token;
|
|
27081
27085
|
});
|
|
27082
27086
|
|
|
27083
|
-
var read_name =
|
|
27087
|
+
var read_name = function () {
|
|
27088
|
+
let start = S.pos, end = start - 1, ch = "c";
|
|
27089
|
+
|
|
27090
|
+
while (
|
|
27091
|
+
(ch = S.text.charAt(++end))
|
|
27092
|
+
&& (ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z")
|
|
27093
|
+
);
|
|
27094
|
+
|
|
27095
|
+
if (end > start + 1 && ch && ch !== "\\" && !is_identifier_char(ch)) {
|
|
27096
|
+
S.pos += end - start;
|
|
27097
|
+
S.col += end - start;
|
|
27098
|
+
return S.text.slice(start, S.pos);
|
|
27099
|
+
}
|
|
27100
|
+
|
|
27101
|
+
return read_name_hard();
|
|
27102
|
+
};
|
|
27103
|
+
|
|
27104
|
+
var read_name_hard = with_eof_error("Unterminated identifier name", function() {
|
|
27084
27105
|
var name = [], ch, escaped = false;
|
|
27085
27106
|
var read_escaped_identifier_char = function() {
|
|
27086
27107
|
escaped = true;
|
|
@@ -27871,24 +27892,19 @@
|
|
|
27871
27892
|
|
|
27872
27893
|
var body = _function_body(is("punc", "{"), false, is_async);
|
|
27873
27894
|
|
|
27874
|
-
var end =
|
|
27875
|
-
body instanceof Array && body.length ? body[body.length - 1].end :
|
|
27876
|
-
body instanceof Array ? start :
|
|
27877
|
-
body.end;
|
|
27878
|
-
|
|
27879
27895
|
return new AST_Arrow({
|
|
27880
27896
|
start : start,
|
|
27881
|
-
end : end,
|
|
27897
|
+
end : body.end,
|
|
27882
27898
|
async : is_async,
|
|
27883
27899
|
argnames : argnames,
|
|
27884
27900
|
body : body
|
|
27885
27901
|
});
|
|
27886
27902
|
};
|
|
27887
27903
|
|
|
27888
|
-
var function_ = function(ctor,
|
|
27904
|
+
var function_ = function(ctor, is_generator, is_async, is_export_default) {
|
|
27889
27905
|
var in_statement = ctor === AST_Defun;
|
|
27890
|
-
|
|
27891
|
-
|
|
27906
|
+
if (is("operator", "*")) {
|
|
27907
|
+
is_generator = true;
|
|
27892
27908
|
next();
|
|
27893
27909
|
}
|
|
27894
27910
|
|
|
@@ -27905,7 +27921,7 @@
|
|
|
27905
27921
|
unexpected(prev());
|
|
27906
27922
|
|
|
27907
27923
|
var args = [];
|
|
27908
|
-
var body = _function_body(true, is_generator
|
|
27924
|
+
var body = _function_body(true, is_generator, is_async, name, args);
|
|
27909
27925
|
return new ctor({
|
|
27910
27926
|
start : args.start,
|
|
27911
27927
|
end : body.end,
|
|
@@ -28537,7 +28553,12 @@
|
|
|
28537
28553
|
});
|
|
28538
28554
|
break;
|
|
28539
28555
|
case "big_int":
|
|
28540
|
-
ret = new AST_BigInt({
|
|
28556
|
+
ret = new AST_BigInt({
|
|
28557
|
+
start: tok,
|
|
28558
|
+
end: tok,
|
|
28559
|
+
value: tok.value,
|
|
28560
|
+
raw: LATEST_RAW,
|
|
28561
|
+
});
|
|
28541
28562
|
break;
|
|
28542
28563
|
case "string":
|
|
28543
28564
|
ret = new AST_String({
|
|
@@ -28801,7 +28822,7 @@
|
|
|
28801
28822
|
|
|
28802
28823
|
// Check property and fetch value
|
|
28803
28824
|
if (!is("punc", ":")) {
|
|
28804
|
-
var concise =
|
|
28825
|
+
var concise = object_or_class_property(name, start);
|
|
28805
28826
|
if (concise) {
|
|
28806
28827
|
a.push(concise);
|
|
28807
28828
|
continue;
|
|
@@ -28836,7 +28857,7 @@
|
|
|
28836
28857
|
const kv = new AST_ObjectKeyVal({
|
|
28837
28858
|
start: start,
|
|
28838
28859
|
quote: start.quote,
|
|
28839
|
-
key: name
|
|
28860
|
+
key: name,
|
|
28840
28861
|
value: value,
|
|
28841
28862
|
end: prev()
|
|
28842
28863
|
});
|
|
@@ -28847,7 +28868,7 @@
|
|
|
28847
28868
|
});
|
|
28848
28869
|
|
|
28849
28870
|
function class_(KindOfClass, is_export_default) {
|
|
28850
|
-
var start, method, class_name, extends_,
|
|
28871
|
+
var start, method, class_name, extends_, properties = [];
|
|
28851
28872
|
|
|
28852
28873
|
S.input.push_directives_stack(); // Push directive stack, but not scope stack
|
|
28853
28874
|
S.input.add_directive("use strict");
|
|
@@ -28876,9 +28897,9 @@
|
|
|
28876
28897
|
while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
|
|
28877
28898
|
while (!is("punc", "}")) {
|
|
28878
28899
|
start = S.token;
|
|
28879
|
-
method =
|
|
28900
|
+
method = object_or_class_property(as_property_name(), start, true);
|
|
28880
28901
|
if (!method) { unexpected(); }
|
|
28881
|
-
|
|
28902
|
+
properties.push(method);
|
|
28882
28903
|
while (is("punc", ";")) { next(); }
|
|
28883
28904
|
}
|
|
28884
28905
|
// mark in class feild,
|
|
@@ -28892,19 +28913,15 @@
|
|
|
28892
28913
|
start: start,
|
|
28893
28914
|
name: class_name,
|
|
28894
28915
|
extends: extends_,
|
|
28895
|
-
properties:
|
|
28916
|
+
properties: properties,
|
|
28896
28917
|
end: prev(),
|
|
28897
28918
|
});
|
|
28898
28919
|
}
|
|
28899
28920
|
|
|
28900
|
-
function
|
|
28901
|
-
const get_symbol_ast = (name, SymbolClass
|
|
28902
|
-
if (typeof name === "string"
|
|
28903
|
-
return new SymbolClass({
|
|
28904
|
-
start,
|
|
28905
|
-
name: "" + name,
|
|
28906
|
-
end: prev()
|
|
28907
|
-
});
|
|
28921
|
+
function object_or_class_property(name, start, is_class) {
|
|
28922
|
+
const get_symbol_ast = (name, SymbolClass) => {
|
|
28923
|
+
if (typeof name === "string") {
|
|
28924
|
+
return new SymbolClass({ start, name, end: prev() });
|
|
28908
28925
|
} else if (name === null) {
|
|
28909
28926
|
unexpected();
|
|
28910
28927
|
}
|
|
@@ -28952,7 +28969,7 @@
|
|
|
28952
28969
|
? AST_ObjectGetter
|
|
28953
28970
|
: AST_ObjectSetter;
|
|
28954
28971
|
|
|
28955
|
-
name = get_symbol_ast(name);
|
|
28972
|
+
name = get_symbol_ast(name, AST_SymbolMethod);
|
|
28956
28973
|
return annotate(new AccessorClass({
|
|
28957
28974
|
start,
|
|
28958
28975
|
static: is_static,
|
|
@@ -28969,7 +28986,7 @@
|
|
|
28969
28986
|
return annotate(new AccessorClass({
|
|
28970
28987
|
start,
|
|
28971
28988
|
static: is_static,
|
|
28972
|
-
key: get_symbol_ast(name),
|
|
28989
|
+
key: get_symbol_ast(name, AST_SymbolMethod),
|
|
28973
28990
|
value: create_accessor(),
|
|
28974
28991
|
end: prev(),
|
|
28975
28992
|
}));
|
|
@@ -28977,15 +28994,13 @@
|
|
|
28977
28994
|
}
|
|
28978
28995
|
|
|
28979
28996
|
if (is("punc", "(")) {
|
|
28980
|
-
name = get_symbol_ast(name);
|
|
28997
|
+
name = get_symbol_ast(name, AST_SymbolMethod);
|
|
28981
28998
|
const AST_MethodVariant = is_private
|
|
28982
28999
|
? AST_PrivateMethod
|
|
28983
29000
|
: AST_ConciseMethod;
|
|
28984
29001
|
var node = new AST_MethodVariant({
|
|
28985
29002
|
start : start,
|
|
28986
29003
|
static : is_static,
|
|
28987
|
-
is_generator: is_generator,
|
|
28988
|
-
async : is_async,
|
|
28989
29004
|
key : name,
|
|
28990
29005
|
quote : name instanceof AST_SymbolMethod ?
|
|
28991
29006
|
property_token.quote : undefined,
|
|
@@ -28996,13 +29011,17 @@
|
|
|
28996
29011
|
}
|
|
28997
29012
|
|
|
28998
29013
|
if (is_class) {
|
|
28999
|
-
const
|
|
29000
|
-
|
|
29001
|
-
|
|
29002
|
-
: undefined;
|
|
29014
|
+
const AST_SymbolVariant = is_private
|
|
29015
|
+
? AST_SymbolPrivateProperty
|
|
29016
|
+
: AST_SymbolClassProperty;
|
|
29003
29017
|
const AST_ClassPropertyVariant = is_private
|
|
29004
29018
|
? AST_ClassPrivateProperty
|
|
29005
29019
|
: AST_ClassProperty;
|
|
29020
|
+
|
|
29021
|
+
const key = get_symbol_ast(name, AST_SymbolVariant);
|
|
29022
|
+
const quote = key instanceof AST_SymbolClassProperty
|
|
29023
|
+
? property_token.quote
|
|
29024
|
+
: undefined;
|
|
29006
29025
|
if (is("operator", "=")) {
|
|
29007
29026
|
next();
|
|
29008
29027
|
return annotate(
|
|
@@ -29022,6 +29041,9 @@
|
|
|
29022
29041
|
|| is("operator", "*")
|
|
29023
29042
|
|| is("punc", ";")
|
|
29024
29043
|
|| is("punc", "}")
|
|
29044
|
+
|| is("string")
|
|
29045
|
+
|| is("num")
|
|
29046
|
+
|| is("big_int")
|
|
29025
29047
|
) {
|
|
29026
29048
|
return annotate(
|
|
29027
29049
|
new AST_ClassPropertyVariant({
|
|
@@ -29146,10 +29168,12 @@
|
|
|
29146
29168
|
} else {
|
|
29147
29169
|
foreign_name = make_symbol(foreign_type, S.token.quote);
|
|
29148
29170
|
}
|
|
29149
|
-
} else if (is_import) {
|
|
29150
|
-
name = new type(foreign_name);
|
|
29151
29171
|
} else {
|
|
29152
|
-
|
|
29172
|
+
if (is_import) {
|
|
29173
|
+
name = new type(foreign_name);
|
|
29174
|
+
} else {
|
|
29175
|
+
foreign_name = new foreign_type(name);
|
|
29176
|
+
}
|
|
29153
29177
|
}
|
|
29154
29178
|
|
|
29155
29179
|
return new AST_NameMapping({
|
|
@@ -29320,12 +29344,14 @@
|
|
|
29320
29344
|
case "name":
|
|
29321
29345
|
case "privatename":
|
|
29322
29346
|
case "string":
|
|
29323
|
-
case "num":
|
|
29324
|
-
case "big_int":
|
|
29325
29347
|
case "keyword":
|
|
29326
29348
|
case "atom":
|
|
29327
29349
|
next();
|
|
29328
29350
|
return tmp.value;
|
|
29351
|
+
case "num":
|
|
29352
|
+
case "big_int":
|
|
29353
|
+
next();
|
|
29354
|
+
return "" + tmp.value;
|
|
29329
29355
|
default:
|
|
29330
29356
|
unexpected(tmp);
|
|
29331
29357
|
}
|
|
@@ -31955,12 +31981,10 @@
|
|
|
31955
31981
|
}
|
|
31956
31982
|
}, AST_ObjectProperty);
|
|
31957
31983
|
|
|
31958
|
-
var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static
|
|
31984
|
+
var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static", function AST_ConciseMethod(props) {
|
|
31959
31985
|
if (props) {
|
|
31960
31986
|
this.quote = props.quote;
|
|
31961
31987
|
this.static = props.static;
|
|
31962
|
-
this.is_generator = props.is_generator;
|
|
31963
|
-
this.async = props.async;
|
|
31964
31988
|
this.key = props.key;
|
|
31965
31989
|
this.value = props.value;
|
|
31966
31990
|
this.start = props.start;
|
|
@@ -31973,8 +31997,6 @@
|
|
|
31973
31997
|
$propdoc: {
|
|
31974
31998
|
quote: "[string|undefined] the original quote character, if any",
|
|
31975
31999
|
static: "[boolean] is this method static (classes only)",
|
|
31976
|
-
is_generator: "[boolean] is this a generator method",
|
|
31977
|
-
async: "[boolean] is this method async",
|
|
31978
32000
|
},
|
|
31979
32001
|
$documentation: "An ES6 concise method inside an object or class",
|
|
31980
32002
|
computed_key() {
|
|
@@ -31982,12 +32004,9 @@
|
|
|
31982
32004
|
}
|
|
31983
32005
|
}, AST_ObjectProperty);
|
|
31984
32006
|
|
|
31985
|
-
var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
|
|
32007
|
+
var AST_PrivateMethod = DEFNODE("PrivateMethod", "static", function AST_PrivateMethod(props) {
|
|
31986
32008
|
if (props) {
|
|
31987
|
-
this.quote = props.quote;
|
|
31988
32009
|
this.static = props.static;
|
|
31989
|
-
this.is_generator = props.is_generator;
|
|
31990
|
-
this.async = props.async;
|
|
31991
32010
|
this.key = props.key;
|
|
31992
32011
|
this.value = props.value;
|
|
31993
32012
|
this.start = props.start;
|
|
@@ -31997,6 +32016,9 @@
|
|
|
31997
32016
|
this.flags = 0;
|
|
31998
32017
|
}, {
|
|
31999
32018
|
$documentation: "A private class method inside a class",
|
|
32019
|
+
$propdoc: {
|
|
32020
|
+
static: "[boolean] is this a static private method",
|
|
32021
|
+
},
|
|
32000
32022
|
computed_key() {
|
|
32001
32023
|
return false;
|
|
32002
32024
|
},
|
|
@@ -32145,7 +32167,6 @@
|
|
|
32145
32167
|
var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_ClassPrivateProperty(props) {
|
|
32146
32168
|
if (props) {
|
|
32147
32169
|
this.static = props.static;
|
|
32148
|
-
this.quote = props.quote;
|
|
32149
32170
|
this.key = props.key;
|
|
32150
32171
|
this.value = props.value;
|
|
32151
32172
|
this.start = props.start;
|
|
@@ -32505,12 +32526,12 @@
|
|
|
32505
32526
|
$documentation: "Symbol referring to an imported name",
|
|
32506
32527
|
}, AST_SymbolBlockDeclaration);
|
|
32507
32528
|
|
|
32508
|
-
var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign",
|
|
32529
|
+
var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", "quote", function AST_SymbolImportForeign(props) {
|
|
32509
32530
|
if (props) {
|
|
32531
|
+
this.quote = props.quote;
|
|
32510
32532
|
this.scope = props.scope;
|
|
32511
32533
|
this.name = props.name;
|
|
32512
32534
|
this.thedef = props.thedef;
|
|
32513
|
-
this.quote = props.quote;
|
|
32514
32535
|
this.start = props.start;
|
|
32515
32536
|
this.end = props.end;
|
|
32516
32537
|
}
|
|
@@ -32557,12 +32578,12 @@
|
|
|
32557
32578
|
$documentation: "Reference to some symbol (not definition/declaration)",
|
|
32558
32579
|
}, AST_Symbol);
|
|
32559
32580
|
|
|
32560
|
-
var AST_SymbolExport = DEFNODE("SymbolExport",
|
|
32581
|
+
var AST_SymbolExport = DEFNODE("SymbolExport", "quote", function AST_SymbolExport(props) {
|
|
32561
32582
|
if (props) {
|
|
32583
|
+
this.quote = props.quote;
|
|
32562
32584
|
this.scope = props.scope;
|
|
32563
32585
|
this.name = props.name;
|
|
32564
32586
|
this.thedef = props.thedef;
|
|
32565
|
-
this.quote = props.quote;
|
|
32566
32587
|
this.start = props.start;
|
|
32567
32588
|
this.end = props.end;
|
|
32568
32589
|
}
|
|
@@ -32572,12 +32593,12 @@
|
|
|
32572
32593
|
$documentation: "Symbol referring to a name to export",
|
|
32573
32594
|
}, AST_SymbolRef);
|
|
32574
32595
|
|
|
32575
|
-
var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign",
|
|
32596
|
+
var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", "quote", function AST_SymbolExportForeign(props) {
|
|
32576
32597
|
if (props) {
|
|
32598
|
+
this.quote = props.quote;
|
|
32577
32599
|
this.scope = props.scope;
|
|
32578
32600
|
this.name = props.name;
|
|
32579
32601
|
this.thedef = props.thedef;
|
|
32580
|
-
this.quote = props.quote;
|
|
32581
32602
|
this.start = props.start;
|
|
32582
32603
|
this.end = props.end;
|
|
32583
32604
|
}
|
|
@@ -32692,9 +32713,10 @@
|
|
|
32692
32713
|
}
|
|
32693
32714
|
}, AST_Constant);
|
|
32694
32715
|
|
|
32695
|
-
var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
|
|
32716
|
+
var AST_BigInt = DEFNODE("BigInt", "value raw", function AST_BigInt(props) {
|
|
32696
32717
|
if (props) {
|
|
32697
32718
|
this.value = props.value;
|
|
32719
|
+
this.raw = props.raw;
|
|
32698
32720
|
this.start = props.start;
|
|
32699
32721
|
this.end = props.end;
|
|
32700
32722
|
}
|
|
@@ -32703,7 +32725,8 @@
|
|
|
32703
32725
|
}, {
|
|
32704
32726
|
$documentation: "A big int literal",
|
|
32705
32727
|
$propdoc: {
|
|
32706
|
-
value: "[string] big int value"
|
|
32728
|
+
value: "[string] big int value, represented as a string",
|
|
32729
|
+
raw: "[string] the original format preserved"
|
|
32707
32730
|
}
|
|
32708
32731
|
}, AST_Constant);
|
|
32709
32732
|
|
|
@@ -32986,6 +33009,28 @@
|
|
|
32986
33009
|
}
|
|
32987
33010
|
}
|
|
32988
33011
|
|
|
33012
|
+
is_within_loop() {
|
|
33013
|
+
let i = this.stack.length - 1;
|
|
33014
|
+
let child = this.stack[i];
|
|
33015
|
+
while (i--) {
|
|
33016
|
+
const node = this.stack[i];
|
|
33017
|
+
|
|
33018
|
+
if (node instanceof AST_Lambda) return false;
|
|
33019
|
+
if (
|
|
33020
|
+
node instanceof AST_IterationStatement
|
|
33021
|
+
// exclude for-loop bits that only run once
|
|
33022
|
+
&& !((node instanceof AST_For) && child === node.init)
|
|
33023
|
+
&& !((node instanceof AST_ForIn || node instanceof AST_ForOf) && child === node.object)
|
|
33024
|
+
) {
|
|
33025
|
+
return true;
|
|
33026
|
+
}
|
|
33027
|
+
|
|
33028
|
+
child = node;
|
|
33029
|
+
}
|
|
33030
|
+
|
|
33031
|
+
return false;
|
|
33032
|
+
}
|
|
33033
|
+
|
|
32989
33034
|
find_scope() {
|
|
32990
33035
|
var stack = this.stack;
|
|
32991
33036
|
for (var i = stack.length; --i >= 0;) {
|
|
@@ -33363,6 +33408,7 @@
|
|
|
33363
33408
|
body[i] = new AST_Directive({
|
|
33364
33409
|
start: body[i].start,
|
|
33365
33410
|
end: body[i].end,
|
|
33411
|
+
quote: '"',
|
|
33366
33412
|
value: body[i].body.value
|
|
33367
33413
|
});
|
|
33368
33414
|
} else {
|
|
@@ -33486,8 +33532,8 @@
|
|
|
33486
33532
|
return new AST_Defun({
|
|
33487
33533
|
start: my_start_token(M),
|
|
33488
33534
|
end: my_end_token(M),
|
|
33489
|
-
name:
|
|
33490
|
-
argnames: M.params.map(
|
|
33535
|
+
name: M.id && from_moz_symbol(AST_SymbolDefun, M.id),
|
|
33536
|
+
argnames: M.params.map(M => from_moz_pattern(M, AST_SymbolFunarg)),
|
|
33491
33537
|
is_generator: M.generator,
|
|
33492
33538
|
async: M.async,
|
|
33493
33539
|
body: normalize_directives(from_moz(M.body).body)
|
|
@@ -33495,15 +33541,7 @@
|
|
|
33495
33541
|
},
|
|
33496
33542
|
|
|
33497
33543
|
FunctionExpression: function(M) {
|
|
33498
|
-
return
|
|
33499
|
-
start: my_start_token(M),
|
|
33500
|
-
end: my_end_token(M),
|
|
33501
|
-
name: from_moz(M.id),
|
|
33502
|
-
argnames: M.params.map(from_moz),
|
|
33503
|
-
is_generator: M.generator,
|
|
33504
|
-
async: M.async,
|
|
33505
|
-
body: normalize_directives(from_moz(M.body).body)
|
|
33506
|
-
});
|
|
33544
|
+
return from_moz_lambda(M, /*is_method=*/false);
|
|
33507
33545
|
},
|
|
33508
33546
|
|
|
33509
33547
|
ArrowFunctionExpression: function(M) {
|
|
@@ -33513,7 +33551,7 @@
|
|
|
33513
33551
|
return new AST_Arrow({
|
|
33514
33552
|
start: my_start_token(M),
|
|
33515
33553
|
end: my_end_token(M),
|
|
33516
|
-
argnames: M.params.map(
|
|
33554
|
+
argnames: M.params.map(p => from_moz_pattern(p, AST_SymbolFunarg)),
|
|
33517
33555
|
body,
|
|
33518
33556
|
async: M.async,
|
|
33519
33557
|
});
|
|
@@ -33542,57 +33580,48 @@
|
|
|
33542
33580
|
},
|
|
33543
33581
|
|
|
33544
33582
|
Property: function(M) {
|
|
33545
|
-
|
|
33546
|
-
|
|
33547
|
-
|
|
33548
|
-
|
|
33549
|
-
|
|
33550
|
-
|
|
33551
|
-
|
|
33552
|
-
|
|
33553
|
-
|
|
33554
|
-
|
|
33555
|
-
|
|
33556
|
-
|
|
33557
|
-
args.async = M.value.async;
|
|
33558
|
-
if (!M.computed) {
|
|
33559
|
-
args.key = new AST_SymbolMethod({ name: args.key });
|
|
33560
|
-
} else {
|
|
33561
|
-
args.key = from_moz(M.key);
|
|
33562
|
-
}
|
|
33563
|
-
return new AST_ConciseMethod(args);
|
|
33564
|
-
}
|
|
33565
|
-
if (M.kind == "init") {
|
|
33566
|
-
if (key.type != "Identifier" && key.type != "Literal") {
|
|
33567
|
-
args.key = from_moz(key);
|
|
33568
|
-
}
|
|
33583
|
+
if (M.kind == "init" && !M.method) {
|
|
33584
|
+
var args = {
|
|
33585
|
+
start : my_start_token(M.key || M.value),
|
|
33586
|
+
end : my_end_token(M.value),
|
|
33587
|
+
key : M.computed
|
|
33588
|
+
? from_moz(M.key)
|
|
33589
|
+
: M.key.name || String(M.key.value),
|
|
33590
|
+
quote : from_moz_quote(M.key, M.computed),
|
|
33591
|
+
static : false, // always an object
|
|
33592
|
+
value : from_moz(M.value)
|
|
33593
|
+
};
|
|
33594
|
+
|
|
33569
33595
|
return new AST_ObjectKeyVal(args);
|
|
33570
|
-
}
|
|
33571
|
-
|
|
33572
|
-
args
|
|
33573
|
-
|
|
33574
|
-
|
|
33575
|
-
|
|
33576
|
-
|
|
33577
|
-
|
|
33578
|
-
|
|
33579
|
-
|
|
33580
|
-
|
|
33581
|
-
|
|
33582
|
-
|
|
33583
|
-
return new
|
|
33596
|
+
} else {
|
|
33597
|
+
var value = from_moz_lambda(M.value, /*is_method=*/true);
|
|
33598
|
+
var args = {
|
|
33599
|
+
start : my_start_token(M.key || M.value),
|
|
33600
|
+
end : my_end_token(M.value),
|
|
33601
|
+
key : M.computed
|
|
33602
|
+
? from_moz(M.key)
|
|
33603
|
+
: from_moz_symbol(AST_SymbolMethod, M.key),
|
|
33604
|
+
quote : from_moz_quote(M.key, M.computed),
|
|
33605
|
+
static : false, // always an object
|
|
33606
|
+
value,
|
|
33607
|
+
};
|
|
33608
|
+
|
|
33609
|
+
if (M.kind == "get") return new AST_ObjectGetter(args);
|
|
33610
|
+
if (M.kind == "set") return new AST_ObjectSetter(args);
|
|
33611
|
+
if (M.method) return new AST_ConciseMethod(args);
|
|
33584
33612
|
}
|
|
33585
33613
|
},
|
|
33586
33614
|
|
|
33587
33615
|
MethodDefinition: function(M) {
|
|
33588
33616
|
const is_private = M.key.type === "PrivateIdentifier";
|
|
33589
|
-
const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value });
|
|
33617
|
+
const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || String(M.key.value) });
|
|
33590
33618
|
|
|
33591
33619
|
var args = {
|
|
33592
33620
|
start : my_start_token(M),
|
|
33593
33621
|
end : my_end_token(M),
|
|
33594
33622
|
key,
|
|
33595
|
-
|
|
33623
|
+
quote : from_moz_quote(M.key, M.computed),
|
|
33624
|
+
value : from_moz_lambda(M.value, /*is_method=*/true),
|
|
33596
33625
|
static : M.static,
|
|
33597
33626
|
};
|
|
33598
33627
|
if (M.kind == "get") {
|
|
@@ -33601,8 +33630,6 @@
|
|
|
33601
33630
|
if (M.kind == "set") {
|
|
33602
33631
|
return new (is_private ? AST_PrivateSetter : AST_ObjectSetter)(args);
|
|
33603
33632
|
}
|
|
33604
|
-
args.is_generator = M.value.generator;
|
|
33605
|
-
args.async = M.value.async;
|
|
33606
33633
|
return new (is_private ? AST_PrivateMethod : AST_ConciseMethod)(args);
|
|
33607
33634
|
},
|
|
33608
33635
|
|
|
@@ -33617,6 +33644,7 @@
|
|
|
33617
33644
|
return new AST_ClassProperty({
|
|
33618
33645
|
start : my_start_token(M),
|
|
33619
33646
|
end : my_end_token(M),
|
|
33647
|
+
quote : from_moz_quote(M.key, M.computed),
|
|
33620
33648
|
key,
|
|
33621
33649
|
value : from_moz(M.value),
|
|
33622
33650
|
static : M.static,
|
|
@@ -33636,15 +33664,13 @@
|
|
|
33636
33664
|
static : M.static,
|
|
33637
33665
|
});
|
|
33638
33666
|
} else {
|
|
33639
|
-
|
|
33640
|
-
throw new Error("Non-Identifier key in PropertyDefinition");
|
|
33641
|
-
}
|
|
33642
|
-
key = from_moz(M.key);
|
|
33667
|
+
key = from_moz_symbol(AST_SymbolClassProperty, M.key);
|
|
33643
33668
|
}
|
|
33644
33669
|
|
|
33645
33670
|
return new AST_ClassProperty({
|
|
33646
33671
|
start : my_start_token(M),
|
|
33647
33672
|
end : my_end_token(M),
|
|
33673
|
+
quote : from_moz_quote(M.key, M.computed),
|
|
33648
33674
|
key,
|
|
33649
33675
|
value : from_moz(M.value),
|
|
33650
33676
|
static : M.static,
|
|
@@ -33736,11 +33762,30 @@
|
|
|
33736
33762
|
},
|
|
33737
33763
|
|
|
33738
33764
|
VariableDeclaration: function(M) {
|
|
33739
|
-
|
|
33740
|
-
|
|
33765
|
+
let decl_type;
|
|
33766
|
+
let sym_type;
|
|
33767
|
+
if (M.kind === "const") {
|
|
33768
|
+
decl_type = AST_Const;
|
|
33769
|
+
sym_type = AST_SymbolConst;
|
|
33770
|
+
} else if (M.kind === "let") {
|
|
33771
|
+
decl_type = AST_Let;
|
|
33772
|
+
sym_type = AST_SymbolLet;
|
|
33773
|
+
} else {
|
|
33774
|
+
decl_type = AST_Var;
|
|
33775
|
+
sym_type = AST_SymbolVar;
|
|
33776
|
+
}
|
|
33777
|
+
const definitions = M.declarations.map(M => {
|
|
33778
|
+
return new AST_VarDef({
|
|
33779
|
+
start: my_start_token(M),
|
|
33780
|
+
end: my_end_token(M),
|
|
33781
|
+
name: from_moz_pattern(M.id, sym_type),
|
|
33782
|
+
value: from_moz(M.init),
|
|
33783
|
+
});
|
|
33784
|
+
});
|
|
33785
|
+
return new decl_type({
|
|
33741
33786
|
start : my_start_token(M),
|
|
33742
33787
|
end : my_end_token(M),
|
|
33743
|
-
definitions :
|
|
33788
|
+
definitions : definitions,
|
|
33744
33789
|
});
|
|
33745
33790
|
},
|
|
33746
33791
|
|
|
@@ -33769,13 +33814,13 @@
|
|
|
33769
33814
|
return new AST_NameMapping({
|
|
33770
33815
|
start: my_start_token(M),
|
|
33771
33816
|
end: my_end_token(M),
|
|
33772
|
-
foreign_name:
|
|
33773
|
-
name:
|
|
33817
|
+
foreign_name: from_moz_symbol(AST_SymbolImportForeign, M.imported, M.imported.type === "Literal"),
|
|
33818
|
+
name: from_moz_symbol(AST_SymbolImport, M.local)
|
|
33774
33819
|
});
|
|
33775
33820
|
},
|
|
33776
33821
|
|
|
33777
33822
|
ImportDefaultSpecifier: function(M) {
|
|
33778
|
-
return
|
|
33823
|
+
return from_moz_symbol(AST_SymbolImport, M.local);
|
|
33779
33824
|
},
|
|
33780
33825
|
|
|
33781
33826
|
ImportNamespaceSpecifier: function(M) {
|
|
@@ -33783,7 +33828,7 @@
|
|
|
33783
33828
|
start: my_start_token(M),
|
|
33784
33829
|
end: my_end_token(M),
|
|
33785
33830
|
foreign_name: new AST_SymbolImportForeign({ name: "*" }),
|
|
33786
|
-
name:
|
|
33831
|
+
name: from_moz_symbol(AST_SymbolImport, M.local)
|
|
33787
33832
|
});
|
|
33788
33833
|
},
|
|
33789
33834
|
|
|
@@ -33805,15 +33850,17 @@
|
|
|
33805
33850
|
},
|
|
33806
33851
|
|
|
33807
33852
|
ExportAllDeclaration: function(M) {
|
|
33808
|
-
var foreign_name = M.exported == null ?
|
|
33853
|
+
var foreign_name = M.exported == null ?
|
|
33809
33854
|
new AST_SymbolExportForeign({ name: "*" }) :
|
|
33810
|
-
|
|
33855
|
+
from_moz_symbol(AST_SymbolExportForeign, M.exported, M.exported.type === "Literal");
|
|
33811
33856
|
return new AST_Export({
|
|
33812
33857
|
start: my_start_token(M),
|
|
33813
33858
|
end: my_end_token(M),
|
|
33814
33859
|
exported_names: [
|
|
33815
33860
|
new AST_NameMapping({
|
|
33816
|
-
|
|
33861
|
+
start: my_start_token(M),
|
|
33862
|
+
end: my_end_token(M),
|
|
33863
|
+
name: new AST_SymbolExport({ name: "*" }),
|
|
33817
33864
|
foreign_name: foreign_name
|
|
33818
33865
|
})
|
|
33819
33866
|
],
|
|
@@ -33823,14 +33870,26 @@
|
|
|
33823
33870
|
},
|
|
33824
33871
|
|
|
33825
33872
|
ExportNamedDeclaration: function(M) {
|
|
33826
|
-
|
|
33827
|
-
|
|
33828
|
-
|
|
33829
|
-
|
|
33830
|
-
|
|
33831
|
-
|
|
33832
|
-
|
|
33833
|
-
|
|
33873
|
+
if (M.declaration) {
|
|
33874
|
+
// export const, export function, ...
|
|
33875
|
+
return new AST_Export({
|
|
33876
|
+
start: my_start_token(M),
|
|
33877
|
+
end: my_end_token(M),
|
|
33878
|
+
exported_definition: from_moz(M.declaration),
|
|
33879
|
+
exported_names: null,
|
|
33880
|
+
module_name: null,
|
|
33881
|
+
attributes: null,
|
|
33882
|
+
});
|
|
33883
|
+
} else {
|
|
33884
|
+
return new AST_Export({
|
|
33885
|
+
start: my_start_token(M),
|
|
33886
|
+
end: my_end_token(M),
|
|
33887
|
+
exported_definition: null,
|
|
33888
|
+
exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(from_moz) : [],
|
|
33889
|
+
module_name: from_moz(M.source),
|
|
33890
|
+
attributes: import_attributes_from_moz(M.attributes || M.assertions),
|
|
33891
|
+
});
|
|
33892
|
+
}
|
|
33834
33893
|
},
|
|
33835
33894
|
|
|
33836
33895
|
ExportDefaultDeclaration: function(M) {
|
|
@@ -33844,8 +33903,10 @@
|
|
|
33844
33903
|
|
|
33845
33904
|
ExportSpecifier: function(M) {
|
|
33846
33905
|
return new AST_NameMapping({
|
|
33847
|
-
|
|
33848
|
-
|
|
33906
|
+
start: my_start_token(M),
|
|
33907
|
+
end: my_end_token(M),
|
|
33908
|
+
foreign_name: from_moz_symbol(AST_SymbolExportForeign, M.exported, M.exported.type === "Literal"),
|
|
33909
|
+
name: from_moz_symbol(AST_SymbolExport, M.local, M.local.type === "Literal"),
|
|
33849
33910
|
});
|
|
33850
33911
|
},
|
|
33851
33912
|
|
|
@@ -33874,27 +33935,13 @@
|
|
|
33874
33935
|
const bi = typeof M.value === "bigint" ? M.value.toString() : M.bigint;
|
|
33875
33936
|
if (typeof bi === "string") {
|
|
33876
33937
|
args.value = bi;
|
|
33938
|
+
args.raw = M.raw;
|
|
33877
33939
|
return new AST_BigInt(args);
|
|
33878
33940
|
}
|
|
33879
33941
|
if (val === null) return new AST_Null(args);
|
|
33880
33942
|
switch (typeof val) {
|
|
33881
33943
|
case "string":
|
|
33882
33944
|
args.quote = "\"";
|
|
33883
|
-
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
|
33884
|
-
if (p.type == "ImportSpecifier") {
|
|
33885
|
-
args.name = val;
|
|
33886
|
-
return new AST_SymbolImportForeign(args);
|
|
33887
|
-
} else if (p.type == "ExportSpecifier") {
|
|
33888
|
-
args.name = val;
|
|
33889
|
-
if (M == p.exported) {
|
|
33890
|
-
return new AST_SymbolExportForeign(args);
|
|
33891
|
-
} else {
|
|
33892
|
-
return new AST_SymbolExport(args);
|
|
33893
|
-
}
|
|
33894
|
-
} else if (p.type == "ExportAllDeclaration" && M == p.exported) {
|
|
33895
|
-
args.name = val;
|
|
33896
|
-
return new AST_SymbolExportForeign(args);
|
|
33897
|
-
}
|
|
33898
33945
|
args.value = val;
|
|
33899
33946
|
return new AST_String(args);
|
|
33900
33947
|
case "number":
|
|
@@ -33921,26 +33968,11 @@
|
|
|
33921
33968
|
},
|
|
33922
33969
|
|
|
33923
33970
|
Identifier: function(M) {
|
|
33924
|
-
|
|
33925
|
-
|
|
33926
|
-
|
|
33927
|
-
|
|
33928
|
-
|
|
33929
|
-
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
|
33930
|
-
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
|
33931
|
-
: p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef
|
|
33932
|
-
: p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
|
|
33933
|
-
: p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)
|
|
33934
|
-
: p.type == "PropertyDefinition" || p.type === "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty)
|
|
33935
|
-
: p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
|
|
33936
|
-
: p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
|
|
33937
|
-
: p.type == "CatchClause" ? AST_SymbolCatch
|
|
33938
|
-
: p.type == "BreakStatement" || p.type == "ContinueStatement" ? AST_LabelRef
|
|
33939
|
-
: AST_SymbolRef)({
|
|
33940
|
-
start : my_start_token(M),
|
|
33941
|
-
end : my_end_token(M),
|
|
33942
|
-
name : M.name
|
|
33943
|
-
});
|
|
33971
|
+
return new AST_SymbolRef({
|
|
33972
|
+
start : my_start_token(M),
|
|
33973
|
+
end : my_end_token(M),
|
|
33974
|
+
name : M.name
|
|
33975
|
+
});
|
|
33944
33976
|
},
|
|
33945
33977
|
|
|
33946
33978
|
EmptyStatement: function(M) {
|
|
@@ -33969,19 +34001,28 @@
|
|
|
33969
34001
|
},
|
|
33970
34002
|
|
|
33971
34003
|
LabeledStatement: function(M) {
|
|
33972
|
-
|
|
33973
|
-
|
|
33974
|
-
|
|
33975
|
-
|
|
33976
|
-
|
|
33977
|
-
|
|
34004
|
+
try {
|
|
34005
|
+
const label = from_moz_symbol(AST_Label, M.label);
|
|
34006
|
+
FROM_MOZ_LABELS.push(label);
|
|
34007
|
+
|
|
34008
|
+
const stat = new AST_LabeledStatement({
|
|
34009
|
+
start: my_start_token(M),
|
|
34010
|
+
end: my_end_token(M),
|
|
34011
|
+
label,
|
|
34012
|
+
body: from_moz(M.body)
|
|
34013
|
+
});
|
|
34014
|
+
|
|
34015
|
+
return stat;
|
|
34016
|
+
} finally {
|
|
34017
|
+
FROM_MOZ_LABELS.pop();
|
|
34018
|
+
}
|
|
33978
34019
|
},
|
|
33979
34020
|
|
|
33980
34021
|
BreakStatement: function(M) {
|
|
33981
34022
|
return new AST_Break({
|
|
33982
34023
|
start: my_start_token(M),
|
|
33983
34024
|
end: my_end_token(M),
|
|
33984
|
-
label:
|
|
34025
|
+
label: from_moz_label_ref(M.label),
|
|
33985
34026
|
});
|
|
33986
34027
|
},
|
|
33987
34028
|
|
|
@@ -33989,7 +34030,7 @@
|
|
|
33989
34030
|
return new AST_Continue({
|
|
33990
34031
|
start: my_start_token(M),
|
|
33991
34032
|
end: my_end_token(M),
|
|
33992
|
-
label:
|
|
34033
|
+
label: from_moz_label_ref(M.label),
|
|
33993
34034
|
});
|
|
33994
34035
|
},
|
|
33995
34036
|
|
|
@@ -34101,20 +34142,11 @@
|
|
|
34101
34142
|
});
|
|
34102
34143
|
},
|
|
34103
34144
|
|
|
34104
|
-
VariableDeclarator: function(M) {
|
|
34105
|
-
return new AST_VarDef({
|
|
34106
|
-
start: my_start_token(M),
|
|
34107
|
-
end: my_end_token(M),
|
|
34108
|
-
name: from_moz(M.id),
|
|
34109
|
-
value: from_moz(M.init)
|
|
34110
|
-
});
|
|
34111
|
-
},
|
|
34112
|
-
|
|
34113
34145
|
CatchClause: function(M) {
|
|
34114
34146
|
return new AST_Catch({
|
|
34115
34147
|
start: my_start_token(M),
|
|
34116
34148
|
end: my_end_token(M),
|
|
34117
|
-
argname:
|
|
34149
|
+
argname: M.param ? from_moz_pattern(M.param, AST_SymbolCatch) : null,
|
|
34118
34150
|
body: from_moz(M.body).body
|
|
34119
34151
|
});
|
|
34120
34152
|
},
|
|
@@ -34122,6 +34154,7 @@
|
|
|
34122
34154
|
ThisExpression: function(M) {
|
|
34123
34155
|
return new AST_This({
|
|
34124
34156
|
start: my_start_token(M),
|
|
34157
|
+
name: "this",
|
|
34125
34158
|
end: my_end_token(M)
|
|
34126
34159
|
});
|
|
34127
34160
|
},
|
|
@@ -34129,7 +34162,8 @@
|
|
|
34129
34162
|
Super: function(M) {
|
|
34130
34163
|
return new AST_Super({
|
|
34131
34164
|
start: my_start_token(M),
|
|
34132
|
-
end: my_end_token(M)
|
|
34165
|
+
end: my_end_token(M),
|
|
34166
|
+
name: "super",
|
|
34133
34167
|
});
|
|
34134
34168
|
},
|
|
34135
34169
|
|
|
@@ -34170,6 +34204,7 @@
|
|
|
34170
34204
|
start: my_start_token(M),
|
|
34171
34205
|
end: my_end_token(M),
|
|
34172
34206
|
operator: M.operator,
|
|
34207
|
+
logical: M.operator === "??=" || M.operator === "&&=" || M.operator === "||=",
|
|
34173
34208
|
left: from_moz(M.left),
|
|
34174
34209
|
right: from_moz(M.right)
|
|
34175
34210
|
});
|
|
@@ -34222,7 +34257,7 @@
|
|
|
34222
34257
|
return new (M.type === "ClassDeclaration" ? AST_DefClass : AST_ClassExpression)({
|
|
34223
34258
|
start : my_start_token(M),
|
|
34224
34259
|
end : my_end_token(M),
|
|
34225
|
-
name :
|
|
34260
|
+
name : M.id && from_moz_symbol(M.type === "ClassDeclaration" ? AST_SymbolDefClass : AST_SymbolClass, M.id),
|
|
34226
34261
|
extends : from_moz(M.superClass),
|
|
34227
34262
|
properties: M.body.body.map(from_moz)
|
|
34228
34263
|
});
|
|
@@ -34357,13 +34392,6 @@
|
|
|
34357
34392
|
init: to_moz(M.value)
|
|
34358
34393
|
};
|
|
34359
34394
|
});
|
|
34360
|
-
def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {
|
|
34361
|
-
return {
|
|
34362
|
-
type: "CatchClause",
|
|
34363
|
-
param: to_moz(M.argname),
|
|
34364
|
-
body: to_moz_block(M)
|
|
34365
|
-
};
|
|
34366
|
-
});
|
|
34367
34395
|
|
|
34368
34396
|
def_to_moz(AST_This, function To_Moz_ThisExpression() {
|
|
34369
34397
|
return {
|
|
@@ -34375,30 +34403,6 @@
|
|
|
34375
34403
|
type: "Super"
|
|
34376
34404
|
};
|
|
34377
34405
|
});
|
|
34378
|
-
def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {
|
|
34379
|
-
return {
|
|
34380
|
-
type: "BinaryExpression",
|
|
34381
|
-
operator: M.operator,
|
|
34382
|
-
left: to_moz(M.left),
|
|
34383
|
-
right: to_moz(M.right)
|
|
34384
|
-
};
|
|
34385
|
-
});
|
|
34386
|
-
def_to_moz(AST_Binary, function To_Moz_LogicalExpression(M) {
|
|
34387
|
-
return {
|
|
34388
|
-
type: "LogicalExpression",
|
|
34389
|
-
operator: M.operator,
|
|
34390
|
-
left: to_moz(M.left),
|
|
34391
|
-
right: to_moz(M.right)
|
|
34392
|
-
};
|
|
34393
|
-
});
|
|
34394
|
-
def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) {
|
|
34395
|
-
return {
|
|
34396
|
-
type: "AssignmentExpression",
|
|
34397
|
-
operator: M.operator,
|
|
34398
|
-
left: to_moz(M.left),
|
|
34399
|
-
right: to_moz(M.right)
|
|
34400
|
-
};
|
|
34401
|
-
});
|
|
34402
34406
|
def_to_moz(AST_Conditional, function To_Moz_ConditionalExpression(M) {
|
|
34403
34407
|
return {
|
|
34404
34408
|
type: "ConditionalExpression",
|
|
@@ -34420,7 +34424,7 @@
|
|
|
34420
34424
|
return {
|
|
34421
34425
|
type: "ImportExpression",
|
|
34422
34426
|
source,
|
|
34423
|
-
options
|
|
34427
|
+
options: options || null
|
|
34424
34428
|
};
|
|
34425
34429
|
}
|
|
34426
34430
|
|
|
@@ -34479,36 +34483,36 @@
|
|
|
34479
34483
|
return {
|
|
34480
34484
|
type: "FunctionDeclaration",
|
|
34481
34485
|
id: to_moz(M.name),
|
|
34482
|
-
params: M.argnames.map(
|
|
34486
|
+
params: M.argnames.map(to_moz_pattern),
|
|
34483
34487
|
generator: M.is_generator,
|
|
34484
34488
|
async: M.async,
|
|
34485
34489
|
body: to_moz_scope("BlockStatement", M)
|
|
34486
34490
|
};
|
|
34487
34491
|
});
|
|
34488
34492
|
|
|
34489
|
-
def_to_moz(AST_Function, function To_Moz_FunctionExpression(M
|
|
34490
|
-
var is_generator = parent.is_generator !== undefined ?
|
|
34491
|
-
parent.is_generator : M.is_generator;
|
|
34493
|
+
def_to_moz(AST_Function, function To_Moz_FunctionExpression(M) {
|
|
34492
34494
|
return {
|
|
34493
34495
|
type: "FunctionExpression",
|
|
34494
34496
|
id: to_moz(M.name),
|
|
34495
|
-
params: M.argnames.map(
|
|
34496
|
-
generator: is_generator,
|
|
34497
|
-
async: M.async,
|
|
34497
|
+
params: M.argnames.map(to_moz_pattern),
|
|
34498
|
+
generator: M.is_generator || false,
|
|
34499
|
+
async: M.async || false,
|
|
34498
34500
|
body: to_moz_scope("BlockStatement", M)
|
|
34499
34501
|
};
|
|
34500
34502
|
});
|
|
34501
34503
|
|
|
34502
34504
|
def_to_moz(AST_Arrow, function To_Moz_ArrowFunctionExpression(M) {
|
|
34503
|
-
var body =
|
|
34504
|
-
|
|
34505
|
-
|
|
34506
|
-
|
|
34505
|
+
var body = M.body.length === 1 && M.body[0] instanceof AST_Return && M.body[0].value
|
|
34506
|
+
? to_moz(M.body[0].value)
|
|
34507
|
+
: {
|
|
34508
|
+
type: "BlockStatement",
|
|
34509
|
+
body: M.body.map(to_moz)
|
|
34510
|
+
};
|
|
34507
34511
|
return {
|
|
34508
34512
|
type: "ArrowFunctionExpression",
|
|
34509
|
-
params: M.argnames.map(
|
|
34513
|
+
params: M.argnames.map(to_moz_pattern),
|
|
34510
34514
|
async: M.async,
|
|
34511
|
-
body: body
|
|
34515
|
+
body: body,
|
|
34512
34516
|
};
|
|
34513
34517
|
});
|
|
34514
34518
|
|
|
@@ -34516,12 +34520,39 @@
|
|
|
34516
34520
|
if (M.is_array) {
|
|
34517
34521
|
return {
|
|
34518
34522
|
type: "ArrayPattern",
|
|
34519
|
-
elements: M.names.map(
|
|
34523
|
+
elements: M.names.map(
|
|
34524
|
+
M => M instanceof AST_Hole ? null : to_moz_pattern(M)
|
|
34525
|
+
),
|
|
34520
34526
|
};
|
|
34521
34527
|
}
|
|
34522
34528
|
return {
|
|
34523
34529
|
type: "ObjectPattern",
|
|
34524
|
-
properties: M.names.map(
|
|
34530
|
+
properties: M.names.map(M => {
|
|
34531
|
+
if (M instanceof AST_ObjectKeyVal) {
|
|
34532
|
+
var computed = M.computed_key();
|
|
34533
|
+
const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
|
|
34534
|
+
|
|
34535
|
+
return {
|
|
34536
|
+
type: "Property",
|
|
34537
|
+
computed,
|
|
34538
|
+
kind: "init",
|
|
34539
|
+
key: key,
|
|
34540
|
+
method: false,
|
|
34541
|
+
shorthand,
|
|
34542
|
+
value: to_moz_pattern(M.value)
|
|
34543
|
+
};
|
|
34544
|
+
} else {
|
|
34545
|
+
return to_moz_pattern(M);
|
|
34546
|
+
}
|
|
34547
|
+
}),
|
|
34548
|
+
};
|
|
34549
|
+
});
|
|
34550
|
+
|
|
34551
|
+
def_to_moz(AST_DefaultAssign, function To_Moz_AssignmentExpression(M) {
|
|
34552
|
+
return {
|
|
34553
|
+
type: "AssignmentPattern",
|
|
34554
|
+
left: to_moz_pattern(M.left),
|
|
34555
|
+
right: to_moz(M.right),
|
|
34525
34556
|
};
|
|
34526
34557
|
});
|
|
34527
34558
|
|
|
@@ -34565,8 +34596,7 @@
|
|
|
34565
34596
|
def_to_moz(AST_Catch, function To_Moz_CatchClause(M) {
|
|
34566
34597
|
return {
|
|
34567
34598
|
type: "CatchClause",
|
|
34568
|
-
param:
|
|
34569
|
-
guard: null,
|
|
34599
|
+
param: M.argname != null ? to_moz_pattern(M.argname) : null,
|
|
34570
34600
|
body: to_moz_block(M)
|
|
34571
34601
|
};
|
|
34572
34602
|
});
|
|
@@ -34601,8 +34631,7 @@
|
|
|
34601
34631
|
def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
|
|
34602
34632
|
if (M.exported_names) {
|
|
34603
34633
|
var first_exported = M.exported_names[0];
|
|
34604
|
-
|
|
34605
|
-
if (first_exported_name.name === "*" && !first_exported_name.quote) {
|
|
34634
|
+
if (first_exported && first_exported.name.name === "*" && !first_exported.name.quote) {
|
|
34606
34635
|
var foreign_name = first_exported.foreign_name;
|
|
34607
34636
|
var exported = foreign_name.name === "*" && !foreign_name.quote
|
|
34608
34637
|
? null
|
|
@@ -34628,10 +34657,20 @@
|
|
|
34628
34657
|
attributes: import_attributes_to_moz(M.attributes)
|
|
34629
34658
|
};
|
|
34630
34659
|
}
|
|
34631
|
-
|
|
34632
|
-
|
|
34633
|
-
|
|
34634
|
-
|
|
34660
|
+
|
|
34661
|
+
if (M.is_default) {
|
|
34662
|
+
return {
|
|
34663
|
+
type: "ExportDefaultDeclaration",
|
|
34664
|
+
declaration: to_moz(M.exported_value || M.exported_definition),
|
|
34665
|
+
};
|
|
34666
|
+
} else {
|
|
34667
|
+
return {
|
|
34668
|
+
type: "ExportNamedDeclaration",
|
|
34669
|
+
declaration: to_moz(M.exported_value || M.exported_definition),
|
|
34670
|
+
specifiers: [],
|
|
34671
|
+
source: null,
|
|
34672
|
+
};
|
|
34673
|
+
}
|
|
34635
34674
|
});
|
|
34636
34675
|
|
|
34637
34676
|
def_to_moz(AST_Import, function To_Moz_ImportDeclaration(M) {
|
|
@@ -34749,6 +34788,15 @@
|
|
|
34749
34788
|
};
|
|
34750
34789
|
});
|
|
34751
34790
|
|
|
34791
|
+
def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) {
|
|
34792
|
+
return {
|
|
34793
|
+
type: "AssignmentExpression",
|
|
34794
|
+
operator: M.operator,
|
|
34795
|
+
left: to_moz(M.left),
|
|
34796
|
+
right: to_moz(M.right)
|
|
34797
|
+
};
|
|
34798
|
+
});
|
|
34799
|
+
|
|
34752
34800
|
def_to_moz(AST_PrivateIn, function To_Moz_BinaryExpression_PrivateIn(M) {
|
|
34753
34801
|
return {
|
|
34754
34802
|
type: "BinaryExpression",
|
|
@@ -34773,29 +34821,10 @@
|
|
|
34773
34821
|
});
|
|
34774
34822
|
|
|
34775
34823
|
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) {
|
|
34776
|
-
var
|
|
34777
|
-
|
|
34778
|
-
|
|
34779
|
-
};
|
|
34780
|
-
if (typeof M.key === "number") {
|
|
34781
|
-
key = {
|
|
34782
|
-
type: "Literal",
|
|
34783
|
-
value: Number(M.key)
|
|
34784
|
-
};
|
|
34785
|
-
}
|
|
34786
|
-
if (typeof M.key === "string") {
|
|
34787
|
-
key = {
|
|
34788
|
-
type: "Identifier",
|
|
34789
|
-
name: M.key
|
|
34790
|
-
};
|
|
34791
|
-
}
|
|
34824
|
+
var computed = M.computed_key();
|
|
34825
|
+
const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
|
|
34826
|
+
|
|
34792
34827
|
var kind;
|
|
34793
|
-
var string_or_num = typeof M.key === "string" || typeof M.key === "number";
|
|
34794
|
-
var computed = string_or_num ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef;
|
|
34795
|
-
if (M instanceof AST_ObjectKeyVal) {
|
|
34796
|
-
kind = "init";
|
|
34797
|
-
computed = !string_or_num;
|
|
34798
|
-
} else
|
|
34799
34828
|
if (M instanceof AST_ObjectGetter) {
|
|
34800
34829
|
kind = "get";
|
|
34801
34830
|
} else
|
|
@@ -34850,31 +34879,51 @@
|
|
|
34850
34879
|
return {
|
|
34851
34880
|
type: "Property",
|
|
34852
34881
|
computed: computed,
|
|
34882
|
+
method: false,
|
|
34883
|
+
shorthand,
|
|
34853
34884
|
kind: kind,
|
|
34854
34885
|
key: key,
|
|
34855
34886
|
value: to_moz(M.value)
|
|
34856
34887
|
};
|
|
34857
34888
|
});
|
|
34858
34889
|
|
|
34890
|
+
def_to_moz(AST_ObjectKeyVal, function To_Moz_Property(M) {
|
|
34891
|
+
var computed = M.computed_key();
|
|
34892
|
+
const [shorthand, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
|
|
34893
|
+
|
|
34894
|
+
return {
|
|
34895
|
+
type: "Property",
|
|
34896
|
+
computed: computed,
|
|
34897
|
+
shorthand: shorthand,
|
|
34898
|
+
method: false,
|
|
34899
|
+
kind: "init",
|
|
34900
|
+
key: key,
|
|
34901
|
+
value: to_moz(M.value)
|
|
34902
|
+
};
|
|
34903
|
+
});
|
|
34904
|
+
|
|
34859
34905
|
def_to_moz(AST_ConciseMethod, function To_Moz_MethodDefinition(M, parent) {
|
|
34906
|
+
const computed = M.computed_key();
|
|
34907
|
+
const [_always_false, key] = to_moz_property_key(M.key, computed, M.quote, M.value);
|
|
34908
|
+
|
|
34860
34909
|
if (parent instanceof AST_Object) {
|
|
34861
34910
|
return {
|
|
34862
34911
|
type: "Property",
|
|
34863
|
-
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
|
|
34864
34912
|
kind: "init",
|
|
34913
|
+
computed,
|
|
34865
34914
|
method: true,
|
|
34866
34915
|
shorthand: false,
|
|
34867
|
-
key
|
|
34868
|
-
value: to_moz(M.value)
|
|
34916
|
+
key,
|
|
34917
|
+
value: to_moz(M.value),
|
|
34869
34918
|
};
|
|
34870
34919
|
}
|
|
34871
34920
|
|
|
34872
34921
|
return {
|
|
34873
34922
|
type: "MethodDefinition",
|
|
34874
|
-
kind: M.key === "constructor" ? "constructor" : "method",
|
|
34875
|
-
|
|
34923
|
+
kind: !computed && M.key.name === "constructor" ? "constructor" : "method",
|
|
34924
|
+
computed,
|
|
34925
|
+
key,
|
|
34876
34926
|
value: to_moz(M.value),
|
|
34877
|
-
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
|
|
34878
34927
|
static: M.static,
|
|
34879
34928
|
};
|
|
34880
34929
|
});
|
|
@@ -34980,6 +35029,7 @@
|
|
|
34980
35029
|
// `M.value` is a string that may be a hex number representation.
|
|
34981
35030
|
// but "bigint" property should have only decimal digits
|
|
34982
35031
|
bigint: typeof BigInt === "function" ? BigInt(M.value).toString() : M.value,
|
|
35032
|
+
raw: M.raw,
|
|
34983
35033
|
}));
|
|
34984
35034
|
|
|
34985
35035
|
AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
|
|
@@ -35023,20 +35073,133 @@
|
|
|
35023
35073
|
);
|
|
35024
35074
|
}
|
|
35025
35075
|
|
|
35026
|
-
var
|
|
35076
|
+
var FROM_MOZ_LABELS = null;
|
|
35027
35077
|
|
|
35028
35078
|
function from_moz(node) {
|
|
35029
|
-
|
|
35030
|
-
|
|
35031
|
-
|
|
35032
|
-
|
|
35079
|
+
if (node == null) return null;
|
|
35080
|
+
return MOZ_TO_ME[node.type](node);
|
|
35081
|
+
}
|
|
35082
|
+
|
|
35083
|
+
function from_moz_quote(moz_key, computed) {
|
|
35084
|
+
if (!computed && moz_key.type === "Literal" && typeof moz_key.value === "string") {
|
|
35085
|
+
return '"';
|
|
35086
|
+
} else {
|
|
35087
|
+
return "";
|
|
35088
|
+
}
|
|
35089
|
+
}
|
|
35090
|
+
|
|
35091
|
+
function from_moz_symbol(symbol_type, M, has_quote) {
|
|
35092
|
+
return new symbol_type({
|
|
35093
|
+
start: my_start_token(M),
|
|
35094
|
+
quote: has_quote ? '"' : undefined,
|
|
35095
|
+
name: M.type === "Identifier" ? M.name : String(M.value),
|
|
35096
|
+
end: my_end_token(M),
|
|
35097
|
+
});
|
|
35098
|
+
}
|
|
35099
|
+
|
|
35100
|
+
function from_moz_lambda(M, is_method) {
|
|
35101
|
+
return new (is_method ? AST_Accessor : AST_Function)({
|
|
35102
|
+
start: my_start_token(M),
|
|
35103
|
+
end: my_end_token(M),
|
|
35104
|
+
name: M.id && from_moz_symbol(is_method ? AST_SymbolMethod : AST_SymbolLambda, M.id),
|
|
35105
|
+
argnames: M.params.map(M => from_moz_pattern(M, AST_SymbolFunarg)),
|
|
35106
|
+
is_generator: M.generator,
|
|
35107
|
+
async: M.async,
|
|
35108
|
+
body: normalize_directives(from_moz(M.body).body)
|
|
35109
|
+
});
|
|
35110
|
+
}
|
|
35111
|
+
|
|
35112
|
+
function from_moz_pattern(M, sym_type) {
|
|
35113
|
+
switch (M.type) {
|
|
35114
|
+
case "ObjectPattern":
|
|
35115
|
+
return new AST_Destructuring({
|
|
35116
|
+
start: my_start_token(M),
|
|
35117
|
+
end: my_end_token(M),
|
|
35118
|
+
names: M.properties.map(p => from_moz_pattern(p, sym_type)),
|
|
35119
|
+
is_array: false
|
|
35120
|
+
});
|
|
35121
|
+
|
|
35122
|
+
case "Property":
|
|
35123
|
+
var key = M.key;
|
|
35124
|
+
var args = {
|
|
35125
|
+
start : my_start_token(key || M.value),
|
|
35126
|
+
end : my_end_token(M.value),
|
|
35127
|
+
key : key.type == "Identifier" ? key.name : String(key.value),
|
|
35128
|
+
quote : !M.computed && key.type === "Literal" && typeof key.value === "string"
|
|
35129
|
+
? '"'
|
|
35130
|
+
: "",
|
|
35131
|
+
value : from_moz_pattern(M.value, sym_type)
|
|
35132
|
+
};
|
|
35133
|
+
if (M.computed) {
|
|
35134
|
+
args.key = from_moz(M.key);
|
|
35135
|
+
}
|
|
35136
|
+
return new AST_ObjectKeyVal(args);
|
|
35137
|
+
|
|
35138
|
+
case "ArrayPattern":
|
|
35139
|
+
return new AST_Destructuring({
|
|
35140
|
+
start: my_start_token(M),
|
|
35141
|
+
end: my_end_token(M),
|
|
35142
|
+
names: M.elements.map(function(elm) {
|
|
35143
|
+
if (elm === null) {
|
|
35144
|
+
return new AST_Hole();
|
|
35145
|
+
}
|
|
35146
|
+
return from_moz_pattern(elm, sym_type);
|
|
35147
|
+
}),
|
|
35148
|
+
is_array: true
|
|
35149
|
+
});
|
|
35150
|
+
|
|
35151
|
+
case "SpreadElement":
|
|
35152
|
+
case "RestElement":
|
|
35153
|
+
return new AST_Expansion({
|
|
35154
|
+
start: my_start_token(M),
|
|
35155
|
+
end: my_end_token(M),
|
|
35156
|
+
expression: from_moz_pattern(M.argument, sym_type),
|
|
35157
|
+
});
|
|
35158
|
+
|
|
35159
|
+
case "AssignmentPattern":
|
|
35160
|
+
return new AST_DefaultAssign({
|
|
35161
|
+
start : my_start_token(M),
|
|
35162
|
+
end : my_end_token(M),
|
|
35163
|
+
left : from_moz_pattern(M.left, sym_type),
|
|
35164
|
+
operator: "=",
|
|
35165
|
+
right : from_moz(M.right),
|
|
35166
|
+
});
|
|
35167
|
+
|
|
35168
|
+
case "Identifier":
|
|
35169
|
+
return new sym_type({
|
|
35170
|
+
start : my_start_token(M),
|
|
35171
|
+
end : my_end_token(M),
|
|
35172
|
+
name : M.name,
|
|
35173
|
+
});
|
|
35174
|
+
|
|
35175
|
+
default:
|
|
35176
|
+
throw new Error("Invalid node type for destructuring: " + M.type);
|
|
35177
|
+
}
|
|
35178
|
+
}
|
|
35179
|
+
|
|
35180
|
+
function from_moz_label_ref(m_label) {
|
|
35181
|
+
if (!m_label) return null;
|
|
35182
|
+
|
|
35183
|
+
const label = from_moz_symbol(AST_LabelRef, m_label);
|
|
35184
|
+
|
|
35185
|
+
let i = FROM_MOZ_LABELS.length;
|
|
35186
|
+
while (i--) {
|
|
35187
|
+
const label_origin = FROM_MOZ_LABELS[i];
|
|
35188
|
+
|
|
35189
|
+
if (label.name === label_origin.name) {
|
|
35190
|
+
label.thedef = label_origin;
|
|
35191
|
+
break;
|
|
35192
|
+
}
|
|
35193
|
+
}
|
|
35194
|
+
|
|
35195
|
+
return label;
|
|
35033
35196
|
}
|
|
35034
35197
|
|
|
35035
35198
|
AST_Node.from_mozilla_ast = function(node) {
|
|
35036
|
-
var
|
|
35037
|
-
|
|
35199
|
+
var save_labels = FROM_MOZ_LABELS;
|
|
35200
|
+
FROM_MOZ_LABELS = [];
|
|
35038
35201
|
var ast = from_moz(node);
|
|
35039
|
-
|
|
35202
|
+
FROM_MOZ_LABELS = save_labels;
|
|
35040
35203
|
return ast;
|
|
35041
35204
|
};
|
|
35042
35205
|
|
|
@@ -35078,6 +35241,52 @@
|
|
|
35078
35241
|
return ast;
|
|
35079
35242
|
}
|
|
35080
35243
|
|
|
35244
|
+
/** Object property keys can be number literals, string literals, or raw names. Additionally they can be shorthand. We decide that here. */
|
|
35245
|
+
function to_moz_property_key(key, computed = false, quote = false, value = null) {
|
|
35246
|
+
if (computed) {
|
|
35247
|
+
return [false, to_moz(key)];
|
|
35248
|
+
}
|
|
35249
|
+
|
|
35250
|
+
const key_name = typeof key === "string" ? key : key.name;
|
|
35251
|
+
let moz_key;
|
|
35252
|
+
if (quote) {
|
|
35253
|
+
moz_key = { type: "Literal", value: key_name, raw: JSON.stringify(key_name) };
|
|
35254
|
+
} else if ("" + +key_name === key_name && +key_name >= 0) {
|
|
35255
|
+
// representable as a number
|
|
35256
|
+
moz_key = { type: "Literal", value: +key_name, raw: JSON.stringify(+key_name) };
|
|
35257
|
+
} else {
|
|
35258
|
+
moz_key = { type: "Identifier", name: key_name };
|
|
35259
|
+
}
|
|
35260
|
+
|
|
35261
|
+
const shorthand =
|
|
35262
|
+
moz_key.type === "Identifier"
|
|
35263
|
+
&& moz_key.name === key_name
|
|
35264
|
+
&& (value instanceof AST_Symbol && value.name === key_name
|
|
35265
|
+
|| value instanceof AST_DefaultAssign && value.left.name === key_name);
|
|
35266
|
+
return [shorthand, moz_key];
|
|
35267
|
+
}
|
|
35268
|
+
|
|
35269
|
+
function to_moz_pattern(node) {
|
|
35270
|
+
if (node instanceof AST_Expansion) {
|
|
35271
|
+
return {
|
|
35272
|
+
type: "RestElement",
|
|
35273
|
+
argument: to_moz_pattern(node.expression),
|
|
35274
|
+
};
|
|
35275
|
+
}
|
|
35276
|
+
|
|
35277
|
+
if ((
|
|
35278
|
+
node instanceof AST_Symbol
|
|
35279
|
+
|| node instanceof AST_Destructuring
|
|
35280
|
+
|| node instanceof AST_DefaultAssign
|
|
35281
|
+
|| node instanceof AST_PropAccess
|
|
35282
|
+
)) {
|
|
35283
|
+
// Plain translation
|
|
35284
|
+
return to_moz(node);
|
|
35285
|
+
}
|
|
35286
|
+
|
|
35287
|
+
throw new Error(node.TYPE);
|
|
35288
|
+
}
|
|
35289
|
+
|
|
35081
35290
|
function to_moz_in_destructuring() {
|
|
35082
35291
|
var i = TO_MOZ_STACK.length;
|
|
35083
35292
|
while (i--) {
|
|
@@ -35311,7 +35520,7 @@
|
|
|
35311
35520
|
webkit : false,
|
|
35312
35521
|
width : 80,
|
|
35313
35522
|
wrap_iife : false,
|
|
35314
|
-
wrap_func_args :
|
|
35523
|
+
wrap_func_args : false,
|
|
35315
35524
|
|
|
35316
35525
|
_destroy_ast : false
|
|
35317
35526
|
}, true);
|
|
@@ -36835,11 +37044,11 @@
|
|
|
36835
37044
|
foreign_name.name;
|
|
36836
37045
|
if (!names_are_different &&
|
|
36837
37046
|
foreign_name.name === "*" &&
|
|
36838
|
-
foreign_name.quote != self.name.quote) {
|
|
37047
|
+
!!foreign_name.quote != !!self.name.quote) {
|
|
36839
37048
|
// export * as "*"
|
|
36840
37049
|
names_are_different = true;
|
|
36841
37050
|
}
|
|
36842
|
-
var foreign_name_is_name = foreign_name.quote
|
|
37051
|
+
var foreign_name_is_name = !foreign_name.quote;
|
|
36843
37052
|
if (names_are_different) {
|
|
36844
37053
|
if (is_import) {
|
|
36845
37054
|
if (foreign_name_is_name) {
|
|
@@ -36848,7 +37057,7 @@
|
|
|
36848
37057
|
output.print_string(foreign_name.name, foreign_name.quote);
|
|
36849
37058
|
}
|
|
36850
37059
|
} else {
|
|
36851
|
-
if (self.name.quote
|
|
37060
|
+
if (!self.name.quote) {
|
|
36852
37061
|
self.name.print(output);
|
|
36853
37062
|
} else {
|
|
36854
37063
|
output.print_string(self.name.name, self.name.quote);
|
|
@@ -36868,7 +37077,7 @@
|
|
|
36868
37077
|
}
|
|
36869
37078
|
}
|
|
36870
37079
|
} else {
|
|
36871
|
-
if (self.name.quote
|
|
37080
|
+
if (!self.name.quote) {
|
|
36872
37081
|
self.name.print(output);
|
|
36873
37082
|
} else {
|
|
36874
37083
|
output.print_string(self.name.name, self.name.quote);
|
|
@@ -37257,7 +37466,7 @@
|
|
|
37257
37466
|
|
|
37258
37467
|
output.print("#");
|
|
37259
37468
|
|
|
37260
|
-
print_property_name(self.key.name,
|
|
37469
|
+
print_property_name(self.key.name, undefined, output);
|
|
37261
37470
|
|
|
37262
37471
|
if (self.value) {
|
|
37263
37472
|
output.print("=");
|
|
@@ -37322,22 +37531,22 @@
|
|
|
37322
37531
|
});
|
|
37323
37532
|
DEFPRINT(AST_ConciseMethod, function(self, output) {
|
|
37324
37533
|
var type;
|
|
37325
|
-
if (self.is_generator && self.async) {
|
|
37534
|
+
if (self.value.is_generator && self.value.async) {
|
|
37326
37535
|
type = "async*";
|
|
37327
|
-
} else if (self.is_generator) {
|
|
37536
|
+
} else if (self.value.is_generator) {
|
|
37328
37537
|
type = "*";
|
|
37329
|
-
} else if (self.async) {
|
|
37538
|
+
} else if (self.value.async) {
|
|
37330
37539
|
type = "async";
|
|
37331
37540
|
}
|
|
37332
37541
|
self._print_getter_setter(type, false, output);
|
|
37333
37542
|
});
|
|
37334
37543
|
DEFPRINT(AST_PrivateMethod, function(self, output) {
|
|
37335
37544
|
var type;
|
|
37336
|
-
if (self.is_generator && self.async) {
|
|
37545
|
+
if (self.value.is_generator && self.value.async) {
|
|
37337
37546
|
type = "async*";
|
|
37338
|
-
} else if (self.is_generator) {
|
|
37547
|
+
} else if (self.value.is_generator) {
|
|
37339
37548
|
type = "*";
|
|
37340
|
-
} else if (self.async) {
|
|
37549
|
+
} else if (self.value.async) {
|
|
37341
37550
|
type = "async";
|
|
37342
37551
|
}
|
|
37343
37552
|
self._print_getter_setter(type, true, output);
|
|
@@ -37385,7 +37594,11 @@
|
|
|
37385
37594
|
}
|
|
37386
37595
|
});
|
|
37387
37596
|
DEFPRINT(AST_BigInt, function(self, output) {
|
|
37388
|
-
output.
|
|
37597
|
+
if (output.option("keep_numbers") && self.raw) {
|
|
37598
|
+
output.print(self.raw);
|
|
37599
|
+
} else {
|
|
37600
|
+
output.print(self.getValue() + "n");
|
|
37601
|
+
}
|
|
37389
37602
|
});
|
|
37390
37603
|
|
|
37391
37604
|
const r_slash_script = /(<\s*\/\s*script)/i;
|
|
@@ -37673,13 +37886,13 @@
|
|
|
37673
37886
|
AST_NameMapping.prototype.shallow_cmp = pass_through;
|
|
37674
37887
|
|
|
37675
37888
|
AST_Import.prototype.shallow_cmp = function(other) {
|
|
37676
|
-
return (this.imported_name == null ? other.imported_name == null : this.imported_name === other.imported_name) && (this.imported_names == null ? other.imported_names == null : this.imported_names === other.imported_names);
|
|
37889
|
+
return (this.imported_name == null ? other.imported_name == null : this.imported_name === other.imported_name) && (this.imported_names == null ? other.imported_names == null : this.imported_names === other.imported_names) && (this.attributes == null ? other.attributes == null : this.attributes === other.attributes);
|
|
37677
37890
|
};
|
|
37678
37891
|
|
|
37679
37892
|
AST_ImportMeta.prototype.shallow_cmp = pass_through;
|
|
37680
37893
|
|
|
37681
37894
|
AST_Export.prototype.shallow_cmp = function(other) {
|
|
37682
|
-
return (this.exported_definition == null ? other.exported_definition == null : this.exported_definition === other.exported_definition) && (this.exported_value == null ? other.exported_value == null : this.exported_value === other.exported_value) && (this.exported_names == null ? other.exported_names == null : this.exported_names === other.exported_names) && this.module_name === other.module_name && this.is_default === other.is_default;
|
|
37895
|
+
return (this.exported_definition == null ? other.exported_definition == null : this.exported_definition === other.exported_definition) && (this.exported_value == null ? other.exported_value == null : this.exported_value === other.exported_value) && (this.exported_names == null ? other.exported_names == null : this.exported_names === other.exported_names) && (this.attributes == null ? other.attributes == null : this.attributes === other.attributes) && this.module_name === other.module_name && this.is_default === other.is_default;
|
|
37683
37896
|
};
|
|
37684
37897
|
|
|
37685
37898
|
AST_Call.prototype.shallow_cmp = pass_through;
|
|
@@ -37706,6 +37919,8 @@
|
|
|
37706
37919
|
return this.operator === other.operator;
|
|
37707
37920
|
};
|
|
37708
37921
|
|
|
37922
|
+
AST_PrivateIn.prototype.shallow_cmp = pass_through;
|
|
37923
|
+
|
|
37709
37924
|
AST_Conditional.prototype.shallow_cmp = pass_through;
|
|
37710
37925
|
|
|
37711
37926
|
AST_Array.prototype.shallow_cmp = pass_through;
|
|
@@ -37715,7 +37930,7 @@
|
|
|
37715
37930
|
AST_ObjectProperty.prototype.shallow_cmp = pass_through;
|
|
37716
37931
|
|
|
37717
37932
|
AST_ObjectKeyVal.prototype.shallow_cmp = function(other) {
|
|
37718
|
-
return this.key === other.key;
|
|
37933
|
+
return this.key === other.key && this.quote === other.quote;
|
|
37719
37934
|
};
|
|
37720
37935
|
|
|
37721
37936
|
AST_ObjectSetter.prototype.shallow_cmp = function(other) {
|
|
@@ -37727,11 +37942,11 @@
|
|
|
37727
37942
|
};
|
|
37728
37943
|
|
|
37729
37944
|
AST_ConciseMethod.prototype.shallow_cmp = function(other) {
|
|
37730
|
-
return this.static === other.static
|
|
37945
|
+
return this.static === other.static;
|
|
37731
37946
|
};
|
|
37732
37947
|
|
|
37733
37948
|
AST_PrivateMethod.prototype.shallow_cmp = function(other) {
|
|
37734
|
-
return this.static === other.static
|
|
37949
|
+
return this.static === other.static;
|
|
37735
37950
|
};
|
|
37736
37951
|
|
|
37737
37952
|
AST_Class.prototype.shallow_cmp = function(other) {
|
|
@@ -39068,7 +39283,7 @@
|
|
|
39068
39283
|
};
|
|
39069
39284
|
|
|
39070
39285
|
AST_ConciseMethod.prototype._size = function () {
|
|
39071
|
-
return static_size(this.static) + key_size(this.key)
|
|
39286
|
+
return static_size(this.static) + key_size(this.key);
|
|
39072
39287
|
};
|
|
39073
39288
|
|
|
39074
39289
|
AST_PrivateMethod.prototype._size = function () {
|
|
@@ -41042,7 +41257,7 @@
|
|
|
41042
41257
|
if (e instanceof RegExp)
|
|
41043
41258
|
return this;
|
|
41044
41259
|
return typeof e;
|
|
41045
|
-
case "void": return void
|
|
41260
|
+
case "void": return void e;
|
|
41046
41261
|
case "~": return ~e;
|
|
41047
41262
|
case "-": return -e;
|
|
41048
41263
|
case "+": return +e;
|
|
@@ -43818,7 +44033,7 @@
|
|
|
43818
44033
|
stat = stat.clone();
|
|
43819
44034
|
stat.condition = stat.condition.negate(compressor);
|
|
43820
44035
|
stat.body = make_node(AST_BlockStatement, stat, {
|
|
43821
|
-
body: as_statement_array(stat.alternative).concat(
|
|
44036
|
+
body: as_statement_array(stat.alternative).concat(extract_defuns())
|
|
43822
44037
|
});
|
|
43823
44038
|
stat.alternative = make_node(AST_BlockStatement, stat, {
|
|
43824
44039
|
body: new_else
|
|
@@ -43838,7 +44053,7 @@
|
|
|
43838
44053
|
CHANGED = true;
|
|
43839
44054
|
stat = stat.clone();
|
|
43840
44055
|
stat.body = make_node(AST_BlockStatement, stat.body, {
|
|
43841
|
-
body: as_statement_array(stat.body).concat(
|
|
44056
|
+
body: as_statement_array(stat.body).concat(extract_defuns())
|
|
43842
44057
|
});
|
|
43843
44058
|
stat.alternative = make_node(AST_BlockStatement, stat.alternative, {
|
|
43844
44059
|
body: new_else
|
|
@@ -43943,7 +44158,7 @@
|
|
|
43943
44158
|
|| ab instanceof AST_Break && lct instanceof AST_BlockStatement && self === lct;
|
|
43944
44159
|
}
|
|
43945
44160
|
|
|
43946
|
-
function
|
|
44161
|
+
function extract_defuns() {
|
|
43947
44162
|
var tail = statements.slice(i + 1);
|
|
43948
44163
|
statements.length = i + 1;
|
|
43949
44164
|
return tail.filter(function (stat) {
|
|
@@ -43961,6 +44176,9 @@
|
|
|
43961
44176
|
return undefined;
|
|
43962
44177
|
}
|
|
43963
44178
|
body = body.slice(0, -1);
|
|
44179
|
+
if (!body.every(stat => can_be_evicted_from_block(stat))) {
|
|
44180
|
+
return undefined;
|
|
44181
|
+
}
|
|
43964
44182
|
if (ab.value) {
|
|
43965
44183
|
body.push(make_node(AST_SimpleStatement, ab.value, {
|
|
43966
44184
|
body: ab.value.expression
|
|
@@ -44420,6 +44638,8 @@
|
|
|
44420
44638
|
return self;
|
|
44421
44639
|
}
|
|
44422
44640
|
|
|
44641
|
+
if (dont_inline_lambda_in_loop(compressor, fixed)) return self;
|
|
44642
|
+
|
|
44423
44643
|
let single_use = def.single_use
|
|
44424
44644
|
&& !(parent instanceof AST_Call
|
|
44425
44645
|
&& (parent.is_callee_pure(compressor))
|
|
@@ -44573,6 +44793,11 @@
|
|
|
44573
44793
|
fn = fixed;
|
|
44574
44794
|
}
|
|
44575
44795
|
|
|
44796
|
+
if (
|
|
44797
|
+
dont_inline_lambda_in_loop(compressor, fn)
|
|
44798
|
+
&& !has_annotation(self, _INLINE)
|
|
44799
|
+
) return self;
|
|
44800
|
+
|
|
44576
44801
|
var is_func = fn instanceof AST_Lambda;
|
|
44577
44802
|
|
|
44578
44803
|
var stat = is_func && fn.body[0];
|
|
@@ -44901,6 +45126,14 @@
|
|
|
44901
45126
|
}
|
|
44902
45127
|
}
|
|
44903
45128
|
|
|
45129
|
+
/** prevent inlining functions into loops, for performance reasons */
|
|
45130
|
+
function dont_inline_lambda_in_loop(compressor, maybe_lambda) {
|
|
45131
|
+
return (
|
|
45132
|
+
(maybe_lambda instanceof AST_Lambda || maybe_lambda instanceof AST_Class)
|
|
45133
|
+
&& !!compressor.is_within_loop()
|
|
45134
|
+
);
|
|
45135
|
+
}
|
|
45136
|
+
|
|
44904
45137
|
(function(def_find_defs) {
|
|
44905
45138
|
function to_node(value, orig) {
|
|
44906
45139
|
if (value instanceof AST_Node) {
|
|
@@ -48328,7 +48561,7 @@
|
|
|
48328
48561
|
if ("" + (prop instanceof AST_ConciseMethod ? prop.key.name : prop.key) == key) {
|
|
48329
48562
|
const all_props_flattenable = props.every((p) =>
|
|
48330
48563
|
(p instanceof AST_ObjectKeyVal
|
|
48331
|
-
|| arrows && p instanceof AST_ConciseMethod && !p.is_generator
|
|
48564
|
+
|| arrows && p instanceof AST_ConciseMethod && !p.value.is_generator
|
|
48332
48565
|
)
|
|
48333
48566
|
&& !p.computed_key()
|
|
48334
48567
|
);
|
|
@@ -48814,7 +49047,7 @@
|
|
|
48814
49047
|
// p(){return x;} ---> p:()=>x
|
|
48815
49048
|
if (compressor.option("arrows")
|
|
48816
49049
|
&& compressor.parent() instanceof AST_Object
|
|
48817
|
-
&& !self.is_generator
|
|
49050
|
+
&& !self.value.is_generator
|
|
48818
49051
|
&& !self.value.uses_arguments
|
|
48819
49052
|
&& !self.value.pinned()
|
|
48820
49053
|
&& self.value.body.length == 1
|
|
@@ -48822,8 +49055,8 @@
|
|
|
48822
49055
|
&& self.value.body[0].value
|
|
48823
49056
|
&& !self.value.contains_this()) {
|
|
48824
49057
|
var arrow = make_node(AST_Arrow, self.value, self.value);
|
|
48825
|
-
arrow.async = self.async;
|
|
48826
|
-
arrow.is_generator = self.is_generator;
|
|
49058
|
+
arrow.async = self.value.async;
|
|
49059
|
+
arrow.is_generator = self.value.is_generator;
|
|
48827
49060
|
return make_node(AST_ObjectKeyVal, self, {
|
|
48828
49061
|
key: self.key instanceof AST_SymbolMethod ? self.key.name : self.key,
|
|
48829
49062
|
value: arrow,
|
|
@@ -48851,8 +49084,6 @@
|
|
|
48851
49084
|
&& !value.contains_this();
|
|
48852
49085
|
if ((is_arrow_with_block || value instanceof AST_Function) && !value.name) {
|
|
48853
49086
|
return make_node(AST_ConciseMethod, self, {
|
|
48854
|
-
async: value.async,
|
|
48855
|
-
is_generator: value.is_generator,
|
|
48856
49087
|
key: key instanceof AST_Node ? key : make_node(AST_SymbolMethod, self, {
|
|
48857
49088
|
name: key,
|
|
48858
49089
|
}),
|
|
@@ -60154,9 +60385,7 @@
|
|
|
60154
60385
|
}
|
|
60155
60386
|
}
|
|
60156
60387
|
|
|
60157
|
-
|
|
60158
|
-
return str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, '');
|
|
60159
|
-
}
|
|
60388
|
+
const trimWhitespace = str => str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, '');
|
|
60160
60389
|
|
|
60161
60390
|
function collapseWhitespaceAll(str) {
|
|
60162
60391
|
// Non-breaking space is specifically handled inside the replacer function here:
|
|
@@ -60208,14 +60437,14 @@
|
|
|
60208
60437
|
return lineBreakBefore + str + lineBreakAfter;
|
|
60209
60438
|
}
|
|
60210
60439
|
|
|
60211
|
-
// non-empty
|
|
60212
|
-
const
|
|
60213
|
-
// non-empty
|
|
60440
|
+
// non-empty elements that will maintain whitespace around them
|
|
60441
|
+
const inlineHtmlElements = ['a', 'abbr', 'acronym', 'b', 'bdi', 'bdo', 'big', 'button', 'cite', 'code', 'del', 'dfn', 'em', 'font', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'mark', 'math', 'meter', 'nobr', 'object', 'output', 'progress', 'q', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'select', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'svg', 'textarea', 'time', 'tt', 'u', 'var', 'wbr'];
|
|
60442
|
+
// non-empty elements that will maintain whitespace within them
|
|
60214
60443
|
const inlineTextTags = new Set(['a', 'abbr', 'acronym', 'b', 'big', 'del', 'em', 'font', 'i', 'ins', 'kbd', 'mark', 'nobr', 'rp', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'time', 'tt', 'u', 'var']);
|
|
60215
|
-
// self-closing
|
|
60444
|
+
// self-closing elements that will maintain whitespace around them
|
|
60216
60445
|
const selfClosingInlineTags = new Set(['comment', 'img', 'input', 'wbr']);
|
|
60217
60446
|
|
|
60218
|
-
function collapseWhitespaceSmart(str, prevTag, nextTag, options) {
|
|
60447
|
+
function collapseWhitespaceSmart(str, prevTag, nextTag, options, inlineTags) {
|
|
60219
60448
|
let trimLeft = prevTag && !selfClosingInlineTags.has(prevTag);
|
|
60220
60449
|
if (trimLeft && !options.collapseInlineTagWhitespace) {
|
|
60221
60450
|
trimLeft = prevTag.charAt(0) === '/' ? !inlineTags.has(prevTag.slice(1)) : !inlineTextTags.has(prevTag);
|
|
@@ -61015,6 +61244,7 @@
|
|
|
61015
61244
|
let uidIgnore;
|
|
61016
61245
|
let uidAttr;
|
|
61017
61246
|
let uidPattern;
|
|
61247
|
+
let inlineTags = new Set([...inlineHtmlElements, ...(options.inlineCustomElements ?? [])]);
|
|
61018
61248
|
|
|
61019
61249
|
// temporarily replace ignored chunks with comments,
|
|
61020
61250
|
// so that we don't have to worry what's there.
|
|
@@ -61146,7 +61376,7 @@
|
|
|
61146
61376
|
const match = str.match(/^<\/([\w:-]+)>$/);
|
|
61147
61377
|
if (match) {
|
|
61148
61378
|
endTag = match[1];
|
|
61149
|
-
} else if (/>$/.test(str) || (buffer[index] = collapseWhitespaceSmart(str, null, nextTag, options))) {
|
|
61379
|
+
} else if (/>$/.test(str) || (buffer[index] = collapseWhitespaceSmart(str, null, nextTag, options, inlineTags))) {
|
|
61150
61380
|
break;
|
|
61151
61381
|
}
|
|
61152
61382
|
}
|
|
@@ -61357,7 +61587,7 @@
|
|
|
61357
61587
|
}
|
|
61358
61588
|
}
|
|
61359
61589
|
if (prevTag || nextTag) {
|
|
61360
|
-
text = collapseWhitespaceSmart(text, prevTag, nextTag, options);
|
|
61590
|
+
text = collapseWhitespaceSmart(text, prevTag, nextTag, options, inlineTags);
|
|
61361
61591
|
} else {
|
|
61362
61592
|
text = collapseWhitespace(text, options, true, true);
|
|
61363
61593
|
}
|