terser 5.4.0 → 5.6.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 +9 -0
- package/README.md +2 -2
- package/dist/bundle.min.js +313 -64
- package/lib/ast.js +47 -2
- package/lib/cli.js +4 -14
- package/lib/compress/index.js +6 -6
- package/lib/mozilla-ast.js +75 -6
- package/lib/output.js +67 -9
- package/lib/parse.js +71 -19
- package/lib/propmangle.js +33 -2
- package/lib/scope.js +4 -1
- package/lib/size.js +24 -0
- package/package.json +8 -8
- package/tools/terser.d.ts +1 -0
- package/dist/bundle.min.js.map +0 -1
package/dist/bundle.min.js
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
(function (global, factory) {
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('source-map')) :
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'source-map'], factory) :
|
4
|
-
(global = global || self, factory(global.Terser = {}, global.sourceMap));
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Terser = {}, global.sourceMap));
|
5
5
|
}(this, (function (exports, MOZ_SourceMap) { 'use strict';
|
6
6
|
|
7
|
-
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
8
|
+
|
9
|
+
var MOZ_SourceMap__default = /*#__PURE__*/_interopDefaultLegacy(MOZ_SourceMap);
|
8
10
|
|
9
11
|
/***********************************************************************
|
10
12
|
|
@@ -482,12 +484,14 @@ function is_identifier_char(ch) {
|
|
482
484
|
return UNICODE.ID_Continue.test(ch);
|
483
485
|
}
|
484
486
|
|
487
|
+
const BASIC_IDENT = /^[a-z_$][a-z0-9_$]*$/i;
|
488
|
+
|
485
489
|
function is_basic_identifier_string(str) {
|
486
|
-
return
|
490
|
+
return BASIC_IDENT.test(str);
|
487
491
|
}
|
488
492
|
|
489
493
|
function is_identifier_string(str, allow_surrogates) {
|
490
|
-
if (
|
494
|
+
if (BASIC_IDENT.test(str)) {
|
491
495
|
return true;
|
492
496
|
}
|
493
497
|
if (!allow_surrogates && /[\ud800-\udfff]/.test(str)) {
|
@@ -1033,6 +1037,11 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|
1033
1037
|
: token("keyword", word);
|
1034
1038
|
}
|
1035
1039
|
|
1040
|
+
function read_private_word() {
|
1041
|
+
next();
|
1042
|
+
return token("privatename", read_name());
|
1043
|
+
}
|
1044
|
+
|
1036
1045
|
function with_eof_error(eof_error, cont) {
|
1037
1046
|
return function(x) {
|
1038
1047
|
try {
|
@@ -1102,6 +1111,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|
1102
1111
|
if (PUNC_CHARS.has(ch)) return token("punc", next());
|
1103
1112
|
if (OPERATOR_CHARS.has(ch)) return read_operator();
|
1104
1113
|
if (code == 92 || is_identifier_start(ch)) return read_word();
|
1114
|
+
if (code == 35) return read_private_word();
|
1105
1115
|
break;
|
1106
1116
|
}
|
1107
1117
|
parse_error("Unexpected character '" + ch + "'");
|
@@ -1302,6 +1312,13 @@ function parse($TEXT, options) {
|
|
1302
1312
|
return S.in_async === S.in_function;
|
1303
1313
|
}
|
1304
1314
|
|
1315
|
+
function can_await() {
|
1316
|
+
return (
|
1317
|
+
S.in_async === S.in_function
|
1318
|
+
|| S.in_function === 0 && S.input.has_directive("use strict")
|
1319
|
+
);
|
1320
|
+
}
|
1321
|
+
|
1305
1322
|
function semicolon(optional) {
|
1306
1323
|
if (is("punc", ";")) next();
|
1307
1324
|
else if (!optional && !can_insert_semicolon()) unexpected();
|
@@ -1586,7 +1603,7 @@ function parse($TEXT, options) {
|
|
1586
1603
|
var for_await_error = "`for await` invalid in this context";
|
1587
1604
|
var await_tok = S.token;
|
1588
1605
|
if (await_tok.type == "name" && await_tok.value == "await") {
|
1589
|
-
if (!
|
1606
|
+
if (!can_await()) {
|
1590
1607
|
token_error(await_tok, for_await_error);
|
1591
1608
|
}
|
1592
1609
|
next();
|
@@ -2083,7 +2100,7 @@ function parse($TEXT, options) {
|
|
2083
2100
|
|
2084
2101
|
function _await_expression() {
|
2085
2102
|
// Previous token must be "await" and not be interpreted as an identifier
|
2086
|
-
if (!
|
2103
|
+
if (!can_await()) {
|
2087
2104
|
croak("Unexpected await expression outside async function",
|
2088
2105
|
S.prev.line, S.prev.col, S.prev.pos);
|
2089
2106
|
}
|
@@ -2703,6 +2720,7 @@ function parse($TEXT, options) {
|
|
2703
2720
|
}
|
2704
2721
|
return name;
|
2705
2722
|
};
|
2723
|
+
var privatename = start.type == "privatename";
|
2706
2724
|
var is_async = false;
|
2707
2725
|
var is_static = false;
|
2708
2726
|
var is_generator = false;
|
@@ -2710,16 +2728,19 @@ function parse($TEXT, options) {
|
|
2710
2728
|
if (is_class && name === "static" && !is("punc", "(")) {
|
2711
2729
|
is_static = true;
|
2712
2730
|
property_token = S.token;
|
2731
|
+
privatename = property_token.type == "privatename";
|
2713
2732
|
name = as_property_name();
|
2714
2733
|
}
|
2715
2734
|
if (name === "async" && !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("operator", "=")) {
|
2716
2735
|
is_async = true;
|
2717
2736
|
property_token = S.token;
|
2737
|
+
privatename = property_token.type == "privatename";
|
2718
2738
|
name = as_property_name();
|
2719
2739
|
}
|
2720
2740
|
if (name === null) {
|
2721
2741
|
is_generator = true;
|
2722
2742
|
property_token = S.token;
|
2743
|
+
privatename = property_token.type == "privatename";
|
2723
2744
|
name = as_property_name();
|
2724
2745
|
if (name === null) {
|
2725
2746
|
unexpected();
|
@@ -2727,7 +2748,10 @@ function parse($TEXT, options) {
|
|
2727
2748
|
}
|
2728
2749
|
if (is("punc", "(")) {
|
2729
2750
|
name = get_method_name_ast(name, start);
|
2730
|
-
|
2751
|
+
const AST_MethodVariant = privatename
|
2752
|
+
? AST_PrivateMethod
|
2753
|
+
: AST_ConciseMethod;
|
2754
|
+
var node = new AST_MethodVariant({
|
2731
2755
|
start : start,
|
2732
2756
|
static : is_static,
|
2733
2757
|
is_generator: is_generator,
|
@@ -2741,6 +2765,23 @@ function parse($TEXT, options) {
|
|
2741
2765
|
return node;
|
2742
2766
|
}
|
2743
2767
|
const setter_token = S.token;
|
2768
|
+
if ((name === "get" || name === "set") && setter_token.type === "privatename") {
|
2769
|
+
next();
|
2770
|
+
|
2771
|
+
const AST_AccessorVariant =
|
2772
|
+
name === "get"
|
2773
|
+
? AST_PrivateGetter
|
2774
|
+
: AST_PrivateSetter;
|
2775
|
+
|
2776
|
+
return new AST_AccessorVariant({
|
2777
|
+
start,
|
2778
|
+
static: is_static,
|
2779
|
+
key: get_method_name_ast(setter_token.value, start),
|
2780
|
+
value: create_accessor(),
|
2781
|
+
end: prev(),
|
2782
|
+
});
|
2783
|
+
}
|
2784
|
+
|
2744
2785
|
if (name == "get") {
|
2745
2786
|
if (!is("punc") || is("punc", "[")) {
|
2746
2787
|
name = get_method_name_ast(as_property_name(), start);
|
@@ -2773,9 +2814,12 @@ function parse($TEXT, options) {
|
|
2773
2814
|
const quote = key instanceof AST_SymbolClassProperty
|
2774
2815
|
? property_token.quote
|
2775
2816
|
: undefined;
|
2817
|
+
const AST_ClassPropertyVariant = privatename
|
2818
|
+
? AST_ClassPrivateProperty
|
2819
|
+
: AST_ClassProperty;
|
2776
2820
|
if (is("operator", "=")) {
|
2777
2821
|
next();
|
2778
|
-
return new
|
2822
|
+
return new AST_ClassPropertyVariant({
|
2779
2823
|
start,
|
2780
2824
|
static: is_static,
|
2781
2825
|
quote,
|
@@ -2783,8 +2827,14 @@ function parse($TEXT, options) {
|
|
2783
2827
|
value: expression(false),
|
2784
2828
|
end: prev()
|
2785
2829
|
});
|
2786
|
-
} else if (
|
2787
|
-
|
2830
|
+
} else if (
|
2831
|
+
is("name")
|
2832
|
+
|| is("privatename")
|
2833
|
+
|| is("operator", "*")
|
2834
|
+
|| is("punc", ";")
|
2835
|
+
|| is("punc", "}")
|
2836
|
+
) {
|
2837
|
+
return new AST_ClassPropertyVariant({
|
2788
2838
|
start,
|
2789
2839
|
static: is_static,
|
2790
2840
|
quote,
|
@@ -3023,6 +3073,7 @@ function parse($TEXT, options) {
|
|
3023
3073
|
}
|
3024
3074
|
/* falls through */
|
3025
3075
|
case "name":
|
3076
|
+
case "privatename":
|
3026
3077
|
case "string":
|
3027
3078
|
case "num":
|
3028
3079
|
case "big_int":
|
@@ -3037,7 +3088,7 @@ function parse($TEXT, options) {
|
|
3037
3088
|
|
3038
3089
|
function as_name() {
|
3039
3090
|
var tmp = S.token;
|
3040
|
-
if (tmp.type != "name") unexpected();
|
3091
|
+
if (tmp.type != "name" && tmp.type != "privatename") unexpected();
|
3041
3092
|
next();
|
3042
3093
|
return tmp.value;
|
3043
3094
|
}
|
@@ -3108,7 +3159,8 @@ function parse($TEXT, options) {
|
|
3108
3159
|
var start = expr.start;
|
3109
3160
|
if (is("punc", ".")) {
|
3110
3161
|
next();
|
3111
|
-
|
3162
|
+
const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
|
3163
|
+
return subscripts(new AST_DotVariant({
|
3112
3164
|
start : start,
|
3113
3165
|
expression : expr,
|
3114
3166
|
optional : false,
|
@@ -3159,8 +3211,9 @@ function parse($TEXT, options) {
|
|
3159
3211
|
annotate(call);
|
3160
3212
|
|
3161
3213
|
chain_contents = subscripts(call, true, true);
|
3162
|
-
} else if (is("name")) {
|
3163
|
-
|
3214
|
+
} else if (is("name") || is("privatename")) {
|
3215
|
+
const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
|
3216
|
+
chain_contents = subscripts(new AST_DotVariant({
|
3164
3217
|
start,
|
3165
3218
|
expression: expr,
|
3166
3219
|
optional: true,
|
@@ -3231,13 +3284,9 @@ function parse($TEXT, options) {
|
|
3231
3284
|
|
3232
3285
|
var maybe_unary = function(allow_calls, allow_arrows) {
|
3233
3286
|
var start = S.token;
|
3234
|
-
if (start.type == "name" && start.value == "await") {
|
3235
|
-
|
3236
|
-
|
3237
|
-
return _await_expression();
|
3238
|
-
} else if (S.input.has_directive("use strict")) {
|
3239
|
-
token_error(S.token, "Unexpected await identifier inside strict mode");
|
3240
|
-
}
|
3287
|
+
if (start.type == "name" && start.value == "await" && can_await()) {
|
3288
|
+
next();
|
3289
|
+
return _await_expression();
|
3241
3290
|
}
|
3242
3291
|
if (is("operator") && UNARY_PREFIX.has(start.value)) {
|
3243
3292
|
next();
|
@@ -4450,7 +4499,7 @@ var AST_PropAccess = DEFNODE("PropAccess", "expression property optional", {
|
|
4450
4499
|
$documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`",
|
4451
4500
|
$propdoc: {
|
4452
4501
|
expression: "[AST_Node] the “container” expression",
|
4453
|
-
property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node",
|
4502
|
+
property: "[AST_Node|string] the property to access. For AST_Dot & AST_DotHash this is always a plain string, while for AST_Sub it's an arbitrary AST_Node",
|
4454
4503
|
|
4455
4504
|
optional: "[boolean] whether this is an optional property access (IE ?.)"
|
4456
4505
|
}
|
@@ -4471,6 +4520,18 @@ var AST_Dot = DEFNODE("Dot", "quote", {
|
|
4471
4520
|
},
|
4472
4521
|
}, AST_PropAccess);
|
4473
4522
|
|
4523
|
+
var AST_DotHash = DEFNODE("DotHash", "", {
|
4524
|
+
$documentation: "A dotted property access to a private property",
|
4525
|
+
_walk: function(visitor) {
|
4526
|
+
return visitor._visit(this, function() {
|
4527
|
+
this.expression._walk(visitor);
|
4528
|
+
});
|
4529
|
+
},
|
4530
|
+
_children_backwards(push) {
|
4531
|
+
push(this.expression);
|
4532
|
+
},
|
4533
|
+
}, AST_PropAccess);
|
4534
|
+
|
4474
4535
|
var AST_Sub = DEFNODE("Sub", null, {
|
4475
4536
|
$documentation: "Index-style property access, i.e. `a[\"foo\"]`",
|
4476
4537
|
_walk: function(visitor) {
|
@@ -4488,7 +4549,7 @@ var AST_Sub = DEFNODE("Sub", null, {
|
|
4488
4549
|
var AST_Chain = DEFNODE("Chain", "expression", {
|
4489
4550
|
$documentation: "A chain expression like a?.b?.(c)?.[d]",
|
4490
4551
|
$propdoc: {
|
4491
|
-
expression: "[AST_Call|AST_Dot|AST_Sub] chain element."
|
4552
|
+
expression: "[AST_Call|AST_Dot|AST_DotHash|AST_Sub] chain element."
|
4492
4553
|
},
|
4493
4554
|
_walk: function (visitor) {
|
4494
4555
|
return visitor._visit(this, function() {
|
@@ -4644,6 +4705,26 @@ var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
|
|
4644
4705
|
}
|
4645
4706
|
}, AST_ObjectProperty);
|
4646
4707
|
|
4708
|
+
var AST_PrivateSetter = DEFNODE("PrivateSetter", "static", {
|
4709
|
+
$propdoc: {
|
4710
|
+
static: "[boolean] whether this is a static private setter"
|
4711
|
+
},
|
4712
|
+
$documentation: "A private setter property",
|
4713
|
+
computed_key() {
|
4714
|
+
return false;
|
4715
|
+
}
|
4716
|
+
}, AST_ObjectProperty);
|
4717
|
+
|
4718
|
+
var AST_PrivateGetter = DEFNODE("PrivateGetter", "static", {
|
4719
|
+
$propdoc: {
|
4720
|
+
static: "[boolean] whether this is a static private getter"
|
4721
|
+
},
|
4722
|
+
$documentation: "A private getter property",
|
4723
|
+
computed_key() {
|
4724
|
+
return false;
|
4725
|
+
}
|
4726
|
+
}, AST_ObjectProperty);
|
4727
|
+
|
4647
4728
|
var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", {
|
4648
4729
|
$propdoc: {
|
4649
4730
|
quote: "[string|undefined] the original quote character, if any",
|
@@ -4679,6 +4760,10 @@ var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator asyn
|
|
4679
4760
|
}
|
4680
4761
|
}, AST_ObjectProperty);
|
4681
4762
|
|
4763
|
+
var AST_PrivateMethod = DEFNODE("PrivateMethod", "", {
|
4764
|
+
$documentation: "A private class method inside a class",
|
4765
|
+
}, AST_ConciseMethod);
|
4766
|
+
|
4682
4767
|
var AST_Class = DEFNODE("Class", "name extends properties", {
|
4683
4768
|
$propdoc: {
|
4684
4769
|
name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",
|
@@ -4728,6 +4813,10 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", {
|
|
4728
4813
|
}
|
4729
4814
|
}, AST_ObjectProperty);
|
4730
4815
|
|
4816
|
+
var AST_ClassPrivateProperty = DEFNODE("ClassProperty", "", {
|
4817
|
+
$documentation: "A class property for a private property",
|
4818
|
+
}, AST_ClassProperty);
|
4819
|
+
|
4731
4820
|
var AST_DefClass = DEFNODE("DefClass", null, {
|
4732
4821
|
$documentation: "A class definition",
|
4733
4822
|
}, AST_Class);
|
@@ -5128,6 +5217,7 @@ AST_Catch: AST_Catch,
|
|
5128
5217
|
AST_Chain: AST_Chain,
|
5129
5218
|
AST_Class: AST_Class,
|
5130
5219
|
AST_ClassExpression: AST_ClassExpression,
|
5220
|
+
AST_ClassPrivateProperty: AST_ClassPrivateProperty,
|
5131
5221
|
AST_ClassProperty: AST_ClassProperty,
|
5132
5222
|
AST_ConciseMethod: AST_ConciseMethod,
|
5133
5223
|
AST_Conditional: AST_Conditional,
|
@@ -5144,6 +5234,7 @@ AST_Destructuring: AST_Destructuring,
|
|
5144
5234
|
AST_Directive: AST_Directive,
|
5145
5235
|
AST_Do: AST_Do,
|
5146
5236
|
AST_Dot: AST_Dot,
|
5237
|
+
AST_DotHash: AST_DotHash,
|
5147
5238
|
AST_DWLoop: AST_DWLoop,
|
5148
5239
|
AST_EmptyStatement: AST_EmptyStatement,
|
5149
5240
|
AST_Exit: AST_Exit,
|
@@ -5181,6 +5272,9 @@ AST_ObjectKeyVal: AST_ObjectKeyVal,
|
|
5181
5272
|
AST_ObjectProperty: AST_ObjectProperty,
|
5182
5273
|
AST_ObjectSetter: AST_ObjectSetter,
|
5183
5274
|
AST_PrefixedTemplateString: AST_PrefixedTemplateString,
|
5275
|
+
AST_PrivateGetter: AST_PrivateGetter,
|
5276
|
+
AST_PrivateMethod: AST_PrivateMethod,
|
5277
|
+
AST_PrivateSetter: AST_PrivateSetter,
|
5184
5278
|
AST_PropAccess: AST_PropAccess,
|
5185
5279
|
AST_RegExp: AST_RegExp,
|
5186
5280
|
AST_Return: AST_Return,
|
@@ -5784,6 +5878,23 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
5784
5878
|
static : M.static,
|
5785
5879
|
});
|
5786
5880
|
},
|
5881
|
+
PropertyDefinition: function(M) {
|
5882
|
+
let key;
|
5883
|
+
if (M.computed) {
|
5884
|
+
key = from_moz(M.key);
|
5885
|
+
} else {
|
5886
|
+
if (M.key.type !== "Identifier") throw new Error("Non-Identifier key in PropertyDefinition");
|
5887
|
+
key = from_moz(M.key);
|
5888
|
+
}
|
5889
|
+
|
5890
|
+
return new AST_ClassProperty({
|
5891
|
+
start : my_start_token(M),
|
5892
|
+
end : my_end_token(M),
|
5893
|
+
key,
|
5894
|
+
value : from_moz(M.value),
|
5895
|
+
static : M.static,
|
5896
|
+
});
|
5897
|
+
},
|
5787
5898
|
ArrayExpression: function(M) {
|
5788
5899
|
return new AST_Array({
|
5789
5900
|
start : my_start_token(M),
|
@@ -5972,7 +6083,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
5972
6083
|
: p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef
|
5973
6084
|
: p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
|
5974
6085
|
: p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod)
|
5975
|
-
: p.type == "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty)
|
6086
|
+
: p.type == "PropertyDefinition" || p.type === "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty)
|
5976
6087
|
: p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
|
5977
6088
|
: p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
|
5978
6089
|
: p.type == "CatchClause" ? AST_SymbolCatch
|
@@ -6271,6 +6382,19 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
6271
6382
|
};
|
6272
6383
|
});
|
6273
6384
|
|
6385
|
+
def_to_moz(AST_DotHash, function To_Moz_PrivateMemberExpression(M) {
|
6386
|
+
return {
|
6387
|
+
type: "MemberExpression",
|
6388
|
+
object: to_moz(M.expression),
|
6389
|
+
computed: false,
|
6390
|
+
property: {
|
6391
|
+
type: "PrivateIdentifier",
|
6392
|
+
name: M.property
|
6393
|
+
},
|
6394
|
+
optional: M.optional
|
6395
|
+
};
|
6396
|
+
});
|
6397
|
+
|
6274
6398
|
def_to_moz(AST_PropAccess, function To_Moz_MemberExpression(M) {
|
6275
6399
|
var isComputed = M instanceof AST_Sub;
|
6276
6400
|
return {
|
@@ -6363,12 +6487,38 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
6363
6487
|
if (M instanceof AST_ObjectSetter) {
|
6364
6488
|
kind = "set";
|
6365
6489
|
}
|
6490
|
+
if (M instanceof AST_PrivateGetter || M instanceof AST_PrivateSetter) {
|
6491
|
+
const kind = M instanceof AST_PrivateGetter ? "get" : "set";
|
6492
|
+
return {
|
6493
|
+
type: "MethodDefinition",
|
6494
|
+
computed: false,
|
6495
|
+
kind: kind,
|
6496
|
+
static: M.static,
|
6497
|
+
key: {
|
6498
|
+
type: "PrivateIdentifier",
|
6499
|
+
name: M.key.name
|
6500
|
+
},
|
6501
|
+
value: to_moz(M.value)
|
6502
|
+
};
|
6503
|
+
}
|
6504
|
+
if (M instanceof AST_ClassPrivateProperty) {
|
6505
|
+
return {
|
6506
|
+
type: "PropertyDefinition",
|
6507
|
+
key: {
|
6508
|
+
type: "PrivateIdentifier",
|
6509
|
+
name: M.key.name
|
6510
|
+
},
|
6511
|
+
value: to_moz(M.value),
|
6512
|
+
computed: false,
|
6513
|
+
static: M.static
|
6514
|
+
};
|
6515
|
+
}
|
6366
6516
|
if (M instanceof AST_ClassProperty) {
|
6367
6517
|
return {
|
6368
|
-
type: "
|
6369
|
-
computed,
|
6518
|
+
type: "PropertyDefinition",
|
6370
6519
|
key,
|
6371
6520
|
value: to_moz(M.value),
|
6521
|
+
computed,
|
6372
6522
|
static: M.static
|
6373
6523
|
};
|
6374
6524
|
}
|
@@ -6403,13 +6553,21 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
6403
6553
|
value: to_moz(M.value)
|
6404
6554
|
};
|
6405
6555
|
}
|
6556
|
+
|
6557
|
+
const key = M instanceof AST_PrivateMethod
|
6558
|
+
? {
|
6559
|
+
type: "PrivateIdentifier",
|
6560
|
+
name: M.key.name
|
6561
|
+
}
|
6562
|
+
: to_moz(M.key);
|
6563
|
+
|
6406
6564
|
return {
|
6407
6565
|
type: "MethodDefinition",
|
6408
|
-
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
|
6409
6566
|
kind: M.key === "constructor" ? "constructor" : "method",
|
6567
|
+
key,
|
6568
|
+
value: to_moz(M.value),
|
6569
|
+
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
|
6410
6570
|
static: M.static,
|
6411
|
-
key: to_moz(M.key),
|
6412
|
-
value: to_moz(M.value)
|
6413
6571
|
};
|
6414
6572
|
});
|
6415
6573
|
|
@@ -6824,7 +6982,7 @@ function OutputStream(options) {
|
|
6824
6982
|
let printed_comments = new Set();
|
6825
6983
|
|
6826
6984
|
var to_utf8 = options.ascii_only ? function(str, identifier) {
|
6827
|
-
if (options.ecma >= 2015) {
|
6985
|
+
if (options.ecma >= 2015 && !options.safari10) {
|
6828
6986
|
str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) {
|
6829
6987
|
var code = get_full_char_code(ch, 0).toString(16);
|
6830
6988
|
return "\\u{" + code + "}";
|
@@ -8364,7 +8522,10 @@ function OutputStream(options) {
|
|
8364
8522
|
var prop = self.property;
|
8365
8523
|
var print_computed = RESERVED_WORDS.has(prop)
|
8366
8524
|
? output.option("ie8")
|
8367
|
-
: !is_identifier_string(
|
8525
|
+
: !is_identifier_string(
|
8526
|
+
prop,
|
8527
|
+
output.option("ecma") >= 2015 || output.option("safari10")
|
8528
|
+
);
|
8368
8529
|
|
8369
8530
|
if (self.optional) output.print("?.");
|
8370
8531
|
|
@@ -8385,6 +8546,15 @@ function OutputStream(options) {
|
|
8385
8546
|
output.print_name(prop);
|
8386
8547
|
}
|
8387
8548
|
});
|
8549
|
+
DEFPRINT(AST_DotHash, function(self, output) {
|
8550
|
+
var expr = self.expression;
|
8551
|
+
expr.print(output);
|
8552
|
+
var prop = self.property;
|
8553
|
+
|
8554
|
+
if (self.optional) output.print("?");
|
8555
|
+
output.print(".#");
|
8556
|
+
output.print_name(prop);
|
8557
|
+
});
|
8388
8558
|
DEFPRINT(AST_Sub, function(self, output) {
|
8389
8559
|
self.expression.print(output);
|
8390
8560
|
if (self.optional) output.print("?.");
|
@@ -8534,7 +8704,7 @@ function OutputStream(options) {
|
|
8534
8704
|
var print_string = RESERVED_WORDS.has(key)
|
8535
8705
|
? output.option("ie8")
|
8536
8706
|
: (
|
8537
|
-
output.option("ecma") < 2015
|
8707
|
+
output.option("ecma") < 2015 || output.option("safari10")
|
8538
8708
|
? !is_basic_identifier_string(key)
|
8539
8709
|
: !is_identifier_string(key, true)
|
8540
8710
|
);
|
@@ -8553,7 +8723,10 @@ function OutputStream(options) {
|
|
8553
8723
|
var allowShortHand = output.option("shorthand");
|
8554
8724
|
if (allowShortHand &&
|
8555
8725
|
self.value instanceof AST_Symbol &&
|
8556
|
-
is_identifier_string(
|
8726
|
+
is_identifier_string(
|
8727
|
+
self.key,
|
8728
|
+
output.option("ecma") >= 2015 || output.option("safari10")
|
8729
|
+
) &&
|
8557
8730
|
get_name(self.value) === self.key &&
|
8558
8731
|
!RESERVED_WORDS.has(self.key)
|
8559
8732
|
) {
|
@@ -8562,7 +8735,10 @@ function OutputStream(options) {
|
|
8562
8735
|
} else if (allowShortHand &&
|
8563
8736
|
self.value instanceof AST_DefaultAssign &&
|
8564
8737
|
self.value.left instanceof AST_Symbol &&
|
8565
|
-
is_identifier_string(
|
8738
|
+
is_identifier_string(
|
8739
|
+
self.key,
|
8740
|
+
output.option("ecma") >= 2015 || output.option("safari10")
|
8741
|
+
) &&
|
8566
8742
|
get_name(self.value.left) === self.key
|
8567
8743
|
) {
|
8568
8744
|
print_property_name(self.key, self.quote, output);
|
@@ -8582,6 +8758,23 @@ function OutputStream(options) {
|
|
8582
8758
|
self.value.print(output);
|
8583
8759
|
}
|
8584
8760
|
});
|
8761
|
+
DEFPRINT(AST_ClassPrivateProperty, (self, output) => {
|
8762
|
+
if (self.static) {
|
8763
|
+
output.print("static");
|
8764
|
+
output.space();
|
8765
|
+
}
|
8766
|
+
|
8767
|
+
output.print("#");
|
8768
|
+
|
8769
|
+
print_property_name(self.key.name, self.quote, output);
|
8770
|
+
|
8771
|
+
if (self.value) {
|
8772
|
+
output.print("=");
|
8773
|
+
self.value.print(output);
|
8774
|
+
}
|
8775
|
+
|
8776
|
+
output.semicolon();
|
8777
|
+
});
|
8585
8778
|
DEFPRINT(AST_ClassProperty, (self, output) => {
|
8586
8779
|
if (self.static) {
|
8587
8780
|
output.print("static");
|
@@ -8603,7 +8796,7 @@ function OutputStream(options) {
|
|
8603
8796
|
|
8604
8797
|
output.semicolon();
|
8605
8798
|
});
|
8606
|
-
AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, output) {
|
8799
|
+
AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, is_private, output) {
|
8607
8800
|
var self = this;
|
8608
8801
|
if (self.static) {
|
8609
8802
|
output.print("static");
|
@@ -8614,6 +8807,7 @@ function OutputStream(options) {
|
|
8614
8807
|
output.space();
|
8615
8808
|
}
|
8616
8809
|
if (self.key instanceof AST_SymbolMethod) {
|
8810
|
+
if (is_private) output.print("#");
|
8617
8811
|
print_property_name(self.key.name, self.quote, output);
|
8618
8812
|
} else {
|
8619
8813
|
output.with_square(function() {
|
@@ -8623,10 +8817,27 @@ function OutputStream(options) {
|
|
8623
8817
|
self.value._do_print(output, true);
|
8624
8818
|
});
|
8625
8819
|
DEFPRINT(AST_ObjectSetter, function(self, output) {
|
8626
|
-
self._print_getter_setter("set", output);
|
8820
|
+
self._print_getter_setter("set", false, output);
|
8627
8821
|
});
|
8628
8822
|
DEFPRINT(AST_ObjectGetter, function(self, output) {
|
8629
|
-
self._print_getter_setter("get", output);
|
8823
|
+
self._print_getter_setter("get", false, output);
|
8824
|
+
});
|
8825
|
+
DEFPRINT(AST_PrivateSetter, function(self, output) {
|
8826
|
+
self._print_getter_setter("set", true, output);
|
8827
|
+
});
|
8828
|
+
DEFPRINT(AST_PrivateGetter, function(self, output) {
|
8829
|
+
self._print_getter_setter("get", true, output);
|
8830
|
+
});
|
8831
|
+
DEFPRINT(AST_PrivateMethod, function(self, output) {
|
8832
|
+
var type;
|
8833
|
+
if (self.is_generator && self.async) {
|
8834
|
+
type = "async*";
|
8835
|
+
} else if (self.is_generator) {
|
8836
|
+
type = "*";
|
8837
|
+
} else if (self.async) {
|
8838
|
+
type = "async";
|
8839
|
+
}
|
8840
|
+
self._print_getter_setter(type, true, output);
|
8630
8841
|
});
|
8631
8842
|
DEFPRINT(AST_ConciseMethod, function(self, output) {
|
8632
8843
|
var type;
|
@@ -8637,7 +8848,7 @@ function OutputStream(options) {
|
|
8637
8848
|
} else if (self.async) {
|
8638
8849
|
type = "async";
|
8639
8850
|
}
|
8640
|
-
self._print_getter_setter(type, output);
|
8851
|
+
self._print_getter_setter(type, false, output);
|
8641
8852
|
});
|
8642
8853
|
AST_Symbol.DEFMETHOD("_do_print", function(output) {
|
8643
8854
|
var def = this.definition();
|
@@ -9898,7 +10109,9 @@ AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
|
|
9898
10109
|
if (this instanceof AST_Symbol && !this.unmangleable(options)) {
|
9899
10110
|
base54.consider(this.name, -1);
|
9900
10111
|
} else if (options.properties) {
|
9901
|
-
if (this instanceof
|
10112
|
+
if (this instanceof AST_DotHash) {
|
10113
|
+
base54.consider("#" + this.property, -1);
|
10114
|
+
} else if (this instanceof AST_Dot) {
|
9902
10115
|
base54.consider(this.property, -1);
|
9903
10116
|
} else if (this instanceof AST_Sub) {
|
9904
10117
|
skip_string(this.property);
|
@@ -10186,6 +10399,13 @@ AST_Dot.prototype._size = function () {
|
|
10186
10399
|
return this.property.length + 1;
|
10187
10400
|
};
|
10188
10401
|
|
10402
|
+
AST_DotHash.prototype._size = function () {
|
10403
|
+
if (this.optional) {
|
10404
|
+
return this.property.length + 3;
|
10405
|
+
}
|
10406
|
+
return this.property.length + 2;
|
10407
|
+
};
|
10408
|
+
|
10189
10409
|
AST_Sub.prototype._size = function () {
|
10190
10410
|
return this.optional ? 4 : 2;
|
10191
10411
|
};
|
@@ -10253,6 +10473,14 @@ AST_ConciseMethod.prototype._size = function () {
|
|
10253
10473
|
return static_size(this.static) + key_size(this.key) + lambda_modifiers(this);
|
10254
10474
|
};
|
10255
10475
|
|
10476
|
+
AST_PrivateMethod.prototype._size = function () {
|
10477
|
+
return AST_ConciseMethod.prototype._size.call(this) + 1;
|
10478
|
+
};
|
10479
|
+
|
10480
|
+
AST_PrivateGetter.prototype._size = AST_PrivateSetter.prototype._size = function () {
|
10481
|
+
return AST_ConciseMethod.prototype._size.call(this) + 4;
|
10482
|
+
};
|
10483
|
+
|
10256
10484
|
AST_Class.prototype._size = function () {
|
10257
10485
|
return (
|
10258
10486
|
(this.name ? 8 : 7)
|
@@ -10268,6 +10496,10 @@ AST_ClassProperty.prototype._size = function () {
|
|
10268
10496
|
);
|
10269
10497
|
};
|
10270
10498
|
|
10499
|
+
AST_ClassPrivateProperty.prototype._size = function () {
|
10500
|
+
return AST_ClassProperty.prototype._size.call(this) + 1;
|
10501
|
+
};
|
10502
|
+
|
10271
10503
|
AST_Symbol.prototype._size = function () {
|
10272
10504
|
return !mangle_options || this.definition().unmangleable(mangle_options)
|
10273
10505
|
? this.name.length
|
@@ -13624,7 +13856,7 @@ const pure_prop_access_globals = new Set([
|
|
13624
13856
|
def_has_side_effects(AST_ObjectProperty, function(compressor) {
|
13625
13857
|
return (
|
13626
13858
|
this.computed_key() && this.key.has_side_effects(compressor)
|
13627
|
-
|| this.value.has_side_effects(compressor)
|
13859
|
+
|| this.value && this.value.has_side_effects(compressor)
|
13628
13860
|
);
|
13629
13861
|
});
|
13630
13862
|
def_has_side_effects(AST_ClassProperty, function(compressor) {
|
@@ -13752,7 +13984,7 @@ const pure_prop_access_globals = new Set([
|
|
13752
13984
|
});
|
13753
13985
|
def_may_throw(AST_ObjectProperty, function(compressor) {
|
13754
13986
|
// TODO key may throw too
|
13755
|
-
return this.value.may_throw(compressor);
|
13987
|
+
return this.value ? this.value.may_throw(compressor) : false;
|
13756
13988
|
});
|
13757
13989
|
def_may_throw(AST_ClassProperty, function(compressor) {
|
13758
13990
|
return (
|
@@ -13886,7 +14118,7 @@ const pure_prop_access_globals = new Set([
|
|
13886
14118
|
return this.properties.every((l) => l.is_constant_expression());
|
13887
14119
|
});
|
13888
14120
|
def_is_constant_expression(AST_ObjectProperty, function() {
|
13889
|
-
return !(this.key instanceof AST_Node) && this.value.is_constant_expression();
|
14121
|
+
return !!(!(this.key instanceof AST_Node) && this.value && this.value.is_constant_expression());
|
13890
14122
|
});
|
13891
14123
|
})(function(node, func) {
|
13892
14124
|
node.DEFMETHOD("is_constant_expression", func);
|
@@ -14713,7 +14945,7 @@ AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
|
|
14713
14945
|
def_drop_side_effect_free(AST_ObjectProperty, function(compressor, first_in_statement) {
|
14714
14946
|
const computed_key = this instanceof AST_ObjectKeyVal && this.key instanceof AST_Node;
|
14715
14947
|
const key = computed_key && this.key.drop_side_effect_free(compressor, first_in_statement);
|
14716
|
-
const value = this.value.drop_side_effect_free(compressor, first_in_statement);
|
14948
|
+
const value = this.value && this.value.drop_side_effect_free(compressor, first_in_statement);
|
14717
14949
|
if (key && value) {
|
14718
14950
|
return make_sequence(this, [key, value]);
|
14719
14951
|
}
|
@@ -16436,7 +16668,7 @@ def_optimize(AST_Binary, function(self, compressor) {
|
|
16436
16668
|
var l = self.left;
|
16437
16669
|
var r = self.right.evaluate(compressor);
|
16438
16670
|
if (r != self.right) {
|
16439
|
-
l.segments[l.segments.length - 1].value += r
|
16671
|
+
l.segments[l.segments.length - 1].value += String(r);
|
16440
16672
|
return l;
|
16441
16673
|
}
|
16442
16674
|
}
|
@@ -16445,7 +16677,7 @@ def_optimize(AST_Binary, function(self, compressor) {
|
|
16445
16677
|
var r = self.right;
|
16446
16678
|
var l = self.left.evaluate(compressor);
|
16447
16679
|
if (l != self.left) {
|
16448
|
-
r.segments[0].value = l
|
16680
|
+
r.segments[0].value = String(l) + r.segments[0].value;
|
16449
16681
|
return r;
|
16450
16682
|
}
|
16451
16683
|
}
|
@@ -17971,13 +18203,13 @@ async function SourceMap(options) {
|
|
17971
18203
|
});
|
17972
18204
|
|
17973
18205
|
var orig_map;
|
17974
|
-
var generator = new
|
18206
|
+
var generator = new MOZ_SourceMap__default['default'].SourceMapGenerator({
|
17975
18207
|
file : options.file,
|
17976
18208
|
sourceRoot : options.root
|
17977
18209
|
});
|
17978
18210
|
|
17979
18211
|
if (options.orig) {
|
17980
|
-
orig_map = await new
|
18212
|
+
orig_map = await new MOZ_SourceMap__default['default'].SourceMapConsumer(options.orig);
|
17981
18213
|
orig_map.sources.forEach(function(source) {
|
17982
18214
|
var sourceContent = orig_map.sourceContentFor(source, true);
|
17983
18215
|
if (sourceContent) {
|
@@ -25925,7 +26157,10 @@ function mangle_properties(ast, options) {
|
|
25925
26157
|
if (!options.builtins) find_builtins(reserved);
|
25926
26158
|
|
25927
26159
|
var cname = -1;
|
26160
|
+
var cprivate = -1;
|
26161
|
+
|
25928
26162
|
var cache;
|
26163
|
+
var private_cache = new Map();
|
25929
26164
|
if (options.cache) {
|
25930
26165
|
cache = options.cache.props;
|
25931
26166
|
cache.forEach(function(mangled_name) {
|
@@ -25948,12 +26183,20 @@ function mangle_properties(ast, options) {
|
|
25948
26183
|
|
25949
26184
|
var names_to_mangle = new Set();
|
25950
26185
|
var unmangleable = new Set();
|
26186
|
+
var private_properties = new Set();
|
25951
26187
|
|
25952
26188
|
var keep_quoted_strict = options.keep_quoted === "strict";
|
25953
26189
|
|
25954
26190
|
// step 1: find candidates to mangle
|
25955
26191
|
ast.walk(new TreeWalker(function(node) {
|
25956
|
-
if (
|
26192
|
+
if (
|
26193
|
+
node instanceof AST_ClassPrivateProperty
|
26194
|
+
|| node instanceof AST_PrivateMethod
|
26195
|
+
) {
|
26196
|
+
private_properties.add(node.key.name);
|
26197
|
+
} else if (node instanceof AST_DotHash) {
|
26198
|
+
private_properties.add(node.property);
|
26199
|
+
} else if (node instanceof AST_ObjectKeyVal) {
|
25957
26200
|
if (typeof node.key == "string" &&
|
25958
26201
|
(!keep_quoted_strict || !node.quote)) {
|
25959
26202
|
add(node.key);
|
@@ -25990,7 +26233,14 @@ function mangle_properties(ast, options) {
|
|
25990
26233
|
|
25991
26234
|
// step 2: transform the tree, renaming properties
|
25992
26235
|
return ast.transform(new TreeTransformer(function(node) {
|
25993
|
-
if (
|
26236
|
+
if (
|
26237
|
+
node instanceof AST_ClassPrivateProperty
|
26238
|
+
|| node instanceof AST_PrivateMethod
|
26239
|
+
) {
|
26240
|
+
node.key.name = mangle_private(node.key.name);
|
26241
|
+
} else if (node instanceof AST_DotHash) {
|
26242
|
+
node.property = mangle_private(node.property);
|
26243
|
+
} else if (node instanceof AST_ObjectKeyVal) {
|
25994
26244
|
if (typeof node.key == "string" &&
|
25995
26245
|
(!keep_quoted_strict || !node.quote)) {
|
25996
26246
|
node.key = mangle(node.key);
|
@@ -26070,6 +26320,16 @@ function mangle_properties(ast, options) {
|
|
26070
26320
|
return mangled;
|
26071
26321
|
}
|
26072
26322
|
|
26323
|
+
function mangle_private(name) {
|
26324
|
+
let mangled = private_cache.get(name);
|
26325
|
+
if (!mangled) {
|
26326
|
+
mangled = base54(++cprivate);
|
26327
|
+
private_cache.set(name, mangled);
|
26328
|
+
}
|
26329
|
+
|
26330
|
+
return mangled;
|
26331
|
+
}
|
26332
|
+
|
26073
26333
|
function mangleStrings(node) {
|
26074
26334
|
return node.transform(new TreeTransformer(function(node) {
|
26075
26335
|
if (node instanceof AST_Sequence) {
|
@@ -26352,7 +26612,7 @@ async function run_cli({ program, packageJson, fs, path }) {
|
|
26352
26612
|
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
|
26353
26613
|
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
|
26354
26614
|
program.option("-f, --format [options]", "Format options.", parse_js());
|
26355
|
-
program.option("-b, --beautify [options]", "Alias for --format
|
26615
|
+
program.option("-b, --beautify [options]", "Alias for --format.", parse_js());
|
26356
26616
|
program.option("-o, --output <file>", "Output file (default STDOUT).");
|
26357
26617
|
program.option("--comments [filter]", "Preserve copyright comments in the output.");
|
26358
26618
|
program.option("--config-file <file>", "Read minify() options from JSON file.");
|
@@ -26403,19 +26663,9 @@ async function run_cli({ program, packageJson, fs, path }) {
|
|
26403
26663
|
else
|
26404
26664
|
options.ecma = ecma;
|
26405
26665
|
}
|
26406
|
-
if (program.
|
26407
|
-
|
26408
|
-
|
26409
|
-
}
|
26410
|
-
if (program.beautify) {
|
26411
|
-
options.format = typeof program.beautify == "object" ? program.beautify : {};
|
26412
|
-
if (!("beautify" in options.format)) {
|
26413
|
-
options.format.beautify = true;
|
26414
|
-
}
|
26415
|
-
}
|
26416
|
-
if (program.format) {
|
26417
|
-
options.format = typeof program.format == "object" ? program.format : {};
|
26418
|
-
}
|
26666
|
+
if (program.format || program.beautify) {
|
26667
|
+
const chosenOption = program.format || program.beautify;
|
26668
|
+
options.format = typeof chosenOption === "object" ? chosenOption : {};
|
26419
26669
|
}
|
26420
26670
|
if (program.comments) {
|
26421
26671
|
if (typeof options.format != "object") options.format = {};
|
@@ -26822,4 +27072,3 @@ exports._run_cli = run_cli;
|
|
26822
27072
|
exports.minify = minify;
|
26823
27073
|
|
26824
27074
|
})));
|
26825
|
-
//# sourceMappingURL=bundle.min.js.map
|