terser 3.7.6 → 3.8.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.
Potentially problematic release.
This version of terser might be problematic. Click here for more details.
- package/README.md +55 -15
- package/bin/uglifyjs +19 -7
- package/dist/.gitkeep +0 -0
- package/dist/browser.bundle.js +11960 -0
- package/dist/browser.bundle.js.map +1 -0
- package/lib/ast.js +46 -47
- package/lib/compress.js +309 -254
- package/lib/minify.js +1 -1
- package/lib/mozilla-ast.js +31 -31
- package/lib/output.js +217 -213
- package/lib/parse.js +128 -108
- package/lib/propmangle.js +4 -4
- package/lib/scope.js +19 -19
- package/lib/sourcemap.js +3 -3
- package/lib/transform.js +37 -37
- package/lib/utils.js +29 -29
- package/package.json +35 -6
- package/tools/colorless-console.js +3 -2
- package/tools/exports.js +3 -3
package/README.md
CHANGED
@@ -3,8 +3,14 @@ terser
|
|
3
3
|
|
4
4
|
A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
Why choose terser?
|
8
|
+
------------------
|
9
|
+
|
10
|
+
`uglify-es` is no longer maintained and `uglify-js` does not support ES6+.
|
11
|
+
|
12
|
+
**`terser`** is a fork of `uglify-es` that retains API and CLI compatibility
|
13
|
+
with `uglify-es` and `uglify-js@3`.
|
8
14
|
|
9
15
|
Install
|
10
16
|
-------
|
@@ -19,7 +25,7 @@ From NPM for use as a command line app:
|
|
19
25
|
From NPM for programmatic use:
|
20
26
|
|
21
27
|
npm install terser
|
22
|
-
|
28
|
+
|
23
29
|
# Command line usage
|
24
30
|
|
25
31
|
terser [input files] [options]
|
@@ -635,7 +641,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|
635
641
|
the resultant code is shorter: `m(){return x}` becomes `m:()=>x`.
|
636
642
|
This transform requires that the `ecma` compress option is set to `6` or greater.
|
637
643
|
|
638
|
-
- `arguments` (default: `
|
644
|
+
- `arguments` (default: `false`) -- replace `arguments[index]` with function
|
639
645
|
parameter name whenever possible.
|
640
646
|
|
641
647
|
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
@@ -660,6 +666,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|
660
666
|
enabled `compress` transforms. Useful when you only want to enable a few
|
661
667
|
`compress` options while disabling the rest.
|
662
668
|
|
669
|
+
- `directives` (default: `true`) -- remove redundant or non-standard directives
|
670
|
+
|
663
671
|
- `drop_console` (default: `false`) -- Pass `true` to discard calls to
|
664
672
|
`console.*` functions. If you wish to drop a specific function call
|
665
673
|
such as `console.info` and/or retain side effects from function arguments
|
@@ -785,7 +793,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|
785
793
|
`foo === void 0`. Note: recommend to set this value to `false` for IE10 and
|
786
794
|
earlier versions due to known issues.
|
787
795
|
|
788
|
-
- `unsafe` (default: `false`) -- apply "unsafe" transformations
|
796
|
+
- `unsafe` (default: `false`) -- apply "unsafe" transformations
|
797
|
+
([details](#the-unsafe-compress-option)).
|
789
798
|
|
790
799
|
- `unsafe_arrows` (default: `false`) -- Convert ES5 style anonymous function
|
791
800
|
expressions to arrow functions if the function body does not reference `this`.
|
@@ -939,9 +948,6 @@ can pass additional arguments that control the code output:
|
|
939
948
|
adjust for this text. Can be used to insert a comment containing
|
940
949
|
licensing information, for example.
|
941
950
|
|
942
|
-
- `preserve_line` (default `false`) -- pass `true` to preserve lines, but it
|
943
|
-
only works if `beautify` is set to `false`.
|
944
|
-
|
945
951
|
- `quote_keys` (default `false`) -- pass `true` to quote all keys in literal
|
946
952
|
objects
|
947
953
|
|
@@ -975,7 +981,7 @@ can pass additional arguments that control the code output:
|
|
975
981
|
|
976
982
|
- `wrap_iife` (default `false`) -- pass `true` to wrap immediately invoked
|
977
983
|
function expressions. See
|
978
|
-
[#640](https://github.com/mishoo/
|
984
|
+
[#640](https://github.com/mishoo/UglifyJS2/issues/640) for more details.
|
979
985
|
|
980
986
|
# Miscellaneous
|
981
987
|
|
@@ -1010,14 +1016,16 @@ needs to be kept in the output) are comments attached to toplevel nodes.
|
|
1010
1016
|
### The `unsafe` `compress` option
|
1011
1017
|
|
1012
1018
|
It enables some transformations that *might* break code logic in certain
|
1013
|
-
contrived cases, but should be fine for most code.
|
1014
|
-
|
1015
|
-
|
1019
|
+
contrived cases, but should be fine for most code. It assumes that standard
|
1020
|
+
built-in ECMAScript functions and classes have not been altered or replaced.
|
1021
|
+
You might want to try it on your own code; it should reduce the minified size.
|
1022
|
+
Some examples of the optimizations made when this option is enabled:
|
1016
1023
|
|
1017
1024
|
- `new Array(1, 2, 3)` or `Array(1, 2, 3)` → `[ 1, 2, 3 ]`
|
1018
1025
|
- `new Object()` → `{}`
|
1019
1026
|
- `String(exp)` or `exp.toString()` → `"" + exp`
|
1020
1027
|
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
1028
|
+
- `"foo bar".substr(4)` → `"bar"`
|
1021
1029
|
|
1022
1030
|
### Conditional compilation
|
1023
1031
|
|
@@ -1133,9 +1141,14 @@ var result = Terser.minify(ast, {
|
|
1133
1141
|
|
1134
1142
|
### Working with Terser AST
|
1135
1143
|
|
1136
|
-
|
1137
|
-
[`TreeWalker`](
|
1138
|
-
[`TreeTransformer`](
|
1144
|
+
Traversal and transformation of the native AST can be performed through
|
1145
|
+
[`TreeWalker`](https://github.com/fabiosantoscode/terser/blob/master/lib/ast.js) and
|
1146
|
+
[`TreeTransformer`](https://github.com/fabiosantoscode/terser/blob/master/lib/transform.js)
|
1147
|
+
respectively.
|
1148
|
+
|
1149
|
+
Largely compatible native AST examples can be found in the original UglifyJS
|
1150
|
+
documention. See: [tree walker](http://lisperator.net/uglifyjs/walk) and
|
1151
|
+
[tree transform](http://lisperator.net/uglifyjs/transform).
|
1139
1152
|
|
1140
1153
|
### ESTree / SpiderMonkey AST
|
1141
1154
|
|
@@ -1217,3 +1230,30 @@ To allow for better optimizations, the compiler makes various assumptions:
|
|
1217
1230
|
- Object properties can be added, removed and modified (not prevented with
|
1218
1231
|
`Object.defineProperty()`, `Object.defineProperties()`, `Object.freeze()`,
|
1219
1232
|
`Object.preventExtensions()` or `Object.seal()`).
|
1233
|
+
|
1234
|
+
### Build Tools and Adaptors using Terser
|
1235
|
+
|
1236
|
+
https://www.npmjs.com/browse/depended/terser
|
1237
|
+
|
1238
|
+
### Replacing `uglify-es` with `terser` in a project using `yarn`
|
1239
|
+
|
1240
|
+
A number of JS bundlers and uglify wrappers are still using buggy versions
|
1241
|
+
of `uglify-es` and have not yet upgraded to `terser`. If you are using `yarn`
|
1242
|
+
you can add the following alias to your project's `package.json` file:
|
1243
|
+
|
1244
|
+
```js
|
1245
|
+
"resolutions": {
|
1246
|
+
"uglify-es": "npm:terser"
|
1247
|
+
}
|
1248
|
+
```
|
1249
|
+
|
1250
|
+
to use `terser` instead of `uglify-es` in all deeply nested dependencies
|
1251
|
+
without changing any code.
|
1252
|
+
|
1253
|
+
Note: for this change to take effect you must run the following commands
|
1254
|
+
to remove the existing `yarn` lock file and reinstall all packages:
|
1255
|
+
|
1256
|
+
```
|
1257
|
+
$ rm -rf node_modules yarn.lock
|
1258
|
+
$ yarn
|
1259
|
+
```
|
package/bin/uglifyjs
CHANGED
@@ -3,13 +3,25 @@
|
|
3
3
|
|
4
4
|
"use strict";
|
5
5
|
|
6
|
-
require("../tools/exit");
|
6
|
+
require("../tools/exit.js");
|
7
7
|
|
8
8
|
var fs = require("fs");
|
9
9
|
var info = require("../package.json");
|
10
10
|
var path = require("path");
|
11
11
|
var program = require("commander");
|
12
|
-
|
12
|
+
|
13
|
+
var bundle_path = __dirname + "/../dist/browser.bundle.js";
|
14
|
+
if (process.env.TERSER_DEBUG
|
15
|
+
/* note: commander not initialized yet */
|
16
|
+
&& !/--help|--self/.test(process.argv.toString())
|
17
|
+
&& fs.existsSync(bundle_path)) {
|
18
|
+
var UglifyJS = require(bundle_path);
|
19
|
+
try {
|
20
|
+
require("source-map-support").install();
|
21
|
+
} catch (err) {}
|
22
|
+
} else {
|
23
|
+
var UglifyJS = require("../tools/node.js");
|
24
|
+
}
|
13
25
|
|
14
26
|
var skip_keys = [ "cname", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ];
|
15
27
|
var files = {};
|
@@ -50,7 +62,7 @@ program.option("--name-cache <file>", "File to hold mangled name mappings.");
|
|
50
62
|
program.option("--rename", "Force symbol expansion.");
|
51
63
|
program.option("--no-rename", "Disable symbol expansion.");
|
52
64
|
program.option("--safari10", "Support non-standard Safari 10.");
|
53
|
-
program.option("--self", "Build
|
65
|
+
program.option("--self", "Build Terser as a library (implies --wrap Terser)");
|
54
66
|
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_source_map());
|
55
67
|
program.option("--timings", "Display operations run time on STDERR.");
|
56
68
|
program.option("--toplevel", "Compress and/or mangle variables in toplevel scope.");
|
@@ -112,8 +124,8 @@ if (program.mangleProps) {
|
|
112
124
|
} else {
|
113
125
|
if (typeof program.mangleProps != "object") program.mangleProps = {};
|
114
126
|
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
|
115
|
-
require("../tools/domprops").forEach(function(name) {
|
116
|
-
UglifyJS.
|
127
|
+
require("../tools/domprops.json").forEach(function(name) {
|
128
|
+
UglifyJS.push_uniq(program.mangleProps.reserved, name);
|
117
129
|
});
|
118
130
|
}
|
119
131
|
if (typeof options.mangle != "object") options.mangle = {};
|
@@ -161,7 +173,7 @@ if (program.self) {
|
|
161
173
|
if (program.args.length) {
|
162
174
|
print_error("WARN: Ignoring input files since --self was passed");
|
163
175
|
}
|
164
|
-
if (!options.wrap) options.wrap = "
|
176
|
+
if (!options.wrap) options.wrap = "Terser";
|
165
177
|
simple_glob(UglifyJS.FILES).forEach(function(name) {
|
166
178
|
files[convert_path(name)] = read_file(name);
|
167
179
|
});
|
@@ -343,7 +355,7 @@ function read_file(path, default_value) {
|
|
343
355
|
try {
|
344
356
|
return fs.readFileSync(path, "utf8");
|
345
357
|
} catch (ex) {
|
346
|
-
if (ex.code == "ENOENT" && default_value != null) return default_value;
|
358
|
+
if ((ex.code == "ENOENT" || ex.code == "ENAMETOOLONG") && default_value != null) return default_value;
|
347
359
|
fatal(ex);
|
348
360
|
}
|
349
361
|
}
|
package/dist/.gitkeep
ADDED
File without changes
|