terser 5.16.1 → 5.16.3
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 +14 -0
- package/README.md +4 -4
- package/dist/bundle.min.js +372 -194
- package/lib/ast.js +4 -0
- package/lib/compress/common.js +3 -2
- package/lib/compress/inline.js +119 -114
- package/lib/compress/native-objects.js +22 -0
- package/lib/compress/reduce-vars.js +30 -11
- package/lib/compress/tighten-body.js +9 -2
- package/lib/minify.js +9 -6
- package/lib/mozilla-ast.js +83 -34
- package/lib/output.js +44 -12
- package/lib/parse.js +46 -12
- package/lib/scope.js +3 -1
- package/package.json +1 -1
- package/tools/terser.d.ts +1 -0
- package/bin/terser.mjs +0 -21
package/dist/bundle.min.js
CHANGED
@@ -2255,14 +2255,20 @@ function parse($TEXT, options) {
|
|
2255
2255
|
});
|
2256
2256
|
}
|
2257
2257
|
|
2258
|
+
/**
|
2259
|
+
* var
|
2260
|
+
* vardef1 = 2,
|
2261
|
+
* vardef2 = 3;
|
2262
|
+
*/
|
2258
2263
|
function vardefs(no_in, kind) {
|
2259
|
-
var
|
2264
|
+
var var_defs = [];
|
2260
2265
|
var def;
|
2261
2266
|
for (;;) {
|
2262
2267
|
var sym_type =
|
2263
2268
|
kind === "var" ? AST_SymbolVar :
|
2264
2269
|
kind === "const" ? AST_SymbolConst :
|
2265
2270
|
kind === "let" ? AST_SymbolLet : null;
|
2271
|
+
// var { a } = b
|
2266
2272
|
if (is("punc", "{") || is("punc", "[")) {
|
2267
2273
|
def = new AST_VarDef({
|
2268
2274
|
start: S.token,
|
@@ -2282,12 +2288,12 @@ function parse($TEXT, options) {
|
|
2282
2288
|
});
|
2283
2289
|
if (def.name.name == "import") croak("Unexpected token: import");
|
2284
2290
|
}
|
2285
|
-
|
2291
|
+
var_defs.push(def);
|
2286
2292
|
if (!is("punc", ","))
|
2287
2293
|
break;
|
2288
2294
|
next();
|
2289
2295
|
}
|
2290
|
-
return
|
2296
|
+
return var_defs;
|
2291
2297
|
}
|
2292
2298
|
|
2293
2299
|
var var_ = function(no_in) {
|
@@ -2954,9 +2960,10 @@ function parse($TEXT, options) {
|
|
2954
2960
|
}
|
2955
2961
|
|
2956
2962
|
function map_name(is_import) {
|
2957
|
-
function make_symbol(type) {
|
2963
|
+
function make_symbol(type, quote) {
|
2958
2964
|
return new type({
|
2959
2965
|
name: as_property_name(),
|
2966
|
+
quote: quote || undefined,
|
2960
2967
|
start: prev(),
|
2961
2968
|
end: prev()
|
2962
2969
|
});
|
@@ -2969,16 +2976,16 @@ function parse($TEXT, options) {
|
|
2969
2976
|
var name;
|
2970
2977
|
|
2971
2978
|
if (is_import) {
|
2972
|
-
foreign_name = make_symbol(foreign_type);
|
2979
|
+
foreign_name = make_symbol(foreign_type, start.quote);
|
2973
2980
|
} else {
|
2974
|
-
name = make_symbol(type);
|
2981
|
+
name = make_symbol(type, start.quote);
|
2975
2982
|
}
|
2976
2983
|
if (is("name", "as")) {
|
2977
2984
|
next(); // The "as" word
|
2978
2985
|
if (is_import) {
|
2979
2986
|
name = make_symbol(type);
|
2980
2987
|
} else {
|
2981
|
-
foreign_name = make_symbol(foreign_type);
|
2988
|
+
foreign_name = make_symbol(foreign_type, S.token.quote);
|
2982
2989
|
}
|
2983
2990
|
} else if (is_import) {
|
2984
2991
|
name = new type(foreign_name);
|
@@ -2994,20 +3001,26 @@ function parse($TEXT, options) {
|
|
2994
3001
|
});
|
2995
3002
|
}
|
2996
3003
|
|
2997
|
-
function map_nameAsterisk(is_import,
|
3004
|
+
function map_nameAsterisk(is_import, import_or_export_foreign_name) {
|
2998
3005
|
var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign;
|
2999
3006
|
var type = is_import ? AST_SymbolImport : AST_SymbolExport;
|
3000
3007
|
var start = S.token;
|
3001
|
-
var foreign_name;
|
3008
|
+
var name, foreign_name;
|
3002
3009
|
var end = prev();
|
3003
3010
|
|
3011
|
+
if (is_import) {
|
3012
|
+
name = import_or_export_foreign_name;
|
3013
|
+
} else {
|
3014
|
+
foreign_name = import_or_export_foreign_name;
|
3015
|
+
}
|
3016
|
+
|
3004
3017
|
name = name || new type({
|
3005
3018
|
start: start,
|
3006
3019
|
name: "*",
|
3007
3020
|
end: end,
|
3008
3021
|
});
|
3009
3022
|
|
3010
|
-
foreign_name = new foreign_type({
|
3023
|
+
foreign_name = foreign_name || new foreign_type({
|
3011
3024
|
start: start,
|
3012
3025
|
name: "*",
|
3013
3026
|
end: end,
|
@@ -3036,9 +3049,9 @@ function parse($TEXT, options) {
|
|
3036
3049
|
} else if (is("operator", "*")) {
|
3037
3050
|
var name;
|
3038
3051
|
next();
|
3039
|
-
if (
|
3052
|
+
if (is("name", "as")) {
|
3040
3053
|
next(); // The "as" word
|
3041
|
-
name =
|
3054
|
+
name = is_import ? as_symbol(AST_SymbolImport) : as_symbol_or_string(AST_SymbolExportForeign);
|
3042
3055
|
}
|
3043
3056
|
names = [map_nameAsterisk(is_import, name)];
|
3044
3057
|
}
|
@@ -3203,6 +3216,27 @@ function parse($TEXT, options) {
|
|
3203
3216
|
return sym;
|
3204
3217
|
}
|
3205
3218
|
|
3219
|
+
function as_symbol_or_string(type) {
|
3220
|
+
if (!is("name")) {
|
3221
|
+
if (!is("string")) {
|
3222
|
+
croak("Name or string expected");
|
3223
|
+
}
|
3224
|
+
var tok = S.token;
|
3225
|
+
var ret = new type({
|
3226
|
+
start : tok,
|
3227
|
+
end : tok,
|
3228
|
+
name : tok.value,
|
3229
|
+
quote : tok.quote
|
3230
|
+
});
|
3231
|
+
next();
|
3232
|
+
return ret;
|
3233
|
+
}
|
3234
|
+
var sym = _make_symbol(type);
|
3235
|
+
_verify_symbol(sym);
|
3236
|
+
next();
|
3237
|
+
return sym;
|
3238
|
+
}
|
3239
|
+
|
3206
3240
|
// Annotate AST_Call, AST_Lambda or AST_New with the special comments
|
3207
3241
|
function annotate(node) {
|
3208
3242
|
var start = node.start;
|
@@ -4565,6 +4599,7 @@ var AST_Jump = DEFNODE("Jump", null, function AST_Jump(props) {
|
|
4565
4599
|
$documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"
|
4566
4600
|
}, AST_Statement);
|
4567
4601
|
|
4602
|
+
/** Base class for “exits” (`return` and `throw`) */
|
4568
4603
|
var AST_Exit = DEFNODE("Exit", "value", function AST_Exit(props) {
|
4569
4604
|
if (props) {
|
4570
4605
|
this.value = props.value;
|
@@ -6159,6 +6194,7 @@ var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, function AST_
|
|
6159
6194
|
this.scope = props.scope;
|
6160
6195
|
this.name = props.name;
|
6161
6196
|
this.thedef = props.thedef;
|
6197
|
+
this.quote = props.quote;
|
6162
6198
|
this.start = props.start;
|
6163
6199
|
this.end = props.end;
|
6164
6200
|
}
|
@@ -6210,6 +6246,7 @@ var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(p
|
|
6210
6246
|
this.scope = props.scope;
|
6211
6247
|
this.name = props.name;
|
6212
6248
|
this.thedef = props.thedef;
|
6249
|
+
this.quote = props.quote;
|
6213
6250
|
this.start = props.start;
|
6214
6251
|
this.end = props.end;
|
6215
6252
|
}
|
@@ -6224,6 +6261,7 @@ var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, function AST_
|
|
6224
6261
|
this.scope = props.scope;
|
6225
6262
|
this.name = props.name;
|
6226
6263
|
this.thedef = props.thedef;
|
6264
|
+
this.quote = props.quote;
|
6227
6265
|
this.start = props.start;
|
6228
6266
|
this.end = props.end;
|
6229
6267
|
}
|
@@ -7369,24 +7407,11 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7369
7407
|
var imported_name = null;
|
7370
7408
|
var imported_names = null;
|
7371
7409
|
M.specifiers.forEach(function (specifier) {
|
7372
|
-
if (specifier.type === "ImportSpecifier") {
|
7410
|
+
if (specifier.type === "ImportSpecifier" || specifier.type === "ImportNamespaceSpecifier") {
|
7373
7411
|
if (!imported_names) { imported_names = []; }
|
7374
|
-
imported_names.push(
|
7375
|
-
start: my_start_token(specifier),
|
7376
|
-
end: my_end_token(specifier),
|
7377
|
-
foreign_name: from_moz(specifier.imported),
|
7378
|
-
name: from_moz(specifier.local)
|
7379
|
-
}));
|
7412
|
+
imported_names.push(from_moz(specifier));
|
7380
7413
|
} else if (specifier.type === "ImportDefaultSpecifier") {
|
7381
|
-
imported_name = from_moz(specifier
|
7382
|
-
} else if (specifier.type === "ImportNamespaceSpecifier") {
|
7383
|
-
if (!imported_names) { imported_names = []; }
|
7384
|
-
imported_names.push(new AST_NameMapping({
|
7385
|
-
start: my_start_token(specifier),
|
7386
|
-
end: my_end_token(specifier),
|
7387
|
-
foreign_name: new AST_SymbolImportForeign({ name: "*" }),
|
7388
|
-
name: from_moz(specifier.local)
|
7389
|
-
}));
|
7414
|
+
imported_name = from_moz(specifier);
|
7390
7415
|
}
|
7391
7416
|
});
|
7392
7417
|
return new AST_Import({
|
@@ -7399,14 +7424,39 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7399
7424
|
});
|
7400
7425
|
},
|
7401
7426
|
|
7427
|
+
ImportSpecifier: function(M) {
|
7428
|
+
return new AST_NameMapping({
|
7429
|
+
start: my_start_token(M),
|
7430
|
+
end: my_end_token(M),
|
7431
|
+
foreign_name: from_moz(M.imported),
|
7432
|
+
name: from_moz(M.local)
|
7433
|
+
});
|
7434
|
+
},
|
7435
|
+
|
7436
|
+
ImportDefaultSpecifier: function(M) {
|
7437
|
+
return from_moz(M.local);
|
7438
|
+
},
|
7439
|
+
|
7440
|
+
ImportNamespaceSpecifier: function(M) {
|
7441
|
+
return new AST_NameMapping({
|
7442
|
+
start: my_start_token(M),
|
7443
|
+
end: my_end_token(M),
|
7444
|
+
foreign_name: new AST_SymbolImportForeign({ name: "*" }),
|
7445
|
+
name: from_moz(M.local)
|
7446
|
+
});
|
7447
|
+
},
|
7448
|
+
|
7402
7449
|
ExportAllDeclaration: function(M) {
|
7450
|
+
var foreign_name = M.exported == null ?
|
7451
|
+
new AST_SymbolExportForeign({ name: "*" }) :
|
7452
|
+
from_moz(M.exported);
|
7403
7453
|
return new AST_Export({
|
7404
7454
|
start: my_start_token(M),
|
7405
7455
|
end: my_end_token(M),
|
7406
7456
|
exported_names: [
|
7407
7457
|
new AST_NameMapping({
|
7408
7458
|
name: new AST_SymbolExportForeign({ name: "*" }),
|
7409
|
-
foreign_name:
|
7459
|
+
foreign_name: foreign_name
|
7410
7460
|
})
|
7411
7461
|
],
|
7412
7462
|
module_name: from_moz(M.source),
|
@@ -7420,10 +7470,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7420
7470
|
end: my_end_token(M),
|
7421
7471
|
exported_definition: from_moz(M.declaration),
|
7422
7472
|
exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(function (specifier) {
|
7423
|
-
return
|
7424
|
-
foreign_name: from_moz(specifier.exported),
|
7425
|
-
name: from_moz(specifier.local)
|
7426
|
-
});
|
7473
|
+
return from_moz(specifier);
|
7427
7474
|
}) : null,
|
7428
7475
|
module_name: from_moz(M.source),
|
7429
7476
|
assert_clause: assert_clause_from_moz(M.assertions)
|
@@ -7439,6 +7486,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7439
7486
|
});
|
7440
7487
|
},
|
7441
7488
|
|
7489
|
+
ExportSpecifier: function(M) {
|
7490
|
+
return new AST_NameMapping({
|
7491
|
+
foreign_name: from_moz(M.exported),
|
7492
|
+
name: from_moz(M.local)
|
7493
|
+
});
|
7494
|
+
},
|
7495
|
+
|
7442
7496
|
Literal: function(M) {
|
7443
7497
|
var val = M.value, args = {
|
7444
7498
|
start : my_start_token(M),
|
@@ -7464,6 +7518,22 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
7464
7518
|
if (val === null) return new AST_Null(args);
|
7465
7519
|
switch (typeof val) {
|
7466
7520
|
case "string":
|
7521
|
+
args.quote = "\"";
|
7522
|
+
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
7523
|
+
if (p.type == "ImportSpecifier") {
|
7524
|
+
args.name = val;
|
7525
|
+
return new AST_SymbolImportForeign(args);
|
7526
|
+
} else if (p.type == "ExportSpecifier") {
|
7527
|
+
args.name = val;
|
7528
|
+
if (M == p.exported) {
|
7529
|
+
return new AST_SymbolExportForeign(args);
|
7530
|
+
} else {
|
7531
|
+
return new AST_SymbolExport(args);
|
7532
|
+
}
|
7533
|
+
} else if (p.type == "ExportAllDeclaration" && M == p.exported) {
|
7534
|
+
args.name = val;
|
7535
|
+
return new AST_SymbolExportForeign(args);
|
7536
|
+
}
|
7467
7537
|
args.value = val;
|
7468
7538
|
return new AST_String(args);
|
7469
7539
|
case "number":
|
@@ -8168,10 +8238,17 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8168
8238
|
|
8169
8239
|
def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
|
8170
8240
|
if (M.exported_names) {
|
8171
|
-
|
8241
|
+
var first_exported = M.exported_names[0];
|
8242
|
+
var first_exported_name = first_exported.name;
|
8243
|
+
if (first_exported_name.name === "*" && !first_exported_name.quote) {
|
8244
|
+
var foreign_name = first_exported.foreign_name;
|
8245
|
+
var exported = foreign_name.name === "*" && !foreign_name.quote
|
8246
|
+
? null
|
8247
|
+
: to_moz(foreign_name);
|
8172
8248
|
return {
|
8173
8249
|
type: "ExportAllDeclaration",
|
8174
8250
|
source: to_moz(M.module_name),
|
8251
|
+
exported: exported,
|
8175
8252
|
assertions: assert_clause_to_moz(M.assert_clause)
|
8176
8253
|
};
|
8177
8254
|
}
|
@@ -8203,19 +8280,22 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8203
8280
|
local: to_moz(M.imported_name)
|
8204
8281
|
});
|
8205
8282
|
}
|
8206
|
-
if (M.imported_names
|
8207
|
-
|
8208
|
-
|
8209
|
-
local: to_moz(M.imported_names[0].name)
|
8210
|
-
});
|
8211
|
-
} else if (M.imported_names) {
|
8212
|
-
M.imported_names.forEach(function(name_mapping) {
|
8283
|
+
if (M.imported_names) {
|
8284
|
+
var first_imported_foreign_name = M.imported_names[0].foreign_name;
|
8285
|
+
if (first_imported_foreign_name.name === "*" && !first_imported_foreign_name.quote) {
|
8213
8286
|
specifiers.push({
|
8214
|
-
type: "
|
8215
|
-
local: to_moz(
|
8216
|
-
imported: to_moz(name_mapping.foreign_name)
|
8287
|
+
type: "ImportNamespaceSpecifier",
|
8288
|
+
local: to_moz(M.imported_names[0].name)
|
8217
8289
|
});
|
8218
|
-
}
|
8290
|
+
} else {
|
8291
|
+
M.imported_names.forEach(function(name_mapping) {
|
8292
|
+
specifiers.push({
|
8293
|
+
type: "ImportSpecifier",
|
8294
|
+
local: to_moz(name_mapping.name),
|
8295
|
+
imported: to_moz(name_mapping.foreign_name)
|
8296
|
+
});
|
8297
|
+
});
|
8298
|
+
}
|
8219
8299
|
}
|
8220
8300
|
return {
|
8221
8301
|
type: "ImportDeclaration",
|
@@ -8479,7 +8559,14 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
|
|
8479
8559
|
});
|
8480
8560
|
|
8481
8561
|
def_to_moz(AST_Symbol, function To_Moz_Identifier(M, parent) {
|
8482
|
-
if (
|
8562
|
+
if (
|
8563
|
+
(M instanceof AST_SymbolMethod && parent.quote) ||
|
8564
|
+
((
|
8565
|
+
M instanceof AST_SymbolImportForeign ||
|
8566
|
+
M instanceof AST_SymbolExportForeign ||
|
8567
|
+
M instanceof AST_SymbolExport
|
8568
|
+
) && M.quote)
|
8569
|
+
) {
|
8483
8570
|
return {
|
8484
8571
|
type: "Literal",
|
8485
8572
|
value: M.name
|
@@ -9791,7 +9878,7 @@ function OutputStream(options) {
|
|
9791
9878
|
}
|
9792
9879
|
|
9793
9880
|
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
|
9794
|
-
|
9881
|
+
print_maybe_braced_body(this.body, output);
|
9795
9882
|
});
|
9796
9883
|
|
9797
9884
|
DEFPRINT(AST_Statement, function(self, output) {
|
@@ -10120,7 +10207,7 @@ function OutputStream(options) {
|
|
10120
10207
|
b = b.body;
|
10121
10208
|
} else break;
|
10122
10209
|
}
|
10123
|
-
|
10210
|
+
print_maybe_braced_body(self.body, output);
|
10124
10211
|
}
|
10125
10212
|
DEFPRINT(AST_If, function(self, output) {
|
10126
10213
|
output.print("if");
|
@@ -10137,7 +10224,7 @@ function OutputStream(options) {
|
|
10137
10224
|
if (self.alternative instanceof AST_If)
|
10138
10225
|
self.alternative.print(output);
|
10139
10226
|
else
|
10140
|
-
|
10227
|
+
print_maybe_braced_body(self.alternative, output);
|
10141
10228
|
} else {
|
10142
10229
|
self._do_print_body(output);
|
10143
10230
|
}
|
@@ -10247,7 +10334,9 @@ function OutputStream(options) {
|
|
10247
10334
|
output.space();
|
10248
10335
|
}
|
10249
10336
|
if (self.imported_names) {
|
10250
|
-
if (self.imported_names.length === 1 &&
|
10337
|
+
if (self.imported_names.length === 1 &&
|
10338
|
+
self.imported_names[0].foreign_name.name === "*" &&
|
10339
|
+
!self.imported_names[0].foreign_name.quote) {
|
10251
10340
|
self.imported_names[0].print(output);
|
10252
10341
|
} else {
|
10253
10342
|
output.print("{");
|
@@ -10281,14 +10370,31 @@ function OutputStream(options) {
|
|
10281
10370
|
DEFPRINT(AST_NameMapping, function(self, output) {
|
10282
10371
|
var is_import = output.parent() instanceof AST_Import;
|
10283
10372
|
var definition = self.name.definition();
|
10373
|
+
var foreign_name = self.foreign_name;
|
10284
10374
|
var names_are_different =
|
10285
10375
|
(definition && definition.mangled_name || self.name.name) !==
|
10286
|
-
|
10376
|
+
foreign_name.name;
|
10377
|
+
if (!names_are_different &&
|
10378
|
+
foreign_name.name === "*" &&
|
10379
|
+
foreign_name.quote != self.name.quote) {
|
10380
|
+
// export * as "*"
|
10381
|
+
names_are_different = true;
|
10382
|
+
}
|
10383
|
+
var foreign_name_is_name = foreign_name.quote == null;
|
10287
10384
|
if (names_are_different) {
|
10288
10385
|
if (is_import) {
|
10289
|
-
|
10386
|
+
if (foreign_name_is_name) {
|
10387
|
+
output.print(foreign_name.name);
|
10388
|
+
} else {
|
10389
|
+
output.print_string(foreign_name.name, foreign_name.quote);
|
10390
|
+
}
|
10290
10391
|
} else {
|
10291
|
-
self.name.
|
10392
|
+
if (self.name.quote == null) {
|
10393
|
+
self.name.print(output);
|
10394
|
+
} else {
|
10395
|
+
output.print_string(self.name.name, self.name.quote);
|
10396
|
+
}
|
10397
|
+
|
10292
10398
|
}
|
10293
10399
|
output.space();
|
10294
10400
|
output.print("as");
|
@@ -10296,10 +10402,18 @@ function OutputStream(options) {
|
|
10296
10402
|
if (is_import) {
|
10297
10403
|
self.name.print(output);
|
10298
10404
|
} else {
|
10299
|
-
|
10405
|
+
if (foreign_name_is_name) {
|
10406
|
+
output.print(foreign_name.name);
|
10407
|
+
} else {
|
10408
|
+
output.print_string(foreign_name.name, foreign_name.quote);
|
10409
|
+
}
|
10300
10410
|
}
|
10301
10411
|
} else {
|
10302
|
-
self.name.
|
10412
|
+
if (self.name.quote == null) {
|
10413
|
+
self.name.print(output);
|
10414
|
+
} else {
|
10415
|
+
output.print_string(self.name.name, self.name.quote);
|
10416
|
+
}
|
10303
10417
|
}
|
10304
10418
|
});
|
10305
10419
|
|
@@ -10311,8 +10425,10 @@ function OutputStream(options) {
|
|
10311
10425
|
output.space();
|
10312
10426
|
}
|
10313
10427
|
if (self.exported_names) {
|
10314
|
-
if (self.exported_names.length === 1 &&
|
10315
|
-
self.exported_names[0].
|
10428
|
+
if (self.exported_names.length === 1 &&
|
10429
|
+
self.exported_names[0].name.name === "*" &&
|
10430
|
+
!self.exported_names[0].name.quote) {
|
10431
|
+
self.exported_names[0].print(output);
|
10316
10432
|
} else {
|
10317
10433
|
output.print("{");
|
10318
10434
|
self.exported_names.forEach(function(name_export, i) {
|
@@ -10832,12 +10948,15 @@ function OutputStream(options) {
|
|
10832
10948
|
}
|
10833
10949
|
});
|
10834
10950
|
|
10835
|
-
|
10951
|
+
/** if, for, while, may or may not have braces surrounding its body */
|
10952
|
+
function print_maybe_braced_body(stat, output) {
|
10836
10953
|
if (output.option("braces")) {
|
10837
10954
|
make_block(stat, output);
|
10838
10955
|
} else {
|
10839
10956
|
if (!stat || stat instanceof AST_EmptyStatement)
|
10840
10957
|
output.force_semicolon();
|
10958
|
+
else if (stat instanceof AST_Let || stat instanceof AST_Const || stat instanceof AST_Class)
|
10959
|
+
make_block(stat, output);
|
10841
10960
|
else
|
10842
10961
|
stat.print(output);
|
10843
10962
|
}
|
@@ -11331,8 +11450,9 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
|
|
11331
11450
|
scope.init_scope_vars(parent_scope);
|
11332
11451
|
scope.uses_with = save_scope.uses_with;
|
11333
11452
|
scope.uses_eval = save_scope.uses_eval;
|
11453
|
+
|
11334
11454
|
if (options.safari10) {
|
11335
|
-
if (node instanceof AST_For || node instanceof AST_ForIn) {
|
11455
|
+
if (node instanceof AST_For || node instanceof AST_ForIn || node instanceof AST_ForOf) {
|
11336
11456
|
for_scopes.push(scope);
|
11337
11457
|
}
|
11338
11458
|
}
|
@@ -12828,9 +12948,10 @@ function is_func_expr(node) {
|
|
12828
12948
|
return node instanceof AST_Arrow || node instanceof AST_Function;
|
12829
12949
|
}
|
12830
12950
|
|
12951
|
+
/**
|
12952
|
+
* Used to determine whether the node can benefit from negation.
|
12953
|
+
* Not the case with arrow functions (you need an extra set of parens). */
|
12831
12954
|
function is_iife_call(node) {
|
12832
|
-
// Used to determine whether the node can benefit from negation.
|
12833
|
-
// Not the case with arrow functions (you need an extra set of parens).
|
12834
12955
|
if (node.TYPE != "Call") return false;
|
12835
12956
|
return node.expression instanceof AST_Function || is_iife_call(node.expression);
|
12836
12957
|
}
|
@@ -13010,6 +13131,9 @@ const object_methods = [
|
|
13010
13131
|
|
13011
13132
|
const is_pure_native_method = make_nested_lookup({
|
13012
13133
|
Array: [
|
13134
|
+
"at",
|
13135
|
+
"flat",
|
13136
|
+
"includes",
|
13013
13137
|
"indexOf",
|
13014
13138
|
"join",
|
13015
13139
|
"lastIndexOf",
|
@@ -13030,22 +13154,41 @@ const is_pure_native_method = make_nested_lookup({
|
|
13030
13154
|
...object_methods,
|
13031
13155
|
],
|
13032
13156
|
String: [
|
13157
|
+
"at",
|
13033
13158
|
"charAt",
|
13034
13159
|
"charCodeAt",
|
13160
|
+
"charPointAt",
|
13035
13161
|
"concat",
|
13162
|
+
"endsWith",
|
13163
|
+
"fromCharCode",
|
13164
|
+
"fromCodePoint",
|
13165
|
+
"includes",
|
13036
13166
|
"indexOf",
|
13037
13167
|
"italics",
|
13038
13168
|
"lastIndexOf",
|
13169
|
+
"localeCompare",
|
13039
13170
|
"match",
|
13171
|
+
"matchAll",
|
13172
|
+
"normalize",
|
13173
|
+
"padStart",
|
13174
|
+
"padEnd",
|
13175
|
+
"repeat",
|
13040
13176
|
"replace",
|
13177
|
+
"replaceAll",
|
13041
13178
|
"search",
|
13042
13179
|
"slice",
|
13043
13180
|
"split",
|
13181
|
+
"startsWith",
|
13044
13182
|
"substr",
|
13045
13183
|
"substring",
|
13184
|
+
"repeat",
|
13185
|
+
"toLocaleLowerCase",
|
13186
|
+
"toLocaleUpperCase",
|
13046
13187
|
"toLowerCase",
|
13047
13188
|
"toUpperCase",
|
13048
13189
|
"trim",
|
13190
|
+
"trimEnd",
|
13191
|
+
"trimStart",
|
13049
13192
|
...object_methods,
|
13050
13193
|
],
|
13051
13194
|
});
|
@@ -15209,15 +15352,17 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
15209
15352
|
|
15210
15353
|
***********************************************************************/
|
15211
15354
|
|
15212
|
-
|
15213
|
-
|
15214
|
-
|
15355
|
+
/**
|
15356
|
+
* Define the method AST_Node#reduce_vars, which goes through the AST in
|
15357
|
+
* execution order to perform basic flow analysis
|
15358
|
+
*/
|
15215
15359
|
function def_reduce_vars(node, func) {
|
15216
15360
|
node.DEFMETHOD("reduce_vars", func);
|
15217
15361
|
}
|
15218
15362
|
|
15219
15363
|
def_reduce_vars(AST_Node, noop);
|
15220
15364
|
|
15365
|
+
/** Clear definition properties */
|
15221
15366
|
function reset_def(compressor, def) {
|
15222
15367
|
def.assignments = 0;
|
15223
15368
|
def.chained = false;
|
@@ -15226,7 +15371,10 @@ function reset_def(compressor, def) {
|
|
15226
15371
|
def.recursive_refs = 0;
|
15227
15372
|
def.references = [];
|
15228
15373
|
def.single_use = undefined;
|
15229
|
-
if (
|
15374
|
+
if (
|
15375
|
+
def.scope.pinned()
|
15376
|
+
|| (def.orig[0] instanceof AST_SymbolFunarg && def.scope.uses_arguments)
|
15377
|
+
) {
|
15230
15378
|
def.fixed = false;
|
15231
15379
|
} else if (def.orig[0] instanceof AST_SymbolConst || !compressor.exposed(def)) {
|
15232
15380
|
def.fixed = def.init;
|
@@ -15548,15 +15696,23 @@ def_reduce_vars(AST_Default, function(tw, descend) {
|
|
15548
15696
|
|
15549
15697
|
function mark_lambda(tw, descend, compressor) {
|
15550
15698
|
clear_flag(this, INLINED);
|
15551
|
-
|
15552
|
-
|
15553
|
-
|
15554
|
-
|
15555
|
-
|
15556
|
-
|
15699
|
+
|
15700
|
+
// Sometimes we detach the lambda for safety, and instead of push()
|
15701
|
+
// we go to an entirely fresh lineage of safe_ids.
|
15702
|
+
let previous_safe_ids;
|
15703
|
+
if (this instanceof AST_Defun || this.uses_arguments || this.pinned()) {
|
15704
|
+
previous_safe_ids = tw.safe_ids;
|
15705
|
+
tw.safe_ids = Object.create(null);
|
15706
|
+
} else {
|
15707
|
+
push(tw);
|
15557
15708
|
}
|
15709
|
+
|
15710
|
+
reset_variables(tw, compressor, this);
|
15711
|
+
|
15558
15712
|
var iife;
|
15559
15713
|
if (!this.name
|
15714
|
+
&& !this.uses_arguments
|
15715
|
+
&& !this.pinned()
|
15560
15716
|
&& (iife = tw.parent()) instanceof AST_Call
|
15561
15717
|
&& iife.expression === this
|
15562
15718
|
&& !iife.args.some(arg => arg instanceof AST_Expansion)
|
@@ -15582,7 +15738,13 @@ function mark_lambda(tw, descend, compressor) {
|
|
15582
15738
|
});
|
15583
15739
|
}
|
15584
15740
|
descend();
|
15585
|
-
|
15741
|
+
|
15742
|
+
if (previous_safe_ids) {
|
15743
|
+
tw.safe_ids = previous_safe_ids;
|
15744
|
+
} else {
|
15745
|
+
pop(tw);
|
15746
|
+
}
|
15747
|
+
|
15586
15748
|
return true;
|
15587
15749
|
}
|
15588
15750
|
|
@@ -17085,14 +17247,21 @@ function tighten_body(statements, compressor) {
|
|
17085
17247
|
CHANGED = true;
|
17086
17248
|
stat.init = exprs.length ? make_sequence(stat.init, exprs) : null;
|
17087
17249
|
statements[++j] = stat;
|
17088
|
-
} else if (
|
17250
|
+
} else if (
|
17251
|
+
prev instanceof AST_Var
|
17252
|
+
&& (!stat.init || stat.init.TYPE == prev.TYPE)
|
17253
|
+
) {
|
17089
17254
|
if (stat.init) {
|
17090
17255
|
prev.definitions = prev.definitions.concat(stat.init.definitions);
|
17091
17256
|
}
|
17092
17257
|
stat.init = prev;
|
17093
17258
|
statements[j] = stat;
|
17094
17259
|
CHANGED = true;
|
17095
|
-
} else if (
|
17260
|
+
} else if (
|
17261
|
+
defs instanceof AST_Var
|
17262
|
+
&& stat.init instanceof AST_Var
|
17263
|
+
&& declarations_only(stat.init)
|
17264
|
+
) {
|
17096
17265
|
defs.definitions = defs.definitions.concat(stat.init.definitions);
|
17097
17266
|
stat.init = null;
|
17098
17267
|
statements[++j] = stat;
|
@@ -17184,6 +17353,13 @@ function tighten_body(statements, compressor) {
|
|
17184
17353
|
|
17185
17354
|
***********************************************************************/
|
17186
17355
|
|
17356
|
+
/**
|
17357
|
+
* Module that contains the inlining logic.
|
17358
|
+
*
|
17359
|
+
* @module
|
17360
|
+
*
|
17361
|
+
* The stars of the show are `inline_into_symbolref` and `inline_into_call`.
|
17362
|
+
*/
|
17187
17363
|
|
17188
17364
|
function within_array_or_object_literal(compressor) {
|
17189
17365
|
var node, level = 0;
|
@@ -17214,136 +17390,135 @@ function scope_encloses_variables_in_this_scope(scope, pulled_scope) {
|
|
17214
17390
|
|
17215
17391
|
function inline_into_symbolref(self, compressor) {
|
17216
17392
|
const parent = compressor.parent();
|
17217
|
-
|
17218
|
-
|
17219
|
-
|
17220
|
-
|
17221
|
-
|
17222
|
-
|
17223
|
-
|
17393
|
+
|
17394
|
+
const def = self.definition();
|
17395
|
+
const nearest_scope = compressor.find_scope();
|
17396
|
+
if (compressor.top_retain && def.global && compressor.top_retain(def)) {
|
17397
|
+
def.fixed = false;
|
17398
|
+
def.single_use = false;
|
17399
|
+
return self;
|
17400
|
+
}
|
17401
|
+
|
17402
|
+
let fixed = self.fixed_value();
|
17403
|
+
let single_use = def.single_use
|
17404
|
+
&& !(parent instanceof AST_Call
|
17405
|
+
&& (parent.is_callee_pure(compressor))
|
17406
|
+
|| has_annotation(parent, _NOINLINE))
|
17407
|
+
&& !(parent instanceof AST_Export
|
17408
|
+
&& fixed instanceof AST_Lambda
|
17409
|
+
&& fixed.name);
|
17410
|
+
|
17411
|
+
if (single_use && fixed instanceof AST_Node) {
|
17412
|
+
single_use =
|
17413
|
+
!fixed.has_side_effects(compressor)
|
17414
|
+
&& !fixed.may_throw(compressor);
|
17415
|
+
}
|
17416
|
+
|
17417
|
+
if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
|
17418
|
+
if (retain_top_func(fixed, compressor)) {
|
17419
|
+
single_use = false;
|
17420
|
+
} else if (def.scope !== self.scope
|
17421
|
+
&& (def.escaped == 1
|
17422
|
+
|| has_flag(fixed, INLINED)
|
17423
|
+
|| within_array_or_object_literal(compressor)
|
17424
|
+
|| !compressor.option("reduce_funcs"))) {
|
17425
|
+
single_use = false;
|
17426
|
+
} else if (is_recursive_ref(compressor, def)) {
|
17427
|
+
single_use = false;
|
17428
|
+
} else if (def.scope !== self.scope || def.orig[0] instanceof AST_SymbolFunarg) {
|
17429
|
+
single_use = fixed.is_constant_expression(self.scope);
|
17430
|
+
if (single_use == "f") {
|
17431
|
+
var scope = self.scope;
|
17432
|
+
do {
|
17433
|
+
if (scope instanceof AST_Defun || is_func_expr(scope)) {
|
17434
|
+
set_flag(scope, INLINED);
|
17435
|
+
}
|
17436
|
+
} while (scope = scope.parent_scope);
|
17437
|
+
}
|
17224
17438
|
}
|
17439
|
+
}
|
17225
17440
|
|
17226
|
-
|
17227
|
-
|
17228
|
-
|
17229
|
-
&& (
|
17230
|
-
|
17231
|
-
|
17232
|
-
&& fixed
|
17233
|
-
&& fixed.name);
|
17234
|
-
|
17235
|
-
|
17236
|
-
|
17237
|
-
|
17238
|
-
|
17239
|
-
|
17240
|
-
|
17241
|
-
if (
|
17242
|
-
|
17243
|
-
|
17244
|
-
|
17245
|
-
|
17246
|
-
|
17247
|
-
|
17248
|
-
|
17249
|
-
|
17250
|
-
|
17251
|
-
|
17252
|
-
|
17253
|
-
|
17254
|
-
|
17255
|
-
|
17256
|
-
|
17257
|
-
|
17258
|
-
|
17259
|
-
}
|
17260
|
-
} while (scope = scope.parent_scope);
|
17441
|
+
if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) {
|
17442
|
+
single_use =
|
17443
|
+
def.scope === self.scope
|
17444
|
+
&& !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
|
17445
|
+
|| parent instanceof AST_Call
|
17446
|
+
&& parent.expression === self
|
17447
|
+
&& !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
|
17448
|
+
&& !(fixed.name && fixed.name.definition().recursive_refs > 0);
|
17449
|
+
}
|
17450
|
+
|
17451
|
+
if (single_use && fixed) {
|
17452
|
+
if (fixed instanceof AST_DefClass) {
|
17453
|
+
set_flag(fixed, SQUEEZED);
|
17454
|
+
fixed = make_node(AST_ClassExpression, fixed, fixed);
|
17455
|
+
}
|
17456
|
+
if (fixed instanceof AST_Defun) {
|
17457
|
+
set_flag(fixed, SQUEEZED);
|
17458
|
+
fixed = make_node(AST_Function, fixed, fixed);
|
17459
|
+
}
|
17460
|
+
if (def.recursive_refs > 0 && fixed.name instanceof AST_SymbolDefun) {
|
17461
|
+
const defun_def = fixed.name.definition();
|
17462
|
+
let lambda_def = fixed.variables.get(fixed.name.name);
|
17463
|
+
let name = lambda_def && lambda_def.orig[0];
|
17464
|
+
if (!(name instanceof AST_SymbolLambda)) {
|
17465
|
+
name = make_node(AST_SymbolLambda, fixed.name, fixed.name);
|
17466
|
+
name.scope = fixed;
|
17467
|
+
fixed.name = name;
|
17468
|
+
lambda_def = fixed.def_function(name);
|
17469
|
+
}
|
17470
|
+
walk(fixed, node => {
|
17471
|
+
if (node instanceof AST_SymbolRef && node.definition() === defun_def) {
|
17472
|
+
node.thedef = lambda_def;
|
17473
|
+
lambda_def.references.push(node);
|
17261
17474
|
}
|
17262
|
-
}
|
17475
|
+
});
|
17263
17476
|
}
|
17477
|
+
if (
|
17478
|
+
(fixed instanceof AST_Lambda || fixed instanceof AST_Class)
|
17479
|
+
&& fixed.parent_scope !== nearest_scope
|
17480
|
+
) {
|
17481
|
+
fixed = fixed.clone(true, compressor.get_toplevel());
|
17264
17482
|
|
17265
|
-
|
17266
|
-
single_use =
|
17267
|
-
def.scope === self.scope
|
17268
|
-
&& !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
|
17269
|
-
|| parent instanceof AST_Call
|
17270
|
-
&& parent.expression === self
|
17271
|
-
&& !scope_encloses_variables_in_this_scope(nearest_scope, fixed)
|
17272
|
-
&& !(fixed.name && fixed.name.definition().recursive_refs > 0);
|
17483
|
+
nearest_scope.add_child_scope(fixed);
|
17273
17484
|
}
|
17485
|
+
return fixed.optimize(compressor);
|
17486
|
+
}
|
17274
17487
|
|
17275
|
-
|
17276
|
-
|
17277
|
-
|
17278
|
-
|
17279
|
-
|
17280
|
-
if (
|
17281
|
-
|
17282
|
-
|
17283
|
-
|
17284
|
-
|
17285
|
-
const defun_def = fixed.name.definition();
|
17286
|
-
let lambda_def = fixed.variables.get(fixed.name.name);
|
17287
|
-
let name = lambda_def && lambda_def.orig[0];
|
17288
|
-
if (!(name instanceof AST_SymbolLambda)) {
|
17289
|
-
name = make_node(AST_SymbolLambda, fixed.name, fixed.name);
|
17290
|
-
name.scope = fixed;
|
17291
|
-
fixed.name = name;
|
17292
|
-
lambda_def = fixed.def_function(name);
|
17293
|
-
}
|
17294
|
-
walk(fixed, node => {
|
17295
|
-
if (node instanceof AST_SymbolRef && node.definition() === defun_def) {
|
17296
|
-
node.thedef = lambda_def;
|
17297
|
-
lambda_def.references.push(node);
|
17298
|
-
}
|
17299
|
-
});
|
17488
|
+
// multiple uses
|
17489
|
+
if (fixed) {
|
17490
|
+
let replace;
|
17491
|
+
|
17492
|
+
if (fixed instanceof AST_This) {
|
17493
|
+
if (!(def.orig[0] instanceof AST_SymbolFunarg)
|
17494
|
+
&& def.references.every((ref) =>
|
17495
|
+
def.scope === ref.scope
|
17496
|
+
)) {
|
17497
|
+
replace = fixed;
|
17300
17498
|
}
|
17499
|
+
} else {
|
17500
|
+
var ev = fixed.evaluate(compressor);
|
17301
17501
|
if (
|
17302
|
-
|
17303
|
-
&&
|
17502
|
+
ev !== fixed
|
17503
|
+
&& (compressor.option("unsafe_regexp") || !(ev instanceof RegExp))
|
17304
17504
|
) {
|
17305
|
-
|
17306
|
-
|
17307
|
-
nearest_scope.add_child_scope(fixed);
|
17505
|
+
replace = make_node_from_constant(ev, fixed);
|
17308
17506
|
}
|
17309
|
-
return fixed.optimize(compressor);
|
17310
17507
|
}
|
17311
17508
|
|
17312
|
-
|
17313
|
-
|
17314
|
-
|
17509
|
+
if (replace) {
|
17510
|
+
const name_length = self.size(compressor);
|
17511
|
+
const replace_size = replace.size(compressor);
|
17315
17512
|
|
17316
|
-
|
17317
|
-
|
17318
|
-
|
17319
|
-
|
17320
|
-
)
|
17321
|
-
replace = fixed;
|
17322
|
-
}
|
17323
|
-
} else {
|
17324
|
-
var ev = fixed.evaluate(compressor);
|
17325
|
-
if (
|
17326
|
-
ev !== fixed
|
17327
|
-
&& (compressor.option("unsafe_regexp") || !(ev instanceof RegExp))
|
17328
|
-
) {
|
17329
|
-
replace = make_node_from_constant(ev, fixed);
|
17330
|
-
}
|
17513
|
+
let overhead = 0;
|
17514
|
+
if (compressor.option("unused") && !compressor.exposed(def)) {
|
17515
|
+
overhead =
|
17516
|
+
(name_length + 2 + replace_size) /
|
17517
|
+
(def.references.length - def.assignments);
|
17331
17518
|
}
|
17332
17519
|
|
17333
|
-
if (
|
17334
|
-
|
17335
|
-
const replace_size = replace.size(compressor);
|
17336
|
-
|
17337
|
-
let overhead = 0;
|
17338
|
-
if (compressor.option("unused") && !compressor.exposed(def)) {
|
17339
|
-
overhead =
|
17340
|
-
(name_length + 2 + replace_size) /
|
17341
|
-
(def.references.length - def.assignments);
|
17342
|
-
}
|
17343
|
-
|
17344
|
-
if (replace_size <= name_length + overhead) {
|
17345
|
-
return replace;
|
17346
|
-
}
|
17520
|
+
if (replace_size <= name_length + overhead) {
|
17521
|
+
return replace;
|
17347
17522
|
}
|
17348
17523
|
}
|
17349
17524
|
}
|
@@ -29543,12 +29718,15 @@ function mangle_properties(ast, options) {
|
|
29543
29718
|
}
|
29544
29719
|
}
|
29545
29720
|
|
29546
|
-
|
29547
|
-
|
29548
|
-
|
29549
|
-
var
|
29550
|
-
|
29551
|
-
|
29721
|
+
// to/from base64 functions
|
29722
|
+
// Prefer built-in Buffer, if available, then use hack
|
29723
|
+
// https://developer.mozilla.org/en-US/docs/Glossary/Base64#The_Unicode_Problem
|
29724
|
+
var to_ascii = typeof Buffer !== "undefined"
|
29725
|
+
? (b64) => Buffer.from(b64, "base64").toString()
|
29726
|
+
: (b64) => decodeURIComponent(escape(atob(b64)));
|
29727
|
+
var to_base64 = typeof Buffer !== "undefined"
|
29728
|
+
? (str) => Buffer.from(str).toString("base64")
|
29729
|
+
: (str) => btoa(unescape(encodeURIComponent(str)));
|
29552
29730
|
|
29553
29731
|
function read_source_map(code) {
|
29554
29732
|
var match = /(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;[\w=-]*)?;base64,([+/0-9A-Za-z]*=*)\s*$/.exec(code);
|