terser 5.12.0 → 5.13.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 +16 -0
- package/dist/bundle.min.js +5032 -3341
- package/lib/ast.js +1686 -350
- package/lib/compress/common.js +48 -0
- package/lib/compress/evaluate.js +4 -3
- package/lib/compress/index.js +23 -546
- package/lib/compress/inline.js +641 -0
- package/lib/compress/tighten-body.js +1 -1
- package/lib/equivalent-to.js +81 -107
- package/lib/mozilla-ast.js +474 -81
- package/lib/output.js +2 -1
- package/lib/parse.js +58 -56
- package/lib/propmangle.js +1 -1
- package/lib/scope.js +22 -0
- package/lib/size.js +6 -8
- package/package.json +2 -2
- package/tools/domprops.js +11 -0
package/lib/compress/common.js
CHANGED
@@ -80,9 +80,13 @@ import {
|
|
80
80
|
AST_Undefined,
|
81
81
|
|
82
82
|
TreeWalker,
|
83
|
+
walk,
|
84
|
+
walk_abort,
|
85
|
+
walk_parent,
|
83
86
|
} from "../ast.js";
|
84
87
|
import { make_node, regexp_source_fix, string_template, makePredicate } from "../utils/index.js";
|
85
88
|
import { first_in_statement } from "../utils/first_in_statement.js";
|
89
|
+
import { has_flag, TOP } from "./compressor-flags.js";
|
86
90
|
|
87
91
|
export function merge_sequence(array, node) {
|
88
92
|
if (node instanceof AST_Sequence) {
|
@@ -244,6 +248,13 @@ export function is_iife_call(node) {
|
|
244
248
|
return node.expression instanceof AST_Function || is_iife_call(node.expression);
|
245
249
|
}
|
246
250
|
|
251
|
+
export function is_empty(thing) {
|
252
|
+
if (thing === null) return true;
|
253
|
+
if (thing instanceof AST_EmptyStatement) return true;
|
254
|
+
if (thing instanceof AST_BlockStatement) return thing.body.length == 0;
|
255
|
+
return false;
|
256
|
+
}
|
257
|
+
|
247
258
|
export const identifier_atom = makePredicate("Infinity NaN undefined");
|
248
259
|
export function is_identifier_atom(node) {
|
249
260
|
return node instanceof AST_Infinity
|
@@ -281,6 +292,34 @@ export function as_statement_array(thing) {
|
|
281
292
|
throw new Error("Can't convert thing to statement array");
|
282
293
|
}
|
283
294
|
|
295
|
+
export function is_reachable(scope_node, defs) {
|
296
|
+
const find_ref = node => {
|
297
|
+
if (node instanceof AST_SymbolRef && defs.includes(node.definition())) {
|
298
|
+
return walk_abort;
|
299
|
+
}
|
300
|
+
};
|
301
|
+
|
302
|
+
return walk_parent(scope_node, (node, info) => {
|
303
|
+
if (node instanceof AST_Scope && node !== scope_node) {
|
304
|
+
var parent = info.parent();
|
305
|
+
|
306
|
+
if (
|
307
|
+
parent instanceof AST_Call
|
308
|
+
&& parent.expression === node
|
309
|
+
// Async/Generators aren't guaranteed to sync evaluate all of
|
310
|
+
// their body steps, so it's possible they close over the variable.
|
311
|
+
&& !(node.async || node.is_generator)
|
312
|
+
) {
|
313
|
+
return;
|
314
|
+
}
|
315
|
+
|
316
|
+
if (walk(node, find_ref)) return walk_abort;
|
317
|
+
|
318
|
+
return true;
|
319
|
+
}
|
320
|
+
});
|
321
|
+
}
|
322
|
+
|
284
323
|
/** Check if a ref refers to the name of a function/class it's defined within */
|
285
324
|
export function is_recursive_ref(compressor, def) {
|
286
325
|
var node;
|
@@ -294,3 +333,12 @@ export function is_recursive_ref(compressor, def) {
|
|
294
333
|
}
|
295
334
|
return false;
|
296
335
|
}
|
336
|
+
|
337
|
+
// TODO this only works with AST_Defun, shouldn't it work for other ways of defining functions?
|
338
|
+
export function retain_top_func(fn, compressor) {
|
339
|
+
return compressor.top_retain
|
340
|
+
&& fn instanceof AST_Defun
|
341
|
+
&& has_flag(fn, TOP)
|
342
|
+
&& fn.name
|
343
|
+
&& compressor.top_retain(fn.name);
|
344
|
+
}
|
package/lib/compress/evaluate.js
CHANGED
@@ -128,14 +128,15 @@ def_eval(AST_Constant, function () {
|
|
128
128
|
def_eval(AST_BigInt, return_this);
|
129
129
|
|
130
130
|
def_eval(AST_RegExp, function (compressor) {
|
131
|
-
let evaluated = compressor.evaluated_regexps.get(this);
|
131
|
+
let evaluated = compressor.evaluated_regexps.get(this.value);
|
132
132
|
if (evaluated === undefined) {
|
133
133
|
try {
|
134
|
-
|
134
|
+
const { source, flags } = this.value;
|
135
|
+
evaluated = new RegExp(source, flags);
|
135
136
|
} catch (e) {
|
136
137
|
evaluated = null;
|
137
138
|
}
|
138
|
-
compressor.evaluated_regexps.set(this, evaluated);
|
139
|
+
compressor.evaluated_regexps.set(this.value, evaluated);
|
139
140
|
}
|
140
141
|
return evaluated || this;
|
141
142
|
});
|