terser 3.14.0 → 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 +28 -0
- package/PATRONS.md +5 -0
- package/README.md +49 -14
- package/bin/uglifyjs +34 -26
- package/bin/uglifyjsnobundle +3 -2
- package/dist/bundle.js +21955 -45
- package/dist/bundle.js.map +1 -1
- package/dist/bundle.min.js +2 -0
- package/dist/bundle.min.js.map +1 -0
- package/package.json +33 -22
- package/tools/domprops.js +5 -1
- package/tools/node.js +3 -36
- package/lib/ast.js +0 -1260
- package/lib/compress.js +0 -6801
- package/lib/minify.js +0 -260
- package/lib/mozilla-ast.js +0 -1087
- package/lib/output.js +0 -1939
- package/lib/parse.js +0 -2986
- package/lib/propmangle.js +0 -267
- package/lib/scope.js +0 -723
- package/lib/sourcemap.js +0 -97
- package/lib/transform.js +0 -275
- package/lib/utils.js +0 -350
- package/tools/exports.js +0 -14
package/lib/minify.js
DELETED
@@ -1,260 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var to_ascii = typeof atob == "undefined" ? function(b64) {
|
4
|
-
if (Buffer.from && Buffer.from !== Uint8Array.from) {
|
5
|
-
// Node >= 4.5.0
|
6
|
-
return Buffer.from(b64, "base64").toString();
|
7
|
-
} else {
|
8
|
-
// Node < 4.5.0, old API, manual safeguards
|
9
|
-
if (typeof b64 !== "string") throw new Errror("\"b64\" must be a string");
|
10
|
-
return new Buffer(b64, "base64").toString();
|
11
|
-
}
|
12
|
-
} : atob;
|
13
|
-
var to_base64 = typeof btoa == "undefined" ? function(str) {
|
14
|
-
if (Buffer.from && Buffer.from !== Uint8Array.from) {
|
15
|
-
// Node >= 4.5.0
|
16
|
-
return Buffer.from(str).toString("base64");
|
17
|
-
} else {
|
18
|
-
// Node < 4.5.0, old API, manual safeguards
|
19
|
-
if (typeof str !== "string") throw new Errror("\"str\" must be a string");
|
20
|
-
return new Buffer(str).toString("base64");
|
21
|
-
}
|
22
|
-
} : btoa;
|
23
|
-
|
24
|
-
function read_source_map(code) {
|
25
|
-
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code);
|
26
|
-
if (!match) {
|
27
|
-
AST_Node.warn("inline source map not found");
|
28
|
-
return null;
|
29
|
-
}
|
30
|
-
return to_ascii(match[2]);
|
31
|
-
}
|
32
|
-
|
33
|
-
function set_shorthand(name, options, keys) {
|
34
|
-
if (options[name]) {
|
35
|
-
keys.forEach(function(key) {
|
36
|
-
if (options[key]) {
|
37
|
-
if (typeof options[key] != "object") options[key] = {};
|
38
|
-
if (!(name in options[key])) options[key][name] = options[name];
|
39
|
-
}
|
40
|
-
});
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
function init_cache(cache) {
|
45
|
-
if (!cache) return;
|
46
|
-
if (!("props" in cache)) {
|
47
|
-
cache.props = new Dictionary();
|
48
|
-
} else if (!(cache.props instanceof Dictionary)) {
|
49
|
-
cache.props = Dictionary.fromObject(cache.props);
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
function to_json(cache) {
|
54
|
-
return {
|
55
|
-
props: cache.props.toObject()
|
56
|
-
};
|
57
|
-
}
|
58
|
-
|
59
|
-
function minify(files, options) {
|
60
|
-
var warn_function = AST_Node.warn_function;
|
61
|
-
try {
|
62
|
-
options = defaults(options, {
|
63
|
-
compress: {},
|
64
|
-
ecma: undefined,
|
65
|
-
enclose: false,
|
66
|
-
ie8: false,
|
67
|
-
keep_classnames: undefined,
|
68
|
-
keep_fnames: false,
|
69
|
-
mangle: {},
|
70
|
-
module: false,
|
71
|
-
nameCache: null,
|
72
|
-
output: {},
|
73
|
-
parse: {},
|
74
|
-
rename: undefined,
|
75
|
-
safari10: false,
|
76
|
-
sourceMap: false,
|
77
|
-
timings: false,
|
78
|
-
toplevel: false,
|
79
|
-
warnings: false,
|
80
|
-
wrap: false,
|
81
|
-
}, true);
|
82
|
-
var timings = options.timings && {
|
83
|
-
start: Date.now()
|
84
|
-
};
|
85
|
-
if (options.keep_classnames === undefined) {
|
86
|
-
options.keep_classnames = options.keep_fnames;
|
87
|
-
}
|
88
|
-
if (options.rename === undefined) {
|
89
|
-
options.rename = options.compress && options.mangle;
|
90
|
-
}
|
91
|
-
set_shorthand("ecma", options, [ "parse", "compress", "output" ]);
|
92
|
-
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
93
|
-
set_shorthand("keep_classnames", options, [ "compress", "mangle" ]);
|
94
|
-
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
95
|
-
set_shorthand("module", options, [ "parse", "compress", "mangle" ]);
|
96
|
-
set_shorthand("safari10", options, [ "mangle", "output" ]);
|
97
|
-
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
98
|
-
set_shorthand("warnings", options, [ "compress" ]);
|
99
|
-
var quoted_props;
|
100
|
-
if (options.mangle) {
|
101
|
-
options.mangle = defaults(options.mangle, {
|
102
|
-
cache: options.nameCache && (options.nameCache.vars || {}),
|
103
|
-
eval: false,
|
104
|
-
ie8: false,
|
105
|
-
keep_classnames: false,
|
106
|
-
keep_fnames: false,
|
107
|
-
module: false,
|
108
|
-
properties: false,
|
109
|
-
reserved: [],
|
110
|
-
safari10: false,
|
111
|
-
toplevel: false,
|
112
|
-
}, true);
|
113
|
-
if (options.mangle.properties) {
|
114
|
-
if (typeof options.mangle.properties != "object") {
|
115
|
-
options.mangle.properties = {};
|
116
|
-
}
|
117
|
-
if (options.mangle.properties.keep_quoted) {
|
118
|
-
quoted_props = options.mangle.properties.reserved;
|
119
|
-
if (!Array.isArray(quoted_props)) quoted_props = [];
|
120
|
-
options.mangle.properties.reserved = quoted_props;
|
121
|
-
}
|
122
|
-
if (options.nameCache && !("cache" in options.mangle.properties)) {
|
123
|
-
options.mangle.properties.cache = options.nameCache.props || {};
|
124
|
-
}
|
125
|
-
}
|
126
|
-
init_cache(options.mangle.cache);
|
127
|
-
init_cache(options.mangle.properties.cache);
|
128
|
-
}
|
129
|
-
if (options.sourceMap) {
|
130
|
-
options.sourceMap = defaults(options.sourceMap, {
|
131
|
-
content: null,
|
132
|
-
filename: null,
|
133
|
-
includeSources: false,
|
134
|
-
root: null,
|
135
|
-
url: null,
|
136
|
-
}, true);
|
137
|
-
}
|
138
|
-
var warnings = [];
|
139
|
-
if (options.warnings && !AST_Node.warn_function) {
|
140
|
-
AST_Node.warn_function = function(warning) {
|
141
|
-
warnings.push(warning);
|
142
|
-
};
|
143
|
-
}
|
144
|
-
if (timings) timings.parse = Date.now();
|
145
|
-
var toplevel;
|
146
|
-
if (files instanceof AST_Toplevel) {
|
147
|
-
toplevel = files;
|
148
|
-
} else {
|
149
|
-
if (typeof files == "string") {
|
150
|
-
files = [ files ];
|
151
|
-
}
|
152
|
-
options.parse = options.parse || {};
|
153
|
-
options.parse.toplevel = null;
|
154
|
-
for (var name in files) if (HOP(files, name)) {
|
155
|
-
options.parse.filename = name;
|
156
|
-
options.parse.toplevel = parse(files[name], options.parse);
|
157
|
-
if (options.sourceMap && options.sourceMap.content == "inline") {
|
158
|
-
if (Object.keys(files).length > 1)
|
159
|
-
throw new Error("inline source map only works with singular input");
|
160
|
-
options.sourceMap.content = read_source_map(files[name]);
|
161
|
-
}
|
162
|
-
}
|
163
|
-
toplevel = options.parse.toplevel;
|
164
|
-
}
|
165
|
-
if (quoted_props) {
|
166
|
-
reserve_quoted_keys(toplevel, quoted_props);
|
167
|
-
}
|
168
|
-
if (options.wrap) {
|
169
|
-
toplevel = toplevel.wrap_commonjs(options.wrap);
|
170
|
-
}
|
171
|
-
if (options.enclose) {
|
172
|
-
toplevel = toplevel.wrap_enclose(options.enclose);
|
173
|
-
}
|
174
|
-
if (timings) timings.rename = Date.now();
|
175
|
-
// disable rename on harmony due to expand_names bug in for-of loops
|
176
|
-
// https://github.com/mishoo/UglifyJS2/issues/2794
|
177
|
-
if (0 && options.rename) {
|
178
|
-
toplevel.figure_out_scope(options.mangle);
|
179
|
-
toplevel.expand_names(options.mangle);
|
180
|
-
}
|
181
|
-
if (timings) timings.compress = Date.now();
|
182
|
-
if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
|
183
|
-
if (timings) timings.scope = Date.now();
|
184
|
-
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
185
|
-
if (timings) timings.mangle = Date.now();
|
186
|
-
if (options.mangle) {
|
187
|
-
base54.reset();
|
188
|
-
toplevel.compute_char_frequency(options.mangle);
|
189
|
-
toplevel.mangle_names(options.mangle);
|
190
|
-
}
|
191
|
-
if (timings) timings.properties = Date.now();
|
192
|
-
if (options.mangle && options.mangle.properties) {
|
193
|
-
toplevel = mangle_properties(toplevel, options.mangle.properties);
|
194
|
-
}
|
195
|
-
if (timings) timings.output = Date.now();
|
196
|
-
var result = {};
|
197
|
-
if (options.output.ast) {
|
198
|
-
result.ast = toplevel;
|
199
|
-
}
|
200
|
-
if (!HOP(options.output, "code") || options.output.code) {
|
201
|
-
if (options.sourceMap) {
|
202
|
-
if (typeof options.sourceMap.content == "string") {
|
203
|
-
options.sourceMap.content = JSON.parse(options.sourceMap.content);
|
204
|
-
}
|
205
|
-
options.output.source_map = SourceMap({
|
206
|
-
file: options.sourceMap.filename,
|
207
|
-
orig: options.sourceMap.content,
|
208
|
-
root: options.sourceMap.root
|
209
|
-
});
|
210
|
-
if (options.sourceMap.includeSources) {
|
211
|
-
if (files instanceof AST_Toplevel) {
|
212
|
-
throw new Error("original source content unavailable");
|
213
|
-
} else for (var name in files) if (HOP(files, name)) {
|
214
|
-
options.output.source_map.get().setSourceContent(name, files[name]);
|
215
|
-
}
|
216
|
-
}
|
217
|
-
}
|
218
|
-
delete options.output.ast;
|
219
|
-
delete options.output.code;
|
220
|
-
var stream = OutputStream(options.output);
|
221
|
-
toplevel.print(stream);
|
222
|
-
result.code = stream.get();
|
223
|
-
if (options.sourceMap) {
|
224
|
-
result.map = options.output.source_map.toString();
|
225
|
-
if (options.sourceMap.url == "inline") {
|
226
|
-
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
227
|
-
} else if (options.sourceMap.url) {
|
228
|
-
result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}
|
232
|
-
if (options.nameCache && options.mangle) {
|
233
|
-
if (options.mangle.cache) options.nameCache.vars = to_json(options.mangle.cache);
|
234
|
-
if (options.mangle.properties && options.mangle.properties.cache) {
|
235
|
-
options.nameCache.props = to_json(options.mangle.properties.cache);
|
236
|
-
}
|
237
|
-
}
|
238
|
-
if (timings) {
|
239
|
-
timings.end = Date.now();
|
240
|
-
result.timings = {
|
241
|
-
parse: 1e-3 * (timings.rename - timings.parse),
|
242
|
-
rename: 1e-3 * (timings.compress - timings.rename),
|
243
|
-
compress: 1e-3 * (timings.scope - timings.compress),
|
244
|
-
scope: 1e-3 * (timings.mangle - timings.scope),
|
245
|
-
mangle: 1e-3 * (timings.properties - timings.mangle),
|
246
|
-
properties: 1e-3 * (timings.output - timings.properties),
|
247
|
-
output: 1e-3 * (timings.end - timings.output),
|
248
|
-
total: 1e-3 * (timings.end - timings.start)
|
249
|
-
};
|
250
|
-
}
|
251
|
-
if (warnings.length) {
|
252
|
-
result.warnings = warnings;
|
253
|
-
}
|
254
|
-
return result;
|
255
|
-
} catch (ex) {
|
256
|
-
return { error: ex };
|
257
|
-
} finally {
|
258
|
-
AST_Node.warn_function = warn_function;
|
259
|
-
}
|
260
|
-
}
|