terser 5.6.1 → 5.8.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 +39 -0
- package/README.md +46 -21
- package/dist/bundle.min.js +4718 -3740
- package/lib/ast.js +13 -7
- package/lib/cli.js +0 -2
- package/lib/compress/common.js +296 -0
- package/lib/compress/compressor-flags.js +63 -0
- package/lib/compress/drop-side-effect-free.js +353 -0
- package/lib/compress/evaluate.js +458 -0
- package/lib/compress/index.js +483 -3608
- package/lib/compress/inference.js +934 -0
- package/lib/compress/native-objects.js +183 -0
- package/lib/compress/reduce-vars.js +675 -0
- package/lib/compress/tighten-body.js +1461 -0
- package/lib/equivalent-to.js +5 -0
- package/lib/minify.js +28 -11
- package/lib/output.js +20 -7
- package/lib/parse.js +76 -82
- package/lib/propmangle.js +54 -31
- package/lib/scope.js +49 -24
- package/lib/transform.js +2 -2
- package/lib/utils/index.js +3 -5
- package/package.json +13 -12
- package/tools/terser.d.ts +37 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.8.0
|
4
|
+
|
5
|
+
- Fixed shadowing variables while moving code in some cases (#1065)
|
6
|
+
- Stop mangling computed & quoted properties when keep_quoted is enabled.
|
7
|
+
- Fix for mangling private getter/setter and .#private access (#1060, #1068)
|
8
|
+
- Array.from has a new optimization when the unsafe option is set (#737)
|
9
|
+
- Mangle/propmangle let you generate your own identifiers through the nth_identifier option (#1061)
|
10
|
+
- More optimizations to switch statements (#1044)
|
11
|
+
|
12
|
+
## v5.7.2
|
13
|
+
|
14
|
+
- Fixed issues with compressing functions defined in `global_defs` option (#1036)
|
15
|
+
- New recipe for using Terser in gulp was added to RECIPES.md (#1035)
|
16
|
+
- Fixed issues with `??` and `?.` (#1045)
|
17
|
+
- Future reserved words such as `package` no longer require you to disable strict mode to be used as names.
|
18
|
+
- Refactored huge compressor file into multiple more focused files.
|
19
|
+
- Avoided unparenthesized `in` operator in some for loops (it breaks parsing because of for..in loops)
|
20
|
+
- Improved documentation (#1021, #1025)
|
21
|
+
- More type definitions (#1021)
|
22
|
+
|
23
|
+
## v5.7.1
|
24
|
+
|
25
|
+
- Avoided collapsing assignments together if it would place a chain assignment on the left hand side, which is invalid syntax (`a?.b = c`)
|
26
|
+
- Removed undefined from object expansions (`{ ...void 0 }` -> `{}`)
|
27
|
+
- Fix crash when checking if something is nullish or undefined (#1009)
|
28
|
+
- Fixed comparison of private class properties (#1015)
|
29
|
+
- Minor performance improvements (#993)
|
30
|
+
- Fixed scope of function defs in strict mode (they are block scoped)
|
31
|
+
|
32
|
+
## v5.7.0
|
33
|
+
|
34
|
+
- Several compile-time evaluation and inlining fixes
|
35
|
+
- Allow `reduce_funcs` to be disabled again.
|
36
|
+
- Add `spidermonkey` options to parse and format (#974)
|
37
|
+
- Accept `{get = "default val"}` and `{set = "default val"}` in destructuring arguments.
|
38
|
+
- Change package.json export map to help require.resolve (#971)
|
39
|
+
- Improve docs
|
40
|
+
- Fix `export default` of an anonymous class with `extends`
|
41
|
+
|
3
42
|
## v5.6.1
|
4
43
|
|
5
44
|
- Mark assignments to the `.prototype` of a class as pure
|
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://
|
25
|
-
[travis-url]: https://travis-ci.
|
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
|
|
@@ -416,7 +416,7 @@ Browser loading is also supported:
|
|
416
416
|
|
417
417
|
There is a single async high level function, **`async minify(code, options)`**,
|
418
418
|
which will perform all minification [phases](#minify-options) in a configurable
|
419
|
-
manner.
|
419
|
+
manner. By default `minify()` will enable [`compress`](#compress-options)
|
420
420
|
and [`mangle`](#mangle-options). Example:
|
421
421
|
```javascript
|
422
422
|
var code = "function add(first, second) { return first + second; }";
|
@@ -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,13 +607,14 @@ 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,
|
608
614
|
module: false,
|
609
615
|
nameCache: null, // or specify a name cache object
|
610
616
|
safari10: false,
|
611
|
-
toplevel: false
|
617
|
+
toplevel: false
|
612
618
|
}
|
613
619
|
```
|
614
620
|
|
@@ -669,6 +675,8 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
|
|
669
675
|
|
670
676
|
- `shebang` (default `true`) -- support `#!command` as the first line
|
671
677
|
|
678
|
+
- `spidermonkey` (default `false`) -- accept a Spidermonkey (Mozilla) AST
|
679
|
+
|
672
680
|
## Compress options
|
673
681
|
|
674
682
|
- `defaults` (default: `true`) -- Pass `false` to disable most default
|
@@ -795,11 +803,13 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
|
|
795
803
|
Specify `"strict"` to treat `foo.bar` as side-effect-free only when
|
796
804
|
`foo` is certain to not throw, i.e. not `null` or `undefined`.
|
797
805
|
|
798
|
-
- `reduce_funcs` (legacy option, safely ignored for backwards compatibility).
|
799
|
-
|
800
806
|
- `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and
|
801
807
|
used as constant values.
|
802
808
|
|
809
|
+
- `reduce_funcs` (default: `true`) -- Inline single-use functions when
|
810
|
+
possible. Depends on `reduce_vars` being enabled. Disabling this option
|
811
|
+
sometimes improves performance of the output code.
|
812
|
+
|
803
813
|
- `sequences` (default: `true`) -- join consecutive simple statements using the
|
804
814
|
comma operator. May be set to a positive integer to specify the maximum number
|
805
815
|
of consecutive comma sequences that will be generated. If this option is set to
|
@@ -848,7 +858,7 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
|
|
848
858
|
- `unsafe_math` (default: `false`) -- optimize numerical expressions like
|
849
859
|
`2 * x * 3` into `6 * x`, which may give imprecise floating point results.
|
850
860
|
|
851
|
-
- `unsafe_symbols` (default: `false`) -- removes keys from native Symbol
|
861
|
+
- `unsafe_symbols` (default: `false`) -- removes keys from native Symbol
|
852
862
|
declarations, e.g `Symbol("kDog")` becomes `Symbol()`.
|
853
863
|
|
854
864
|
- `unsafe_methods` (default: false) -- Converts `{ m: function(){} }` to
|
@@ -881,13 +891,19 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
|
|
881
891
|
See also: the `keep_classnames` [compress option](#compress-options).
|
882
892
|
|
883
893
|
- `keep_fnames` (default `false`) -- Pass `true` to not mangle function names.
|
884
|
-
Pass a regular expression to only keep
|
894
|
+
Pass a regular expression to only keep function names matching that regex.
|
885
895
|
Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames`
|
886
896
|
[compress option](#compress-options).
|
887
897
|
|
888
898
|
- `module` (default `false`) -- Pass `true` an ES6 modules, where the toplevel
|
889
899
|
scope is not the global scope. Implies `toplevel`.
|
890
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
|
+
|
891
907
|
- `reserved` (default `[]`) -- Pass an array of identifiers that should be
|
892
908
|
excluded from mangling. Example: `["foo", "bar"]`.
|
893
909
|
|
@@ -929,11 +945,16 @@ await minify(code, { mangle: { toplevel: true } }).code;
|
|
929
945
|
- `debug` (default: `false`) — Mangle names with the original name still present.
|
930
946
|
Pass an empty string `""` to enable, or a non-empty string to set the debug suffix.
|
931
947
|
|
932
|
-
- `keep_quoted` (default: `false`) —
|
933
|
-
- `
|
934
|
-
|
935
|
-
- `
|
936
|
-
|
948
|
+
- `keep_quoted` (default: `false`) — How quoting properties (`{"prop": ...}` and `obj["prop"]`) controls what gets mangled.
|
949
|
+
- `"strict"` (recommended) -- `obj.prop` is mangled.
|
950
|
+
- `false` -- `obj["prop"]` is mangled.
|
951
|
+
- `true` -- `obj.prop` is mangled unless there is `obj["prop"]` elsewhere in the code.
|
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.
|
937
958
|
|
938
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.
|
939
960
|
|
@@ -954,19 +975,17 @@ as "output options".
|
|
954
975
|
- `ascii_only` (default `false`) -- escape Unicode characters in strings and
|
955
976
|
regexps (affects directives with non-ascii characters becoming invalid)
|
956
977
|
|
957
|
-
- `beautify` (default `false`) -- whether to
|
958
|
-
|
959
|
-
when you want to generate minified code, in order to specify additional
|
960
|
-
arguments, so you can use `-b beautify=false` to override it.
|
978
|
+
- `beautify` (default `false`) -- (DEPRECATED) whether to beautify the output.
|
979
|
+
When using the legacy `-b` CLI flag, this is set to true by default.
|
961
980
|
|
962
981
|
- `braces` (default `false`) -- always insert braces in `if`, `for`,
|
963
982
|
`do`, `while` or `with` statements, even if their body is a single
|
964
983
|
statement.
|
965
984
|
|
966
985
|
- `comments` (default `"some"`) -- by default it keeps JSDoc-style comments
|
967
|
-
that contain "@license"
|
968
|
-
comments, `false` to omit comments in the output,
|
969
|
-
(e.g. `/^!/`) or a function.
|
986
|
+
that contain "@license", "@preserve" or start with `!`, pass `true` or
|
987
|
+
`"all"` to preserve all comments, `false` to omit comments in the output,
|
988
|
+
a regular expression string (e.g. `/^!/`) or a function.
|
970
989
|
|
971
990
|
- `ecma` (default `5`) -- set desired EcmaScript standard version for output.
|
972
991
|
Set `ecma` to `2015` or greater to emit shorthand object properties - i.e.:
|
@@ -1019,6 +1038,8 @@ as "output options".
|
|
1019
1038
|
|
1020
1039
|
- `shebang` (default `true`) -- preserve shebang `#!` in preamble (bash scripts)
|
1021
1040
|
|
1041
|
+
- `spidermonkey` (default `false`) -- produce a Spidermonkey (Mozilla) AST
|
1042
|
+
|
1022
1043
|
- `webkit` (default `false`) -- enable workarounds for WebKit bugs.
|
1023
1044
|
PhantomJS users should set this option to `true`.
|
1024
1045
|
|
@@ -1069,6 +1090,7 @@ You might want to try it on your own code; it should reduce the minified size.
|
|
1069
1090
|
Some examples of the optimizations made when this option is enabled:
|
1070
1091
|
|
1071
1092
|
- `new Array(1, 2, 3)` or `Array(1, 2, 3)` → `[ 1, 2, 3 ]`
|
1093
|
+
- `Array.from([1, 2, 3])` → `[1, 2, 3]`
|
1072
1094
|
- `new Object()` → `{}`
|
1073
1095
|
- `String(exp)` or `exp.toString()` → `"" + exp`
|
1074
1096
|
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
@@ -1190,6 +1212,9 @@ JavaScript, but JS code described in SpiderMonkey AST in JSON. Therefore we
|
|
1190
1212
|
don't use our own parser in this case, but just transform that AST into our
|
1191
1213
|
internal AST.
|
1192
1214
|
|
1215
|
+
`spidermonkey` is also available in `minify` as `parse` and `format` options to
|
1216
|
+
accept and/or produce a spidermonkey AST.
|
1217
|
+
|
1193
1218
|
### Use Acorn for parsing
|
1194
1219
|
|
1195
1220
|
More for fun, I added the `-p acorn` option which will use Acorn to do all
|