1 | import { RawSourceMap } from "source-map";
|
2 | export interface ParseOptions {
|
3 | |
4 |
|
5 |
|
6 |
|
7 | bare_returns?: boolean | undefined;
|
8 |
|
9 | html5_comments?: boolean | undefined;
|
10 | |
11 |
|
12 |
|
13 |
|
14 | shebang?: boolean | undefined;
|
15 | }
|
16 |
|
17 | export interface CompressOptions {
|
18 | |
19 |
|
20 |
|
21 |
|
22 | arguments?: boolean | undefined;
|
23 | |
24 |
|
25 |
|
26 |
|
27 | assignments?: boolean | undefined;
|
28 | |
29 |
|
30 |
|
31 |
|
32 | booleans?: boolean | undefined;
|
33 | |
34 |
|
35 |
|
36 |
|
37 | collapse_vars?: boolean | undefined;
|
38 | |
39 |
|
40 |
|
41 |
|
42 | comparisons?: boolean | undefined;
|
43 | |
44 |
|
45 |
|
46 |
|
47 | conditionals?: boolean | undefined;
|
48 | |
49 |
|
50 |
|
51 |
|
52 | dead_code?: boolean | undefined;
|
53 | |
54 |
|
55 |
|
56 |
|
57 | directives?: boolean | undefined;
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | drop_console?: boolean | undefined;
|
65 | |
66 |
|
67 |
|
68 |
|
69 | drop_debugger?: boolean | undefined;
|
70 | |
71 |
|
72 |
|
73 |
|
74 | evaluate?: boolean | undefined;
|
75 | |
76 |
|
77 |
|
78 |
|
79 | expression?: boolean | undefined;
|
80 | |
81 |
|
82 |
|
83 |
|
84 | functions?: boolean | undefined;
|
85 | |
86 |
|
87 |
|
88 | global_defs?: object | undefined;
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 | |
95 |
|
96 |
|
97 |
|
98 | hoist_exports?: boolean | undefined;
|
99 | hoist_funs?: boolean | undefined;
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | hoist_props?: boolean | undefined;
|
107 | |
108 |
|
109 |
|
110 |
|
111 | hoist_vars?: boolean | undefined;
|
112 | |
113 |
|
114 |
|
115 |
|
116 | if_return?: boolean | undefined;
|
117 | |
118 |
|
119 |
|
120 |
|
121 | imports?: boolean | undefined;
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | inline?: boolean | InlineFunctions | undefined;
|
133 | |
134 |
|
135 |
|
136 |
|
137 | join_vars?: boolean | undefined;
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 | keep_fargs?: "strict" | boolean | undefined;
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 | keep_fnames?: boolean | undefined;
|
150 | |
151 |
|
152 |
|
153 |
|
154 | keep_infinity?: boolean | undefined;
|
155 | |
156 |
|
157 |
|
158 |
|
159 | loops?: boolean | undefined;
|
160 | |
161 |
|
162 |
|
163 |
|
164 | merge_vars?: boolean | undefined;
|
165 | |
166 |
|
167 |
|
168 |
|
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 |
|
332 | export enum InlineFunctions {
|
333 | Disabled = 0,
|
334 | SimpleFunctions = 1,
|
335 | WithArguments = 2,
|
336 | WithArgumentsAndVariables = 3,
|
337 | }
|
338 | export 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 |
|
350 | export 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 |
|
363 | export 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 |
|
384 | export enum OutputQuoteStyle {
|
385 | PreferDouble = 0,
|
386 | AlwaysSingle = 1,
|
387 | AlwaysDouble = 2,
|
388 | AlwaysOriginal = 3,
|
389 | }
|
390 |
|
391 | export 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 |
|
467 | export interface MinifyOutput {
|
468 | error?: Error | undefined;
|
469 | warnings?: string[] | undefined;
|
470 | code: string;
|
471 | map: string;
|
472 | }
|
473 |
|
474 | export 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 |
|
487 | export function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): MinifyOutput;
|
488 |
|
\ | No newline at end of file |