terser 5.16.1 → 5.17.7
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 +80 -0
- package/README.md +19 -5
- package/dist/bundle.min.js +931 -459
- package/lib/ast.js +82 -9
- package/lib/compress/common.js +6 -3
- package/lib/compress/drop-side-effect-free.js +32 -20
- package/lib/compress/drop-unused.js +29 -30
- package/lib/compress/evaluate.js +20 -1
- package/lib/compress/index.js +63 -54
- package/lib/compress/inference.js +31 -3
- package/lib/compress/inline.js +119 -114
- package/lib/compress/native-objects.js +22 -0
- package/lib/compress/reduce-vars.js +111 -11
- package/lib/compress/tighten-body.js +61 -21
- package/lib/equivalent-to.js +1 -1
- package/lib/minify.js +23 -17
- package/lib/mozilla-ast.js +119 -41
- package/lib/output.js +98 -44
- package/lib/parse.js +78 -19
- package/lib/propmangle.js +11 -0
- package/lib/scope.js +5 -9
- package/lib/size.js +1 -3
- package/lib/transform.js +4 -10
- package/lib/utils/index.js +24 -39
- package/package.json +8 -9
- package/tools/domprops.js +3 -0
- package/tools/terser.d.ts +1 -0
- package/bin/terser.mjs +0 -21
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,85 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v5.17.7
|
4
|
+
- Update some dependencies
|
5
|
+
- Add consistent sorting for `v` RegExp flag
|
6
|
+
- Add `inert` DOM attribute to domprops
|
7
|
+
|
8
|
+
## v5.17.6
|
9
|
+
- Fixes to mozilla AST input and output, for class properties, private properties and static blocks
|
10
|
+
- Fix outputting a shorthand property in quotes when safari10 and ecma=2015 options are enabled
|
11
|
+
- `configurable` and `enumerable`, used in Object.defineProperty, added to domprops (#1393)
|
12
|
+
|
13
|
+
## v5.17.5
|
14
|
+
- Take into account the non-deferred bits of a class, such as static properties, while dropping unused code.
|
15
|
+
|
16
|
+
## v5.17.4
|
17
|
+
|
18
|
+
- Fix crash when trying to negate a class (`!class{}`)
|
19
|
+
- Avoid outputting comments between `yield`/`await` and its argument
|
20
|
+
- Fix detection of left-hand-side of assignment, to avoid optimizing it like any other expression in some edge cases
|
21
|
+
|
22
|
+
## v5.17.3
|
23
|
+
|
24
|
+
- Fix issue with trimming a static class property's contents accessing the class as `this`.
|
25
|
+
|
26
|
+
## v5.17.2
|
27
|
+
- Be less conservative when detecting use-before-definition of `var` in hoisted functions.
|
28
|
+
- Support unusual (but perfectly valid) initializers of for-in and for-of loops.
|
29
|
+
- Fix issue where hoisted function would be dropped if it was after a `continue` statement
|
30
|
+
|
31
|
+
## v5.17.1
|
32
|
+
- Fix evaluating `.length` when the source array might've been mutated
|
33
|
+
|
34
|
+
## v5.17.0
|
35
|
+
- Drop vestigial `= undefined` default argument in IIFE calls (#1366)
|
36
|
+
- Evaluate known arrays' `.length` property when statically determinable
|
37
|
+
- Add `@__KEY__` annotation to mangle string literals (#1365)
|
38
|
+
|
39
|
+
## v5.16.9
|
40
|
+
- Fix parentheses in output of optional chains (`a?.b`) (#1374)
|
41
|
+
- More documentation on source maps (#1368)
|
42
|
+
- New `lhs_constants` option, allowing to stop Terser from swapping comparison operands (#1361)
|
43
|
+
|
44
|
+
## v5.16.8
|
45
|
+
|
46
|
+
- Become even less conservative around function definitions for `reduce_vars`
|
47
|
+
- Fix parsing context of `import.meta` expressions such that method calls are allowed
|
48
|
+
|
49
|
+
## v5.16.6
|
50
|
+
|
51
|
+
- Become less conservative with analyzing function definitions for `reduce_vars`
|
52
|
+
- Parse `import.meta` as a real AST node and not an `object.property`
|
53
|
+
|
54
|
+
## v5.16.5
|
55
|
+
|
56
|
+
- Correctly handle AST transform functions that mutate children arrays
|
57
|
+
- Don't mutate the options object passed to Terser (#1342)
|
58
|
+
- Do not treat BigInt like a number
|
59
|
+
|
60
|
+
## v5.16.4
|
61
|
+
|
62
|
+
- Keep `(defaultArg = undefined) => ...`, because default args don't count for function length
|
63
|
+
- Prevent inlining variables into `?.` optional chains
|
64
|
+
- Avoid removing unused arguments while transforming
|
65
|
+
- Optimize iterating AST node lists
|
66
|
+
- Make sure `catch` and `finally` aren't children of `try` in the AST
|
67
|
+
- Use modern unicode property escapes (`\p{...}`) to parse identifiers when available
|
68
|
+
|
69
|
+
## v5.16.3
|
70
|
+
|
71
|
+
- Ensure function definitions, don't assume the values of variables defined after them.
|
72
|
+
|
73
|
+
## v5.16.2
|
74
|
+
|
75
|
+
- Fix sourcemaps with non-ascii characters (#1318)
|
76
|
+
- Support string module name and export * as (#1336)
|
77
|
+
- Do not move `let` out of `for` initializers, as it can change scoping
|
78
|
+
- Fix a corner case that would generate the invalid syntax `if (something) let x` ("let" in braceless if body)
|
79
|
+
- Knowledge of more native object properties (#1330)
|
80
|
+
- Got rid of Travis (#1323)
|
81
|
+
- Added semi-secret `asObject` sourcemap option to typescript defs (#1321)
|
82
|
+
|
3
83
|
## v5.16.1
|
4
84
|
|
5
85
|
- Properly handle references in destructurings (`const { [reference]: val } = ...`)
|
package/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![NPM Version][npm-image]][npm-url]
|
4
4
|
[![NPM Downloads][downloads-image]][downloads-url]
|
5
|
-
[![
|
5
|
+
[![CI pipeline][ci-image]][ci-url]
|
6
6
|
[![Opencollective financial contributors][opencollective-contributors]][opencollective-url]
|
7
7
|
|
8
8
|
A JavaScript mangler/compressor toolkit for ES6+.
|
@@ -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
|
-
[
|
25
|
-
[
|
24
|
+
[ci-image]: https://github.com/terser/terser/actions/workflows/ci.yml/badge.svg
|
25
|
+
[ci-url]: https://github.com/terser/terser/actions/workflows/ci.yml
|
26
26
|
[opencollective-contributors]: https://opencollective.com/terser/tiers/badge.svg
|
27
27
|
[opencollective-url]: https://opencollective.com/terser
|
28
28
|
|
@@ -708,7 +708,8 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
|
|
708
708
|
|
709
709
|
- `comparisons` (default: `true`) -- apply certain optimizations to binary nodes,
|
710
710
|
e.g. `!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
|
711
|
-
nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.
|
711
|
+
nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc. Note: `comparisons`
|
712
|
+
works best with `lhs_constants` enabled.
|
712
713
|
|
713
714
|
- `computed_props` (default: `true`) -- Transforms constant computed properties
|
714
715
|
into regular ones: `{["computed"]: 1}` is converted to `{computed: 1}`.
|
@@ -758,7 +759,7 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
|
|
758
759
|
- `3` -- inline functions with arguments and variables
|
759
760
|
- `true` -- same as `3`
|
760
761
|
|
761
|
-
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
762
|
+
- `join_vars` (default: `true`) -- join consecutive `var`, `let` and `const` statements
|
762
763
|
|
763
764
|
- `keep_classnames` (default: `false`) -- Pass `true` to prevent the compressor from
|
764
765
|
discarding class names. Pass a regular expression to only keep class names matching
|
@@ -775,6 +776,9 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
|
|
775
776
|
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
776
777
|
being compressed into `1/0`, which may cause performance issues on Chrome.
|
777
778
|
|
779
|
+
- `lhs_constants` (default: `true`) -- Moves constant values to the left-hand side
|
780
|
+
of binary nodes. `foo == 42 → 42 == foo`
|
781
|
+
|
778
782
|
- `loops` (default: `true`) -- optimizations for `do`, `while` and `for` loops
|
779
783
|
when we can statically determine the condition.
|
780
784
|
|
@@ -1184,6 +1188,7 @@ Annotations in Terser are a way to tell it to treat a certain function call diff
|
|
1184
1188
|
* `/*@__INLINE__*/` - forces a function to be inlined somewhere.
|
1185
1189
|
* `/*@__NOINLINE__*/` - Makes sure the called function is not inlined into the call site.
|
1186
1190
|
* `/*@__PURE__*/` - Marks a function call as pure. That means, it can safely be dropped.
|
1191
|
+
* `/*@__KEY__*/` - Marks a string literal as a property to also mangle it when mangling properties.
|
1187
1192
|
|
1188
1193
|
You can use either a `@` sign at the start, or a `#`.
|
1189
1194
|
|
@@ -1197,6 +1202,9 @@ function_always_inlined_here()
|
|
1197
1202
|
function_cant_be_inlined_into_here()
|
1198
1203
|
|
1199
1204
|
const x = /*#__PURE__*/i_am_dropped_if_x_is_not_used()
|
1205
|
+
|
1206
|
+
function lookup(object, key) { return object[key]; }
|
1207
|
+
lookup({ i_will_be_mangled_too: "bar" }, /*@__KEY__*/ "i_will_be_mangled_too");
|
1200
1208
|
```
|
1201
1209
|
|
1202
1210
|
### ESTree / SpiderMonkey AST
|
@@ -1267,6 +1275,12 @@ expected as code is optimized and mappings are often simply not possible as
|
|
1267
1275
|
some code no longer exists. For highest fidelity in source map debugging
|
1268
1276
|
disable the `compress` option and just use `mangle`.
|
1269
1277
|
|
1278
|
+
When debugging, make sure you enable the **"map scopes"** feature to map mangled variable names back to their original names.
|
1279
|
+
Without this, all variable values will be `undefined`. See https://github.com/terser/terser/issues/1367 for more details.
|
1280
|
+
<br/><br/>
|
1281
|
+
|
1282
|
+

|
1283
|
+
|
1270
1284
|
### Compiler assumptions
|
1271
1285
|
|
1272
1286
|
To allow for better optimizations, the compiler makes various assumptions:
|