terser 5.39.2 → 5.41.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 +15 -0
- package/dist/bundle.min.js +120 -94
- package/lib/ast.js +10 -10
- package/lib/equivalent-to.js +6 -3
- package/lib/mozilla-ast.js +54 -41
- package/lib/output.js +10 -6
- package/lib/parse.js +41 -35
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.41.0
|
4
|
+
|
5
|
+
- fixed semicolon insertion between class fields, when the field names are number literals
|
6
|
+
- `keep_numbers` format option now works for bigint
|
7
|
+
- internal: correctly mark accessors' is_generator property
|
8
|
+
- internal: do not read or assign quote properties without need
|
9
|
+
- internal: add missing equivalent_to comparison
|
10
|
+
|
11
|
+
## v5.40.0
|
12
|
+
|
13
|
+
- Fix exporting AssignmentExpression (default assign pattern) to ESTree
|
14
|
+
- Fix ESTree output of object keys with quotes
|
15
|
+
- Fix handling of an ESTree empty `export {}` (#1601)
|
16
|
+
- Fix some `const` and `let` resulting from ESTree input (#1599)
|
17
|
+
|
3
18
|
## v5.39.2
|
4
19
|
|
5
20
|
- Fix crash when parsing bare `yield` inside a template string.
|
package/dist/bundle.min.js
CHANGED
@@ -1685,14 +1685,9 @@ function parse($TEXT, options) {
|
|
1685
1685
|
|
1686
1686
|
var body = _function_body(is("punc", "{"), false, is_async);
|
1687
1687
|
|
1688
|
-
var end =
|
1689
|
-
body instanceof Array && body.length ? body[body.length - 1].end :
|
1690
|
-
body instanceof Array ? start :
|
1691
|
-
body.end;
|
1692
|
-
|
1693
1688
|
return new AST_Arrow({
|
1694
1689
|
start : start,
|
1695
|
-
end : end,
|
1690
|
+
end : body.end,
|
1696
1691
|
async : is_async,
|
1697
1692
|
argnames : argnames,
|
1698
1693
|
body : body
|
@@ -1723,7 +1718,7 @@ function parse($TEXT, options) {
|
|
1723
1718
|
return new ctor({
|
1724
1719
|
start : args.start,
|
1725
1720
|
end : body.end,
|
1726
|
-
is_generator: is_generator,
|
1721
|
+
is_generator: is_generator || is_generator_property,
|
1727
1722
|
async : is_async,
|
1728
1723
|
name : name,
|
1729
1724
|
argnames: args,
|
@@ -2351,7 +2346,12 @@ function parse($TEXT, options) {
|
|
2351
2346
|
});
|
2352
2347
|
break;
|
2353
2348
|
case "big_int":
|
2354
|
-
ret = new AST_BigInt({
|
2349
|
+
ret = new AST_BigInt({
|
2350
|
+
start: tok,
|
2351
|
+
end: tok,
|
2352
|
+
value: tok.value,
|
2353
|
+
raw: LATEST_RAW,
|
2354
|
+
});
|
2355
2355
|
break;
|
2356
2356
|
case "string":
|
2357
2357
|
ret = new AST_String({
|
@@ -2615,7 +2615,7 @@ function parse($TEXT, options) {
|
|
2615
2615
|
|
2616
2616
|
// Check property and fetch value
|
2617
2617
|
if (!is("punc", ":")) {
|
2618
|
-
var concise =
|
2618
|
+
var concise = object_or_class_property(name, start);
|
2619
2619
|
if (concise) {
|
2620
2620
|
a.push(concise);
|
2621
2621
|
continue;
|
@@ -2650,7 +2650,7 @@ function parse($TEXT, options) {
|
|
2650
2650
|
const kv = new AST_ObjectKeyVal({
|
2651
2651
|
start: start,
|
2652
2652
|
quote: start.quote,
|
2653
|
-
key: name
|
2653
|
+
key: name,
|
2654
2654
|
value: value,
|
2655
2655
|
end: prev()
|
2656
2656
|
});
|
@@ -2661,7 +2661,7 @@ function parse($TEXT, options) {
|
|
2661
2661
|
});
|
2662
2662
|
|
2663
2663
|
function class_(KindOfClass, is_export_default) {
|
2664
|
-
var start, method, class_name, extends_,
|
2664
|
+
var start, method, class_name, extends_, properties = [];
|
2665
2665
|
|
2666
2666
|
S.input.push_directives_stack(); // Push directive stack, but not scope stack
|
2667
2667
|
S.input.add_directive("use strict");
|
@@ -2690,9 +2690,9 @@ function parse($TEXT, options) {
|
|
2690
2690
|
while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
|
2691
2691
|
while (!is("punc", "}")) {
|
2692
2692
|
start = S.token;
|
2693
|
-
method =
|
2693
|
+
method = object_or_class_property(as_property_name(), start, true);
|
2694
2694
|
if (!method) { unexpected(); }
|
2695
|
-
|
2695
|
+
properties.push(method);
|
2696
2696
|
while (is("punc", ";")) { next(); }
|
2697
2697
|
}
|
2698
2698
|
// mark in class feild,
|
@@ -2706,19 +2706,15 @@ function parse($TEXT, options) {
|
|
2706
2706
|
start: start,
|
2707
2707
|
name: class_name,
|
2708
2708
|
extends: extends_,
|
2709
|
-
properties:
|
2709
|
+
properties: properties,
|
2710
2710
|
end: prev(),
|
2711
2711
|
});
|
2712
2712
|
}
|
2713
2713
|
|
2714
|
-
function
|
2715
|
-
const get_symbol_ast = (name, SymbolClass
|
2716
|
-
if (typeof name === "string"
|
2717
|
-
return new SymbolClass({
|
2718
|
-
start,
|
2719
|
-
name: "" + name,
|
2720
|
-
end: prev()
|
2721
|
-
});
|
2714
|
+
function object_or_class_property(name, start, is_class) {
|
2715
|
+
const get_symbol_ast = (name, SymbolClass) => {
|
2716
|
+
if (typeof name === "string") {
|
2717
|
+
return new SymbolClass({ start, name, end: prev() });
|
2722
2718
|
} else if (name === null) {
|
2723
2719
|
unexpected();
|
2724
2720
|
}
|
@@ -2766,7 +2762,7 @@ function parse($TEXT, options) {
|
|
2766
2762
|
? AST_ObjectGetter
|
2767
2763
|
: AST_ObjectSetter;
|
2768
2764
|
|
2769
|
-
name = get_symbol_ast(name);
|
2765
|
+
name = get_symbol_ast(name, AST_SymbolMethod);
|
2770
2766
|
return annotate(new AccessorClass({
|
2771
2767
|
start,
|
2772
2768
|
static: is_static,
|
@@ -2783,7 +2779,7 @@ function parse($TEXT, options) {
|
|
2783
2779
|
return annotate(new AccessorClass({
|
2784
2780
|
start,
|
2785
2781
|
static: is_static,
|
2786
|
-
key: get_symbol_ast(name),
|
2782
|
+
key: get_symbol_ast(name, AST_SymbolMethod),
|
2787
2783
|
value: create_accessor(),
|
2788
2784
|
end: prev(),
|
2789
2785
|
}));
|
@@ -2791,7 +2787,7 @@ function parse($TEXT, options) {
|
|
2791
2787
|
}
|
2792
2788
|
|
2793
2789
|
if (is("punc", "(")) {
|
2794
|
-
name = get_symbol_ast(name);
|
2790
|
+
name = get_symbol_ast(name, AST_SymbolMethod);
|
2795
2791
|
const AST_MethodVariant = is_private
|
2796
2792
|
? AST_PrivateMethod
|
2797
2793
|
: AST_ConciseMethod;
|
@@ -2810,13 +2806,17 @@ function parse($TEXT, options) {
|
|
2810
2806
|
}
|
2811
2807
|
|
2812
2808
|
if (is_class) {
|
2813
|
-
const
|
2814
|
-
|
2815
|
-
|
2816
|
-
: undefined;
|
2809
|
+
const AST_SymbolVariant = is_private
|
2810
|
+
? AST_SymbolPrivateProperty
|
2811
|
+
: AST_SymbolClassProperty;
|
2817
2812
|
const AST_ClassPropertyVariant = is_private
|
2818
2813
|
? AST_ClassPrivateProperty
|
2819
2814
|
: AST_ClassProperty;
|
2815
|
+
|
2816
|
+
const key = get_symbol_ast(name, AST_SymbolVariant);
|
2817
|
+
const quote = key instanceof AST_SymbolClassProperty
|
2818
|
+
? property_token.quote
|
2819
|
+
: undefined;
|
2820
2820
|
if (is("operator", "=")) {
|
2821
2821
|
next();
|
2822
2822
|
return annotate(
|
@@ -2836,6 +2836,9 @@ function parse($TEXT, options) {
|
|
2836
2836
|
|| is("operator", "*")
|
2837
2837
|
|| is("punc", ";")
|
2838
2838
|
|| is("punc", "}")
|
2839
|
+
|| is("string")
|
2840
|
+
|| is("num")
|
2841
|
+
|| is("big_int")
|
2839
2842
|
) {
|
2840
2843
|
return annotate(
|
2841
2844
|
new AST_ClassPropertyVariant({
|
@@ -2960,10 +2963,12 @@ function parse($TEXT, options) {
|
|
2960
2963
|
} else {
|
2961
2964
|
foreign_name = make_symbol(foreign_type, S.token.quote);
|
2962
2965
|
}
|
2963
|
-
} else if (is_import) {
|
2964
|
-
name = new type(foreign_name);
|
2965
2966
|
} else {
|
2966
|
-
|
2967
|
+
if (is_import) {
|
2968
|
+
name = new type(foreign_name);
|
2969
|
+
} else {
|
2970
|
+
foreign_name = new foreign_type(name);
|
2971
|
+
}
|
2967
2972
|
}
|
2968
2973
|
|
2969
2974
|
return new AST_NameMapping({
|
@@ -3134,12 +3139,14 @@ function parse($TEXT, options) {
|
|
3134
3139
|
case "name":
|
3135
3140
|
case "privatename":
|
3136
3141
|
case "string":
|
3137
|
-
case "num":
|
3138
|
-
case "big_int":
|
3139
3142
|
case "keyword":
|
3140
3143
|
case "atom":
|
3141
3144
|
next();
|
3142
3145
|
return tmp.value;
|
3146
|
+
case "num":
|
3147
|
+
case "big_int":
|
3148
|
+
next();
|
3149
|
+
return "" + tmp.value;
|
3143
3150
|
default:
|
3144
3151
|
unexpected(tmp);
|
3145
3152
|
}
|
@@ -5797,7 +5804,6 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
|
|
5797
5804
|
|
5798
5805
|
var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
|
5799
5806
|
if (props) {
|
5800
|
-
this.quote = props.quote;
|
5801
5807
|
this.static = props.static;
|
5802
5808
|
this.is_generator = props.is_generator;
|
5803
5809
|
this.async = props.async;
|
@@ -5958,7 +5964,6 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_Cl
|
|
5958
5964
|
var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_ClassPrivateProperty(props) {
|
5959
5965
|
if (props) {
|
5960
5966
|
this.static = props.static;
|
5961
|
-
this.quote = props.quote;
|
5962
5967
|
this.key = props.key;
|
5963
5968
|
this.value = props.value;
|
5964
5969
|
this.start = props.start;
|
@@ -6318,12 +6323,12 @@ var AST_SymbolImport = DEFNODE("SymbolImport", null, function AST_SymbolImport(p
|
|
6318
6323
|
$documentation: "Symbol referring to an imported name",
|
6319
6324
|
}, AST_SymbolBlockDeclaration);
|
6320
6325
|
|
6321
|
-
var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign",
|
6326
|
+
var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", "quote", function AST_SymbolImportForeign(props) {
|
6322
6327
|
if (props) {
|
6328
|
+
this.quote = props.quote;
|
6323
6329
|
this.scope = props.scope;
|
6324
6330
|
this.name = props.name;
|
6325
6331
|
this.thedef = props.thedef;
|
6326
|
-
this.quote = props.quote;
|
6327
6332
|
this.start = props.start;
|
6328
6333
|
this.end = props.end;
|
6329
6334
|
}
|
@@ -6370,12 +6375,12 @@ var AST_SymbolRef = DEFNODE("SymbolRef", null, function AST_SymbolRef(props) {
|
|
6370
6375
|
$documentation: "Reference to some symbol (not definition/declaration)",
|
6371
6376
|
}, AST_Symbol);
|
6372
6377
|
|
6373
|
-
var AST_SymbolExport = DEFNODE("SymbolExport",
|
6378
|
+
var AST_SymbolExport = DEFNODE("SymbolExport", "quote", function AST_SymbolExport(props) {
|
6374
6379
|
if (props) {
|
6380
|
+
this.quote = props.quote;
|
6375
6381
|
this.scope = props.scope;
|
6376
6382
|
this.name = props.name;
|
6377
6383
|
this.thedef = props.thedef;
|
6378
|
-
this.quote = props.quote;
|
6379
6384
|
this.start = props.start;
|
6380
6385
|
this.end = props.end;
|
6381
6386
|
}
|
@@ -6385,12 +6390,12 @@ var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(p
|
|
6385
6390
|
$documentation: "Symbol referring to a name to export",
|
6386
6391
|
}, AST_SymbolRef);
|
6387
6392
|
|
6388
|
-
var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign",
|
6393
|
+
var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", "quote", function AST_SymbolExportForeign(props) {
|
6389
6394
|
if (props) {
|
6395
|
+
this.quote = props.quote;
|
6390
6396
|
this.scope = props.scope;
|
6391
6397
|
this.name = props.name;
|
6392
6398
|
this.thedef = props.thedef;
|
6393
|
-
this.quote = props.quote;
|
6394
6399
|
this.start = props.start;
|
6395
6400
|
this.end = props.end;
|
6396
6401
|
}
|
@@ -6505,9 +6510,10 @@ var AST_Number = DEFNODE("Number", "value raw", function AST_Number(props) {
|
|
6505
6510
|
}
|
6506
6511
|
}, AST_Constant);
|
6507
6512
|
|
6508
|
-
var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
|
6513
|
+
var AST_BigInt = DEFNODE("BigInt", "value raw", function AST_BigInt(props) {
|
6509
6514
|
if (props) {
|
6510
6515
|
this.value = props.value;
|
6516
|
+
this.raw = props.raw;
|
6511
6517
|
this.start = props.start;
|
6512
6518
|
this.end = props.end;
|
6513
6519
|
}
|
@@ -6516,7 +6522,8 @@ var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
|
|
6516
6522
|
}, {
|
6517
6523
|
$documentation: "A big int literal",
|
6518
6524
|
$propdoc: {
|
6519
|
-
value: "[string] big int value"
|
6525
|
+
value: "[string] big int value, represented as a string",
|
6526
|
+
raw: "[string] the original format preserved"
|
6520
6527
|
}
|
6521
6528
|
}, AST_Constant);
|
6522
6529
|
|
@@ -7358,6 +7365,9 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7358
7365
|
start : my_start_token(key || M.value),
|
7359
7366
|
end : my_end_token(M.value),
|
7360
7367
|
key : key.type == "Identifier" ? key.name : key.value,
|
7368
|
+
quote : !key.computed && key.type === "Literal" && typeof key.value === "string"
|
7369
|
+
? '"'
|
7370
|
+
: null,
|
7361
7371
|
value : from_moz(M.value)
|
7362
7372
|
};
|
7363
7373
|
if (M.computed) {
|
@@ -7390,7 +7400,6 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7390
7400
|
if (M.kind == "method") {
|
7391
7401
|
args.async = M.value.async;
|
7392
7402
|
args.is_generator = M.value.generator;
|
7393
|
-
args.quote = M.computed ? "\"" : null;
|
7394
7403
|
return new AST_ConciseMethod(args);
|
7395
7404
|
}
|
7396
7405
|
},
|
@@ -7634,14 +7643,26 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7634
7643
|
},
|
7635
7644
|
|
7636
7645
|
ExportNamedDeclaration: function(M) {
|
7637
|
-
|
7638
|
-
|
7639
|
-
|
7640
|
-
|
7641
|
-
|
7642
|
-
|
7643
|
-
|
7644
|
-
|
7646
|
+
if (M.declaration) {
|
7647
|
+
// export const, export function, ...
|
7648
|
+
return new AST_Export({
|
7649
|
+
start: my_start_token(M),
|
7650
|
+
end: my_end_token(M),
|
7651
|
+
exported_definition: from_moz(M.declaration),
|
7652
|
+
exported_names: null,
|
7653
|
+
module_name: null,
|
7654
|
+
attributes: null,
|
7655
|
+
});
|
7656
|
+
} else {
|
7657
|
+
return new AST_Export({
|
7658
|
+
start: my_start_token(M),
|
7659
|
+
end: my_end_token(M),
|
7660
|
+
exported_definition: null,
|
7661
|
+
exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(from_moz) : [],
|
7662
|
+
module_name: from_moz(M.source),
|
7663
|
+
attributes: import_attributes_from_moz(M.attributes || M.assertions),
|
7664
|
+
});
|
7665
|
+
}
|
7645
7666
|
},
|
7646
7667
|
|
7647
7668
|
ExportDefaultDeclaration: function(M) {
|
@@ -7733,8 +7754,9 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7733
7754
|
|
7734
7755
|
Identifier: function(M) {
|
7735
7756
|
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
7757
|
+
var q = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 3];
|
7736
7758
|
return new ( p.type == "LabeledStatement" ? AST_Label
|
7737
|
-
: p.type == "VariableDeclarator" && p.id === M ? (
|
7759
|
+
: p.type == "VariableDeclarator" && p.id === M ? (q.kind == "const" ? AST_SymbolConst : q.kind == "let" ? AST_SymbolLet : AST_SymbolVar)
|
7738
7760
|
: /Import.*Specifier/.test(p.type) ? (p.local === M ? AST_SymbolImport : AST_SymbolImportForeign)
|
7739
7761
|
: p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign)
|
7740
7762
|
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
@@ -8186,30 +8208,6 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8186
8208
|
type: "Super"
|
8187
8209
|
};
|
8188
8210
|
});
|
8189
|
-
def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {
|
8190
|
-
return {
|
8191
|
-
type: "BinaryExpression",
|
8192
|
-
operator: M.operator,
|
8193
|
-
left: to_moz(M.left),
|
8194
|
-
right: to_moz(M.right)
|
8195
|
-
};
|
8196
|
-
});
|
8197
|
-
def_to_moz(AST_Binary, function To_Moz_LogicalExpression(M) {
|
8198
|
-
return {
|
8199
|
-
type: "LogicalExpression",
|
8200
|
-
operator: M.operator,
|
8201
|
-
left: to_moz(M.left),
|
8202
|
-
right: to_moz(M.right)
|
8203
|
-
};
|
8204
|
-
});
|
8205
|
-
def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) {
|
8206
|
-
return {
|
8207
|
-
type: "AssignmentExpression",
|
8208
|
-
operator: M.operator,
|
8209
|
-
left: to_moz(M.left),
|
8210
|
-
right: to_moz(M.right)
|
8211
|
-
};
|
8212
|
-
});
|
8213
8211
|
def_to_moz(AST_Conditional, function To_Moz_ConditionalExpression(M) {
|
8214
8212
|
return {
|
8215
8213
|
type: "ConditionalExpression",
|
@@ -8336,6 +8334,14 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8336
8334
|
};
|
8337
8335
|
});
|
8338
8336
|
|
8337
|
+
def_to_moz(AST_DefaultAssign, function To_Moz_AssignmentExpression(M) {
|
8338
|
+
return {
|
8339
|
+
type: "AssignmentPattern",
|
8340
|
+
left: to_moz(M.left),
|
8341
|
+
right: to_moz(M.right),
|
8342
|
+
};
|
8343
|
+
});
|
8344
|
+
|
8339
8345
|
def_to_moz(AST_Directive, function To_Moz_Directive(M) {
|
8340
8346
|
return {
|
8341
8347
|
type: "ExpressionStatement",
|
@@ -8412,8 +8418,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8412
8418
|
def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
|
8413
8419
|
if (M.exported_names) {
|
8414
8420
|
var first_exported = M.exported_names[0];
|
8415
|
-
|
8416
|
-
if (first_exported_name.name === "*" && !first_exported_name.quote) {
|
8421
|
+
if (first_exported && first_exported.name.name === "*" && !first_exported.name.quote) {
|
8417
8422
|
var foreign_name = first_exported.foreign_name;
|
8418
8423
|
var exported = foreign_name.name === "*" && !foreign_name.quote
|
8419
8424
|
? null
|
@@ -8560,6 +8565,15 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8560
8565
|
};
|
8561
8566
|
});
|
8562
8567
|
|
8568
|
+
def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) {
|
8569
|
+
return {
|
8570
|
+
type: "AssignmentExpression",
|
8571
|
+
operator: M.operator,
|
8572
|
+
left: to_moz(M.left),
|
8573
|
+
right: to_moz(M.right)
|
8574
|
+
};
|
8575
|
+
});
|
8576
|
+
|
8563
8577
|
def_to_moz(AST_PrivateIn, function To_Moz_BinaryExpression_PrivateIn(M) {
|
8564
8578
|
return {
|
8565
8579
|
type: "BinaryExpression",
|
@@ -8586,7 +8600,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8586
8600
|
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) {
|
8587
8601
|
var key = M.key instanceof AST_Node ? to_moz(M.key) : {
|
8588
8602
|
type: "Identifier",
|
8589
|
-
value: M.key
|
8603
|
+
value: M.key,
|
8590
8604
|
};
|
8591
8605
|
if (typeof M.key === "number") {
|
8592
8606
|
key = {
|
@@ -8595,10 +8609,16 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8595
8609
|
};
|
8596
8610
|
}
|
8597
8611
|
if (typeof M.key === "string") {
|
8598
|
-
key =
|
8599
|
-
|
8600
|
-
|
8601
|
-
|
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
|
+
};
|
8602
8622
|
}
|
8603
8623
|
var kind;
|
8604
8624
|
var string_or_num = typeof M.key === "string" || typeof M.key === "number";
|
@@ -10645,11 +10665,11 @@ function OutputStream(options) {
|
|
10645
10665
|
foreign_name.name;
|
10646
10666
|
if (!names_are_different &&
|
10647
10667
|
foreign_name.name === "*" &&
|
10648
|
-
foreign_name.quote != self.name.quote) {
|
10668
|
+
!!foreign_name.quote != !!self.name.quote) {
|
10649
10669
|
// export * as "*"
|
10650
10670
|
names_are_different = true;
|
10651
10671
|
}
|
10652
|
-
var foreign_name_is_name = foreign_name.quote
|
10672
|
+
var foreign_name_is_name = !foreign_name.quote;
|
10653
10673
|
if (names_are_different) {
|
10654
10674
|
if (is_import) {
|
10655
10675
|
if (foreign_name_is_name) {
|
@@ -10658,7 +10678,7 @@ function OutputStream(options) {
|
|
10658
10678
|
output.print_string(foreign_name.name, foreign_name.quote);
|
10659
10679
|
}
|
10660
10680
|
} else {
|
10661
|
-
if (self.name.quote
|
10681
|
+
if (!self.name.quote) {
|
10662
10682
|
self.name.print(output);
|
10663
10683
|
} else {
|
10664
10684
|
output.print_string(self.name.name, self.name.quote);
|
@@ -10678,7 +10698,7 @@ function OutputStream(options) {
|
|
10678
10698
|
}
|
10679
10699
|
}
|
10680
10700
|
} else {
|
10681
|
-
if (self.name.quote
|
10701
|
+
if (!self.name.quote) {
|
10682
10702
|
self.name.print(output);
|
10683
10703
|
} else {
|
10684
10704
|
output.print_string(self.name.name, self.name.quote);
|
@@ -11067,7 +11087,7 @@ function OutputStream(options) {
|
|
11067
11087
|
|
11068
11088
|
output.print("#");
|
11069
11089
|
|
11070
|
-
print_property_name(self.key.name,
|
11090
|
+
print_property_name(self.key.name, undefined, output);
|
11071
11091
|
|
11072
11092
|
if (self.value) {
|
11073
11093
|
output.print("=");
|
@@ -11195,7 +11215,11 @@ function OutputStream(options) {
|
|
11195
11215
|
}
|
11196
11216
|
});
|
11197
11217
|
DEFPRINT(AST_BigInt, function(self, output) {
|
11198
|
-
output.
|
11218
|
+
if (output.option("keep_numbers") && self.raw) {
|
11219
|
+
output.print(self.raw);
|
11220
|
+
} else {
|
11221
|
+
output.print(self.getValue() + "n");
|
11222
|
+
}
|
11199
11223
|
});
|
11200
11224
|
|
11201
11225
|
const r_slash_script = /(<\s*\/\s*script)/i;
|
@@ -11483,13 +11507,13 @@ AST_VarDef.prototype.shallow_cmp = function(other) {
|
|
11483
11507
|
AST_NameMapping.prototype.shallow_cmp = pass_through;
|
11484
11508
|
|
11485
11509
|
AST_Import.prototype.shallow_cmp = function(other) {
|
11486
|
-
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);
|
11510
|
+
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);
|
11487
11511
|
};
|
11488
11512
|
|
11489
11513
|
AST_ImportMeta.prototype.shallow_cmp = pass_through;
|
11490
11514
|
|
11491
11515
|
AST_Export.prototype.shallow_cmp = function(other) {
|
11492
|
-
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;
|
11516
|
+
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;
|
11493
11517
|
};
|
11494
11518
|
|
11495
11519
|
AST_Call.prototype.shallow_cmp = pass_through;
|
@@ -11516,6 +11540,8 @@ AST_Binary.prototype.shallow_cmp = function(other) {
|
|
11516
11540
|
return this.operator === other.operator;
|
11517
11541
|
};
|
11518
11542
|
|
11543
|
+
AST_PrivateIn.prototype.shallow_cmp = pass_through;
|
11544
|
+
|
11519
11545
|
AST_Conditional.prototype.shallow_cmp = pass_through;
|
11520
11546
|
|
11521
11547
|
AST_Array.prototype.shallow_cmp = pass_through;
|
@@ -11525,7 +11551,7 @@ AST_Object.prototype.shallow_cmp = pass_through;
|
|
11525
11551
|
AST_ObjectProperty.prototype.shallow_cmp = pass_through;
|
11526
11552
|
|
11527
11553
|
AST_ObjectKeyVal.prototype.shallow_cmp = function(other) {
|
11528
|
-
return this.key === other.key;
|
11554
|
+
return this.key === other.key && this.quote === other.quote;
|
11529
11555
|
};
|
11530
11556
|
|
11531
11557
|
AST_ObjectSetter.prototype.shallow_cmp = function(other) {
|
package/lib/ast.js
CHANGED
@@ -2179,7 +2179,6 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
|
|
2179
2179
|
|
2180
2180
|
var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) {
|
2181
2181
|
if (props) {
|
2182
|
-
this.quote = props.quote;
|
2183
2182
|
this.static = props.static;
|
2184
2183
|
this.is_generator = props.is_generator;
|
2185
2184
|
this.async = props.async;
|
@@ -2340,7 +2339,6 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_Cl
|
|
2340
2339
|
var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_ClassPrivateProperty(props) {
|
2341
2340
|
if (props) {
|
2342
2341
|
this.static = props.static;
|
2343
|
-
this.quote = props.quote;
|
2344
2342
|
this.key = props.key;
|
2345
2343
|
this.value = props.value;
|
2346
2344
|
this.start = props.start;
|
@@ -2700,12 +2698,12 @@ var AST_SymbolImport = DEFNODE("SymbolImport", null, function AST_SymbolImport(p
|
|
2700
2698
|
$documentation: "Symbol referring to an imported name",
|
2701
2699
|
}, AST_SymbolBlockDeclaration);
|
2702
2700
|
|
2703
|
-
var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign",
|
2701
|
+
var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", "quote", function AST_SymbolImportForeign(props) {
|
2704
2702
|
if (props) {
|
2703
|
+
this.quote = props.quote;
|
2705
2704
|
this.scope = props.scope;
|
2706
2705
|
this.name = props.name;
|
2707
2706
|
this.thedef = props.thedef;
|
2708
|
-
this.quote = props.quote;
|
2709
2707
|
this.start = props.start;
|
2710
2708
|
this.end = props.end;
|
2711
2709
|
}
|
@@ -2752,12 +2750,12 @@ var AST_SymbolRef = DEFNODE("SymbolRef", null, function AST_SymbolRef(props) {
|
|
2752
2750
|
$documentation: "Reference to some symbol (not definition/declaration)",
|
2753
2751
|
}, AST_Symbol);
|
2754
2752
|
|
2755
|
-
var AST_SymbolExport = DEFNODE("SymbolExport",
|
2753
|
+
var AST_SymbolExport = DEFNODE("SymbolExport", "quote", function AST_SymbolExport(props) {
|
2756
2754
|
if (props) {
|
2755
|
+
this.quote = props.quote;
|
2757
2756
|
this.scope = props.scope;
|
2758
2757
|
this.name = props.name;
|
2759
2758
|
this.thedef = props.thedef;
|
2760
|
-
this.quote = props.quote;
|
2761
2759
|
this.start = props.start;
|
2762
2760
|
this.end = props.end;
|
2763
2761
|
}
|
@@ -2767,12 +2765,12 @@ var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(p
|
|
2767
2765
|
$documentation: "Symbol referring to a name to export",
|
2768
2766
|
}, AST_SymbolRef);
|
2769
2767
|
|
2770
|
-
var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign",
|
2768
|
+
var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", "quote", function AST_SymbolExportForeign(props) {
|
2771
2769
|
if (props) {
|
2770
|
+
this.quote = props.quote;
|
2772
2771
|
this.scope = props.scope;
|
2773
2772
|
this.name = props.name;
|
2774
2773
|
this.thedef = props.thedef;
|
2775
|
-
this.quote = props.quote;
|
2776
2774
|
this.start = props.start;
|
2777
2775
|
this.end = props.end;
|
2778
2776
|
}
|
@@ -2887,9 +2885,10 @@ var AST_Number = DEFNODE("Number", "value raw", function AST_Number(props) {
|
|
2887
2885
|
}
|
2888
2886
|
}, AST_Constant);
|
2889
2887
|
|
2890
|
-
var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
|
2888
|
+
var AST_BigInt = DEFNODE("BigInt", "value raw", function AST_BigInt(props) {
|
2891
2889
|
if (props) {
|
2892
2890
|
this.value = props.value;
|
2891
|
+
this.raw = props.raw;
|
2893
2892
|
this.start = props.start;
|
2894
2893
|
this.end = props.end;
|
2895
2894
|
}
|
@@ -2898,7 +2897,8 @@ var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) {
|
|
2898
2897
|
}, {
|
2899
2898
|
$documentation: "A big int literal",
|
2900
2899
|
$propdoc: {
|
2901
|
-
value: "[string] big int value"
|
2900
|
+
value: "[string] big int value, represented as a string",
|
2901
|
+
raw: "[string] the original format preserved"
|
2902
2902
|
}
|
2903
2903
|
}, AST_Constant);
|
2904
2904
|
|
package/lib/equivalent-to.js
CHANGED
@@ -44,6 +44,7 @@ import {
|
|
44
44
|
AST_ObjectProperty,
|
45
45
|
AST_ObjectSetter,
|
46
46
|
AST_PrefixedTemplateString,
|
47
|
+
AST_PrivateIn,
|
47
48
|
AST_PrivateMethod,
|
48
49
|
AST_PropAccess,
|
49
50
|
AST_RegExp,
|
@@ -192,13 +193,13 @@ AST_VarDef.prototype.shallow_cmp = function(other) {
|
|
192
193
|
AST_NameMapping.prototype.shallow_cmp = pass_through;
|
193
194
|
|
194
195
|
AST_Import.prototype.shallow_cmp = function(other) {
|
195
|
-
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);
|
196
|
+
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);
|
196
197
|
};
|
197
198
|
|
198
199
|
AST_ImportMeta.prototype.shallow_cmp = pass_through;
|
199
200
|
|
200
201
|
AST_Export.prototype.shallow_cmp = function(other) {
|
201
|
-
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;
|
202
|
+
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;
|
202
203
|
};
|
203
204
|
|
204
205
|
AST_Call.prototype.shallow_cmp = pass_through;
|
@@ -225,6 +226,8 @@ AST_Binary.prototype.shallow_cmp = function(other) {
|
|
225
226
|
return this.operator === other.operator;
|
226
227
|
};
|
227
228
|
|
229
|
+
AST_PrivateIn.prototype.shallow_cmp = pass_through;
|
230
|
+
|
228
231
|
AST_Conditional.prototype.shallow_cmp = pass_through;
|
229
232
|
|
230
233
|
AST_Array.prototype.shallow_cmp = pass_through;
|
@@ -234,7 +237,7 @@ AST_Object.prototype.shallow_cmp = pass_through;
|
|
234
237
|
AST_ObjectProperty.prototype.shallow_cmp = pass_through;
|
235
238
|
|
236
239
|
AST_ObjectKeyVal.prototype.shallow_cmp = function(other) {
|
237
|
-
return this.key === other.key;
|
240
|
+
return this.key === other.key && this.quote === other.quote;
|
238
241
|
};
|
239
242
|
|
240
243
|
AST_ObjectSetter.prototype.shallow_cmp = function(other) {
|
package/lib/mozilla-ast.js
CHANGED
@@ -355,6 +355,9 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
355
355
|
start : my_start_token(key || M.value),
|
356
356
|
end : my_end_token(M.value),
|
357
357
|
key : key.type == "Identifier" ? key.name : key.value,
|
358
|
+
quote : !key.computed && key.type === "Literal" && typeof key.value === "string"
|
359
|
+
? '"'
|
360
|
+
: null,
|
358
361
|
value : from_moz(M.value)
|
359
362
|
};
|
360
363
|
if (M.computed) {
|
@@ -387,7 +390,6 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
387
390
|
if (M.kind == "method") {
|
388
391
|
args.async = M.value.async;
|
389
392
|
args.is_generator = M.value.generator;
|
390
|
-
args.quote = M.computed ? "\"" : null;
|
391
393
|
return new AST_ConciseMethod(args);
|
392
394
|
}
|
393
395
|
},
|
@@ -631,14 +633,26 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
631
633
|
},
|
632
634
|
|
633
635
|
ExportNamedDeclaration: function(M) {
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
636
|
+
if (M.declaration) {
|
637
|
+
// export const, export function, ...
|
638
|
+
return new AST_Export({
|
639
|
+
start: my_start_token(M),
|
640
|
+
end: my_end_token(M),
|
641
|
+
exported_definition: from_moz(M.declaration),
|
642
|
+
exported_names: null,
|
643
|
+
module_name: null,
|
644
|
+
attributes: null,
|
645
|
+
});
|
646
|
+
} else {
|
647
|
+
return new AST_Export({
|
648
|
+
start: my_start_token(M),
|
649
|
+
end: my_end_token(M),
|
650
|
+
exported_definition: null,
|
651
|
+
exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(from_moz) : [],
|
652
|
+
module_name: from_moz(M.source),
|
653
|
+
attributes: import_attributes_from_moz(M.attributes || M.assertions),
|
654
|
+
});
|
655
|
+
}
|
642
656
|
},
|
643
657
|
|
644
658
|
ExportDefaultDeclaration: function(M) {
|
@@ -730,8 +744,9 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
730
744
|
|
731
745
|
Identifier: function(M) {
|
732
746
|
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
747
|
+
var q = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 3];
|
733
748
|
return new ( p.type == "LabeledStatement" ? AST_Label
|
734
|
-
: p.type == "VariableDeclarator" && p.id === M ? (
|
749
|
+
: p.type == "VariableDeclarator" && p.id === M ? (q.kind == "const" ? AST_SymbolConst : q.kind == "let" ? AST_SymbolLet : AST_SymbolVar)
|
735
750
|
: /Import.*Specifier/.test(p.type) ? (p.local === M ? AST_SymbolImport : AST_SymbolImportForeign)
|
736
751
|
: p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign)
|
737
752
|
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
@@ -1183,30 +1198,6 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1183
1198
|
type: "Super"
|
1184
1199
|
};
|
1185
1200
|
});
|
1186
|
-
def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {
|
1187
|
-
return {
|
1188
|
-
type: "BinaryExpression",
|
1189
|
-
operator: M.operator,
|
1190
|
-
left: to_moz(M.left),
|
1191
|
-
right: to_moz(M.right)
|
1192
|
-
};
|
1193
|
-
});
|
1194
|
-
def_to_moz(AST_Binary, function To_Moz_LogicalExpression(M) {
|
1195
|
-
return {
|
1196
|
-
type: "LogicalExpression",
|
1197
|
-
operator: M.operator,
|
1198
|
-
left: to_moz(M.left),
|
1199
|
-
right: to_moz(M.right)
|
1200
|
-
};
|
1201
|
-
});
|
1202
|
-
def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) {
|
1203
|
-
return {
|
1204
|
-
type: "AssignmentExpression",
|
1205
|
-
operator: M.operator,
|
1206
|
-
left: to_moz(M.left),
|
1207
|
-
right: to_moz(M.right)
|
1208
|
-
};
|
1209
|
-
});
|
1210
1201
|
def_to_moz(AST_Conditional, function To_Moz_ConditionalExpression(M) {
|
1211
1202
|
return {
|
1212
1203
|
type: "ConditionalExpression",
|
@@ -1333,6 +1324,14 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1333
1324
|
};
|
1334
1325
|
});
|
1335
1326
|
|
1327
|
+
def_to_moz(AST_DefaultAssign, function To_Moz_AssignmentExpression(M) {
|
1328
|
+
return {
|
1329
|
+
type: "AssignmentPattern",
|
1330
|
+
left: to_moz(M.left),
|
1331
|
+
right: to_moz(M.right),
|
1332
|
+
};
|
1333
|
+
});
|
1334
|
+
|
1336
1335
|
def_to_moz(AST_Directive, function To_Moz_Directive(M) {
|
1337
1336
|
return {
|
1338
1337
|
type: "ExpressionStatement",
|
@@ -1409,8 +1408,7 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1409
1408
|
def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
|
1410
1409
|
if (M.exported_names) {
|
1411
1410
|
var first_exported = M.exported_names[0];
|
1412
|
-
|
1413
|
-
if (first_exported_name.name === "*" && !first_exported_name.quote) {
|
1411
|
+
if (first_exported && first_exported.name.name === "*" && !first_exported.name.quote) {
|
1414
1412
|
var foreign_name = first_exported.foreign_name;
|
1415
1413
|
var exported = foreign_name.name === "*" && !foreign_name.quote
|
1416
1414
|
? null
|
@@ -1557,6 +1555,15 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1557
1555
|
};
|
1558
1556
|
});
|
1559
1557
|
|
1558
|
+
def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) {
|
1559
|
+
return {
|
1560
|
+
type: "AssignmentExpression",
|
1561
|
+
operator: M.operator,
|
1562
|
+
left: to_moz(M.left),
|
1563
|
+
right: to_moz(M.right)
|
1564
|
+
};
|
1565
|
+
});
|
1566
|
+
|
1560
1567
|
def_to_moz(AST_PrivateIn, function To_Moz_BinaryExpression_PrivateIn(M) {
|
1561
1568
|
return {
|
1562
1569
|
type: "BinaryExpression",
|
@@ -1583,7 +1590,7 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1583
1590
|
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) {
|
1584
1591
|
var key = M.key instanceof AST_Node ? to_moz(M.key) : {
|
1585
1592
|
type: "Identifier",
|
1586
|
-
value: M.key
|
1593
|
+
value: M.key,
|
1587
1594
|
};
|
1588
1595
|
if (typeof M.key === "number") {
|
1589
1596
|
key = {
|
@@ -1592,10 +1599,16 @@ import { is_basic_identifier_string } from "./parse.js";
|
|
1592
1599
|
};
|
1593
1600
|
}
|
1594
1601
|
if (typeof M.key === "string") {
|
1595
|
-
key =
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1602
|
+
key = M.quote
|
1603
|
+
? {
|
1604
|
+
type: "Literal",
|
1605
|
+
value: M.key,
|
1606
|
+
raw: JSON.stringify(M.key),
|
1607
|
+
}
|
1608
|
+
: {
|
1609
|
+
type: "Identifier",
|
1610
|
+
name: M.key,
|
1611
|
+
};
|
1599
1612
|
}
|
1600
1613
|
var kind;
|
1601
1614
|
var string_or_num = typeof M.key === "string" || typeof M.key === "number";
|
package/lib/output.js
CHANGED
@@ -1811,11 +1811,11 @@ function OutputStream(options) {
|
|
1811
1811
|
foreign_name.name;
|
1812
1812
|
if (!names_are_different &&
|
1813
1813
|
foreign_name.name === "*" &&
|
1814
|
-
foreign_name.quote != self.name.quote) {
|
1814
|
+
!!foreign_name.quote != !!self.name.quote) {
|
1815
1815
|
// export * as "*"
|
1816
1816
|
names_are_different = true;
|
1817
1817
|
}
|
1818
|
-
var foreign_name_is_name = foreign_name.quote
|
1818
|
+
var foreign_name_is_name = !foreign_name.quote;
|
1819
1819
|
if (names_are_different) {
|
1820
1820
|
if (is_import) {
|
1821
1821
|
if (foreign_name_is_name) {
|
@@ -1824,7 +1824,7 @@ function OutputStream(options) {
|
|
1824
1824
|
output.print_string(foreign_name.name, foreign_name.quote);
|
1825
1825
|
}
|
1826
1826
|
} else {
|
1827
|
-
if (self.name.quote
|
1827
|
+
if (!self.name.quote) {
|
1828
1828
|
self.name.print(output);
|
1829
1829
|
} else {
|
1830
1830
|
output.print_string(self.name.name, self.name.quote);
|
@@ -1844,7 +1844,7 @@ function OutputStream(options) {
|
|
1844
1844
|
}
|
1845
1845
|
}
|
1846
1846
|
} else {
|
1847
|
-
if (self.name.quote
|
1847
|
+
if (!self.name.quote) {
|
1848
1848
|
self.name.print(output);
|
1849
1849
|
} else {
|
1850
1850
|
output.print_string(self.name.name, self.name.quote);
|
@@ -2233,7 +2233,7 @@ function OutputStream(options) {
|
|
2233
2233
|
|
2234
2234
|
output.print("#");
|
2235
2235
|
|
2236
|
-
print_property_name(self.key.name,
|
2236
|
+
print_property_name(self.key.name, undefined, output);
|
2237
2237
|
|
2238
2238
|
if (self.value) {
|
2239
2239
|
output.print("=");
|
@@ -2361,7 +2361,11 @@ function OutputStream(options) {
|
|
2361
2361
|
}
|
2362
2362
|
});
|
2363
2363
|
DEFPRINT(AST_BigInt, function(self, output) {
|
2364
|
-
output.
|
2364
|
+
if (output.option("keep_numbers") && self.raw) {
|
2365
|
+
output.print(self.raw);
|
2366
|
+
} else {
|
2367
|
+
output.print(self.getValue() + "n");
|
2368
|
+
}
|
2365
2369
|
});
|
2366
2370
|
|
2367
2371
|
const r_slash_script = /(<\s*\/\s*script)/i;
|
package/lib/parse.js
CHANGED
@@ -108,7 +108,6 @@ import {
|
|
108
108
|
AST_NameMapping,
|
109
109
|
AST_New,
|
110
110
|
AST_NewTarget,
|
111
|
-
AST_Node,
|
112
111
|
AST_Null,
|
113
112
|
AST_Number,
|
114
113
|
AST_Object,
|
@@ -1540,14 +1539,9 @@ function parse($TEXT, options) {
|
|
1540
1539
|
|
1541
1540
|
var body = _function_body(is("punc", "{"), false, is_async);
|
1542
1541
|
|
1543
|
-
var end =
|
1544
|
-
body instanceof Array && body.length ? body[body.length - 1].end :
|
1545
|
-
body instanceof Array ? start :
|
1546
|
-
body.end;
|
1547
|
-
|
1548
1542
|
return new AST_Arrow({
|
1549
1543
|
start : start,
|
1550
|
-
end : end,
|
1544
|
+
end : body.end,
|
1551
1545
|
async : is_async,
|
1552
1546
|
argnames : argnames,
|
1553
1547
|
body : body
|
@@ -1578,7 +1572,7 @@ function parse($TEXT, options) {
|
|
1578
1572
|
return new ctor({
|
1579
1573
|
start : args.start,
|
1580
1574
|
end : body.end,
|
1581
|
-
is_generator: is_generator,
|
1575
|
+
is_generator: is_generator || is_generator_property,
|
1582
1576
|
async : is_async,
|
1583
1577
|
name : name,
|
1584
1578
|
argnames: args,
|
@@ -2206,7 +2200,12 @@ function parse($TEXT, options) {
|
|
2206
2200
|
});
|
2207
2201
|
break;
|
2208
2202
|
case "big_int":
|
2209
|
-
ret = new AST_BigInt({
|
2203
|
+
ret = new AST_BigInt({
|
2204
|
+
start: tok,
|
2205
|
+
end: tok,
|
2206
|
+
value: tok.value,
|
2207
|
+
raw: LATEST_RAW,
|
2208
|
+
});
|
2210
2209
|
break;
|
2211
2210
|
case "string":
|
2212
2211
|
ret = new AST_String({
|
@@ -2470,7 +2469,7 @@ function parse($TEXT, options) {
|
|
2470
2469
|
|
2471
2470
|
// Check property and fetch value
|
2472
2471
|
if (!is("punc", ":")) {
|
2473
|
-
var concise =
|
2472
|
+
var concise = object_or_class_property(name, start);
|
2474
2473
|
if (concise) {
|
2475
2474
|
a.push(concise);
|
2476
2475
|
continue;
|
@@ -2505,7 +2504,7 @@ function parse($TEXT, options) {
|
|
2505
2504
|
const kv = new AST_ObjectKeyVal({
|
2506
2505
|
start: start,
|
2507
2506
|
quote: start.quote,
|
2508
|
-
key: name
|
2507
|
+
key: name,
|
2509
2508
|
value: value,
|
2510
2509
|
end: prev()
|
2511
2510
|
});
|
@@ -2516,7 +2515,7 @@ function parse($TEXT, options) {
|
|
2516
2515
|
});
|
2517
2516
|
|
2518
2517
|
function class_(KindOfClass, is_export_default) {
|
2519
|
-
var start, method, class_name, extends_,
|
2518
|
+
var start, method, class_name, extends_, properties = [];
|
2520
2519
|
|
2521
2520
|
S.input.push_directives_stack(); // Push directive stack, but not scope stack
|
2522
2521
|
S.input.add_directive("use strict");
|
@@ -2545,9 +2544,9 @@ function parse($TEXT, options) {
|
|
2545
2544
|
while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
|
2546
2545
|
while (!is("punc", "}")) {
|
2547
2546
|
start = S.token;
|
2548
|
-
method =
|
2547
|
+
method = object_or_class_property(as_property_name(), start, true);
|
2549
2548
|
if (!method) { unexpected(); }
|
2550
|
-
|
2549
|
+
properties.push(method);
|
2551
2550
|
while (is("punc", ";")) { next(); }
|
2552
2551
|
}
|
2553
2552
|
// mark in class feild,
|
@@ -2561,19 +2560,15 @@ function parse($TEXT, options) {
|
|
2561
2560
|
start: start,
|
2562
2561
|
name: class_name,
|
2563
2562
|
extends: extends_,
|
2564
|
-
properties:
|
2563
|
+
properties: properties,
|
2565
2564
|
end: prev(),
|
2566
2565
|
});
|
2567
2566
|
}
|
2568
2567
|
|
2569
|
-
function
|
2570
|
-
const get_symbol_ast = (name, SymbolClass
|
2571
|
-
if (typeof name === "string"
|
2572
|
-
return new SymbolClass({
|
2573
|
-
start,
|
2574
|
-
name: "" + name,
|
2575
|
-
end: prev()
|
2576
|
-
});
|
2568
|
+
function object_or_class_property(name, start, is_class) {
|
2569
|
+
const get_symbol_ast = (name, SymbolClass) => {
|
2570
|
+
if (typeof name === "string") {
|
2571
|
+
return new SymbolClass({ start, name, end: prev() });
|
2577
2572
|
} else if (name === null) {
|
2578
2573
|
unexpected();
|
2579
2574
|
}
|
@@ -2621,7 +2616,7 @@ function parse($TEXT, options) {
|
|
2621
2616
|
? AST_ObjectGetter
|
2622
2617
|
: AST_ObjectSetter;
|
2623
2618
|
|
2624
|
-
name = get_symbol_ast(name);
|
2619
|
+
name = get_symbol_ast(name, AST_SymbolMethod);
|
2625
2620
|
return annotate(new AccessorClass({
|
2626
2621
|
start,
|
2627
2622
|
static: is_static,
|
@@ -2638,7 +2633,7 @@ function parse($TEXT, options) {
|
|
2638
2633
|
return annotate(new AccessorClass({
|
2639
2634
|
start,
|
2640
2635
|
static: is_static,
|
2641
|
-
key: get_symbol_ast(name),
|
2636
|
+
key: get_symbol_ast(name, AST_SymbolMethod),
|
2642
2637
|
value: create_accessor(),
|
2643
2638
|
end: prev(),
|
2644
2639
|
}));
|
@@ -2646,7 +2641,7 @@ function parse($TEXT, options) {
|
|
2646
2641
|
}
|
2647
2642
|
|
2648
2643
|
if (is("punc", "(")) {
|
2649
|
-
name = get_symbol_ast(name);
|
2644
|
+
name = get_symbol_ast(name, AST_SymbolMethod);
|
2650
2645
|
const AST_MethodVariant = is_private
|
2651
2646
|
? AST_PrivateMethod
|
2652
2647
|
: AST_ConciseMethod;
|
@@ -2665,13 +2660,17 @@ function parse($TEXT, options) {
|
|
2665
2660
|
}
|
2666
2661
|
|
2667
2662
|
if (is_class) {
|
2668
|
-
const
|
2669
|
-
|
2670
|
-
|
2671
|
-
: undefined;
|
2663
|
+
const AST_SymbolVariant = is_private
|
2664
|
+
? AST_SymbolPrivateProperty
|
2665
|
+
: AST_SymbolClassProperty;
|
2672
2666
|
const AST_ClassPropertyVariant = is_private
|
2673
2667
|
? AST_ClassPrivateProperty
|
2674
2668
|
: AST_ClassProperty;
|
2669
|
+
|
2670
|
+
const key = get_symbol_ast(name, AST_SymbolVariant);
|
2671
|
+
const quote = key instanceof AST_SymbolClassProperty
|
2672
|
+
? property_token.quote
|
2673
|
+
: undefined;
|
2675
2674
|
if (is("operator", "=")) {
|
2676
2675
|
next();
|
2677
2676
|
return annotate(
|
@@ -2691,6 +2690,9 @@ function parse($TEXT, options) {
|
|
2691
2690
|
|| is("operator", "*")
|
2692
2691
|
|| is("punc", ";")
|
2693
2692
|
|| is("punc", "}")
|
2693
|
+
|| is("string")
|
2694
|
+
|| is("num")
|
2695
|
+
|| is("big_int")
|
2694
2696
|
) {
|
2695
2697
|
return annotate(
|
2696
2698
|
new AST_ClassPropertyVariant({
|
@@ -2815,10 +2817,12 @@ function parse($TEXT, options) {
|
|
2815
2817
|
} else {
|
2816
2818
|
foreign_name = make_symbol(foreign_type, S.token.quote);
|
2817
2819
|
}
|
2818
|
-
} else if (is_import) {
|
2819
|
-
name = new type(foreign_name);
|
2820
2820
|
} else {
|
2821
|
-
|
2821
|
+
if (is_import) {
|
2822
|
+
name = new type(foreign_name);
|
2823
|
+
} else {
|
2824
|
+
foreign_name = new foreign_type(name);
|
2825
|
+
}
|
2822
2826
|
}
|
2823
2827
|
|
2824
2828
|
return new AST_NameMapping({
|
@@ -2989,12 +2993,14 @@ function parse($TEXT, options) {
|
|
2989
2993
|
case "name":
|
2990
2994
|
case "privatename":
|
2991
2995
|
case "string":
|
2992
|
-
case "num":
|
2993
|
-
case "big_int":
|
2994
2996
|
case "keyword":
|
2995
2997
|
case "atom":
|
2996
2998
|
next();
|
2997
2999
|
return tmp.value;
|
3000
|
+
case "num":
|
3001
|
+
case "big_int":
|
3002
|
+
next();
|
3003
|
+
return "" + tmp.value;
|
2998
3004
|
default:
|
2999
3005
|
unexpected(tmp);
|
3000
3006
|
}
|