terser 5.16.5 → 5.16.6
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 +5 -0
- package/dist/bundle.min.js +30 -21
- package/lib/ast.js +17 -3
- package/lib/compress/index.js +1 -1
- package/lib/compress/inference.js +8 -0
- package/lib/compress/reduce-vars.js +3 -15
- package/lib/parse.js +2 -2
- package/package.json +1 -1
- package/bin/terser.mjs +0 -21
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.16.7
|
4
|
+
|
5
|
+
- Become less conservative with analyzing function definitions for `reduce_vars`
|
6
|
+
- Parse `import.meta` as a real AST node and not an `object.property`
|
7
|
+
|
3
8
|
## v5.16.5
|
4
9
|
|
5
10
|
- Correctly handle AST transform functions that mutate children arrays
|
package/dist/bundle.min.js
CHANGED
@@ -2450,7 +2450,7 @@ function parse($TEXT, options) {
|
|
2450
2450
|
if (is("operator", "new")) {
|
2451
2451
|
return new_(allow_calls);
|
2452
2452
|
}
|
2453
|
-
if (is("
|
2453
|
+
if (is("name", "import") && is_token(peek(), "punc", ".")) {
|
2454
2454
|
return import_meta();
|
2455
2455
|
}
|
2456
2456
|
var start = S.token;
|
@@ -2946,7 +2946,7 @@ function parse($TEXT, options) {
|
|
2946
2946
|
|
2947
2947
|
function import_meta() {
|
2948
2948
|
var start = S.token;
|
2949
|
-
expect_token("
|
2949
|
+
expect_token("name", "import");
|
2950
2950
|
expect_token("punc", ".");
|
2951
2951
|
expect_token("name", "meta");
|
2952
2952
|
return subscripts(new AST_ImportMeta({
|
@@ -3850,8 +3850,21 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", function AST_Simple
|
|
3850
3850
|
|
3851
3851
|
function walk_body(node, visitor) {
|
3852
3852
|
const body = node.body;
|
3853
|
-
|
3854
|
-
body
|
3853
|
+
if (visitor.walk_defun_first) {
|
3854
|
+
for (var i = 0, len = body.length; i < len; i++) {
|
3855
|
+
if (body[i] instanceof AST_Defun) {
|
3856
|
+
body[i]._walk(visitor);
|
3857
|
+
}
|
3858
|
+
}
|
3859
|
+
for (var i = 0, len = body.length; i < len; i++) {
|
3860
|
+
if (!(body[i] instanceof AST_Defun)) {
|
3861
|
+
body[i]._walk(visitor);
|
3862
|
+
}
|
3863
|
+
}
|
3864
|
+
} else {
|
3865
|
+
for (var i = 0, len = body.length; i < len; i++) {
|
3866
|
+
body[i]._walk(visitor);
|
3867
|
+
}
|
3855
3868
|
}
|
3856
3869
|
}
|
3857
3870
|
|
@@ -6630,10 +6643,11 @@ const walk_abort = Symbol("abort walk");
|
|
6630
6643
|
/* -----[ TreeWalker ]----- */
|
6631
6644
|
|
6632
6645
|
class TreeWalker {
|
6633
|
-
constructor(callback) {
|
6646
|
+
constructor(callback, { walk_defun_first = false } = {}) {
|
6634
6647
|
this.visit = callback;
|
6635
6648
|
this.stack = [];
|
6636
6649
|
this.directives = Object.create(null);
|
6650
|
+
this.walk_defun_first = walk_defun_first;
|
6637
6651
|
}
|
6638
6652
|
|
6639
6653
|
_visit(node, descend) {
|
@@ -13489,6 +13503,7 @@ function is_nullish(node, compressor) {
|
|
13489
13503
|
|| this.body && this.body.has_side_effects(compressor)
|
13490
13504
|
|| this.alternative && this.alternative.has_side_effects(compressor);
|
13491
13505
|
});
|
13506
|
+
def_has_side_effects(AST_ImportMeta, return_false);
|
13492
13507
|
def_has_side_effects(AST_LabeledStatement, function(compressor) {
|
13493
13508
|
return this.body.has_side_effects(compressor);
|
13494
13509
|
});
|
@@ -13592,6 +13607,7 @@ function is_nullish(node, compressor) {
|
|
13592
13607
|
def_may_throw(AST_Lambda, return_false);
|
13593
13608
|
def_may_throw(AST_SymbolDeclaration, return_false);
|
13594
13609
|
def_may_throw(AST_This, return_false);
|
13610
|
+
def_may_throw(AST_ImportMeta, return_false);
|
13595
13611
|
|
13596
13612
|
function any(list, compressor) {
|
13597
13613
|
for (var i = list.length; --i >= 0;)
|
@@ -13955,6 +13971,11 @@ function is_lhs(node, parent) {
|
|
13955
13971
|
var name = this.name + suffix;
|
13956
13972
|
if (HOP(defines, name)) return to_node(defines[name], this);
|
13957
13973
|
});
|
13974
|
+
def_find_defs(AST_ImportMeta, function(compressor, suffix) {
|
13975
|
+
var defines = compressor.option("global_defs");
|
13976
|
+
var name = "import.meta" + suffix;
|
13977
|
+
if (HOP(defines, name)) return to_node(defines[name], this);
|
13978
|
+
});
|
13958
13979
|
})(function(node, func) {
|
13959
13980
|
node.DEFMETHOD("_find_defs", func);
|
13960
13981
|
});
|
@@ -15703,15 +15724,7 @@ def_reduce_vars(AST_Default, function(tw, descend) {
|
|
15703
15724
|
function mark_lambda(tw, descend, compressor) {
|
15704
15725
|
clear_flag(this, INLINED);
|
15705
15726
|
|
15706
|
-
|
15707
|
-
// we go to an entirely fresh lineage of safe_ids.
|
15708
|
-
let previous_safe_ids;
|
15709
|
-
if (this instanceof AST_Defun || this.uses_arguments || this.pinned()) {
|
15710
|
-
previous_safe_ids = tw.safe_ids;
|
15711
|
-
tw.safe_ids = Object.create(null);
|
15712
|
-
} else {
|
15713
|
-
push(tw);
|
15714
|
-
}
|
15727
|
+
push(tw);
|
15715
15728
|
|
15716
15729
|
reset_variables(tw, compressor, this);
|
15717
15730
|
|
@@ -15743,13 +15756,9 @@ function mark_lambda(tw, descend, compressor) {
|
|
15743
15756
|
}
|
15744
15757
|
});
|
15745
15758
|
}
|
15746
|
-
descend();
|
15747
15759
|
|
15748
|
-
|
15749
|
-
|
15750
|
-
} else {
|
15751
|
-
pop(tw);
|
15752
|
-
}
|
15760
|
+
descend();
|
15761
|
+
pop(tw);
|
15753
15762
|
|
15754
15763
|
return true;
|
15755
15764
|
}
|
@@ -18249,7 +18258,7 @@ AST_Toplevel.DEFMETHOD("reset_opt_flags", function(compressor) {
|
|
18249
18258
|
}
|
18250
18259
|
return node.reduce_vars(preparation, descend, compressor);
|
18251
18260
|
}
|
18252
|
-
});
|
18261
|
+
}, { walk_defun_first: true });
|
18253
18262
|
// Stack of look-up tables to keep track of whether a `SymbolDef` has been
|
18254
18263
|
// properly assigned before use:
|
18255
18264
|
// - `push()` & `pop()` when visiting conditional branches
|
package/lib/ast.js
CHANGED
@@ -249,8 +249,21 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", function AST_Simple
|
|
249
249
|
|
250
250
|
function walk_body(node, visitor) {
|
251
251
|
const body = node.body;
|
252
|
-
|
253
|
-
body
|
252
|
+
if (visitor.walk_defun_first) {
|
253
|
+
for (var i = 0, len = body.length; i < len; i++) {
|
254
|
+
if (body[i] instanceof AST_Defun) {
|
255
|
+
body[i]._walk(visitor);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
for (var i = 0, len = body.length; i < len; i++) {
|
259
|
+
if (!(body[i] instanceof AST_Defun)) {
|
260
|
+
body[i]._walk(visitor);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
} else {
|
264
|
+
for (var i = 0, len = body.length; i < len; i++) {
|
265
|
+
body[i]._walk(visitor);
|
266
|
+
}
|
254
267
|
}
|
255
268
|
}
|
256
269
|
|
@@ -3029,10 +3042,11 @@ const walk_abort = Symbol("abort walk");
|
|
3029
3042
|
/* -----[ TreeWalker ]----- */
|
3030
3043
|
|
3031
3044
|
class TreeWalker {
|
3032
|
-
constructor(callback) {
|
3045
|
+
constructor(callback, { walk_defun_first = false } = {}) {
|
3033
3046
|
this.visit = callback;
|
3034
3047
|
this.stack = [];
|
3035
3048
|
this.directives = Object.create(null);
|
3049
|
+
this.walk_defun_first = walk_defun_first;
|
3036
3050
|
}
|
3037
3051
|
|
3038
3052
|
_visit(node, descend) {
|
package/lib/compress/index.js
CHANGED
@@ -539,7 +539,7 @@ AST_Toplevel.DEFMETHOD("reset_opt_flags", function(compressor) {
|
|
539
539
|
}
|
540
540
|
return node.reduce_vars(preparation, descend, compressor);
|
541
541
|
}
|
542
|
-
});
|
542
|
+
}, { walk_defun_first: true });
|
543
543
|
// Stack of look-up tables to keep track of whether a `SymbolDef` has been
|
544
544
|
// properly assigned before use:
|
545
545
|
// - `push()` & `pop()` when visiting conditional branches
|
@@ -67,6 +67,7 @@ import {
|
|
67
67
|
AST_Function,
|
68
68
|
AST_If,
|
69
69
|
AST_Import,
|
70
|
+
AST_ImportMeta,
|
70
71
|
AST_Jump,
|
71
72
|
AST_LabeledStatement,
|
72
73
|
AST_Lambda,
|
@@ -310,6 +311,7 @@ export function is_nullish(node, compressor) {
|
|
310
311
|
|| this.body && this.body.has_side_effects(compressor)
|
311
312
|
|| this.alternative && this.alternative.has_side_effects(compressor);
|
312
313
|
});
|
314
|
+
def_has_side_effects(AST_ImportMeta, return_false);
|
313
315
|
def_has_side_effects(AST_LabeledStatement, function(compressor) {
|
314
316
|
return this.body.has_side_effects(compressor);
|
315
317
|
});
|
@@ -413,6 +415,7 @@ export function is_nullish(node, compressor) {
|
|
413
415
|
def_may_throw(AST_Lambda, return_false);
|
414
416
|
def_may_throw(AST_SymbolDeclaration, return_false);
|
415
417
|
def_may_throw(AST_This, return_false);
|
418
|
+
def_may_throw(AST_ImportMeta, return_false);
|
416
419
|
|
417
420
|
function any(list, compressor) {
|
418
421
|
for (var i = list.length; --i >= 0;)
|
@@ -776,6 +779,11 @@ export function is_lhs(node, parent) {
|
|
776
779
|
var name = this.name + suffix;
|
777
780
|
if (HOP(defines, name)) return to_node(defines[name], this);
|
778
781
|
});
|
782
|
+
def_find_defs(AST_ImportMeta, function(compressor, suffix) {
|
783
|
+
var defines = compressor.option("global_defs");
|
784
|
+
var name = "import.meta" + suffix;
|
785
|
+
if (HOP(defines, name)) return to_node(defines[name], this);
|
786
|
+
});
|
779
787
|
})(function(node, func) {
|
780
788
|
node.DEFMETHOD("_find_defs", func);
|
781
789
|
});
|
@@ -448,15 +448,7 @@ def_reduce_vars(AST_Default, function(tw, descend) {
|
|
448
448
|
function mark_lambda(tw, descend, compressor) {
|
449
449
|
clear_flag(this, INLINED);
|
450
450
|
|
451
|
-
|
452
|
-
// we go to an entirely fresh lineage of safe_ids.
|
453
|
-
let previous_safe_ids;
|
454
|
-
if (this instanceof AST_Defun || this.uses_arguments || this.pinned()) {
|
455
|
-
previous_safe_ids = tw.safe_ids;
|
456
|
-
tw.safe_ids = Object.create(null);
|
457
|
-
} else {
|
458
|
-
push(tw);
|
459
|
-
}
|
451
|
+
push(tw);
|
460
452
|
|
461
453
|
reset_variables(tw, compressor, this);
|
462
454
|
|
@@ -488,13 +480,9 @@ function mark_lambda(tw, descend, compressor) {
|
|
488
480
|
}
|
489
481
|
});
|
490
482
|
}
|
491
|
-
descend();
|
492
483
|
|
493
|
-
|
494
|
-
|
495
|
-
} else {
|
496
|
-
pop(tw);
|
497
|
-
}
|
484
|
+
descend();
|
485
|
+
pop(tw);
|
498
486
|
|
499
487
|
return true;
|
500
488
|
}
|
package/lib/parse.js
CHANGED
@@ -2307,7 +2307,7 @@ function parse($TEXT, options) {
|
|
2307
2307
|
if (is("operator", "new")) {
|
2308
2308
|
return new_(allow_calls);
|
2309
2309
|
}
|
2310
|
-
if (is("
|
2310
|
+
if (is("name", "import") && is_token(peek(), "punc", ".")) {
|
2311
2311
|
return import_meta();
|
2312
2312
|
}
|
2313
2313
|
var start = S.token;
|
@@ -2803,7 +2803,7 @@ function parse($TEXT, options) {
|
|
2803
2803
|
|
2804
2804
|
function import_meta() {
|
2805
2805
|
var start = S.token;
|
2806
|
-
expect_token("
|
2806
|
+
expect_token("name", "import");
|
2807
2807
|
expect_token("punc", ".");
|
2808
2808
|
expect_token("name", "meta");
|
2809
2809
|
return subscripts(new AST_ImportMeta({
|
package/package.json
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
|
-
});
|