terser 5.26.0 → 5.27.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 +6 -0
- package/README.md +3 -1
- package/dist/bundle.min.js +44 -5
- package/lib/compress/tighten-body.js +10 -1
- package/lib/minify.js +32 -2
- package/lib/sourcemap.js +2 -2
- package/main.js +1 -1
- package/package.json +1 -1
- package/tools/terser.d.ts +1 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.27.1
|
4
|
+
- Fixed case where `collapse_vars` inlines `await` expressions into non-async functions.
|
5
|
+
|
6
|
+
## v5.27.0
|
7
|
+
- Created `minify_sync()` alternative to `minify()` since there's no async code left.
|
8
|
+
|
3
9
|
## v5.26.0
|
4
10
|
- Do not take the `/*#__PURE__*/` annotation into account when the `side_effects` compress option is off.
|
5
11
|
- The `preserve_annotations` option now automatically opts annotation comments in, instead of requiring the `comments` option to be configured for this.
|
package/README.md
CHANGED
@@ -424,7 +424,7 @@ Browser loading is also supported. It exposes a global variable `Terser` contain
|
|
424
424
|
<script src="https://cdn.jsdelivr.net/npm/terser/dist/bundle.min.js"></script>
|
425
425
|
```
|
426
426
|
|
427
|
-
There is
|
427
|
+
There is an async high level function, **`async minify(code, options)`**,
|
428
428
|
which will perform all minification [phases](#minify-options) in a configurable
|
429
429
|
manner. By default `minify()` will enable [`compress`](#compress-options)
|
430
430
|
and [`mangle`](#mangle-options). Example:
|
@@ -435,6 +435,8 @@ console.log(result.code); // minified output: function add(n,d){return n+d}
|
|
435
435
|
console.log(result.map); // source map
|
436
436
|
```
|
437
437
|
|
438
|
+
There is also a `minify_sync()` alternative version of it, which returns instantly.
|
439
|
+
|
438
440
|
You can `minify` more than one JavaScript file at a time by using an object
|
439
441
|
for the first argument where the keys are file names and the values are source
|
440
442
|
code:
|
package/dist/bundle.min.js
CHANGED
@@ -16725,6 +16725,14 @@ function tighten_body(statements, compressor) {
|
|
16725
16725
|
return found;
|
16726
16726
|
}
|
16727
16727
|
|
16728
|
+
function arg_is_injectable(arg) {
|
16729
|
+
if (arg instanceof AST_Expansion) return false;
|
16730
|
+
const contains_await = walk(arg, (node) => {
|
16731
|
+
if (node instanceof AST_Await) return walk_abort;
|
16732
|
+
});
|
16733
|
+
if (contains_await) return false;
|
16734
|
+
return true;
|
16735
|
+
}
|
16728
16736
|
function extract_args() {
|
16729
16737
|
var iife, fn = compressor.self();
|
16730
16738
|
if (is_func_expr(fn)
|
@@ -16733,7 +16741,8 @@ function tighten_body(statements, compressor) {
|
|
16733
16741
|
&& !fn.pinned()
|
16734
16742
|
&& (iife = compressor.parent()) instanceof AST_Call
|
16735
16743
|
&& iife.expression === fn
|
16736
|
-
&& iife.args.every(
|
16744
|
+
&& iife.args.every(arg_is_injectable)
|
16745
|
+
) {
|
16737
16746
|
var fn_strict = compressor.has_directive("use strict");
|
16738
16747
|
if (fn_strict && !member(fn_strict, fn.body))
|
16739
16748
|
fn_strict = false;
|
@@ -21990,7 +21999,7 @@ def_optimize(AST_Destructuring, function(self, compressor) {
|
|
21990
21999
|
***********************************************************************/
|
21991
22000
|
|
21992
22001
|
// a small wrapper around source-map and @jridgewell/source-map
|
21993
|
-
|
22002
|
+
function* SourceMap(options) {
|
21994
22003
|
options = defaults(options, {
|
21995
22004
|
file : null,
|
21996
22005
|
root : null,
|
@@ -22013,7 +22022,7 @@ async function SourceMap(options) {
|
|
22013
22022
|
// We support both @jridgewell/source-map (which has a sync
|
22014
22023
|
// SourceMapConsumer) and source-map (which has an async
|
22015
22024
|
// SourceMapConsumer).
|
22016
|
-
orig_map =
|
22025
|
+
orig_map = yield new sourceMap.SourceMapConsumer(options.orig);
|
22017
22026
|
if (orig_map.sourcesContent) {
|
22018
22027
|
orig_map.sources.forEach(function(source, i) {
|
22019
22028
|
var content = orig_map.sourcesContent[i];
|
@@ -30577,7 +30586,7 @@ function log_input(files, options, fs, debug_folder) {
|
|
30577
30586
|
fs.writeFileSync(log_path, "Options: \n" + options_str + "\n\nInput files:\n\n" + files_str(files) + "\n");
|
30578
30587
|
}
|
30579
30588
|
|
30580
|
-
|
30589
|
+
function* minify_sync_or_async(files, options, _fs_module) {
|
30581
30590
|
if (
|
30582
30591
|
_fs_module
|
30583
30592
|
&& typeof process === "object"
|
@@ -30782,7 +30791,7 @@ async function minify(files, options, _fs_module) {
|
|
30782
30791
|
if (options.sourceMap.includeSources && files instanceof AST_Toplevel) {
|
30783
30792
|
throw new Error("original source content unavailable");
|
30784
30793
|
}
|
30785
|
-
format_options.source_map =
|
30794
|
+
format_options.source_map = yield* SourceMap({
|
30786
30795
|
file: options.sourceMap.filename,
|
30787
30796
|
orig: options.sourceMap.content,
|
30788
30797
|
root: options.sourceMap.root,
|
@@ -30844,6 +30853,35 @@ async function minify(files, options, _fs_module) {
|
|
30844
30853
|
return result;
|
30845
30854
|
}
|
30846
30855
|
|
30856
|
+
async function minify(files, options, _fs_module) {
|
30857
|
+
const gen = minify_sync_or_async(files, options, _fs_module);
|
30858
|
+
|
30859
|
+
let yielded;
|
30860
|
+
let val;
|
30861
|
+
do {
|
30862
|
+
val = gen.next(await yielded);
|
30863
|
+
yielded = val.value;
|
30864
|
+
} while (!val.done);
|
30865
|
+
|
30866
|
+
return val.value;
|
30867
|
+
}
|
30868
|
+
|
30869
|
+
function minify_sync(files, options, _fs_module) {
|
30870
|
+
const gen = minify_sync_or_async(files, options, _fs_module);
|
30871
|
+
|
30872
|
+
let yielded;
|
30873
|
+
let val;
|
30874
|
+
do {
|
30875
|
+
if (yielded && typeof yielded.then === "function") {
|
30876
|
+
throw new Error("minify_sync cannot be used with the legacy source-map module");
|
30877
|
+
}
|
30878
|
+
val = gen.next(yielded);
|
30879
|
+
yielded = val.value;
|
30880
|
+
} while (!val.done);
|
30881
|
+
|
30882
|
+
return val.value;
|
30883
|
+
}
|
30884
|
+
|
30847
30885
|
async function run_cli({ program, packageJson, fs, path }) {
|
30848
30886
|
const skip_keys = new Set([ "cname", "parent_scope", "scope", "uses_eval", "uses_with" ]);
|
30849
30887
|
var files = {};
|
@@ -31334,5 +31372,6 @@ async function infer_options(options) {
|
|
31334
31372
|
exports._default_options = _default_options;
|
31335
31373
|
exports._run_cli = run_cli;
|
31336
31374
|
exports.minify = minify;
|
31375
|
+
exports.minify_sync = minify_sync;
|
31337
31376
|
|
31338
31377
|
}));
|
@@ -574,6 +574,14 @@ export function tighten_body(statements, compressor) {
|
|
574
574
|
return found;
|
575
575
|
}
|
576
576
|
|
577
|
+
function arg_is_injectable(arg) {
|
578
|
+
if (arg instanceof AST_Expansion) return false;
|
579
|
+
const contains_await = walk(arg, (node) => {
|
580
|
+
if (node instanceof AST_Await) return walk_abort;
|
581
|
+
});
|
582
|
+
if (contains_await) return false;
|
583
|
+
return true;
|
584
|
+
}
|
577
585
|
function extract_args() {
|
578
586
|
var iife, fn = compressor.self();
|
579
587
|
if (is_func_expr(fn)
|
@@ -582,7 +590,8 @@ export function tighten_body(statements, compressor) {
|
|
582
590
|
&& !fn.pinned()
|
583
591
|
&& (iife = compressor.parent()) instanceof AST_Call
|
584
592
|
&& iife.expression === fn
|
585
|
-
&& iife.args.every(
|
593
|
+
&& iife.args.every(arg_is_injectable)
|
594
|
+
) {
|
586
595
|
var fn_strict = compressor.has_directive("use strict");
|
587
596
|
if (fn_strict && !member(fn_strict, fn.body))
|
588
597
|
fn_strict = false;
|
package/lib/minify.js
CHANGED
@@ -103,7 +103,7 @@ function log_input(files, options, fs, debug_folder) {
|
|
103
103
|
fs.writeFileSync(log_path, "Options: \n" + options_str + "\n\nInput files:\n\n" + files_str(files) + "\n");
|
104
104
|
}
|
105
105
|
|
106
|
-
|
106
|
+
function* minify_sync_or_async(files, options, _fs_module) {
|
107
107
|
if (
|
108
108
|
_fs_module
|
109
109
|
&& typeof process === "object"
|
@@ -314,7 +314,7 @@ async function minify(files, options, _fs_module) {
|
|
314
314
|
if (options.sourceMap.includeSources && files instanceof AST_Toplevel) {
|
315
315
|
throw new Error("original source content unavailable");
|
316
316
|
}
|
317
|
-
format_options.source_map =
|
317
|
+
format_options.source_map = yield* SourceMap({
|
318
318
|
file: options.sourceMap.filename,
|
319
319
|
orig: options.sourceMap.content,
|
320
320
|
root: options.sourceMap.root,
|
@@ -376,7 +376,37 @@ async function minify(files, options, _fs_module) {
|
|
376
376
|
return result;
|
377
377
|
}
|
378
378
|
|
379
|
+
async function minify(files, options, _fs_module) {
|
380
|
+
const gen = minify_sync_or_async(files, options, _fs_module);
|
381
|
+
|
382
|
+
let yielded;
|
383
|
+
let val;
|
384
|
+
do {
|
385
|
+
val = gen.next(await yielded);
|
386
|
+
yielded = val.value;
|
387
|
+
} while (!val.done);
|
388
|
+
|
389
|
+
return val.value;
|
390
|
+
}
|
391
|
+
|
392
|
+
function minify_sync(files, options, _fs_module) {
|
393
|
+
const gen = minify_sync_or_async(files, options, _fs_module);
|
394
|
+
|
395
|
+
let yielded;
|
396
|
+
let val;
|
397
|
+
do {
|
398
|
+
if (yielded && typeof yielded.then === "function") {
|
399
|
+
throw new Error("minify_sync cannot be used with the legacy source-map module");
|
400
|
+
}
|
401
|
+
val = gen.next(yielded);
|
402
|
+
yielded = val.value;
|
403
|
+
} while (!val.done);
|
404
|
+
|
405
|
+
return val.value;
|
406
|
+
}
|
407
|
+
|
379
408
|
export {
|
380
409
|
minify,
|
410
|
+
minify_sync,
|
381
411
|
to_ascii,
|
382
412
|
};
|
package/lib/sourcemap.js
CHANGED
@@ -47,7 +47,7 @@ import {SourceMapConsumer, SourceMapGenerator} from "@jridgewell/source-map";
|
|
47
47
|
import {defaults, HOP} from "./utils/index.js";
|
48
48
|
|
49
49
|
// a small wrapper around source-map and @jridgewell/source-map
|
50
|
-
|
50
|
+
function* SourceMap(options) {
|
51
51
|
options = defaults(options, {
|
52
52
|
file : null,
|
53
53
|
root : null,
|
@@ -70,7 +70,7 @@ async function SourceMap(options) {
|
|
70
70
|
// We support both @jridgewell/source-map (which has a sync
|
71
71
|
// SourceMapConsumer) and source-map (which has an async
|
72
72
|
// SourceMapConsumer).
|
73
|
-
orig_map =
|
73
|
+
orig_map = yield new SourceMapConsumer(options.orig);
|
74
74
|
if (orig_map.sourcesContent) {
|
75
75
|
orig_map.sources.forEach(function(source, i) {
|
76
76
|
var content = orig_map.sourcesContent[i];
|
package/main.js
CHANGED
@@ -2,7 +2,7 @@ import "./lib/transform.js";
|
|
2
2
|
import "./lib/mozilla-ast.js";
|
3
3
|
import { minify } from "./lib/minify.js";
|
4
4
|
|
5
|
-
export { minify } from "./lib/minify.js";
|
5
|
+
export { minify, minify_sync } from "./lib/minify.js";
|
6
6
|
export { run_cli as _run_cli } from "./lib/cli.js";
|
7
7
|
|
8
8
|
export async function _default_options() {
|
package/package.json
CHANGED
package/tools/terser.d.ts
CHANGED
@@ -213,3 +213,4 @@ export interface SourceMapOptions {
|
|
213
213
|
}
|
214
214
|
|
215
215
|
export function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): Promise<MinifyOutput>;
|
216
|
+
export function minify_sync(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): MinifyOutput;
|