terser 5.9.0 → 5.14.2
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 +63 -0
- package/README.md +30 -8
- package/dist/bundle.min.js +5407 -3433
- package/lib/ast.js +1685 -348
- package/lib/cli.js +13 -9
- package/lib/compress/common.js +48 -0
- package/lib/compress/evaluate.js +18 -17
- package/lib/compress/index.js +57 -551
- package/lib/compress/inline.js +641 -0
- package/lib/compress/native-objects.js +1 -0
- package/lib/compress/tighten-body.js +1 -1
- package/lib/equivalent-to.js +81 -107
- package/lib/minify.js +96 -15
- package/lib/mozilla-ast.js +522 -87
- package/lib/output.js +94 -24
- package/lib/parse.js +91 -72
- package/lib/propmangle.js +1 -1
- package/lib/scope.js +27 -4
- package/lib/size.js +6 -8
- package/lib/sourcemap.js +60 -26
- package/lib/utils/index.js +9 -1
- package/package.json +9 -5
- package/tools/domprops.js +12 -0
- package/tools/terser.d.ts +6 -3
package/lib/size.js
CHANGED
@@ -115,6 +115,7 @@ AST_Directive.prototype._size = function () {
|
|
115
115
|
return 2 + this.value.length;
|
116
116
|
};
|
117
117
|
|
118
|
+
/** Count commas/semicolons necessary to show a list of expressions/statements */
|
118
119
|
const list_overhead = (array) => array.length && array.length - 1;
|
119
120
|
|
120
121
|
AST_Block.prototype._size = function () {
|
@@ -167,7 +168,7 @@ AST_Arrow.prototype._size = function () {
|
|
167
168
|
&& this.argnames[0] instanceof AST_Symbol
|
168
169
|
)
|
169
170
|
) {
|
170
|
-
args_and_arrow += 2;
|
171
|
+
args_and_arrow += 2; // parens around the args
|
171
172
|
}
|
172
173
|
|
173
174
|
const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2;
|
@@ -229,19 +230,16 @@ AST_Finally.prototype._size = function () {
|
|
229
230
|
return 7 + list_overhead(this.body);
|
230
231
|
};
|
231
232
|
|
232
|
-
/*#__INLINE__*/
|
233
|
-
const def_size = (size, def) => size + list_overhead(def.definitions);
|
234
|
-
|
235
233
|
AST_Var.prototype._size = function () {
|
236
|
-
return
|
234
|
+
return 4 + list_overhead(this.definitions);
|
237
235
|
};
|
238
236
|
|
239
237
|
AST_Let.prototype._size = function () {
|
240
|
-
return
|
238
|
+
return 4 + list_overhead(this.definitions);
|
241
239
|
};
|
242
240
|
|
243
241
|
AST_Const.prototype._size = function () {
|
244
|
-
return
|
242
|
+
return 6 + list_overhead(this.definitions);
|
245
243
|
};
|
246
244
|
|
247
245
|
AST_VarDef.prototype._size = function () {
|
@@ -477,7 +475,7 @@ AST_NaN.prototype._size = () => 3;
|
|
477
475
|
|
478
476
|
AST_Undefined.prototype._size = () => 6; // "void 0"
|
479
477
|
|
480
|
-
AST_Hole.prototype._size = () => 0; // comma is taken into account
|
478
|
+
AST_Hole.prototype._size = () => 0; // comma is taken into account by list_overhead()
|
481
479
|
|
482
480
|
AST_Infinity.prototype._size = () => 8;
|
483
481
|
|
package/lib/sourcemap.js
CHANGED
@@ -43,45 +43,59 @@
|
|
43
43
|
|
44
44
|
"use strict";
|
45
45
|
|
46
|
-
import
|
47
|
-
import {
|
48
|
-
defaults,
|
49
|
-
} from "./utils/index.js";
|
46
|
+
import {SourceMapConsumer, SourceMapGenerator} from "@jridgewell/source-map";
|
47
|
+
import {defaults, HOP} from "./utils/index.js";
|
50
48
|
|
51
|
-
// a small wrapper around
|
49
|
+
// a small wrapper around source-map and @jridgewell/source-map
|
52
50
|
async function SourceMap(options) {
|
53
51
|
options = defaults(options, {
|
54
52
|
file : null,
|
55
53
|
root : null,
|
56
54
|
orig : null,
|
57
|
-
|
58
|
-
orig_line_diff : 0,
|
59
|
-
dest_line_diff : 0,
|
55
|
+
files: {},
|
60
56
|
});
|
61
57
|
|
62
58
|
var orig_map;
|
63
|
-
var generator = new
|
59
|
+
var generator = new SourceMapGenerator({
|
64
60
|
file : options.file,
|
65
61
|
sourceRoot : options.root
|
66
62
|
});
|
67
63
|
|
64
|
+
let sourcesContent = {__proto__: null};
|
65
|
+
let files = options.files;
|
66
|
+
for (var name in files) if (HOP(files, name)) {
|
67
|
+
sourcesContent[name] = files[name];
|
68
|
+
}
|
68
69
|
if (options.orig) {
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
// We support both @jridgewell/source-map (which has a sync
|
71
|
+
// SourceMapConsumer) and source-map (which has an async
|
72
|
+
// SourceMapConsumer).
|
73
|
+
orig_map = await new SourceMapConsumer(options.orig);
|
74
|
+
if (orig_map.sourcesContent) {
|
75
|
+
orig_map.sources.forEach(function(source, i) {
|
76
|
+
var content = orig_map.sourcesContent[i];
|
77
|
+
if (content) {
|
78
|
+
sourcesContent[source] = content;
|
79
|
+
}
|
80
|
+
});
|
81
|
+
}
|
76
82
|
}
|
77
83
|
|
78
84
|
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
|
85
|
+
let generatedPos = { line: gen_line, column: gen_col };
|
86
|
+
|
79
87
|
if (orig_map) {
|
80
88
|
var info = orig_map.originalPositionFor({
|
81
89
|
line: orig_line,
|
82
90
|
column: orig_col
|
83
91
|
});
|
84
92
|
if (info.source === null) {
|
93
|
+
generator.addMapping({
|
94
|
+
generated: generatedPos,
|
95
|
+
original: null,
|
96
|
+
source: null,
|
97
|
+
name: null
|
98
|
+
});
|
85
99
|
return;
|
86
100
|
}
|
87
101
|
source = info.source;
|
@@ -90,22 +104,42 @@ async function SourceMap(options) {
|
|
90
104
|
name = info.name || name;
|
91
105
|
}
|
92
106
|
generator.addMapping({
|
93
|
-
generated :
|
94
|
-
original : { line: orig_line
|
107
|
+
generated : generatedPos,
|
108
|
+
original : { line: orig_line, column: orig_col },
|
95
109
|
source : source,
|
96
110
|
name : name
|
97
111
|
});
|
112
|
+
generator.setSourceContent(source, sourcesContent[source]);
|
113
|
+
}
|
114
|
+
|
115
|
+
function clean(map) {
|
116
|
+
const allNull = map.sourcesContent && map.sourcesContent.every(c => c == null);
|
117
|
+
if (allNull) delete map.sourcesContent;
|
118
|
+
if (map.file === undefined) delete map.file;
|
119
|
+
if (map.sourceRoot === undefined) delete map.sourceRoot;
|
120
|
+
return map;
|
121
|
+
}
|
122
|
+
|
123
|
+
function getDecoded() {
|
124
|
+
if (!generator.toDecodedMap) return null;
|
125
|
+
return clean(generator.toDecodedMap());
|
126
|
+
}
|
127
|
+
|
128
|
+
function getEncoded() {
|
129
|
+
return clean(generator.toJSON());
|
130
|
+
}
|
131
|
+
|
132
|
+
function destroy() {
|
133
|
+
// @jridgewell/source-map's SourceMapConsumer does not need to be
|
134
|
+
// manually freed.
|
135
|
+
if (orig_map && orig_map.destroy) orig_map.destroy();
|
98
136
|
}
|
99
137
|
|
100
138
|
return {
|
101
|
-
add
|
102
|
-
|
103
|
-
|
104
|
-
destroy
|
105
|
-
if (orig_map && orig_map.destroy) {
|
106
|
-
orig_map.destroy();
|
107
|
-
}
|
108
|
-
}
|
139
|
+
add,
|
140
|
+
getDecoded,
|
141
|
+
getEncoded,
|
142
|
+
destroy,
|
109
143
|
};
|
110
144
|
}
|
111
145
|
|
package/lib/utils/index.js
CHANGED
@@ -249,7 +249,15 @@ function regexp_source_fix(source) {
|
|
249
249
|
return (escaped ? "" : "\\") + lineTerminatorEscape[match];
|
250
250
|
});
|
251
251
|
}
|
252
|
-
|
252
|
+
|
253
|
+
// Subset of regexps that is not going to cause regexp based DDOS
|
254
|
+
// https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
|
255
|
+
const re_safe_regexp = /^[\\/|\0\s\w^$.[\]()]*$/;
|
256
|
+
|
257
|
+
/** Check if the regexp is safe for Terser to create without risking a RegExp DOS */
|
258
|
+
export const regexp_is_safe = (source) => re_safe_regexp.test(source);
|
259
|
+
|
260
|
+
const all_flags = "dgimsuy";
|
253
261
|
function sort_regexp_flags(flags) {
|
254
262
|
const existing_flags = new Set(flags.split(""));
|
255
263
|
let out = "";
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"homepage": "https://terser.org",
|
5
5
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
6
6
|
"license": "BSD-2-Clause",
|
7
|
-
"version": "5.
|
7
|
+
"version": "5.14.2",
|
8
8
|
"engines": {
|
9
9
|
"node": ">=10"
|
10
10
|
},
|
@@ -18,6 +18,7 @@
|
|
18
18
|
"exports": {
|
19
19
|
".": [
|
20
20
|
{
|
21
|
+
"types": "./tools/terser.d.ts",
|
21
22
|
"import": "./main.js",
|
22
23
|
"require": "./dist/bundle.min.js"
|
23
24
|
},
|
@@ -43,22 +44,23 @@
|
|
43
44
|
"main.js"
|
44
45
|
],
|
45
46
|
"dependencies": {
|
47
|
+
"@jridgewell/source-map": "^0.3.2",
|
48
|
+
"acorn": "^8.5.0",
|
46
49
|
"commander": "^2.20.0",
|
47
|
-
"source-map": "~0.7.2",
|
48
50
|
"source-map-support": "~0.5.20"
|
49
51
|
},
|
50
52
|
"devDependencies": {
|
51
53
|
"@ls-lint/ls-lint": "^1.10.0",
|
52
|
-
"acorn": "^8.5.0",
|
53
54
|
"astring": "^1.7.5",
|
54
55
|
"eslint": "^7.32.0",
|
55
56
|
"eslump": "^3.0.0",
|
56
57
|
"esm": "^3.2.25",
|
57
|
-
"mocha": "^9.
|
58
|
+
"mocha": "^9.2.0",
|
58
59
|
"pre-commit": "^1.2.2",
|
59
60
|
"rimraf": "^3.0.2",
|
60
61
|
"rollup": "2.56.3",
|
61
|
-
"semver": "^7.3.4"
|
62
|
+
"semver": "^7.3.4",
|
63
|
+
"source-map": "~0.8.0-beta.0"
|
62
64
|
},
|
63
65
|
"scripts": {
|
64
66
|
"test": "node test/compress.js && mocha test/mocha",
|
@@ -104,6 +106,8 @@
|
|
104
106
|
"describe": false,
|
105
107
|
"it": false,
|
106
108
|
"require": false,
|
109
|
+
"before": false,
|
110
|
+
"after": false,
|
107
111
|
"global": false,
|
108
112
|
"process": false
|
109
113
|
},
|
package/tools/domprops.js
CHANGED
@@ -320,6 +320,7 @@ export var domprops = [
|
|
320
320
|
"COMMENT_NODE",
|
321
321
|
"COMPARE_REF_TO_TEXTURE",
|
322
322
|
"COMPILE_STATUS",
|
323
|
+
"COMPLETION_STATUS_KHR",
|
323
324
|
"COMPRESSED_RGBA_S3TC_DXT1_EXT",
|
324
325
|
"COMPRESSED_RGBA_S3TC_DXT3_EXT",
|
325
326
|
"COMPRESSED_RGBA_S3TC_DXT5_EXT",
|
@@ -2979,6 +2980,7 @@ export var domprops = [
|
|
2979
2980
|
"applyElement",
|
2980
2981
|
"arc",
|
2981
2982
|
"arcTo",
|
2983
|
+
"architecture",
|
2982
2984
|
"archive",
|
2983
2985
|
"areas",
|
2984
2986
|
"arguments",
|
@@ -3153,6 +3155,7 @@ export var domprops = [
|
|
3153
3155
|
"bindTexture",
|
3154
3156
|
"bindTransformFeedback",
|
3155
3157
|
"bindVertexArray",
|
3158
|
+
"bitness",
|
3156
3159
|
"blendColor",
|
3157
3160
|
"blendEquation",
|
3158
3161
|
"blendEquationSeparate",
|
@@ -3314,6 +3317,8 @@ export var domprops = [
|
|
3314
3317
|
"boxDecorationBreak",
|
3315
3318
|
"boxShadow",
|
3316
3319
|
"boxSizing",
|
3320
|
+
"brand",
|
3321
|
+
"brands",
|
3317
3322
|
"break-after",
|
3318
3323
|
"break-before",
|
3319
3324
|
"break-inside",
|
@@ -4312,6 +4317,7 @@ export var domprops = [
|
|
4312
4317
|
"fround",
|
4313
4318
|
"fullPath",
|
4314
4319
|
"fullScreen",
|
4320
|
+
"fullVersionList",
|
4315
4321
|
"fullscreen",
|
4316
4322
|
"fullscreenElement",
|
4317
4323
|
"fullscreenEnabled",
|
@@ -4437,6 +4443,7 @@ export var domprops = [
|
|
4437
4443
|
"getFrequencyResponse",
|
4438
4444
|
"getFullYear",
|
4439
4445
|
"getGamepads",
|
4446
|
+
"getHighEntropyValues",
|
4440
4447
|
"getHitTestResults",
|
4441
4448
|
"getHitTestResultsForTransientInput",
|
4442
4449
|
"getHours",
|
@@ -5277,7 +5284,9 @@ export var domprops = [
|
|
5277
5284
|
"mix-blend-mode",
|
5278
5285
|
"mixBlendMode",
|
5279
5286
|
"mm",
|
5287
|
+
"mobile",
|
5280
5288
|
"mode",
|
5289
|
+
"model",
|
5281
5290
|
"modify",
|
5282
5291
|
"mount",
|
5283
5292
|
"move",
|
@@ -6183,6 +6192,7 @@ export var domprops = [
|
|
6183
6192
|
"placeItems",
|
6184
6193
|
"placeSelf",
|
6185
6194
|
"placeholder",
|
6195
|
+
"platformVersion",
|
6186
6196
|
"platform",
|
6187
6197
|
"platforms",
|
6188
6198
|
"play",
|
@@ -7421,6 +7431,7 @@ export var domprops = [
|
|
7421
7431
|
"user-select",
|
7422
7432
|
"userActivation",
|
7423
7433
|
"userAgent",
|
7434
|
+
"userAgentData",
|
7424
7435
|
"userChoice",
|
7425
7436
|
"userHandle",
|
7426
7437
|
"userHint",
|
@@ -7734,6 +7745,7 @@ export var domprops = [
|
|
7734
7745
|
"wordSpacing",
|
7735
7746
|
"wordWrap",
|
7736
7747
|
"workerStart",
|
7748
|
+
"wow64",
|
7737
7749
|
"wrap",
|
7738
7750
|
"wrapKey",
|
7739
7751
|
"writable",
|
package/tools/terser.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
/// <reference lib="es2015" />
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { SectionedSourceMapInput, EncodedSourceMap, DecodedSourceMap } from '@jridgewell/source-map';
|
4
4
|
|
5
5
|
export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
|
6
6
|
|
7
7
|
export interface ParseOptions {
|
8
8
|
bare_returns?: boolean;
|
9
|
+
/** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
|
9
10
|
ecma?: ECMA;
|
10
11
|
html5_comments?: boolean;
|
11
12
|
shebang?: boolean;
|
@@ -144,6 +145,7 @@ export interface FormatOptions {
|
|
144
145
|
}) => boolean );
|
145
146
|
ecma?: ECMA;
|
146
147
|
ie8?: boolean;
|
148
|
+
keep_numbers?: boolean;
|
147
149
|
indent_level?: number;
|
148
150
|
indent_start?: number;
|
149
151
|
inline_script?: boolean;
|
@@ -192,12 +194,13 @@ export interface MinifyOptions {
|
|
192
194
|
|
193
195
|
export interface MinifyOutput {
|
194
196
|
code?: string;
|
195
|
-
map?:
|
197
|
+
map?: EncodedSourceMap | string;
|
198
|
+
decoded_map?: DecodedSourceMap | null;
|
196
199
|
}
|
197
200
|
|
198
201
|
export interface SourceMapOptions {
|
199
202
|
/** Source map object, 'inline' or source map file content */
|
200
|
-
content?:
|
203
|
+
content?: SectionedSourceMapInput | string;
|
201
204
|
includeSources?: boolean;
|
202
205
|
filename?: string;
|
203
206
|
root?: string;
|