1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-02 20:00:05 +02:00

update node modules

This commit is contained in:
s2
2021-05-07 15:56:33 +02:00
parent d81e8e9fb8
commit 3ec373077c
550 changed files with 84712 additions and 15991 deletions

257
node_modules/terser/README.md generated vendored
View File

@@ -21,8 +21,8 @@ Find the changelog in [CHANGELOG.md](https://github.com/terser/terser/blob/maste
[npm-url]: https://npmjs.org/package/terser
[downloads-image]: https://img.shields.io/npm/dm/terser.svg
[downloads-url]: https://npmjs.org/package/terser
[travis-image]: https://img.shields.io/travis/terser/terser/master.svg
[travis-url]: https://travis-ci.org/terser/terser
[travis-image]: https://travis-ci.com/terser/terser.svg?branch=master
[travis-url]: https://travis-ci.com/terser/terser
[opencollective-contributors]: https://opencollective.com/terser/tiers/badge.svg
[opencollective-url]: https://opencollective.com/terser
@@ -50,6 +50,8 @@ From NPM for programmatic use:
# Command line usage
<!-- CLI_USAGE:START -->
terser [input files] [options]
Terser can take multiple input files. It's recommended that you pass the
@@ -99,7 +101,7 @@ a double dash to prevent input files being used as option arguments:
being automatically reserved.
`regex` Only mangle matched property names.
`reserved` List of names that should not be mangled.
-b, --beautify [options] Specify output options:
-f, --format [options] Specify format options.
`preamble` Preamble to prepend to the output. You
can use this to insert a comment, for
example for licensing information.
@@ -137,7 +139,7 @@ a double dash to prevent input files being used as option arguments:
arguments and values.
--ie8 Support non-standard Internet Explorer 8.
Equivalent to setting `ie8: true` in `minify()`
for `compress`, `mangle` and `output` options.
for `compress`, `mangle` and `format` options.
By default Terser will not try to be IE-proof.
--keep-classnames Do not mangle/drop class names.
--keep-fnames Do not mangle/drop function names. Useful for
@@ -147,7 +149,7 @@ a double dash to prevent input files being used as option arguments:
--name-cache <file> File to hold mangled name mappings.
--safari10 Support non-standard Safari 10/11.
Equivalent to setting `safari10: true` in `minify()`
for `mangle` and `output` options.
for `mangle` and `format` options.
By default `terser` will not work around
Safari 10/11 bugs.
--source-map [options] Enable source map/specify source map options:
@@ -166,8 +168,6 @@ a double dash to prevent input files being used as option arguments:
`//# sourceMappingURL`.
--timings Display operations run time on STDERR.
--toplevel Compress and/or mangle variables in top level scope.
--verbose Print diagnostic messages.
--warn Print warning messages.
--wrap <name> Embed everything in a big function, making the
“exports” and “global” variables available. You
need to pass an argument to this option to
@@ -389,29 +389,40 @@ random number on every compile to simulate mangling changing with different
inputs (e.g. as you update the input script with new properties), and to help
identify mistakes like writing mangled keys to storage.
<!-- CLI_USAGE:END -->
# API Reference
<!-- API_REFERENCE:START -->
Assuming installation via NPM, you can load Terser in your application
like this:
```javascript
var Terser = require("terser");
```
Browser loading is also supported:
```html
<script src="node_modules/source-map/dist/source-map.min.js"></script>
<script src="dist/bundle.min.js"></script>
const { minify } = require("terser");
```
There is a single high level function, **`minify(code, options)`**,
Or,
```javascript
import { minify } from "terser";
```
Browser loading is also supported:
```html
<script src="https://cdn.jsdelivr.net/npm/source-map@0.7.3/dist/source-map.js"></script>
<script src="https://cdn.jsdelivr.net/npm/terser/dist/bundle.min.js"></script>
```
There is a single async high level function, **`async minify(code, options)`**,
which will perform all minification [phases](#minify-options) in a configurable
manner. By default `minify()` will enable the options [`compress`](#compress-options)
manner. By default `minify()` will enable [`compress`](#compress-options)
and [`mangle`](#mangle-options). Example:
```javascript
var code = "function add(first, second) { return first + second; }";
var result = Terser.minify(code);
console.log(result.error); // runtime error, or `undefined` if no error
var result = await minify(code, { sourceMap: true });
console.log(result.code); // minified output: function add(n,d){return n+d}
console.log(result.map); // source map
```
You can `minify` more than one JavaScript file at a time by using an object
@@ -422,7 +433,7 @@ var code = {
"file1.js": "function add(first, second) { return first + second; }",
"file2.js": "console.log(add(1 + 2, 3 + 4));"
};
var result = Terser.minify(code);
var result = await minify(code);
console.log(result.code);
// function add(d,n){return d+n}console.log(add(3,7));
```
@@ -434,7 +445,7 @@ var code = {
"file2.js": "console.log(add(1 + 2, 3 + 4));"
};
var options = { toplevel: true };
var result = Terser.minify(code, options);
var result = await minify(code, options);
console.log(result.code);
// console.log(3+7);
```
@@ -447,10 +458,10 @@ var options = {
},
nameCache: {}
};
var result1 = Terser.minify({
var result1 = await minify({
"file1.js": "function add(first, second) { return first + second; }"
}, options);
var result2 = Terser.minify({
var result2 = await minify({
"file2.js": "console.log(add(1 + 2, 3 + 4));"
}, options);
console.log(result1.code);
@@ -468,11 +479,11 @@ var options = {
},
nameCache: JSON.parse(fs.readFileSync(cacheFileName, "utf8"))
};
fs.writeFileSync("part1.js", Terser.minify({
fs.writeFileSync("part1.js", await minify({
"file1.js": fs.readFileSync("file1.js", "utf8"),
"file2.js": fs.readFileSync("file2.js", "utf8")
}, options).code, "utf8");
fs.writeFileSync("part2.js", Terser.minify({
fs.writeFileSync("part2.js", await minify({
"file3.js": fs.readFileSync("file3.js", "utf8"),
"file4.js": fs.readFileSync("file4.js", "utf8")
}, options).code, "utf8");
@@ -493,47 +504,31 @@ var options = {
},
passes: 2
},
output: {
beautify: false,
format: {
preamble: "/* minified */"
}
};
var result = Terser.minify(code, options);
var result = await minify(code, options);
console.log(result.code);
// /* minified */
// alert(10);"
```
To produce warnings:
```javascript
var code = "function f(){ var u; return 2 + 3; }";
var options = { warnings: true };
var result = Terser.minify(code, options);
console.log(result.error); // runtime error, `undefined` in this case
console.log(result.warnings); // [ 'Dropping unused variable u [0:1,18]' ]
console.log(result.code); // function f(){return 5}
```
An error example:
```javascript
var result = Terser.minify({"foo.js" : "if (0) else console.log(1);"});
console.log(JSON.stringify(result.error));
// {"message":"Unexpected token: keyword (else)","filename":"foo.js","line":1,"col":7,"pos":7}
```
Note: unlike `uglify-js@2.x`, the Terser API does not throw errors.
To achieve a similar effect one could do the following:
```javascript
var result = Terser.minify(code, options);
if (result.error) throw result.error;
try {
const result = await minify({"foo.js" : "if (0) else console.log(1);"});
// Do something with result
} catch (error) {
const { message, filename, line, col, pos } = error;
// Do something with error
}
```
## Minify options
- `ecma` (default `undefined`) - pass `5`, `2015`, `2016`, etc to override `parse`,
`compress` and `output`'s `ecma` options.
- `warnings` (default `false`) — pass `true` to return compressor warnings
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
- `ecma` (default `undefined`) - pass `5`, `2015`, `2016`, etc to override
`compress` and `format`'s `ecma` options.
- `parse` (default `{}`) — pass an object if you wish to specify some
additional [parse options](#parse-options).
@@ -551,8 +546,8 @@ if (result.error) throw result.error;
is implied and names can be mangled on the top scope. If `compress` or
`mangle` is enabled then the `toplevel` option will be enabled.
- `output` (default `null`) — pass an object if you wish to specify
additional [output options](#output-options). The defaults are optimized
- `format` or `output` (default `null`) — pass an object if you wish to specify
additional [format options](#format-options). The defaults are optimized
for best compression.
- `sourceMap` (default `false`) - pass an object if you wish to specify
@@ -581,7 +576,7 @@ if (result.error) throw result.error;
- `safari10` (default: `false`) - pass `true` to work around Safari 10/11 bugs in
loop scoping and `await`. See `safari10` options in [`mangle`](#mangle-options)
and [`output`](#output-options) for details.
and [`format`](#format-options) for details.
## Minify options structure
@@ -600,8 +595,8 @@ if (result.error) throw result.error;
// mangle property options
}
},
output: {
// output options
format: {
// format options (can also use `output` for backwards compatibility)
},
sourceMap: {
// source map options
@@ -613,8 +608,7 @@ if (result.error) throw result.error;
module: false,
nameCache: null, // or specify a name cache object
safari10: false,
toplevel: false,
warnings: false,
toplevel: false
}
```
@@ -622,7 +616,7 @@ if (result.error) throw result.error;
To generate a source map:
```javascript
var result = Terser.minify({"file1.js": "var a = function() {};"}, {
var result = await minify({"file1.js": "var a = function() {};"}, {
sourceMap: {
filename: "out.js",
url: "out.js.map"
@@ -643,7 +637,7 @@ be appended to code.
You can also specify sourceRoot property to be included in source map:
```javascript
var result = Terser.minify({"file1.js": "var a = function() {};"}, {
var result = await minify({"file1.js": "var a = function() {};"}, {
sourceMap: {
root: "http://example.com/src",
url: "out.js.map"
@@ -654,7 +648,7 @@ var result = Terser.minify({"file1.js": "var a = function() {};"}, {
If you're compressing compiled JavaScript and have a source map for it, you
can use `sourceMap.content`:
```javascript
var result = Terser.minify({"compiled.js": "compiled code"}, {
var result = await minify({"compiled.js": "compiled code"}, {
sourceMap: {
content: "content from compiled.js.map",
url: "minified.js.map"
@@ -671,14 +665,12 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
- `bare_returns` (default `false`) -- support top level `return` statements
- `ecma` (default: `2017`) -- specify one of `5`, `2015`, `2016` or `2017`. Note: this setting
is not presently enforced except for ES8 optional trailing commas in function
parameter lists and calls with `ecma` `2017`.
- `html5_comments` (default `true`)
- `shebang` (default `true`) -- support `#!command` as the first line
- `spidermonkey` (default `false`) -- accept a Spidermonkey (Mozilla) AST
## Compress options
- `defaults` (default: `true`) -- Pass `false` to disable most default
@@ -758,7 +750,7 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
- `keep_classnames` (default: `false`) -- Pass `true` to prevent the compressor from
discarding class names. Pass a regular expression to only keep class names matching
that regex. See also: the `keep_classnames` [mangle option](#mangle).
that regex. See also: the `keep_classnames` [mangle option](#mangle-options).
- `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused
function arguments. You need this for code which relies on `Function.length`.
@@ -766,7 +758,7 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
compressor from discarding function names. Pass a regular expression to only keep
function names matching that regex. Useful for code relying on `Function.prototype.name`.
See also: the `keep_fnames` [mangle option](#mangle).
See also: the `keep_fnames` [mangle option](#mangle-options).
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
being compressed into `1/0`, which may cause performance issues on Chrome.
@@ -805,11 +797,13 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
Specify `"strict"` to treat `foo.bar` as side-effect-free only when
`foo` is certain to not throw, i.e. not `null` or `undefined`.
- `reduce_funcs` (legacy option, safely ignored for backwards compatibility).
- `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and
used as constant values.
- `reduce_funcs` (default: `true`) -- Inline single-use functions when
possible. Depends on `reduce_vars` being enabled. Disabling this option
sometimes improves performance of the output code.
- `sequences` (default: `true`) -- join consecutive simple statements using the
comma operator. May be set to a positive integer to specify the maximum number
of consecutive comma sequences that will be generated. If this option is set to
@@ -819,10 +813,8 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
occasions the default sequences limit leads to very slow compress times in which
case a value of `20` or less is recommended.
- `side_effects` (default: `true`) -- Pass `false` to disable potentially dropping
function calls marked as "pure". A function call is marked as "pure" if a comment
annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For
example: `/*@__PURE__*/foo();`
- `side_effects` (default: `true`) -- Remove expressions which have no side effects
and whose results aren't used.
- `switches` (default: `true`) -- de-duplicate and remove unreachable `switch` branches
@@ -860,7 +852,7 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
- `unsafe_math` (default: `false`) -- optimize numerical expressions like
`2 * x * 3` into `6 * x`, which may give imprecise floating point results.
- `unsafe_symbols` (default: `false`) -- removes keys from native Symbol
- `unsafe_symbols` (default: `false`) -- removes keys from native Symbol
declarations, e.g `Symbol("kDog")` becomes `Symbol()`.
- `unsafe_methods` (default: false) -- Converts `{ m: function(){} }` to
@@ -883,9 +875,6 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
- `unused` (default: `true`) -- drop unreferenced functions and variables (simple
direct variable assignments do not count as references unless set to `"keep_assign"`)
- `warnings` (default: `false`) -- display warnings when dropping unreachable
code or unused declarations etc.
## Mangle options
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
@@ -912,7 +901,7 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
- `safari10` (default `false`) -- Pass `true` to work around the Safari 10 loop
iterator [bug](https://bugs.webkit.org/show_bug.cgi?id=171041)
"Cannot declare a let variable twice".
See also: the `safari10` [output option](#output-options).
See also: the `safari10` [format option](#format-options).
Examples:
@@ -926,13 +915,13 @@ function funcName(firstLongName, anotherLongName) {
```javascript
var code = fs.readFileSync("test.js", "utf8");
Terser.minify(code).code;
await minify(code).code;
// 'function funcName(a,n){}var globalVar;'
Terser.minify(code, { mangle: { reserved: ['firstLongName'] } }).code;
await minify(code, { mangle: { reserved: ['firstLongName'] } }).code;
// 'function funcName(firstLongName,a){}var globalVar;'
Terser.minify(code, { mangle: { toplevel: true } }).code;
await minify(code, { mangle: { toplevel: true } }).code;
// 'function n(n,a){}var a;'
```
@@ -944,11 +933,10 @@ Terser.minify(code, { mangle: { toplevel: true } }).code;
- `debug` (default: `false`) — Mangle names with the original name still present.
Pass an empty string `""` to enable, or a non-empty string to set the debug suffix.
- `keep_quoted` (default: `false`) — Only mangle unquoted property names.
- `true` -- Quoted property names are automatically reserved and any unquoted
property names will not be mangled.
- `"strict"` -- Advanced, all unquoted property names are mangled unless
explicitly reserved.
- `keep_quoted` (default: `false`) — How quoting properties (`{"prop": ...}` and `obj["prop"]`) controls what gets mangled.
- `"strict"` (recommended) -- `obj.prop` is mangled.
- `false` -- `obj["prop"]` is mangled.
- `true` -- `obj.prop` is mangled unless there is `obj["prop"]` elsewhere in the code.
- `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.
@@ -960,35 +948,33 @@ Terser.minify(code, { mangle: { toplevel: true } }).code;
found in input code. May be useful when only minifying parts of a project.
See [#397](https://github.com/terser/terser/issues/397) for more details.
## Output options
The code generator tries to output shortest code possible by default. In
case you want beautified output, pass `--beautify` (`-b`). Optionally you
can pass additional arguments that control the code output:
## Format options
These options control the format of Terser's output code. Previously known
as "output options".
- `ascii_only` (default `false`) -- escape Unicode characters in strings and
regexps (affects directives with non-ascii characters becoming invalid)
- `beautify` (default `true`) -- whether to actually beautify the output.
Passing `-b` will set this to true, but you might need to pass `-b` even
when you want to generate minified code, in order to specify additional
arguments, so you can use `-b beautify=false` to override it.
- `beautify` (default `false`) -- (DEPRECATED) whether to beautify the output.
When using the legacy `-b` CLI flag, this is set to true by default.
- `braces` (default `false`) -- always insert braces in `if`, `for`,
`do`, `while` or `with` statements, even if their body is a single
statement.
- `comments` (default `"some"`) -- by default it keeps JSDoc-style comments
that contain "@license" or "@preserve", pass `true` or `"all"` to preserve all
comments, `false` to omit comments in the output, a regular expression string
(e.g. `/^!/`) or a function.
that contain "@license", "@preserve" or start with `!`, pass `true` or
`"all"` to preserve all comments, `false` to omit comments in the output,
a regular expression string (e.g. `/^!/`) or a function.
- `ecma` (default `5`) -- set output printing mode. Set `ecma` to `2015` or
greater to emit shorthand object properties - i.e.: `{a}` instead of `{a: a}`.
The `ecma` option will only change the output in direct control of the
beautifier. Non-compatible features in the abstract syntax tree will still
be output as is. For example: an `ecma` setting of `5` will **not** convert
ES6+ code to ES5.
- `ecma` (default `5`) -- set desired EcmaScript standard version for output.
Set `ecma` to `2015` or greater to emit shorthand object properties - i.e.:
`{a}` instead of `{a: a}`. The `ecma` option will only change the output in
direct control of the beautifier. Non-compatible features in your input will
still be output as is. For example: an `ecma` setting of `5` will **not**
convert modern code to ES5.
- `indent_level` (default `4`)
@@ -1034,6 +1020,8 @@ can pass additional arguments that control the code output:
- `shebang` (default `true`) -- preserve shebang `#!` in preamble (bash scripts)
- `spidermonkey` (default `false`) -- produce a Spidermonkey (Mozilla) AST
- `webkit` (default `false`) -- enable workarounds for WebKit bugs.
PhantomJS users should set this option to `true`.
@@ -1103,10 +1091,6 @@ if (DEBUG) {
You can specify nested constants in the form of `--define env.DEBUG=false`.
Terser will warn about the condition being always false and about dropping
unreachable code; for now there is no option to turn off only this specific
warning, you can pass `warnings=false` to turn off *all* warnings.
Another way of doing that is to declare your globals as constants in a
separate file and include it into the build. For example you can have a
`build/defines.js` file with the following:
@@ -1132,7 +1116,7 @@ You can also use conditional compilation via the programmatic API. With the diff
property name is `global_defs` and is a compressor property:
```javascript
var result = Terser.minify(fs.readFileSync("input.js", "utf8"), {
var result = await minify(fs.readFileSync("input.js", "utf8"), {
compress: {
dead_code: true,
global_defs: {
@@ -1146,7 +1130,7 @@ To replace an identifier with an arbitrary non-constant expression it is
necessary to prefix the `global_defs` key with `"@"` to instruct Terser
to parse the value as an expression:
```javascript
Terser.minify("alert('hello');", {
await minify("alert('hello');", {
compress: {
global_defs: {
"@alert": "console.log"
@@ -1158,7 +1142,7 @@ Terser.minify("alert('hello');", {
Otherwise it would be replaced as string literal:
```javascript
Terser.minify("alert('hello');", {
await minify("alert('hello');", {
compress: {
global_defs: {
"alert": "console.log"
@@ -1168,40 +1152,6 @@ Terser.minify("alert('hello');", {
// returns: '"console.log"("hello");'
```
### Using native Terser AST with `minify()`
```javascript
// example: parse only, produce native Terser AST
var result = Terser.minify(code, {
parse: {},
compress: false,
mangle: false,
output: {
ast: true,
code: false // optional - faster if false
}
});
// result.ast contains native Terser AST
```
```javascript
// example: accept native Terser AST input and then compress and mangle
// to produce both code and native AST.
var result = Terser.minify(ast, {
compress: {},
mangle: {},
output: {
ast: true,
code: true // optional - faster if false
}
});
// result.ast contains native Terser AST
// result.code contains the minified code in string form.
```
### Annotations
Annotations in Terser are a way to tell it to treat a certain function call differently. The following annotations are available:
@@ -1224,18 +1174,6 @@ function_cant_be_inlined_into_here()
const x = /*#__PURE__*/i_am_dropped_if_x_is_not_used()
```
### Working with Terser AST
Traversal and transformation of the native AST can be performed through
[`TreeWalker`](https://github.com/fabiosantoscode/terser/blob/master/lib/ast.js) and
[`TreeTransformer`](https://github.com/fabiosantoscode/terser/blob/master/lib/transform.js)
respectively.
Largely compatible native AST examples can be found in the original UglifyJS
documentation. See: [tree walker](http://lisperator.net/uglifyjs/walk) and
[tree transform](http://lisperator.net/uglifyjs/transform).
### ESTree / SpiderMonkey AST
Terser has its own abstract syntax tree format; for
@@ -1255,6 +1193,9 @@ JavaScript, but JS code described in SpiderMonkey AST in JSON. Therefore we
don't use our own parser in this case, but just transform that AST into our
internal AST.
`spidermonkey` is also available in `minify` as `parse` and `format` options to
accept and/or produce a spidermonkey AST.
### Use Acorn for parsing
More for fun, I added the `-p acorn` option which will use Acorn to do all
@@ -1290,7 +1231,7 @@ terser file.js -m
```
To enable fast minify mode with the API use:
```js
Terser.minify(code, { compress: false, mangle: true });
await minify(code, { compress: false, mangle: true });
```
#### Source maps and debugging
@@ -1346,9 +1287,11 @@ $ rm -rf node_modules yarn.lock
$ yarn
```
<!-- API_REFERENCE:END -->
# Reporting issues
In the terser CLI we use [source-map-support](https://npmjs.com/source-map-support) to produce good error stacks. In your own app, you're expected to enable source-map-support (read their docs) to have nice stack traces that will make good issues.
In the terser CLI we use [source-map-support](https://npmjs.com/source-map-support) to produce good error stacks. In your own app, you're expected to enable source-map-support (read their docs) to have nice stack traces that will help you write good issues.
# README.md Patrons: