terser 3.16.1 → 3.17.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.
Potentially problematic release.
This version of terser might be problematic. Click here for more details.
- package/CHANGELOG.md +10 -1
- package/README.md +39 -11
- package/bin/uglifyjs +26 -16
- package/bin/uglifyjsnobundle +3 -2
- package/dist/bundle.js +314 -304
- package/dist/bundle.js.map +1 -1
- package/dist/bundle.min.js +1 -1
- package/dist/bundle.min.js.map +1 -1
- package/package.json +16 -15
- package/tools/domprops.js +4 -0
package/CHANGELOG.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v3.17.0
|
4
|
+
|
5
|
+
- More DOM properties added to --mangle-properties's DOM property list
|
6
|
+
- Closed issue where if 2 functions had the same argument name, Terser would not inline them together properly
|
7
|
+
- Fixed issue with `hasOwnProperty.call`
|
8
|
+
- You can now list files to minify in a Terser config file
|
9
|
+
- Started replacing `new Array(<number>)` with an array literal
|
10
|
+
- Started using ES6 capabilities like `Set` and the `includes` method for strings and arrays
|
11
|
+
|
3
12
|
## v3.16.1
|
4
13
|
|
5
|
-
- Fixed issue where Terser being imported with `import` would cause it not to work due to the `__esModule` property.
|
14
|
+
- Fixed issue where Terser being imported with `import` would cause it not to work due to the `__esModule` property. (PR #254 was submitted, which was nice, but since it wasn't a pure commonJS approach I decided to go with my own solution)
|
6
15
|
|
7
16
|
## v3.16.0
|
8
17
|
|
package/README.md
CHANGED
@@ -5,16 +5,18 @@ terser
|
|
5
5
|
|
6
6
|
A JavaScript parser and mangler/compressor toolkit for ES6+.
|
7
7
|
|
8
|
-
*note*: You can support this project on patreon: <a target="_blank" rel="nofollow" href="https://www.patreon.com/
|
8
|
+
*note*: You can support this project on patreon: <a target="_blank" rel="nofollow" href="https://www.patreon.com/fabiosantoscode"><img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" alt="patron" width="100px" height="auto"></a>. Check out PATRONS.md for our first-tier patrons.
|
9
9
|
|
10
10
|
Terser recommends you use RollupJS to bundle your modules, as that produces smaller code overall.
|
11
11
|
|
12
12
|
*Beautification* has been undocumented and is *being removed* from terser, we recommend you use [prettier](https://npmjs.com/package/prettier).
|
13
13
|
|
14
|
-
[](https://travis-ci.org/terser-js/terser)
|
14
|
+
[](https://travis-ci.org/terser-js/terser)
|
15
15
|
|
16
16
|
Find the changelog in [CHANGELOG.md](https://github.com/terser-js/terser/blob/master/CHANGELOG.md)
|
17
17
|
|
18
|
+
A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.
|
19
|
+
|
18
20
|
|
19
21
|
Why choose terser?
|
20
22
|
------------------
|
@@ -87,6 +89,7 @@ a double dash to prevent input files being used as option arguments:
|
|
87
89
|
`keep_quoted` Only mangle unquoted properties.
|
88
90
|
`regex` Only mangle matched property names.
|
89
91
|
`reserved` List of names that should not be mangled.
|
92
|
+
-b, --beautify [options] Specify output options:
|
90
93
|
`preamble` Preamble to prepend to the output. You
|
91
94
|
can use this to insert a comment, for
|
92
95
|
example for licensing information.
|
@@ -239,11 +242,28 @@ to prevent the `require`, `exports` and `$` names from being changed.
|
|
239
242
|
|
240
243
|
### CLI mangling property names (`--mangle-props`)
|
241
244
|
|
242
|
-
**Note:** THIS
|
243
|
-
|
244
|
-
|
245
|
+
**Note:** THIS **WILL** BREAK YOUR CODE. A good rule of thumb is not to use this unless you know exactly what you're doing and how this works and read this section until the end.
|
246
|
+
|
247
|
+
Mangling property names is a separate step, different from variable name mangling. Pass
|
248
|
+
`--mangle-props` to enable it. The least dangerous
|
249
|
+
way to use this is to use the `regex` option like so:
|
250
|
+
|
251
|
+
```
|
252
|
+
terser example.js -c -m --mangle-props regex=/_$/
|
253
|
+
```
|
254
|
+
|
255
|
+
This will mangle all properties that start with an
|
256
|
+
underscore. So you can use it to mangle internal methods.
|
257
|
+
|
258
|
+
By default, it will mangle all properties in the
|
245
259
|
input code with the exception of built in DOM properties and properties
|
246
|
-
in core JavaScript classes
|
260
|
+
in core JavaScript classes, which is what will break your code if you don't:
|
261
|
+
|
262
|
+
1. Control all the code you're mangling
|
263
|
+
2. Avoid using a module bundler, as they usually will call Terser on each file individually, making it impossible to pass mangled objects between modules.
|
264
|
+
3. Avoid calling functions like `defineProperty` or `hasOwnProperty`, because they refer to object properties using strings and will break your code if you don't know what you are doing.
|
265
|
+
|
266
|
+
An example:
|
247
267
|
|
248
268
|
```javascript
|
249
269
|
// example.js
|
@@ -258,21 +278,21 @@ x.bar_ = 2;
|
|
258
278
|
x["baz_"] = 3;
|
259
279
|
console.log(x.calc());
|
260
280
|
```
|
261
|
-
Mangle all properties (except for JavaScript `builtins`):
|
281
|
+
Mangle all properties (except for JavaScript `builtins`) (**very** unsafe):
|
262
282
|
```bash
|
263
283
|
$ terser example.js -c -m --mangle-props
|
264
284
|
```
|
265
285
|
```javascript
|
266
286
|
var x={o:0,_:1,l:function(){return this._+this.o}};x.t=2,x.o=3,console.log(x.l());
|
267
287
|
```
|
268
|
-
Mangle all properties except for `reserved` properties:
|
288
|
+
Mangle all properties except for `reserved` properties (still very unsafe):
|
269
289
|
```bash
|
270
290
|
$ terser example.js -c -m --mangle-props reserved=[foo_,bar_]
|
271
291
|
```
|
272
292
|
```javascript
|
273
293
|
var x={o:0,foo_:1,_:function(){return this.foo_+this.o}};x.bar_=2,x.o=3,console.log(x._());
|
274
294
|
```
|
275
|
-
Mangle all properties matching a `regex
|
295
|
+
Mangle all properties matching a `regex` (not as unsafe but still unsafe):
|
276
296
|
```bash
|
277
297
|
$ terser example.js -c -m --mangle-props regex=/_$/
|
278
298
|
```
|
@@ -466,6 +486,7 @@ var options = {
|
|
466
486
|
passes: 2
|
467
487
|
},
|
468
488
|
output: {
|
489
|
+
beautify: false,
|
469
490
|
preamble: "/* minified */"
|
470
491
|
}
|
471
492
|
};
|
@@ -923,12 +944,18 @@ Terser.minify(code, { mangle: { toplevel: true } }).code;
|
|
923
944
|
|
924
945
|
## Output options
|
925
946
|
|
926
|
-
The code generator tries to output shortest code possible
|
947
|
+
The code generator tries to output shortest code possible by default. In
|
948
|
+
case you want beautified output, pass `--beautify` (`-b`). Optionally you
|
927
949
|
can pass additional arguments that control the code output:
|
928
950
|
|
929
951
|
- `ascii_only` (default `false`) -- escape Unicode characters in strings and
|
930
952
|
regexps (affects directives with non-ascii characters becoming invalid)
|
931
953
|
|
954
|
+
- `beautify` (default `true`) -- whether to actually beautify the output.
|
955
|
+
Passing `-b` will set this to true, but you might need to pass `-b` even
|
956
|
+
when you want to generate minified code, in order to specify additional
|
957
|
+
arguments, so you can use `-b beautify=false` to override it.
|
958
|
+
|
932
959
|
- `braces` (default `false`) -- always insert braces in `if`, `for`,
|
933
960
|
`do`, `while` or `with` statements, even if their body is a single
|
934
961
|
statement.
|
@@ -939,7 +966,8 @@ can pass additional arguments that control the code output:
|
|
939
966
|
|
940
967
|
- `ecma` (default `5`) -- set output printing mode. Set `ecma` to `6` or
|
941
968
|
greater to emit shorthand object properties - i.e.: `{a}` instead of `{a: a}`.
|
942
|
-
|
969
|
+
The `ecma` option will only change the output in direct control of the
|
970
|
+
beautifier. Non-compatible features in the abstract syntax tree will still
|
943
971
|
be output as is. For example: an `ecma` setting of `5` will **not** convert
|
944
972
|
ES6+ code to ES5.
|
945
973
|
|
package/bin/uglifyjs
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
// -*- js -*-
|
3
|
+
/* eslint-env node */
|
3
4
|
|
4
5
|
"use strict";
|
5
6
|
|
@@ -27,12 +28,12 @@ var options = {
|
|
27
28
|
program.version(info.name + " " + info.version);
|
28
29
|
program.parseArgv = program.parse;
|
29
30
|
program.parse = undefined;
|
30
|
-
if (process.argv.
|
31
|
-
else if (process.argv.
|
31
|
+
if (process.argv.includes("ast")) program.helpInformation = describe_ast;
|
32
|
+
else if (process.argv.includes("options")) program.helpInformation = function() {
|
32
33
|
var text = [];
|
33
34
|
var options = UglifyJS.default_options();
|
34
35
|
for (var option in options) {
|
35
|
-
text.push("--" + (option
|
36
|
+
text.push("--" + (option === "output" ? "beautify" : option === "sourceMap" ? "source-map" : option) + " options:");
|
36
37
|
text.push(format_object(options[option]));
|
37
38
|
text.push("");
|
38
39
|
}
|
@@ -160,8 +161,18 @@ if (program.verbose) {
|
|
160
161
|
} else if (program.warn) {
|
161
162
|
options.warnings = true;
|
162
163
|
}
|
163
|
-
|
164
|
-
|
164
|
+
|
165
|
+
let filesList;
|
166
|
+
if (options.files && options.files.length) {
|
167
|
+
filesList = options.files;
|
168
|
+
|
169
|
+
delete options.files;
|
170
|
+
} else if (program.args.length) {
|
171
|
+
filesList = program.args;
|
172
|
+
}
|
173
|
+
|
174
|
+
if (filesList) {
|
175
|
+
simple_glob(filesList).forEach(function(name) {
|
165
176
|
files[convert_path(name)] = read_file(name);
|
166
177
|
});
|
167
178
|
run();
|
@@ -297,7 +308,7 @@ function run() {
|
|
297
308
|
}
|
298
309
|
|
299
310
|
function fatal(message) {
|
300
|
-
if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:")
|
311
|
+
if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:");
|
301
312
|
print_error(message);
|
302
313
|
process.exit(1);
|
303
314
|
}
|
@@ -390,7 +401,7 @@ function parse_js(flag) {
|
|
390
401
|
}
|
391
402
|
}
|
392
403
|
return options;
|
393
|
-
}
|
404
|
+
};
|
394
405
|
}
|
395
406
|
|
396
407
|
function parse_source_map() {
|
@@ -399,15 +410,14 @@ function parse_source_map() {
|
|
399
410
|
var hasContent = options && "content" in options;
|
400
411
|
var settings = parse(value, options);
|
401
412
|
if (!hasContent && settings.content && settings.content != "inline") {
|
402
|
-
print_error("INFO: Using input source map: " + settings.content);
|
403
413
|
settings.content = read_file(settings.content, settings.content);
|
404
414
|
}
|
405
415
|
return settings;
|
406
|
-
}
|
416
|
+
};
|
407
417
|
}
|
408
418
|
|
409
419
|
function skip_key(key) {
|
410
|
-
return skip_keys.
|
420
|
+
return skip_keys.includes(key);
|
411
421
|
}
|
412
422
|
|
413
423
|
function symdef(def) {
|
@@ -442,13 +452,13 @@ function describe_ast() {
|
|
442
452
|
var out = UglifyJS.OutputStream({ beautify: true });
|
443
453
|
function doitem(ctor) {
|
444
454
|
out.print("AST_" + ctor.TYPE);
|
445
|
-
var props = ctor.SELF_PROPS.filter(function(prop){
|
455
|
+
var props = ctor.SELF_PROPS.filter(function(prop) {
|
446
456
|
return !/^\$/.test(prop);
|
447
457
|
});
|
448
458
|
if (props.length > 0) {
|
449
459
|
out.space();
|
450
|
-
out.with_parens(function(){
|
451
|
-
props.forEach(function(prop, i){
|
460
|
+
out.with_parens(function() {
|
461
|
+
props.forEach(function(prop, i) {
|
452
462
|
if (i) out.space();
|
453
463
|
out.print(prop);
|
454
464
|
});
|
@@ -460,15 +470,15 @@ function describe_ast() {
|
|
460
470
|
}
|
461
471
|
if (ctor.SUBCLASSES.length > 0) {
|
462
472
|
out.space();
|
463
|
-
out.with_block(function(){
|
464
|
-
ctor.SUBCLASSES.forEach(function(ctor, i){
|
473
|
+
out.with_block(function() {
|
474
|
+
ctor.SUBCLASSES.forEach(function(ctor, i) {
|
465
475
|
out.indent();
|
466
476
|
doitem(ctor);
|
467
477
|
out.newline();
|
468
478
|
});
|
469
479
|
});
|
470
480
|
}
|
471
|
-
}
|
481
|
+
}
|
472
482
|
doitem(UglifyJS.AST_Node);
|
473
483
|
return out + "\n";
|
474
484
|
}
|
package/bin/uglifyjsnobundle
CHANGED