terser 5.26.0 → 5.27.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 +3 -0
- package/README.md +3 -1
- package/dist/bundle.min.js +34 -4
- 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,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.27.0
|
4
|
+
- Created `minify_sync()` alternative to `minify()` since there's no async code left.
|
5
|
+
|
3
6
|
## v5.26.0
|
4
7
|
- Do not take the `/*#__PURE__*/` annotation into account when the `side_effects` compress option is off.
|
5
8
|
- 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
@@ -21990,7 +21990,7 @@ def_optimize(AST_Destructuring, function(self, compressor) {
|
|
21990
21990
|
***********************************************************************/
|
21991
21991
|
|
21992
21992
|
// a small wrapper around source-map and @jridgewell/source-map
|
21993
|
-
|
21993
|
+
function* SourceMap(options) {
|
21994
21994
|
options = defaults(options, {
|
21995
21995
|
file : null,
|
21996
21996
|
root : null,
|
@@ -22013,7 +22013,7 @@ async function SourceMap(options) {
|
|
22013
22013
|
// We support both @jridgewell/source-map (which has a sync
|
22014
22014
|
// SourceMapConsumer) and source-map (which has an async
|
22015
22015
|
// SourceMapConsumer).
|
22016
|
-
orig_map =
|
22016
|
+
orig_map = yield new sourceMap.SourceMapConsumer(options.orig);
|
22017
22017
|
if (orig_map.sourcesContent) {
|
22018
22018
|
orig_map.sources.forEach(function(source, i) {
|
22019
22019
|
var content = orig_map.sourcesContent[i];
|
@@ -30577,7 +30577,7 @@ function log_input(files, options, fs, debug_folder) {
|
|
30577
30577
|
fs.writeFileSync(log_path, "Options: \n" + options_str + "\n\nInput files:\n\n" + files_str(files) + "\n");
|
30578
30578
|
}
|
30579
30579
|
|
30580
|
-
|
30580
|
+
function* minify_sync_or_async(files, options, _fs_module) {
|
30581
30581
|
if (
|
30582
30582
|
_fs_module
|
30583
30583
|
&& typeof process === "object"
|
@@ -30782,7 +30782,7 @@ async function minify(files, options, _fs_module) {
|
|
30782
30782
|
if (options.sourceMap.includeSources && files instanceof AST_Toplevel) {
|
30783
30783
|
throw new Error("original source content unavailable");
|
30784
30784
|
}
|
30785
|
-
format_options.source_map =
|
30785
|
+
format_options.source_map = yield* SourceMap({
|
30786
30786
|
file: options.sourceMap.filename,
|
30787
30787
|
orig: options.sourceMap.content,
|
30788
30788
|
root: options.sourceMap.root,
|
@@ -30844,6 +30844,35 @@ async function minify(files, options, _fs_module) {
|
|
30844
30844
|
return result;
|
30845
30845
|
}
|
30846
30846
|
|
30847
|
+
async function minify(files, options, _fs_module) {
|
30848
|
+
const gen = minify_sync_or_async(files, options, _fs_module);
|
30849
|
+
|
30850
|
+
let yielded;
|
30851
|
+
let val;
|
30852
|
+
do {
|
30853
|
+
val = gen.next(await yielded);
|
30854
|
+
yielded = val.value;
|
30855
|
+
} while (!val.done);
|
30856
|
+
|
30857
|
+
return val.value;
|
30858
|
+
}
|
30859
|
+
|
30860
|
+
function minify_sync(files, options, _fs_module) {
|
30861
|
+
const gen = minify_sync_or_async(files, options, _fs_module);
|
30862
|
+
|
30863
|
+
let yielded;
|
30864
|
+
let val;
|
30865
|
+
do {
|
30866
|
+
if (yielded && typeof yielded.then === "function") {
|
30867
|
+
throw new Error("minify_sync cannot be used with the legacy source-map module");
|
30868
|
+
}
|
30869
|
+
val = gen.next(yielded);
|
30870
|
+
yielded = val.value;
|
30871
|
+
} while (!val.done);
|
30872
|
+
|
30873
|
+
return val.value;
|
30874
|
+
}
|
30875
|
+
|
30847
30876
|
async function run_cli({ program, packageJson, fs, path }) {
|
30848
30877
|
const skip_keys = new Set([ "cname", "parent_scope", "scope", "uses_eval", "uses_with" ]);
|
30849
30878
|
var files = {};
|
@@ -31334,5 +31363,6 @@ async function infer_options(options) {
|
|
31334
31363
|
exports._default_options = _default_options;
|
31335
31364
|
exports._run_cli = run_cli;
|
31336
31365
|
exports.minify = minify;
|
31366
|
+
exports.minify_sync = minify_sync;
|
31337
31367
|
|
31338
31368
|
}));
|
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;
|