UNPKG

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