terser 5.6.0 → 5.7.2
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 +46 -0
- package/README.md +33 -21
- package/dist/bundle.min.js +4315 -3624
- package/lib/ast.js +15 -6
- package/lib/cli.js +0 -2
- package/lib/compress/common.js +296 -0
- package/lib/compress/compressor-flags.js +63 -0
- package/lib/compress/drop-side-effect-free.js +353 -0
- package/lib/compress/evaluate.js +458 -0
- package/lib/compress/index.js +261 -3626
- package/lib/compress/inference.js +934 -0
- package/lib/compress/native-objects.js +183 -0
- package/lib/compress/reduce-vars.js +675 -0
- package/lib/compress/tighten-body.js +1439 -0
- package/lib/equivalent-to.js +5 -0
- package/lib/minify.js +26 -9
- package/lib/output.js +17 -6
- package/lib/parse.js +76 -82
- package/lib/scope.js +12 -7
- package/lib/size.js +9 -2
- package/lib/utils/index.js +6 -6
- package/package.json +5 -4
- package/tools/domprops.js +1 -0
- package/tools/terser.d.ts +1 -0
- package/bin/terser.mjs +0 -21
package/lib/equivalent-to.js
CHANGED
@@ -18,6 +18,7 @@ import {
|
|
18
18
|
AST_Directive,
|
19
19
|
AST_Do,
|
20
20
|
AST_Dot,
|
21
|
+
AST_DotHash,
|
21
22
|
AST_EmptyStatement,
|
22
23
|
AST_Expansion,
|
23
24
|
AST_Export,
|
@@ -233,6 +234,10 @@ AST_Dot.prototype.shallow_cmp = mkshallow({
|
|
233
234
|
property: "eq"
|
234
235
|
});
|
235
236
|
|
237
|
+
AST_DotHash.prototype.shallow_cmp = mkshallow({
|
238
|
+
property: "eq"
|
239
|
+
});
|
240
|
+
|
236
241
|
AST_Unary.prototype.shallow_cmp = mkshallow({
|
237
242
|
operator: "eq"
|
238
243
|
});
|
package/lib/minify.js
CHANGED
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
map_to_object,
|
8
8
|
HOP,
|
9
9
|
} from "./utils/index.js";
|
10
|
-
import { AST_Toplevel } from "./ast.js";
|
10
|
+
import { AST_Toplevel, AST_Node } from "./ast.js";
|
11
11
|
import { parse } from "./parse.js";
|
12
12
|
import { OutputStream } from "./output.js";
|
13
13
|
import { Compressor } from "./compress/index.js";
|
@@ -77,6 +77,7 @@ async function minify(files, options) {
|
|
77
77
|
rename: undefined,
|
78
78
|
safari10: false,
|
79
79
|
sourceMap: false,
|
80
|
+
spidermonkey: false,
|
80
81
|
timings: false,
|
81
82
|
toplevel: false,
|
82
83
|
warnings: false,
|
@@ -148,20 +149,32 @@ async function minify(files, options) {
|
|
148
149
|
if (files instanceof AST_Toplevel) {
|
149
150
|
toplevel = files;
|
150
151
|
} else {
|
151
|
-
if (typeof files == "string") {
|
152
|
+
if (typeof files == "string" || (options.parse.spidermonkey && !Array.isArray(files))) {
|
152
153
|
files = [ files ];
|
153
154
|
}
|
154
155
|
options.parse = options.parse || {};
|
155
156
|
options.parse.toplevel = null;
|
156
|
-
|
157
|
-
|
158
|
-
options.parse.toplevel =
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
157
|
+
|
158
|
+
if (options.parse.spidermonkey) {
|
159
|
+
options.parse.toplevel = AST_Node.from_mozilla_ast(Object.keys(files).reduce(function(toplevel, name) {
|
160
|
+
if (!toplevel) return files[name];
|
161
|
+
toplevel.body = toplevel.body.concat(files[name].body);
|
162
|
+
return toplevel;
|
163
|
+
}, null));
|
164
|
+
} else {
|
165
|
+
delete options.parse.spidermonkey;
|
166
|
+
|
167
|
+
for (var name in files) if (HOP(files, name)) {
|
168
|
+
options.parse.filename = name;
|
169
|
+
options.parse.toplevel = parse(files[name], options.parse);
|
170
|
+
if (options.sourceMap && options.sourceMap.content == "inline") {
|
171
|
+
if (Object.keys(files).length > 1)
|
172
|
+
throw new Error("inline source map only works with singular input");
|
173
|
+
options.sourceMap.content = read_source_map(files[name]);
|
174
|
+
}
|
163
175
|
}
|
164
176
|
}
|
177
|
+
|
165
178
|
toplevel = options.parse.toplevel;
|
166
179
|
}
|
167
180
|
if (quoted_props && options.mangle.properties.keep_quoted !== "strict") {
|
@@ -203,6 +216,9 @@ async function minify(files, options) {
|
|
203
216
|
if (options.format.ast) {
|
204
217
|
result.ast = toplevel;
|
205
218
|
}
|
219
|
+
if (options.format.spidermonkey) {
|
220
|
+
result.ast = toplevel.to_mozilla_ast();
|
221
|
+
}
|
206
222
|
if (!HOP(options.format, "code") || options.format.code) {
|
207
223
|
if (options.sourceMap) {
|
208
224
|
options.format.source_map = await SourceMap({
|
@@ -220,6 +236,7 @@ async function minify(files, options) {
|
|
220
236
|
}
|
221
237
|
delete options.format.ast;
|
222
238
|
delete options.format.code;
|
239
|
+
delete options.format.spidermonkey;
|
223
240
|
var stream = OutputStream(options.format);
|
224
241
|
toplevel.print(stream);
|
225
242
|
result.code = stream.get();
|
package/lib/output.js
CHANGED
@@ -159,7 +159,7 @@ import {
|
|
159
159
|
is_basic_identifier_string,
|
160
160
|
is_identifier_string,
|
161
161
|
PRECEDENCE,
|
162
|
-
|
162
|
+
ALL_RESERVED_WORDS,
|
163
163
|
} from "./parse.js";
|
164
164
|
|
165
165
|
const EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
|
@@ -349,11 +349,15 @@ function OutputStream(options) {
|
|
349
349
|
var do_add_mapping = mappings ? function() {
|
350
350
|
mappings.forEach(function(mapping) {
|
351
351
|
try {
|
352
|
+
let name = !mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name;
|
353
|
+
if (name instanceof AST_Symbol) {
|
354
|
+
name = name.name;
|
355
|
+
}
|
352
356
|
options.source_map.add(
|
353
357
|
mapping.token.file,
|
354
358
|
mapping.line, mapping.col,
|
355
359
|
mapping.token.line, mapping.token.col,
|
356
|
-
|
360
|
+
is_basic_identifier_string(name) ? name : undefined
|
357
361
|
);
|
358
362
|
} catch(ex) {
|
359
363
|
// Ignore bad mapping
|
@@ -933,6 +937,7 @@ function OutputStream(options) {
|
|
933
937
|
var p = output.parent();
|
934
938
|
return p instanceof AST_PropAccess && p.expression === this
|
935
939
|
|| p instanceof AST_Call && p.expression === this
|
940
|
+
|| p instanceof AST_Binary && p.operator === "**" && p.left === this
|
936
941
|
|| output.option("safari10") && p instanceof AST_UnaryPrefix;
|
937
942
|
});
|
938
943
|
|
@@ -1712,7 +1717,11 @@ function OutputStream(options) {
|
|
1712
1717
|
// https://github.com/mishoo/UglifyJS2/issues/60
|
1713
1718
|
if (noin) {
|
1714
1719
|
parens = walk(node, node => {
|
1715
|
-
|
1720
|
+
// Don't go into scopes -- except arrow functions:
|
1721
|
+
// https://github.com/terser/terser/issues/1019#issuecomment-877642607
|
1722
|
+
if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) {
|
1723
|
+
return true;
|
1724
|
+
}
|
1716
1725
|
if (node instanceof AST_Binary && node.operator == "in") {
|
1717
1726
|
return walk_abort; // makes walk() return true
|
1718
1727
|
}
|
@@ -1782,7 +1791,7 @@ function OutputStream(options) {
|
|
1782
1791
|
var expr = self.expression;
|
1783
1792
|
expr.print(output);
|
1784
1793
|
var prop = self.property;
|
1785
|
-
var print_computed =
|
1794
|
+
var print_computed = ALL_RESERVED_WORDS.has(prop)
|
1786
1795
|
? output.option("ie8")
|
1787
1796
|
: !is_identifier_string(
|
1788
1797
|
prop,
|
@@ -1963,7 +1972,7 @@ function OutputStream(options) {
|
|
1963
1972
|
}
|
1964
1973
|
return output.print(make_num(key));
|
1965
1974
|
}
|
1966
|
-
var print_string =
|
1975
|
+
var print_string = ALL_RESERVED_WORDS.has(key)
|
1967
1976
|
? output.option("ie8")
|
1968
1977
|
: (
|
1969
1978
|
output.option("ecma") < 2015 || output.option("safari10")
|
@@ -1990,7 +1999,7 @@ function OutputStream(options) {
|
|
1990
1999
|
output.option("ecma") >= 2015 || output.option("safari10")
|
1991
2000
|
) &&
|
1992
2001
|
get_name(self.value) === self.key &&
|
1993
|
-
!
|
2002
|
+
!ALL_RESERVED_WORDS.has(self.key)
|
1994
2003
|
) {
|
1995
2004
|
print_property_name(self.key, self.quote, output);
|
1996
2005
|
|
@@ -2150,7 +2159,9 @@ function OutputStream(options) {
|
|
2150
2159
|
source = regexp_source_fix(source);
|
2151
2160
|
flags = flags ? sort_regexp_flags(flags) : "";
|
2152
2161
|
source = source.replace(r_slash_script, slash_script_replace);
|
2162
|
+
|
2153
2163
|
output.print(output.to_utf8(`/${source}/${flags}`));
|
2164
|
+
|
2154
2165
|
const parent = output.parent();
|
2155
2166
|
if (
|
2156
2167
|
parent instanceof AST_Binary
|
package/lib/parse.js
CHANGED
@@ -102,7 +102,6 @@ import {
|
|
102
102
|
AST_Label,
|
103
103
|
AST_LabeledStatement,
|
104
104
|
AST_LabelRef,
|
105
|
-
AST_Lambda,
|
106
105
|
AST_Let,
|
107
106
|
AST_NameMapping,
|
108
107
|
AST_New,
|
@@ -167,13 +166,15 @@ var LATEST_TEMPLATE_END = true;
|
|
167
166
|
|
168
167
|
var KEYWORDS = "break case catch class const continue debugger default delete do else export extends finally for function if in instanceof let new return switch throw try typeof var void while with";
|
169
168
|
var KEYWORDS_ATOM = "false null true";
|
170
|
-
var RESERVED_WORDS = "enum
|
169
|
+
var RESERVED_WORDS = "enum import super this " + KEYWORDS_ATOM + " " + KEYWORDS;
|
170
|
+
var ALL_RESERVED_WORDS = "implements interface package private protected public static " + RESERVED_WORDS;
|
171
171
|
var KEYWORDS_BEFORE_EXPRESSION = "return new delete throw else case yield await";
|
172
172
|
|
173
173
|
KEYWORDS = makePredicate(KEYWORDS);
|
174
174
|
RESERVED_WORDS = makePredicate(RESERVED_WORDS);
|
175
175
|
KEYWORDS_BEFORE_EXPRESSION = makePredicate(KEYWORDS_BEFORE_EXPRESSION);
|
176
176
|
KEYWORDS_ATOM = makePredicate(KEYWORDS_ATOM);
|
177
|
+
ALL_RESERVED_WORDS = makePredicate(ALL_RESERVED_WORDS);
|
177
178
|
|
178
179
|
var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));
|
179
180
|
|
@@ -1293,7 +1294,7 @@ function parse($TEXT, options) {
|
|
1293
1294
|
if (is_if_body) {
|
1294
1295
|
croak("classes are not allowed as the body of an if");
|
1295
1296
|
}
|
1296
|
-
return class_(AST_DefClass);
|
1297
|
+
return class_(AST_DefClass, is_export_default);
|
1297
1298
|
|
1298
1299
|
case "function":
|
1299
1300
|
next();
|
@@ -2488,7 +2489,7 @@ function parse($TEXT, options) {
|
|
2488
2489
|
return new AST_Object({ properties: a });
|
2489
2490
|
});
|
2490
2491
|
|
2491
|
-
function class_(KindOfClass) {
|
2492
|
+
function class_(KindOfClass, is_export_default) {
|
2492
2493
|
var start, method, class_name, extends_, a = [];
|
2493
2494
|
|
2494
2495
|
S.input.push_directives_stack(); // Push directive stack, but not scope stack
|
@@ -2499,7 +2500,11 @@ function parse($TEXT, options) {
|
|
2499
2500
|
}
|
2500
2501
|
|
2501
2502
|
if (KindOfClass === AST_DefClass && !class_name) {
|
2502
|
-
|
2503
|
+
if (is_export_default) {
|
2504
|
+
KindOfClass = AST_ClassExpression;
|
2505
|
+
} else {
|
2506
|
+
unexpected();
|
2507
|
+
}
|
2503
2508
|
}
|
2504
2509
|
|
2505
2510
|
if (S.token.value == "extends") {
|
@@ -2532,9 +2537,9 @@ function parse($TEXT, options) {
|
|
2532
2537
|
}
|
2533
2538
|
|
2534
2539
|
function concise_method_or_getset(name, start, is_class) {
|
2535
|
-
|
2540
|
+
const get_symbol_ast = (name, SymbolClass = AST_SymbolMethod) => {
|
2536
2541
|
if (typeof name === "string" || typeof name === "number") {
|
2537
|
-
return new
|
2542
|
+
return new SymbolClass({
|
2538
2543
|
start,
|
2539
2544
|
name: "" + name,
|
2540
2545
|
end: prev()
|
@@ -2544,47 +2549,71 @@ function parse($TEXT, options) {
|
|
2544
2549
|
}
|
2545
2550
|
return name;
|
2546
2551
|
};
|
2547
|
-
|
2548
|
-
|
2549
|
-
|
2550
|
-
|
2551
|
-
end: property_token,
|
2552
|
-
name: "" + name
|
2553
|
-
});
|
2554
|
-
} else if (name === null) {
|
2555
|
-
unexpected();
|
2556
|
-
}
|
2557
|
-
return name;
|
2558
|
-
};
|
2559
|
-
var privatename = start.type == "privatename";
|
2552
|
+
|
2553
|
+
const is_not_method_start = () =>
|
2554
|
+
!is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("operator", "=");
|
2555
|
+
|
2560
2556
|
var is_async = false;
|
2561
2557
|
var is_static = false;
|
2562
2558
|
var is_generator = false;
|
2563
|
-
var
|
2564
|
-
|
2559
|
+
var is_private = false;
|
2560
|
+
var accessor_type = null;
|
2561
|
+
|
2562
|
+
if (is_class && name === "static" && is_not_method_start()) {
|
2565
2563
|
is_static = true;
|
2566
|
-
property_token = S.token;
|
2567
|
-
privatename = property_token.type == "privatename";
|
2568
2564
|
name = as_property_name();
|
2569
2565
|
}
|
2570
|
-
if (name === "async" &&
|
2566
|
+
if (name === "async" && is_not_method_start()) {
|
2571
2567
|
is_async = true;
|
2572
|
-
property_token = S.token;
|
2573
|
-
privatename = property_token.type == "privatename";
|
2574
2568
|
name = as_property_name();
|
2575
2569
|
}
|
2576
|
-
if (
|
2570
|
+
if (prev().type === "operator" && prev().value === "*") {
|
2577
2571
|
is_generator = true;
|
2578
|
-
property_token = S.token;
|
2579
|
-
privatename = property_token.type == "privatename";
|
2580
2572
|
name = as_property_name();
|
2581
|
-
|
2582
|
-
|
2573
|
+
}
|
2574
|
+
if ((name === "get" || name === "set") && is_not_method_start()) {
|
2575
|
+
accessor_type = name;
|
2576
|
+
name = as_property_name();
|
2577
|
+
}
|
2578
|
+
if (prev().type === "privatename") {
|
2579
|
+
is_private = true;
|
2580
|
+
}
|
2581
|
+
|
2582
|
+
const property_token = prev();
|
2583
|
+
|
2584
|
+
if (accessor_type != null) {
|
2585
|
+
if (!is_private) {
|
2586
|
+
const AccessorClass = accessor_type === "get"
|
2587
|
+
? AST_ObjectGetter
|
2588
|
+
: AST_ObjectSetter;
|
2589
|
+
|
2590
|
+
name = get_symbol_ast(name);
|
2591
|
+
return new AccessorClass({
|
2592
|
+
start,
|
2593
|
+
static: is_static,
|
2594
|
+
key: name,
|
2595
|
+
quote: name instanceof AST_SymbolMethod ? property_token.quote : undefined,
|
2596
|
+
value: create_accessor(),
|
2597
|
+
end: prev()
|
2598
|
+
});
|
2599
|
+
} else {
|
2600
|
+
const AccessorClass = accessor_type === "get"
|
2601
|
+
? AST_PrivateGetter
|
2602
|
+
: AST_PrivateSetter;
|
2603
|
+
|
2604
|
+
return new AccessorClass({
|
2605
|
+
start,
|
2606
|
+
static: is_static,
|
2607
|
+
key: get_symbol_ast(name),
|
2608
|
+
value: create_accessor(),
|
2609
|
+
end: prev(),
|
2610
|
+
});
|
2583
2611
|
}
|
2584
2612
|
}
|
2613
|
+
|
2585
2614
|
if (is("punc", "(")) {
|
2586
|
-
name =
|
2587
|
-
const AST_MethodVariant =
|
2615
|
+
name = get_symbol_ast(name);
|
2616
|
+
const AST_MethodVariant = is_private
|
2588
2617
|
? AST_PrivateMethod
|
2589
2618
|
: AST_ConciseMethod;
|
2590
2619
|
var node = new AST_MethodVariant({
|
@@ -2600,57 +2629,13 @@ function parse($TEXT, options) {
|
|
2600
2629
|
});
|
2601
2630
|
return node;
|
2602
2631
|
}
|
2603
|
-
const setter_token = S.token;
|
2604
|
-
if ((name === "get" || name === "set") && setter_token.type === "privatename") {
|
2605
|
-
next();
|
2606
|
-
|
2607
|
-
const AST_AccessorVariant =
|
2608
|
-
name === "get"
|
2609
|
-
? AST_PrivateGetter
|
2610
|
-
: AST_PrivateSetter;
|
2611
|
-
|
2612
|
-
return new AST_AccessorVariant({
|
2613
|
-
start,
|
2614
|
-
static: is_static,
|
2615
|
-
key: get_method_name_ast(setter_token.value, start),
|
2616
|
-
value: create_accessor(),
|
2617
|
-
end: prev(),
|
2618
|
-
});
|
2619
|
-
}
|
2620
2632
|
|
2621
|
-
if (name == "get") {
|
2622
|
-
if (!is("punc") || is("punc", "[")) {
|
2623
|
-
name = get_method_name_ast(as_property_name(), start);
|
2624
|
-
return new AST_ObjectGetter({
|
2625
|
-
start : start,
|
2626
|
-
static: is_static,
|
2627
|
-
key : name,
|
2628
|
-
quote : name instanceof AST_SymbolMethod ?
|
2629
|
-
setter_token.quote : undefined,
|
2630
|
-
value : create_accessor(),
|
2631
|
-
end : prev()
|
2632
|
-
});
|
2633
|
-
}
|
2634
|
-
} else if (name == "set") {
|
2635
|
-
if (!is("punc") || is("punc", "[")) {
|
2636
|
-
name = get_method_name_ast(as_property_name(), start);
|
2637
|
-
return new AST_ObjectSetter({
|
2638
|
-
start : start,
|
2639
|
-
static: is_static,
|
2640
|
-
key : name,
|
2641
|
-
quote : name instanceof AST_SymbolMethod ?
|
2642
|
-
setter_token.quote : undefined,
|
2643
|
-
value : create_accessor(),
|
2644
|
-
end : prev()
|
2645
|
-
});
|
2646
|
-
}
|
2647
|
-
}
|
2648
2633
|
if (is_class) {
|
2649
|
-
const key =
|
2634
|
+
const key = get_symbol_ast(name, AST_SymbolClassProperty);
|
2650
2635
|
const quote = key instanceof AST_SymbolClassProperty
|
2651
2636
|
? property_token.quote
|
2652
2637
|
: undefined;
|
2653
|
-
const AST_ClassPropertyVariant =
|
2638
|
+
const AST_ClassPropertyVariant = is_private
|
2654
2639
|
? AST_ClassPrivateProperty
|
2655
2640
|
: AST_ClassProperty;
|
2656
2641
|
if (is("operator", "=")) {
|
@@ -2872,8 +2857,17 @@ function parse($TEXT, options) {
|
|
2872
2857
|
semicolon();
|
2873
2858
|
} else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {
|
2874
2859
|
unexpected(node.start);
|
2875
|
-
} else if (
|
2860
|
+
} else if (
|
2861
|
+
node instanceof AST_Definitions
|
2862
|
+
|| node instanceof AST_Defun
|
2863
|
+
|| node instanceof AST_DefClass
|
2864
|
+
) {
|
2876
2865
|
exported_definition = node;
|
2866
|
+
} else if (
|
2867
|
+
node instanceof AST_ClassExpression
|
2868
|
+
|| node instanceof AST_Function
|
2869
|
+
) {
|
2870
|
+
exported_value = node;
|
2877
2871
|
} else if (node instanceof AST_SimpleStatement) {
|
2878
2872
|
exported_value = node.body;
|
2879
2873
|
} else {
|
@@ -3347,6 +3341,6 @@ export {
|
|
3347
3341
|
JS_Parse_Error,
|
3348
3342
|
parse,
|
3349
3343
|
PRECEDENCE,
|
3350
|
-
|
3344
|
+
ALL_RESERVED_WORDS,
|
3351
3345
|
tokenizer,
|
3352
3346
|
};
|
package/lib/scope.js
CHANGED
@@ -107,7 +107,7 @@ import {
|
|
107
107
|
walk
|
108
108
|
} from "./ast.js";
|
109
109
|
import {
|
110
|
-
|
110
|
+
ALL_RESERVED_WORDS,
|
111
111
|
js_error,
|
112
112
|
} from "./parse.js";
|
113
113
|
|
@@ -299,7 +299,14 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
|
|
299
299
|
// scope when we encounter the AST_Defun node (which is
|
300
300
|
// instanceof AST_Scope) but we get to the symbol a bit
|
301
301
|
// later.
|
302
|
-
|
302
|
+
const closest_scope = defun.parent_scope;
|
303
|
+
|
304
|
+
// In strict mode, function definitions are block-scoped
|
305
|
+
node.scope = tw.directives["use strict"]
|
306
|
+
? closest_scope
|
307
|
+
: closest_scope.get_defun_scope();
|
308
|
+
|
309
|
+
mark_export(node.scope.def_function(node, defun), 1);
|
303
310
|
} else if (node instanceof AST_SymbolClass) {
|
304
311
|
mark_export(defun.def_variable(node, defun), 1);
|
305
312
|
} else if (node instanceof AST_SymbolImport) {
|
@@ -478,7 +485,6 @@ AST_Toplevel.DEFMETHOD("def_global", function(node) {
|
|
478
485
|
|
479
486
|
AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) {
|
480
487
|
this.variables = new Map(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
|
481
|
-
this.functions = new Map(); // map name to AST_SymbolDefun (functions defined in this scope)
|
482
488
|
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
|
483
489
|
this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
|
484
490
|
this.parent_scope = parent_scope; // the parent scope
|
@@ -641,7 +647,6 @@ AST_Scope.DEFMETHOD("find_variable", function(name) {
|
|
641
647
|
AST_Scope.DEFMETHOD("def_function", function(symbol, init) {
|
642
648
|
var def = this.def_variable(symbol, init);
|
643
649
|
if (!def.init || def.init instanceof AST_Defun) def.init = init;
|
644
|
-
this.functions.set(symbol.name, def);
|
645
650
|
return def;
|
646
651
|
});
|
647
652
|
|
@@ -664,7 +669,7 @@ function next_mangled(scope, options) {
|
|
664
669
|
var ext = scope.enclosed;
|
665
670
|
out: while (true) {
|
666
671
|
var m = base54(++scope.cname);
|
667
|
-
if (
|
672
|
+
if (ALL_RESERVED_WORDS.has(m)) continue; // skip over "do"
|
668
673
|
|
669
674
|
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
|
670
675
|
// shadow a name reserved from mangling.
|
@@ -812,7 +817,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|
812
817
|
let name;
|
813
818
|
do {
|
814
819
|
name = base54(++lname);
|
815
|
-
} while (
|
820
|
+
} while (ALL_RESERVED_WORDS.has(name));
|
816
821
|
node.mangled_name = name;
|
817
822
|
return true;
|
818
823
|
}
|
@@ -888,7 +893,7 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
|
888
893
|
var name;
|
889
894
|
do {
|
890
895
|
name = base54(cname++);
|
891
|
-
} while (avoid.has(name) ||
|
896
|
+
} while (avoid.has(name) || ALL_RESERVED_WORDS.has(name));
|
892
897
|
return name;
|
893
898
|
}
|
894
899
|
|
package/lib/size.js
CHANGED
@@ -92,6 +92,12 @@ AST_Node.prototype.size = function (compressor, stack) {
|
|
92
92
|
let size = 0;
|
93
93
|
walk_parent(this, (node, info) => {
|
94
94
|
size += node._size(info);
|
95
|
+
|
96
|
+
// Braceless arrow functions have fake "return" statements
|
97
|
+
if (node instanceof AST_Arrow && node.is_braceless()) {
|
98
|
+
size += node.body[0].value._size(info);
|
99
|
+
return true;
|
100
|
+
}
|
95
101
|
}, stack || (compressor && compressor.stack));
|
96
102
|
|
97
103
|
// just to save a bit of memory
|
@@ -136,7 +142,6 @@ AST_With.prototype._size = () => 6;
|
|
136
142
|
|
137
143
|
AST_Expansion.prototype._size = () => 3;
|
138
144
|
|
139
|
-
/*#__INLINE__*/
|
140
145
|
const lambda_modifiers = func =>
|
141
146
|
(func.is_generator ? 1 : 0) + (func.async ? 6 : 0);
|
142
147
|
|
@@ -165,7 +170,9 @@ AST_Arrow.prototype._size = function () {
|
|
165
170
|
args_and_arrow += 2;
|
166
171
|
}
|
167
172
|
|
168
|
-
|
173
|
+
const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2;
|
174
|
+
|
175
|
+
return lambda_modifiers(this) + args_and_arrow + body_overhead;
|
169
176
|
};
|
170
177
|
|
171
178
|
AST_Destructuring.prototype._size = () => 2;
|
package/lib/utils/index.js
CHANGED
@@ -64,10 +64,8 @@ class DefaultsError extends Error {
|
|
64
64
|
function defaults(args, defs, croak) {
|
65
65
|
if (args === true) {
|
66
66
|
args = {};
|
67
|
-
}
|
68
|
-
|
69
|
-
if (args != null && typeof args === "object") {
|
70
|
-
args = Object.assign({}, args);
|
67
|
+
} else if (args != null && typeof args === "object") {
|
68
|
+
args = {...args};
|
71
69
|
}
|
72
70
|
|
73
71
|
const ret = args || {};
|
@@ -196,7 +194,7 @@ function mergeSort(array, cmp) {
|
|
196
194
|
function makePredicate(words) {
|
197
195
|
if (!Array.isArray(words)) words = words.split(" ");
|
198
196
|
|
199
|
-
return new Set(words);
|
197
|
+
return new Set(words.sort());
|
200
198
|
}
|
201
199
|
|
202
200
|
function map_add(map, key, value) {
|
@@ -235,6 +233,7 @@ function keep_name(keep_setting, name) {
|
|
235
233
|
}
|
236
234
|
|
237
235
|
var lineTerminatorEscape = {
|
236
|
+
"\0": "0",
|
238
237
|
"\n": "n",
|
239
238
|
"\r": "r",
|
240
239
|
"\u2028": "u2028",
|
@@ -242,7 +241,8 @@ var lineTerminatorEscape = {
|
|
242
241
|
};
|
243
242
|
function regexp_source_fix(source) {
|
244
243
|
// V8 does not escape line terminators in regexp patterns in node 12
|
245
|
-
|
244
|
+
// We'll also remove literal \0
|
245
|
+
return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) {
|
246
246
|
var escaped = source[offset - 1] == "\\"
|
247
247
|
&& (source[offset - 2] != "\\"
|
248
248
|
|| /(?:^|[^\\])(?:\\{2})*$/.test(source.slice(0, offset - 1)));
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"homepage": "https://terser.org",
|
5
5
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
6
6
|
"license": "BSD-2-Clause",
|
7
|
-
"version": "5.
|
7
|
+
"version": "5.7.2",
|
8
8
|
"engines": {
|
9
9
|
"node": ">=10"
|
10
10
|
},
|
@@ -24,7 +24,8 @@
|
|
24
24
|
"./dist/bundle.min.js"
|
25
25
|
],
|
26
26
|
"./package": "./package.json",
|
27
|
-
"./package.json": "./package.json"
|
27
|
+
"./package.json": "./package.json",
|
28
|
+
"./bin/terser": "./bin/terser"
|
28
29
|
},
|
29
30
|
"types": "tools/terser.d.ts",
|
30
31
|
"bin": {
|
@@ -92,7 +93,7 @@
|
|
92
93
|
"eslintConfig": {
|
93
94
|
"parserOptions": {
|
94
95
|
"sourceType": "module",
|
95
|
-
"ecmaVersion":
|
96
|
+
"ecmaVersion": 2020
|
96
97
|
},
|
97
98
|
"env": {
|
98
99
|
"node": true,
|
@@ -124,7 +125,7 @@
|
|
124
125
|
"no-unused-vars": [
|
125
126
|
"error",
|
126
127
|
{
|
127
|
-
"varsIgnorePattern": "^_
|
128
|
+
"varsIgnorePattern": "^_"
|
128
129
|
}
|
129
130
|
],
|
130
131
|
"no-tabs": "error",
|
package/tools/domprops.js
CHANGED
package/tools/terser.d.ts
CHANGED
package/bin/terser.mjs
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
"use strict";
|
4
|
-
|
5
|
-
import "../tools/exit.cjs";
|
6
|
-
|
7
|
-
import fs from "fs"
|
8
|
-
import path from "path"
|
9
|
-
import program from "commander"
|
10
|
-
|
11
|
-
import { run_cli } from "../lib/cli.js"
|
12
|
-
|
13
|
-
const packageJson = {
|
14
|
-
name: "terser",
|
15
|
-
version: "experimental module CLI"
|
16
|
-
}
|
17
|
-
|
18
|
-
run_cli({ program, packageJson, fs, path }).catch((error) => {
|
19
|
-
console.error(error);
|
20
|
-
process.exitCode = 1;
|
21
|
-
});
|