terser 5.40.0 → 5.42.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 +13 -0
- package/dist/bundle.min.js +445 -252
- package/lib/ast.js +10 -10
- package/lib/equivalent-to.js +6 -3
- package/lib/mozilla-ast.js +355 -197
- package/lib/output.js +10 -6
- package/lib/parse.js +65 -37
- package/package.json +1 -1
package/lib/output.js
CHANGED
@@ -1811,11 +1811,11 @@ function OutputStream(options) {
|
|
1811
1811
|
foreign_name.name;
|
1812
1812
|
if (!names_are_different &&
|
1813
1813
|
foreign_name.name === "*" &&
|
1814
|
-
foreign_name.quote != self.name.quote) {
|
1814
|
+
!!foreign_name.quote != !!self.name.quote) {
|
1815
1815
|
// export * as "*"
|
1816
1816
|
names_are_different = true;
|
1817
1817
|
}
|
1818
|
-
var foreign_name_is_name = foreign_name.quote
|
1818
|
+
var foreign_name_is_name = !foreign_name.quote;
|
1819
1819
|
if (names_are_different) {
|
1820
1820
|
if (is_import) {
|
1821
1821
|
if (foreign_name_is_name) {
|
@@ -1824,7 +1824,7 @@ function OutputStream(options) {
|
|
1824
1824
|
output.print_string(foreign_name.name, foreign_name.quote);
|
1825
1825
|
}
|
1826
1826
|
} else {
|
1827
|
-
if (self.name.quote
|
1827
|
+
if (!self.name.quote) {
|
1828
1828
|
self.name.print(output);
|
1829
1829
|
} else {
|
1830
1830
|
output.print_string(self.name.name, self.name.quote);
|
@@ -1844,7 +1844,7 @@ function OutputStream(options) {
|
|
1844
1844
|
}
|
1845
1845
|
}
|
1846
1846
|
} else {
|
1847
|
-
if (self.name.quote
|
1847
|
+
if (!self.name.quote) {
|
1848
1848
|
self.name.print(output);
|
1849
1849
|
} else {
|
1850
1850
|
output.print_string(self.name.name, self.name.quote);
|
@@ -2233,7 +2233,7 @@ function OutputStream(options) {
|
|
2233
2233
|
|
2234
2234
|
output.print("#");
|
2235
2235
|
|
2236
|
-
print_property_name(self.key.name,
|
2236
|
+
print_property_name(self.key.name, undefined, output);
|
2237
2237
|
|
2238
2238
|
if (self.value) {
|
2239
2239
|
output.print("=");
|
@@ -2361,7 +2361,11 @@ function OutputStream(options) {
|
|
2361
2361
|
}
|
2362
2362
|
});
|
2363
2363
|
DEFPRINT(AST_BigInt, function(self, output) {
|
2364
|
-
output.
|
2364
|
+
if (output.option("keep_numbers") && self.raw) {
|
2365
|
+
output.print(self.raw);
|
2366
|
+
} else {
|
2367
|
+
output.print(self.getValue() + "n");
|
2368
|
+
}
|
2365
2369
|
});
|
2366
2370
|
|
2367
2371
|
const r_slash_script = /(<\s*\/\s*script)/i;
|
package/lib/parse.js
CHANGED
@@ -108,7 +108,6 @@ import {
|
|
108
108
|
AST_NameMapping,
|
109
109
|
AST_New,
|
110
110
|
AST_NewTarget,
|
111
|
-
AST_Node,
|
112
111
|
AST_Null,
|
113
112
|
AST_Number,
|
114
113
|
AST_Object,
|
@@ -184,7 +183,6 @@ ALL_RESERVED_WORDS = makePredicate(ALL_RESERVED_WORDS);
|
|
184
183
|
|
185
184
|
var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));
|
186
185
|
|
187
|
-
var RE_NUM_LITERAL = /[0-9a-f]/i;
|
188
186
|
var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
|
189
187
|
var RE_OCT_NUMBER = /^0[0-7]+$/;
|
190
188
|
var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;
|
@@ -549,15 +547,16 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|
549
547
|
return after_e;
|
550
548
|
case (after_e = false, 46): // .
|
551
549
|
return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;
|
552
|
-
|
553
|
-
|
554
|
-
if (ch === "n") {
|
550
|
+
case 110: // n
|
555
551
|
is_big_int = true;
|
556
|
-
|
557
552
|
return true;
|
558
553
|
}
|
559
554
|
|
560
|
-
return
|
555
|
+
return (
|
556
|
+
code >= 48 && code <= 57 // 0-9
|
557
|
+
|| code >= 97 && code <= 102 // a-f
|
558
|
+
|| code >= 65 && code <= 70 // A-F
|
559
|
+
);
|
561
560
|
});
|
562
561
|
if (prefix) num = prefix + num;
|
563
562
|
|
@@ -574,7 +573,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|
574
573
|
}
|
575
574
|
num = num.replace(/_/g, "");
|
576
575
|
}
|
577
|
-
if (
|
576
|
+
if (is_big_int) {
|
578
577
|
const without_n = num.slice(0, -1);
|
579
578
|
const allow_e = RE_HEX_NUMBER.test(without_n);
|
580
579
|
const valid = parse_js_number(without_n, allow_e);
|
@@ -749,7 +748,24 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|
749
748
|
return next_token;
|
750
749
|
});
|
751
750
|
|
752
|
-
var read_name =
|
751
|
+
var read_name = function () {
|
752
|
+
let start = S.pos, end = start - 1, ch = "c";
|
753
|
+
|
754
|
+
while (
|
755
|
+
(ch = S.text.charAt(++end))
|
756
|
+
&& (ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z")
|
757
|
+
);
|
758
|
+
|
759
|
+
if (end > start + 1 && ch && ch !== "\\" && !is_identifier_char(ch)) {
|
760
|
+
S.pos += end - start;
|
761
|
+
S.col += end - start;
|
762
|
+
return S.text.slice(start, S.pos);
|
763
|
+
}
|
764
|
+
|
765
|
+
return read_name_hard();
|
766
|
+
};
|
767
|
+
|
768
|
+
var read_name_hard = with_eof_error("Unterminated identifier name", function() {
|
753
769
|
var name = [], ch, escaped = false;
|
754
770
|
var read_escaped_identifier_char = function() {
|
755
771
|
escaped = true;
|
@@ -1573,7 +1589,7 @@ function parse($TEXT, options) {
|
|
1573
1589
|
return new ctor({
|
1574
1590
|
start : args.start,
|
1575
1591
|
end : body.end,
|
1576
|
-
is_generator: is_generator,
|
1592
|
+
is_generator: is_generator || is_generator_property,
|
1577
1593
|
async : is_async,
|
1578
1594
|
name : name,
|
1579
1595
|
argnames: args,
|
@@ -2201,7 +2217,12 @@ function parse($TEXT, options) {
|
|
2201
2217
|
});
|
2202
2218
|
break;
|
2203
2219
|
case "big_int":
|
2204
|
-
ret = new AST_BigInt({
|
2220
|
+
ret = new AST_BigInt({
|
2221
|
+
start: tok,
|
2222
|
+
end: tok,
|
2223
|
+
value: tok.value,
|
2224
|
+
raw: LATEST_RAW,
|
2225
|
+
});
|
2205
2226
|
break;
|
2206
2227
|
case "string":
|
2207
2228
|
ret = new AST_String({
|
@@ -2465,7 +2486,7 @@ function parse($TEXT, options) {
|
|
2465
2486
|
|
2466
2487
|
// Check property and fetch value
|
2467
2488
|
if (!is("punc", ":")) {
|
2468
|
-
var concise =
|
2489
|
+
var concise = object_or_class_property(name, start);
|
2469
2490
|
if (concise) {
|
2470
2491
|
a.push(concise);
|
2471
2492
|
continue;
|
@@ -2500,7 +2521,7 @@ function parse($TEXT, options) {
|
|
2500
2521
|
const kv = new AST_ObjectKeyVal({
|
2501
2522
|
start: start,
|
2502
2523
|
quote: start.quote,
|
2503
|
-
key: name
|
2524
|
+
key: name,
|
2504
2525
|
value: value,
|
2505
2526
|
end: prev()
|
2506
2527
|
});
|
@@ -2511,7 +2532,7 @@ function parse($TEXT, options) {
|
|
2511
2532
|
});
|
2512
2533
|
|
2513
2534
|
function class_(KindOfClass, is_export_default) {
|
2514
|
-
var start, method, class_name, extends_,
|
2535
|
+
var start, method, class_name, extends_, properties = [];
|
2515
2536
|
|
2516
2537
|
S.input.push_directives_stack(); // Push directive stack, but not scope stack
|
2517
2538
|
S.input.add_directive("use strict");
|
@@ -2540,9 +2561,9 @@ function parse($TEXT, options) {
|
|
2540
2561
|
while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
|
2541
2562
|
while (!is("punc", "}")) {
|
2542
2563
|
start = S.token;
|
2543
|
-
method =
|
2564
|
+
method = object_or_class_property(as_property_name(), start, true);
|
2544
2565
|
if (!method) { unexpected(); }
|
2545
|
-
|
2566
|
+
properties.push(method);
|
2546
2567
|
while (is("punc", ";")) { next(); }
|
2547
2568
|
}
|
2548
2569
|
// mark in class feild,
|
@@ -2556,19 +2577,15 @@ function parse($TEXT, options) {
|
|
2556
2577
|
start: start,
|
2557
2578
|
name: class_name,
|
2558
2579
|
extends: extends_,
|
2559
|
-
properties:
|
2580
|
+
properties: properties,
|
2560
2581
|
end: prev(),
|
2561
2582
|
});
|
2562
2583
|
}
|
2563
2584
|
|
2564
|
-
function
|
2565
|
-
const get_symbol_ast = (name, SymbolClass
|
2566
|
-
if (typeof name === "string"
|
2567
|
-
return new SymbolClass({
|
2568
|
-
start,
|
2569
|
-
name: "" + name,
|
2570
|
-
end: prev()
|
2571
|
-
});
|
2585
|
+
function object_or_class_property(name, start, is_class) {
|
2586
|
+
const get_symbol_ast = (name, SymbolClass) => {
|
2587
|
+
if (typeof name === "string") {
|
2588
|
+
return new SymbolClass({ start, name, end: prev() });
|
2572
2589
|
} else if (name === null) {
|
2573
2590
|
unexpected();
|
2574
2591
|
}
|
@@ -2616,7 +2633,7 @@ function parse($TEXT, options) {
|
|
2616
2633
|
? AST_ObjectGetter
|
2617
2634
|
: AST_ObjectSetter;
|
2618
2635
|
|
2619
|
-
name = get_symbol_ast(name);
|
2636
|
+
name = get_symbol_ast(name, AST_SymbolMethod);
|
2620
2637
|
return annotate(new AccessorClass({
|
2621
2638
|
start,
|
2622
2639
|
static: is_static,
|
@@ -2633,7 +2650,7 @@ function parse($TEXT, options) {
|
|
2633
2650
|
return annotate(new AccessorClass({
|
2634
2651
|
start,
|
2635
2652
|
static: is_static,
|
2636
|
-
key: get_symbol_ast(name),
|
2653
|
+
key: get_symbol_ast(name, AST_SymbolMethod),
|
2637
2654
|
value: create_accessor(),
|
2638
2655
|
end: prev(),
|
2639
2656
|
}));
|
@@ -2641,7 +2658,7 @@ function parse($TEXT, options) {
|
|
2641
2658
|
}
|
2642
2659
|
|
2643
2660
|
if (is("punc", "(")) {
|
2644
|
-
name = get_symbol_ast(name);
|
2661
|
+
name = get_symbol_ast(name, AST_SymbolMethod);
|
2645
2662
|
const AST_MethodVariant = is_private
|
2646
2663
|
? AST_PrivateMethod
|
2647
2664
|
: AST_ConciseMethod;
|
@@ -2660,13 +2677,17 @@ function parse($TEXT, options) {
|
|
2660
2677
|
}
|
2661
2678
|
|
2662
2679
|
if (is_class) {
|
2663
|
-
const
|
2664
|
-
|
2665
|
-
|
2666
|
-
: undefined;
|
2680
|
+
const AST_SymbolVariant = is_private
|
2681
|
+
? AST_SymbolPrivateProperty
|
2682
|
+
: AST_SymbolClassProperty;
|
2667
2683
|
const AST_ClassPropertyVariant = is_private
|
2668
2684
|
? AST_ClassPrivateProperty
|
2669
2685
|
: AST_ClassProperty;
|
2686
|
+
|
2687
|
+
const key = get_symbol_ast(name, AST_SymbolVariant);
|
2688
|
+
const quote = key instanceof AST_SymbolClassProperty
|
2689
|
+
? property_token.quote
|
2690
|
+
: undefined;
|
2670
2691
|
if (is("operator", "=")) {
|
2671
2692
|
next();
|
2672
2693
|
return annotate(
|
@@ -2686,6 +2707,9 @@ function parse($TEXT, options) {
|
|
2686
2707
|
|| is("operator", "*")
|
2687
2708
|
|| is("punc", ";")
|
2688
2709
|
|| is("punc", "}")
|
2710
|
+
|| is("string")
|
2711
|
+
|| is("num")
|
2712
|
+
|| is("big_int")
|
2689
2713
|
) {
|
2690
2714
|
return annotate(
|
2691
2715
|
new AST_ClassPropertyVariant({
|
@@ -2810,10 +2834,12 @@ function parse($TEXT, options) {
|
|
2810
2834
|
} else {
|
2811
2835
|
foreign_name = make_symbol(foreign_type, S.token.quote);
|
2812
2836
|
}
|
2813
|
-
} else if (is_import) {
|
2814
|
-
name = new type(foreign_name);
|
2815
2837
|
} else {
|
2816
|
-
|
2838
|
+
if (is_import) {
|
2839
|
+
name = new type(foreign_name);
|
2840
|
+
} else {
|
2841
|
+
foreign_name = new foreign_type(name);
|
2842
|
+
}
|
2817
2843
|
}
|
2818
2844
|
|
2819
2845
|
return new AST_NameMapping({
|
@@ -2984,12 +3010,14 @@ function parse($TEXT, options) {
|
|
2984
3010
|
case "name":
|
2985
3011
|
case "privatename":
|
2986
3012
|
case "string":
|
2987
|
-
case "num":
|
2988
|
-
case "big_int":
|
2989
3013
|
case "keyword":
|
2990
3014
|
case "atom":
|
2991
3015
|
next();
|
2992
3016
|
return tmp.value;
|
3017
|
+
case "num":
|
3018
|
+
case "big_int":
|
3019
|
+
next();
|
3020
|
+
return "" + tmp.value;
|
2993
3021
|
default:
|
2994
3022
|
unexpected(tmp);
|
2995
3023
|
}
|