terser 5.16.0 → 5.16.1
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 +8 -0
- package/dist/bundle.min.js +3098 -3044
- package/lib/ast.js +3 -2
- package/lib/compress/drop-unused.js +482 -0
- package/lib/compress/evaluate.js +7 -0
- package/lib/compress/index.js +5 -392
- package/lib/compress/inference.js +1 -2
- package/lib/compress/inline.js +1 -19
- package/lib/compress/tighten-body.js +29 -28
- package/lib/parse.js +2 -1
- package/lib/scope.js +30 -8
- package/lib/size.js +6 -8
- package/package.json +1 -1
package/lib/parse.js
CHANGED
@@ -2548,6 +2548,7 @@ function parse($TEXT, options) {
|
|
2548
2548
|
|
2549
2549
|
expect("{");
|
2550
2550
|
// mark in class feild,
|
2551
|
+
const save_in_class = S.in_class;
|
2551
2552
|
S.in_class = true;
|
2552
2553
|
while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
|
2553
2554
|
while (!is("punc", "}")) {
|
@@ -2558,7 +2559,7 @@ function parse($TEXT, options) {
|
|
2558
2559
|
while (is("punc", ";")) { next(); }
|
2559
2560
|
}
|
2560
2561
|
// mark in class feild,
|
2561
|
-
S.in_class =
|
2562
|
+
S.in_class = save_in_class;
|
2562
2563
|
|
2563
2564
|
S.input.pop_directives_stack();
|
2564
2565
|
|
package/lib/scope.js
CHANGED
@@ -104,7 +104,8 @@ import {
|
|
104
104
|
AST_VarDef,
|
105
105
|
AST_With,
|
106
106
|
TreeWalker,
|
107
|
-
walk
|
107
|
+
walk,
|
108
|
+
walk_abort
|
108
109
|
} from "./ast.js";
|
109
110
|
import {
|
110
111
|
ALL_RESERVED_WORDS,
|
@@ -418,7 +419,7 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
|
|
418
419
|
sym = toplevel.def_global(node);
|
419
420
|
if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE;
|
420
421
|
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
|
421
|
-
sym.scope.uses_arguments = true;
|
422
|
+
sym.scope.get_defun_scope().uses_arguments = true;
|
422
423
|
}
|
423
424
|
node.thedef = sym;
|
424
425
|
node.reference();
|
@@ -520,7 +521,25 @@ AST_Scope.DEFMETHOD("add_child_scope", function (scope) {
|
|
520
521
|
|
521
522
|
scope.parent_scope = this;
|
522
523
|
|
523
|
-
//
|
524
|
+
// Propagate to this.uses_arguments from arrow functions
|
525
|
+
if ((scope instanceof AST_Arrow) && !this.uses_arguments) {
|
526
|
+
this.uses_arguments = walk(scope, node => {
|
527
|
+
if (
|
528
|
+
node instanceof AST_SymbolRef
|
529
|
+
&& node.scope instanceof AST_Lambda
|
530
|
+
&& node.name === "arguments"
|
531
|
+
) {
|
532
|
+
return walk_abort;
|
533
|
+
}
|
534
|
+
|
535
|
+
if (node instanceof AST_Lambda && !(node instanceof AST_Arrow)) {
|
536
|
+
return true;
|
537
|
+
}
|
538
|
+
});
|
539
|
+
}
|
540
|
+
|
541
|
+
this.uses_with = this.uses_with || scope.uses_with;
|
542
|
+
this.uses_eval = this.uses_eval || scope.uses_eval;
|
524
543
|
|
525
544
|
const scope_ancestry = (() => {
|
526
545
|
const ancestry = [];
|
@@ -756,7 +775,10 @@ AST_Symbol.DEFMETHOD("global", function() {
|
|
756
775
|
return this.thedef.global;
|
757
776
|
});
|
758
777
|
|
759
|
-
|
778
|
+
/**
|
779
|
+
* Format the mangler options (if any) into their appropriate types
|
780
|
+
*/
|
781
|
+
export function format_mangler_options(options) {
|
760
782
|
options = defaults(options, {
|
761
783
|
eval : false,
|
762
784
|
nth_identifier : base54,
|
@@ -777,10 +799,10 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
|
|
777
799
|
// Never mangle arguments
|
778
800
|
options.reserved.add("arguments");
|
779
801
|
return options;
|
780
|
-
}
|
802
|
+
}
|
781
803
|
|
782
804
|
AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
783
|
-
options =
|
805
|
+
options = format_mangler_options(options);
|
784
806
|
var nth_identifier = options.nth_identifier;
|
785
807
|
|
786
808
|
// We only need to mangle declaration nodes. Special logic wired
|
@@ -904,7 +926,7 @@ AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
|
904
926
|
});
|
905
927
|
|
906
928
|
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
907
|
-
options =
|
929
|
+
options = format_mangler_options(options);
|
908
930
|
var nth_identifier = options.nth_identifier;
|
909
931
|
if (nth_identifier.reset && nth_identifier.sort) {
|
910
932
|
nth_identifier.reset();
|
@@ -947,7 +969,7 @@ AST_Sequence.DEFMETHOD("tail_node", function() {
|
|
947
969
|
});
|
948
970
|
|
949
971
|
AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
|
950
|
-
options =
|
972
|
+
options = format_mangler_options(options);
|
951
973
|
var nth_identifier = options.nth_identifier;
|
952
974
|
if (!nth_identifier.reset || !nth_identifier.consider || !nth_identifier.sort) {
|
953
975
|
// If the identifier mangler is invariant, skip computing character frequency.
|
package/lib/size.js
CHANGED
@@ -425,9 +425,11 @@ AST_ClassPrivateProperty.prototype._size = function () {
|
|
425
425
|
};
|
426
426
|
|
427
427
|
AST_Symbol.prototype._size = function () {
|
428
|
-
|
429
|
-
|
430
|
-
|
428
|
+
if (!(mangle_options && this.thedef && !this.thedef.unmangleable(mangle_options))) {
|
429
|
+
return this.name.length;
|
430
|
+
} else {
|
431
|
+
return 1;
|
432
|
+
}
|
431
433
|
};
|
432
434
|
|
433
435
|
// TODO take propmangle into account
|
@@ -436,11 +438,7 @@ AST_SymbolClassProperty.prototype._size = function () {
|
|
436
438
|
};
|
437
439
|
|
438
440
|
AST_SymbolRef.prototype._size = AST_SymbolDeclaration.prototype._size = function () {
|
439
|
-
|
440
|
-
|
441
|
-
if (thedef && thedef.global) return name.length;
|
442
|
-
|
443
|
-
if (name === "arguments") return 9;
|
441
|
+
if (this.name === "arguments") return 9;
|
444
442
|
|
445
443
|
return AST_Symbol.prototype._size.call(this);
|
446
444
|
};
|