1 | // Type definitions for UglifyJS 3.13
|
2 | // Project: https://github.com/mishoo/UglifyJS
|
3 | // Definitions by: Alan Agius <https://github.com/alan-agius4>
|
4 | // Tanguy Krotoff <https://github.com/tkrotoff>
|
5 | // John Reilly <https://github.com/johnnyreilly>
|
6 | // Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
7 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
8 |
|
9 | import { RawSourceMap } from 'source-map';
|
10 | export interface ParseOptions {
|
11 | /**
|
12 | * Support top level `return` statements
|
13 | * @default false
|
14 | */
|
15 | bare_returns?: boolean | undefined;
|
16 | /** @default true */
|
17 | html5_comments?: boolean | undefined;
|
18 | /**
|
19 | * Support `#!command` as the first line
|
20 | * @default true
|
21 | */
|
22 | shebang?: boolean | undefined;
|
23 | }
|
24 |
|
25 | export interface CompressOptions {
|
26 | /**
|
27 | * Replace `arguments[index]` with function parameter name whenever possible.
|
28 | * @default true
|
29 | */
|
30 | arguments?: boolean | undefined;
|
31 | /**
|
32 | * Apply optimizations to assignment expressions
|
33 | * @default ture
|
34 | */
|
35 | assignments?: boolean | undefined;
|
36 | /**
|
37 | * Various optimizations for boolean context, for example `!!a ? b : c → a ? b : c`
|
38 | * @default true
|
39 | */
|
40 | booleans?: boolean | undefined;
|
41 | /**
|
42 | * Collapse single-use non-constant variables, side effects permitting.
|
43 | * @default true
|
44 | */
|
45 | collapse_vars?: boolean | undefined;
|
46 | /**
|
47 | * Apply certain optimizations to binary nodes, e.g. `!(a <= b) → a > b,` attempts to negate binary nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc
|
48 | * @default true
|
49 | */
|
50 | comparisons?: boolean | undefined;
|
51 | /**
|
52 | * Apply optimizations for `if-s` and conditional expressions.
|
53 | * @default true
|
54 | */
|
55 | conditionals?: boolean | undefined;
|
56 | /**
|
57 | * Remove unreachable code
|
58 | * @default true
|
59 | */
|
60 | dead_code?: boolean | undefined;
|
61 | /**
|
62 | * remove redundant or non-standard directives
|
63 | * @default true
|
64 | */
|
65 | directives?: boolean | undefined;
|
66 | /**
|
67 | * Pass `true` to discard calls to console.* functions.
|
68 | * If you wish to drop a specific function call such as `console.info` and/or retain side effects from function
|
69 | * arguments after dropping the function call then use `pure_funcs` instead.
|
70 | * @default true
|
71 | */
|
72 | drop_console?: boolean | undefined;
|
73 | /**
|
74 | * Remove `debugger;` statements
|
75 | * @default true
|
76 | */
|
77 | drop_debugger?: boolean | undefined;
|
78 | /**
|
79 | * Attempt to evaluate constant expressions
|
80 | * @default true
|
81 | */
|
82 | evaluate?: boolean | undefined;
|
83 | /**
|
84 | * Pass `true` to preserve completion values from terminal statements without `return`, e.g. in bookmarklets.
|
85 | * @default false
|
86 | */
|
87 | expression?: boolean | undefined;
|
88 | /**
|
89 | * convert declarations from varto function whenever possible
|
90 | * @default true
|
91 | */
|
92 | functions?: boolean | undefined;
|
93 | /**
|
94 | * @default {}
|
95 | */
|
96 | global_defs?: object | undefined;
|
97 | /**
|
98 | * hoist function declarations
|
99 | * @default false
|
100 | */
|
101 |
|
102 | /**
|
103 | * hoist `export` statements to facilitate various `compress` and `mangle` optimizations.
|
104 | * @default true
|
105 | */
|
106 | hoist_exports?: boolean | undefined;
|
107 | hoist_funs?: boolean | undefined;
|
108 | /**
|
109 | * Hoist properties from constant object and array literals into regular variables subject to a set of constraints.
|
110 | * For example: `var o={p:1, q:2}; f(o.p, o.q);` is converted to `f(1, 2);`. Note: `hoist_props` works best with mangle enabled,
|
111 | * the compress option passes set to 2 or higher, and the compress option toplevel enabled.
|
112 | * @default true
|
113 | */
|
114 | hoist_props?: boolean | undefined;
|
115 | /**
|
116 | * Hoist var declarations (this is `false` by default because it seems to increase the size of the output in general)
|
117 | * @default false
|
118 | */
|
119 | hoist_vars?: boolean | undefined;
|
120 | /**
|
121 | * Optimizations for if/return and if/continue
|
122 | * @default true
|
123 | */
|
124 | if_return?: boolean | undefined;
|
125 | /**
|
126 | * drop unreferenced import symbols when used with `unused`
|
127 | * @default true
|
128 | */
|
129 | imports?: boolean | undefined;
|
130 | /**
|
131 | * Inline calls to function with simple/return statement
|
132 | * - false -- same as `Disabled`
|
133 | * - `Disabled` -- disabled inlining
|
134 | * - `SimpleFunctions` -- inline simple functions
|
135 | * - `WithArguments` -- inline functions with arguments
|
136 | * - `WithArgumentsAndVariables` -- inline functions with arguments and variables
|
137 | * - true -- same as `WithArgumentsAndVariables`
|
138 | * @default true
|
139 | */
|
140 | inline?: boolean | InlineFunctions | undefined;
|
141 | /**
|
142 | * join consecutive `var` statements
|
143 | * @default true
|
144 | */
|
145 | join_vars?: boolean | undefined;
|
146 | /**
|
147 | * Prevents the compressor from discarding unused function arguments.
|
148 | * You need this for code which relies on `Function.length`
|
149 | * @default 'strict'
|
150 | */
|
151 | keep_fargs?: 'strict' | boolean | undefined;
|
152 | /**
|
153 | * Pass true to prevent the compressor from discarding function names.
|
154 | * Useful for code relying on `Function.prototype.name`.
|
155 | * @default false
|
156 | */
|
157 | keep_fnames?: boolean | undefined;
|
158 | /**
|
159 | * Pass true to prevent Infinity from being compressed into `1/0`, which may cause performance issues on `Chrome`
|
160 | * @default false
|
161 | */
|
162 | keep_infinity?: boolean | undefined;
|
163 | /**
|
164 | * Optimizations for `do`, `while` and `for` loops when we can statically determine the condition.
|
165 | * @default true
|
166 | */
|
167 | loops?: boolean | undefined;
|
168 | /**
|
169 | * combine and reuse variables.
|
170 | * @default true
|
171 | */
|
172 | merge_vars?: boolean | undefined;
|
173 | /**
|
174 | * negate `Immediately-Called Function Expressions` where the return value is discarded,
|
175 | * to avoid the parens that the code generator would insert.
|
176 | * @default true
|
177 | */
|
178 | negate_iife?: boolean | undefined;
|
179 | /**
|
180 | * compact duplicate keys in object literals
|
181 | * @default true
|
182 | */
|
183 | objects?: boolean | undefined;
|
184 | /**
|
185 | * The maximum number of times to run compress.
|
186 | * In some cases more than one pass leads to further compressed code.
|
187 | * Keep in mind more passes will take more time.
|
188 | * @default 1
|
189 | */
|
190 | passes?: number | undefined;
|
191 | /**
|
192 | * Rewrite property access using the dot notation, for example `foo["bar"]` to `foo.bar`
|
193 | * @default true
|
194 | */
|
195 | properties?: boolean | undefined;
|
196 | /**
|
197 | * An array of names and UglifyJS will assume that those functions do not produce side effects.
|
198 | * DANGER: will not check if the name is redefined in scope.
|
199 | * An example case here, for instance `var q = Math.floor(a/b)`.
|
200 | * If variable q is not used elsewhere, UglifyJS will drop it, but will still keep the `Math.floor(a/b)`,
|
201 | * not knowing what it does. You can pass `pure_funcs: [ 'Math.floor' ]` to let it know that this function
|
202 | * won't produce any side effect, in which case the whole statement would get discarded. The current
|
203 | * implementation adds some overhead (compression will be slower).
|
204 | * @default null
|
205 | */
|
206 | pure_funcs?: string[] | null | undefined;
|
207 | /**
|
208 | * If you pass true for this, UglifyJS will assume that object property access
|
209 | * (e.g. foo.bar or foo["bar"]) doesn't have any side effects.
|
210 | * Specify "strict" to treat foo.bar as side-effect-free only when foo is certain to not throw,
|
211 | * i.e. not null or undefine
|
212 | * @default 'strict'
|
213 | */
|
214 | pure_getters?: boolean | 'strict' | undefined;
|
215 | /**
|
216 | * Allows single-use functions to be inlined as function expressions when permissible allowing further optimization.
|
217 | * Enabled by default. Option depends on reduce_vars being enabled. Some code runs faster in the Chrome V8 engine if
|
218 | * this option is disabled. Does not negatively impact other major browsers.
|
219 | * @default true
|
220 | */
|
221 | reduce_funcs?: boolean | undefined;
|
222 | /**
|
223 | * Improve optimization on variables assigned with and used as constant values.
|
224 | * @default true
|
225 | */
|
226 | reduce_vars?: boolean | undefined;
|
227 | /**
|
228 | * join consecutive simple statements using the comma operator.
|
229 | * May be set to a positive integer to specify the maximum number of
|
230 | * consecutive comma sequences that will be generated.
|
231 | * If this option is set to true then the default sequences limit is 200.
|
232 | * Set option to false or 0 to disable. The smallest sequences length is 2.
|
233 | * A sequences value of 1 is grandfathered to be equivalent to true and as such means 200.
|
234 | * On rare occasions the default sequences limit leads to very slow compress times in which case
|
235 | * a value of 20 or less is recommended
|
236 | * @default true
|
237 | */
|
238 | sequences?: boolean | undefined;
|
239 | /**
|
240 | * Pass false to disable potentially dropping functions marked as "pure".
|
241 | * @default true
|
242 | */
|
243 | side_effects?: boolean | undefined;
|
244 | /**
|
245 | * compact string concatenations
|
246 | * @default true
|
247 | */
|
248 | strings?: boolean | undefined;
|
249 | /**
|
250 | * De-duplicate and remove unreachable `switch` branches.
|
251 | * @default true
|
252 | */
|
253 | switches?: boolean | undefined;
|
254 | /**
|
255 | * Compact template literals by embedding expressions and/or converting to string literals, e.g. `foo ${42}` → "foo 42"
|
256 | * @default true
|
257 | */
|
258 | templates?: boolean | undefined;
|
259 | /**
|
260 | * Drop unreferenced functions ("funcs") and/or variables ("vars") in the top level scope (false by default,
|
261 | * true to drop both unreferenced functions and variables)
|
262 | * @default false
|
263 | */
|
264 | toplevel?: boolean | undefined;
|
265 | /**
|
266 | * Prevent specific toplevel functions and variables from unused removal
|
267 | * (can be array, comma-separated, RegExp or function. Implies toplevel)
|
268 | * @default null
|
269 | */
|
270 | top_retain?: boolean | null | undefined;
|
271 | /**
|
272 | * Transforms typeof foo == "undefined" into foo === void 0.
|
273 | * Note: recommend to set this value to false for IE10 and earlier versions due to known issues
|
274 | * @default true
|
275 | */
|
276 | typeofs?: boolean | undefined;
|
277 | /**
|
278 | * apply "unsafe" transformations (discussion below)
|
279 | * @default false
|
280 | */
|
281 | unsafe?: boolean | undefined;
|
282 | /**
|
283 | * Compress expressions like a `<= b` assuming none of the operands can be (coerced to) `NaN`.
|
284 | * @default false
|
285 | */
|
286 | unsafe_comps?: boolean | undefined;
|
287 | /**
|
288 | * Compress and mangle `Function(args, code)` when both args and code are string literals.
|
289 | * @default false
|
290 | */
|
291 | unsafe_Function?: boolean | undefined;
|
292 | /**
|
293 | * Optimize numerical expressions like `2 * x * 3` into `6 * x`,
|
294 | * which may give imprecise floating point results.
|
295 | * @default false
|
296 | */
|
297 | unsafe_math?: boolean | undefined;
|
298 | /**
|
299 | * Optimize expressions like `Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
300 | * @default false
|
301 | */
|
302 | unsafe_proto?: boolean | undefined;
|
303 | /**
|
304 | * Enable substitutions of variables with `RegExp` values the same way as if they are constants.
|
305 | * @default false
|
306 | */
|
307 | unsafe_regexp?: boolean | undefined;
|
308 | /**
|
309 | * substitute void 0 if there is a variable named undefined in scope
|
310 | * (variable name will be mangled, typically reduced to a single character)
|
311 | * @default false
|
312 | */
|
313 | unsafe_undefined?: boolean | undefined;
|
314 | /**
|
315 | * drop unreferenced functions and variables
|
316 | * (simple direct variable assignments do not count as references unless set to "keep_assign")
|
317 | * @default true
|
318 | */
|
319 | unused?: boolean | undefined;
|
320 | /**
|
321 | * convert block-scoped declaractions into `var`
|
322 | * whenever safe to do so
|
323 | * @default true
|
324 | */
|
325 | varify?: boolean | undefined;
|
326 | }
|
327 |
|
328 | export enum InlineFunctions {
|
329 | Disabled = 0,
|
330 | SimpleFunctions = 1,
|
331 | WithArguments = 2,
|
332 | WithArgumentsAndVariables = 3,
|
333 | }
|
334 | export interface MangleOptions {
|
335 | /** Pass true to mangle names visible in scopes where `eval` or with are used. */
|
336 | eval?: boolean | undefined;
|
337 | /** Pass true to not mangle function names. Useful for code relying on `Function.prototype.name`. */
|
338 | keep_fnames?: boolean | undefined;
|
339 | /** Pass an array of identifiers that should be excluded from mangling. Example: `["foo", "bar"]`. */
|
340 | reserved?: string[] | undefined;
|
341 | /** Pass true to mangle names declared in the top level scope. */
|
342 | toplevel?: boolean | undefined;
|
343 | properties?: boolean | ManglePropertiesOptions | undefined;
|
344 | }
|
345 |
|
346 | export interface ManglePropertiesOptions {
|
347 | /** Use true to allow the mangling of builtin DOM properties. Not recommended to override this setting. */
|
348 | builtins?: boolean | undefined;
|
349 | /** Mangle names with the original name still present. Pass an empty string "" to enable, or a non-empty string to set the debug suffix. */
|
350 | debug?: boolean | undefined;
|
351 | /** Only mangle unquoted property names */
|
352 | keep_quoted?: boolean | undefined;
|
353 | /** Pass a RegExp literal to only mangle property names matching the regular expression. */
|
354 | regex?: RegExp | undefined;
|
355 | /** Do not mangle property names listed in the reserved array */
|
356 | reserved?: string[] | undefined;
|
357 | }
|
358 |
|
359 | export interface OutputOptions {
|
360 | ascii_only?: boolean | undefined;
|
361 | beautify?: boolean | undefined;
|
362 | braces?: boolean | undefined;
|
363 | comments?: boolean | 'all' | 'some' | RegExp | undefined;
|
364 | indent_level?: number | undefined;
|
365 | indent_start?: boolean | undefined;
|
366 | inline_script?: boolean | undefined;
|
367 | keep_quoted_props?: boolean | undefined;
|
368 | max_line_len?: boolean | number | undefined;
|
369 | preamble?: string | undefined;
|
370 | preserve_line?: boolean | undefined;
|
371 | quote_keys?: boolean | undefined;
|
372 | quote_style?: OutputQuoteStyle | undefined;
|
373 | semicolons?: boolean | undefined;
|
374 | shebang?: boolean | undefined;
|
375 | webkit?: boolean | undefined;
|
376 | width?: number | undefined;
|
377 | wrap_iife?: boolean | undefined;
|
378 | }
|
379 |
|
380 | export enum OutputQuoteStyle {
|
381 | PreferDouble = 0,
|
382 | AlwaysSingle = 1,
|
383 | AlwaysDouble = 2,
|
384 | AlwaysOriginal = 3,
|
385 | }
|
386 |
|
387 | export interface MinifyOptions {
|
388 | /**
|
389 | * Pass `true` to return compressor warnings in result.warnings.
|
390 | * Use the value `verbose` for more detailed warnings.
|
391 | * @default false
|
392 | */
|
393 | warnings?: boolean | 'verbose' | undefined;
|
394 | /**
|
395 | * Pass an object if you wish to specify some additional parse options.
|
396 | */
|
397 | parse?: ParseOptions | undefined;
|
398 | /**
|
399 | * Pass `false` to skip compressing entirely.
|
400 | * Pass an object to specify custom compress options.
|
401 | * @default {}
|
402 | */
|
403 | compress?: false | CompressOptions | undefined;
|
404 | /**
|
405 | * Pass `false` to skip mangling names,
|
406 | * or pass an object to specify mangle options (see below).
|
407 | * @default true
|
408 | */
|
409 | mangle?: boolean | MangleOptions | undefined;
|
410 | /**
|
411 | * Pass an object if you wish to specify additional output options.
|
412 | * The defaults are optimized for best compression
|
413 | */
|
414 | output?: OutputOptions | undefined;
|
415 | /**
|
416 | * Pass an object if you wish to specify source map options.
|
417 | * @default false
|
418 | */
|
419 | sourceMap?: boolean | SourceMapOptions | undefined;
|
420 | /**
|
421 | * Set to `true` if you wish to enable top level variable and function name mangling
|
422 | * and to drop unused variables and functions.
|
423 | * @default false
|
424 | */
|
425 | toplevel?: boolean | undefined;
|
426 | /**
|
427 | * Pass an empty object {} or a previously used nameCache object
|
428 | * if you wish to cache mangled variable and property names across multiple invocations of minify().
|
429 | * Note: this is a read/write property. `minify()` will read the name cache state of this object
|
430 | * and update it during minification so that it may be reused or externally persisted by the user
|
431 | */
|
432 | nameCache?: object | undefined;
|
433 | /**
|
434 | * Set to true to support IE8
|
435 | * @default false
|
436 | */
|
437 | ie8?: boolean | undefined;
|
438 | /**
|
439 | * Pass true to prevent discarding or mangling of function names.
|
440 | * Useful for code relying on Function.prototype.name.
|
441 | * @default false
|
442 | */
|
443 | keep_fnames?: boolean | undefined;
|
444 | }
|
445 |
|
446 | export interface MinifyOutput {
|
447 | error?: Error | undefined;
|
448 | warnings?: string[] | undefined;
|
449 | code: string;
|
450 | map: string;
|
451 | }
|
452 |
|
453 | export interface SourceMapOptions {
|
454 | includeSources?: boolean | undefined;
|
455 | filename?: string | undefined;
|
456 | /**
|
457 | * Include symbol names in the source map
|
458 | * @default true
|
459 | */
|
460 | names?: boolean | undefined;
|
461 | url?: string | 'inline' | undefined;
|
462 | root?: string | undefined;
|
463 | content?: RawSourceMap | 'inline' | undefined;
|
464 | }
|
465 |
|
466 | export function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): MinifyOutput;
|