terser 5.7.1 → 5.10.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 +42 -0
- package/README.md +23 -4
- package/bin/terser.mjs +7 -9
- package/dist/bundle.min.js +4847 -3745
- package/lib/ast.js +6 -6
- package/lib/compress/common.js +296 -0
- package/lib/compress/compressor-flags.js +63 -0
- package/lib/compress/drop-side-effect-free.js +350 -0
- package/lib/compress/evaluate.js +461 -0
- package/lib/compress/index.js +474 -3575
- package/lib/compress/inference.js +948 -0
- package/lib/compress/native-objects.js +184 -0
- package/lib/compress/reduce-vars.js +675 -0
- package/lib/compress/tighten-body.js +1461 -0
- package/lib/minify.js +3 -1
- package/lib/mozilla-ast.js +48 -6
- package/lib/output.js +87 -28
- package/lib/parse.js +28 -10
- package/lib/propmangle.js +57 -34
- package/lib/scope.js +46 -25
- package/lib/transform.js +2 -2
- package/package.json +17 -10
- package/tools/terser.d.ts +37 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,47 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.10.0
|
4
|
+
|
5
|
+
- Massive optimization to max_line_len (#1109)
|
6
|
+
- Basic support for import assertions
|
7
|
+
- Marked ES2022 Object.hasOwn as a pure function
|
8
|
+
- Fix `delete optional?.property`
|
9
|
+
- New CI/CD pipeline with github actions (#1057)
|
10
|
+
- Fix reordering of switch branches (#1092), (#1084)
|
11
|
+
- Fix error when creating a class property called `get`
|
12
|
+
- Acorn dependency is now an optional peerDependency
|
13
|
+
- Fix mangling collision with exported variables (#1072)
|
14
|
+
- Fix an issue with `return someVariable = (async () => { ... })()` (#1073)
|
15
|
+
|
16
|
+
## v5.9.0
|
17
|
+
|
18
|
+
- Collapsing switch cases with the same bodies (even if they're not next to each other) (#1070).
|
19
|
+
- Fix evaluation of optional chain expressions (#1062)
|
20
|
+
- Fix mangling collision in ESM exports (#1063)
|
21
|
+
- Fix issue with mutating function objects after a second pass (#1047)
|
22
|
+
- Fix for inlining object spread `{ ...obj }` (#1071)
|
23
|
+
- Typescript typings fix (#1069)
|
24
|
+
|
25
|
+
## v5.8.0
|
26
|
+
|
27
|
+
- Fixed shadowing variables while moving code in some cases (#1065)
|
28
|
+
- Stop mangling computed & quoted properties when keep_quoted is enabled.
|
29
|
+
- Fix for mangling private getter/setter and .#private access (#1060, #1068)
|
30
|
+
- Array.from has a new optimization when the unsafe option is set (#737)
|
31
|
+
- Mangle/propmangle let you generate your own identifiers through the nth_identifier option (#1061)
|
32
|
+
- More optimizations to switch statements (#1044)
|
33
|
+
|
34
|
+
## v5.7.2
|
35
|
+
|
36
|
+
- Fixed issues with compressing functions defined in `global_defs` option (#1036)
|
37
|
+
- New recipe for using Terser in gulp was added to RECIPES.md (#1035)
|
38
|
+
- Fixed issues with `??` and `?.` (#1045)
|
39
|
+
- Future reserved words such as `package` no longer require you to disable strict mode to be used as names.
|
40
|
+
- Refactored huge compressor file into multiple more focused files.
|
41
|
+
- Avoided unparenthesized `in` operator in some for loops (it breaks parsing because of for..in loops)
|
42
|
+
- Improved documentation (#1021, #1025)
|
43
|
+
- More type definitions (#1021)
|
44
|
+
|
3
45
|
## v5.7.1
|
4
46
|
|
5
47
|
- Avoided collapsing assignments together if it would place a chain assignment on the left hand side, which is invalid syntax (`a?.b = c`)
|
package/README.md
CHANGED
@@ -21,8 +21,8 @@ Find the changelog in [CHANGELOG.md](https://github.com/terser/terser/blob/maste
|
|
21
21
|
[npm-url]: https://npmjs.org/package/terser
|
22
22
|
[downloads-image]: https://img.shields.io/npm/dm/terser.svg
|
23
23
|
[downloads-url]: https://npmjs.org/package/terser
|
24
|
-
[travis-image]: https://travis-ci.com/terser/terser.svg?branch=master
|
25
|
-
[travis-url]: https://travis-ci.com/terser/terser
|
24
|
+
[travis-image]: https://app.travis-ci.com/terser/terser.svg?branch=master
|
25
|
+
[travis-url]: https://app.travis-ci.com/github/terser/terser
|
26
26
|
[opencollective-contributors]: https://opencollective.com/terser/tiers/badge.svg
|
27
27
|
[opencollective-url]: https://opencollective.com/terser
|
28
28
|
|
@@ -530,6 +530,11 @@ try {
|
|
530
530
|
- `ecma` (default `undefined`) - pass `5`, `2015`, `2016`, etc to override
|
531
531
|
`compress` and `format`'s `ecma` options.
|
532
532
|
|
533
|
+
- `enclose` (default `false`) - pass `true`, or a string in the format
|
534
|
+
of `"args[:values]"`, where `args` and `values` are comma-separated
|
535
|
+
argument names and values, respectively, to embed the output in a big
|
536
|
+
function with the configurable arguments and values.
|
537
|
+
|
533
538
|
- `parse` (default `{}`) — pass an object if you wish to specify some
|
534
539
|
additional [parse options](#parse-options).
|
535
540
|
|
@@ -569,7 +574,7 @@ try {
|
|
569
574
|
of class names. Pass a regular expression to only keep class names matching that regex.
|
570
575
|
|
571
576
|
- `keep_fnames` (default: `false`) - pass `true` to prevent discarding or mangling
|
572
|
-
of function names. Pass a regular expression to only keep
|
577
|
+
of function names. Pass a regular expression to only keep function names matching that regex.
|
573
578
|
Useful for code relying on `Function.prototype.name`. If the top level minify option
|
574
579
|
`keep_classnames` is `undefined` it will be overridden with the value of the top level
|
575
580
|
minify option `keep_fnames`.
|
@@ -602,6 +607,7 @@ try {
|
|
602
607
|
// source map options
|
603
608
|
},
|
604
609
|
ecma: 5, // specify one of: 5, 2015, 2016, etc.
|
610
|
+
enclose: false, // or specify true, or "args:values"
|
605
611
|
keep_classnames: false,
|
606
612
|
keep_fnames: false,
|
607
613
|
ie8: false,
|
@@ -885,13 +891,19 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
|
|
885
891
|
See also: the `keep_classnames` [compress option](#compress-options).
|
886
892
|
|
887
893
|
- `keep_fnames` (default `false`) -- Pass `true` to not mangle function names.
|
888
|
-
Pass a regular expression to only keep
|
894
|
+
Pass a regular expression to only keep function names matching that regex.
|
889
895
|
Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames`
|
890
896
|
[compress option](#compress-options).
|
891
897
|
|
892
898
|
- `module` (default `false`) -- Pass `true` an ES6 modules, where the toplevel
|
893
899
|
scope is not the global scope. Implies `toplevel`.
|
894
900
|
|
901
|
+
- `nth_identifier` (default: an internal mangler that weights based on character
|
902
|
+
frequency analysis) -- Pass an object with a `get(n)` function that converts an
|
903
|
+
ordinal into the nth most favored (usually shortest) identifier.
|
904
|
+
Optionally also provide `reset()`, `sort()`, and `consider(chars, delta)` to
|
905
|
+
use character frequency analysis of the source code.
|
906
|
+
|
895
907
|
- `reserved` (default `[]`) -- Pass an array of identifiers that should be
|
896
908
|
excluded from mangling. Example: `["foo", "bar"]`.
|
897
909
|
|
@@ -938,6 +950,12 @@ await minify(code, { mangle: { toplevel: true } }).code;
|
|
938
950
|
- `false` -- `obj["prop"]` is mangled.
|
939
951
|
- `true` -- `obj.prop` is mangled unless there is `obj["prop"]` elsewhere in the code.
|
940
952
|
|
953
|
+
- `nth_identifer` (default: an internal mangler that weights based on character
|
954
|
+
frequency analysis) -- Pass an object with a `get(n)` function that converts an
|
955
|
+
ordinal into the nth most favored (usually shortest) identifier.
|
956
|
+
Optionally also provide `reset()`, `sort()`, and `consider(chars, delta)` to
|
957
|
+
use character frequency analysis of the source code.
|
958
|
+
|
941
959
|
- `regex` (default: `null`) — Pass a [RegExp literal or pattern string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to only mangle property matching the regular expression.
|
942
960
|
|
943
961
|
- `reserved` (default: `[]`) — Do not mangle property names listed in the
|
@@ -1072,6 +1090,7 @@ You might want to try it on your own code; it should reduce the minified size.
|
|
1072
1090
|
Some examples of the optimizations made when this option is enabled:
|
1073
1091
|
|
1074
1092
|
- `new Array(1, 2, 3)` or `Array(1, 2, 3)` → `[ 1, 2, 3 ]`
|
1093
|
+
- `Array.from([1, 2, 3])` → `[1, 2, 3]`
|
1075
1094
|
- `new Object()` → `{}`
|
1076
1095
|
- `String(exp)` or `exp.toString()` → `"" + exp`
|
1077
1096
|
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
package/bin/terser.mjs
CHANGED
@@ -2,19 +2,17 @@
|
|
2
2
|
|
3
3
|
"use strict";
|
4
4
|
|
5
|
-
import
|
5
|
+
import '../tools/exit.cjs'
|
6
|
+
import fs from 'fs'
|
7
|
+
import path from 'path'
|
8
|
+
import program from 'commander'
|
6
9
|
|
7
|
-
import
|
8
|
-
import path from "path"
|
9
|
-
import program from "commander"
|
10
|
-
|
11
|
-
import { run_cli } from "../lib/cli.js"
|
10
|
+
import { _run_cli as run_cli } from '../main.js'
|
12
11
|
|
13
12
|
const packageJson = {
|
14
|
-
name:
|
15
|
-
version:
|
13
|
+
name: 'terser',
|
14
|
+
version: 'development-cli'
|
16
15
|
}
|
17
|
-
|
18
16
|
run_cli({ program, packageJson, fs, path }).catch((error) => {
|
19
17
|
console.error(error);
|
20
18
|
process.exitCode = 1;
|