1 | /// <reference lib="es2015" />
|
---|
2 |
|
---|
3 | import { SectionedSourceMapInput, EncodedSourceMap, DecodedSourceMap } from '@jridgewell/source-map';
|
---|
4 |
|
---|
5 | export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
|
---|
6 |
|
---|
7 | export type ConsoleProperty = keyof typeof console;
|
---|
8 | type DropConsoleOption = boolean | ConsoleProperty[];
|
---|
9 |
|
---|
10 | export interface ParseOptions {
|
---|
11 | bare_returns?: boolean;
|
---|
12 | /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
|
---|
13 | ecma?: ECMA;
|
---|
14 | html5_comments?: boolean;
|
---|
15 | shebang?: boolean;
|
---|
16 | }
|
---|
17 |
|
---|
18 | export interface CompressOptions {
|
---|
19 | arguments?: boolean;
|
---|
20 | arrows?: boolean;
|
---|
21 | booleans_as_integers?: boolean;
|
---|
22 | booleans?: boolean;
|
---|
23 | collapse_vars?: boolean;
|
---|
24 | comparisons?: boolean;
|
---|
25 | computed_props?: boolean;
|
---|
26 | conditionals?: boolean;
|
---|
27 | dead_code?: boolean;
|
---|
28 | defaults?: boolean;
|
---|
29 | directives?: boolean;
|
---|
30 | drop_console?: DropConsoleOption;
|
---|
31 | drop_debugger?: boolean;
|
---|
32 | ecma?: ECMA;
|
---|
33 | evaluate?: boolean;
|
---|
34 | expression?: boolean;
|
---|
35 | global_defs?: object;
|
---|
36 | hoist_funs?: boolean;
|
---|
37 | hoist_props?: boolean;
|
---|
38 | hoist_vars?: boolean;
|
---|
39 | ie8?: boolean;
|
---|
40 | if_return?: boolean;
|
---|
41 | inline?: boolean | InlineFunctions;
|
---|
42 | join_vars?: boolean;
|
---|
43 | keep_classnames?: boolean | RegExp;
|
---|
44 | keep_fargs?: boolean;
|
---|
45 | keep_fnames?: boolean | RegExp;
|
---|
46 | keep_infinity?: boolean;
|
---|
47 | loops?: boolean;
|
---|
48 | module?: boolean;
|
---|
49 | negate_iife?: boolean;
|
---|
50 | passes?: number;
|
---|
51 | properties?: boolean;
|
---|
52 | pure_funcs?: string[];
|
---|
53 | pure_new?: boolean;
|
---|
54 | pure_getters?: boolean | 'strict';
|
---|
55 | reduce_funcs?: boolean;
|
---|
56 | reduce_vars?: boolean;
|
---|
57 | sequences?: boolean | number;
|
---|
58 | side_effects?: boolean;
|
---|
59 | switches?: boolean;
|
---|
60 | toplevel?: boolean;
|
---|
61 | top_retain?: null | string | string[] | RegExp;
|
---|
62 | typeofs?: boolean;
|
---|
63 | unsafe_arrows?: boolean;
|
---|
64 | unsafe?: boolean;
|
---|
65 | unsafe_comps?: boolean;
|
---|
66 | unsafe_Function?: boolean;
|
---|
67 | unsafe_math?: boolean;
|
---|
68 | unsafe_symbols?: boolean;
|
---|
69 | unsafe_methods?: boolean;
|
---|
70 | unsafe_proto?: boolean;
|
---|
71 | unsafe_regexp?: boolean;
|
---|
72 | unsafe_undefined?: boolean;
|
---|
73 | unused?: boolean;
|
---|
74 | }
|
---|
75 |
|
---|
76 | export enum InlineFunctions {
|
---|
77 | Disabled = 0,
|
---|
78 | SimpleFunctions = 1,
|
---|
79 | WithArguments = 2,
|
---|
80 | WithArgumentsAndVariables = 3
|
---|
81 | }
|
---|
82 |
|
---|
83 | export interface MangleOptions {
|
---|
84 | eval?: boolean;
|
---|
85 | keep_classnames?: boolean | RegExp;
|
---|
86 | keep_fnames?: boolean | RegExp;
|
---|
87 | module?: boolean;
|
---|
88 | nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler;
|
---|
89 | properties?: boolean | ManglePropertiesOptions;
|
---|
90 | reserved?: string[];
|
---|
91 | safari10?: boolean;
|
---|
92 | toplevel?: boolean;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * An identifier mangler for which the output is invariant with respect to the source code.
|
---|
97 | */
|
---|
98 | export interface SimpleIdentifierMangler {
|
---|
99 | /**
|
---|
100 | * Obtains the nth most favored (usually shortest) identifier to rename a variable to.
|
---|
101 | * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
|
---|
102 | * This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
|
---|
103 | * @param n The ordinal of the identifier.
|
---|
104 | */
|
---|
105 | get(n: number): string;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * An identifier mangler that leverages character frequency analysis to determine identifier precedence.
|
---|
110 | */
|
---|
111 | export interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
|
---|
112 | /**
|
---|
113 | * Modifies the internal weighting of the input characters by the specified delta.
|
---|
114 | * Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
|
---|
115 | * @param chars The characters to modify the weighting of.
|
---|
116 | * @param delta The numeric weight to add to the characters.
|
---|
117 | */
|
---|
118 | consider(chars: string, delta: number): number;
|
---|
119 | /**
|
---|
120 | * Resets character weights.
|
---|
121 | */
|
---|
122 | reset(): void;
|
---|
123 | /**
|
---|
124 | * Sorts identifiers by character frequency, in preparation for calls to get(n).
|
---|
125 | */
|
---|
126 | sort(): void;
|
---|
127 | }
|
---|
128 |
|
---|
129 | export interface ManglePropertiesOptions {
|
---|
130 | builtins?: boolean;
|
---|
131 | debug?: boolean;
|
---|
132 | keep_quoted?: boolean | 'strict';
|
---|
133 | nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler;
|
---|
134 | regex?: RegExp | string;
|
---|
135 | reserved?: string[];
|
---|
136 | }
|
---|
137 |
|
---|
138 | export interface FormatOptions {
|
---|
139 | ascii_only?: boolean;
|
---|
140 | /** @deprecated Not implemented anymore */
|
---|
141 | beautify?: boolean;
|
---|
142 | braces?: boolean;
|
---|
143 | comments?: boolean | 'all' | 'some' | RegExp | ( (node: any, comment: {
|
---|
144 | value: string,
|
---|
145 | type: 'comment1' | 'comment2' | 'comment3' | 'comment4',
|
---|
146 | pos: number,
|
---|
147 | line: number,
|
---|
148 | col: number,
|
---|
149 | }) => boolean );
|
---|
150 | ecma?: ECMA;
|
---|
151 | ie8?: boolean;
|
---|
152 | keep_numbers?: boolean;
|
---|
153 | indent_level?: number;
|
---|
154 | indent_start?: number;
|
---|
155 | inline_script?: boolean;
|
---|
156 | keep_quoted_props?: boolean;
|
---|
157 | max_line_len?: number | false;
|
---|
158 | preamble?: string;
|
---|
159 | preserve_annotations?: boolean;
|
---|
160 | quote_keys?: boolean;
|
---|
161 | quote_style?: OutputQuoteStyle;
|
---|
162 | safari10?: boolean;
|
---|
163 | semicolons?: boolean;
|
---|
164 | shebang?: boolean;
|
---|
165 | shorthand?: boolean;
|
---|
166 | source_map?: SourceMapOptions;
|
---|
167 | webkit?: boolean;
|
---|
168 | width?: number;
|
---|
169 | wrap_iife?: boolean;
|
---|
170 | wrap_func_args?: boolean;
|
---|
171 | }
|
---|
172 |
|
---|
173 | export enum OutputQuoteStyle {
|
---|
174 | PreferDouble = 0,
|
---|
175 | AlwaysSingle = 1,
|
---|
176 | AlwaysDouble = 2,
|
---|
177 | AlwaysOriginal = 3
|
---|
178 | }
|
---|
179 |
|
---|
180 | export interface MinifyOptions {
|
---|
181 | compress?: boolean | CompressOptions;
|
---|
182 | ecma?: ECMA;
|
---|
183 | enclose?: boolean | string;
|
---|
184 | ie8?: boolean;
|
---|
185 | keep_classnames?: boolean | RegExp;
|
---|
186 | keep_fnames?: boolean | RegExp;
|
---|
187 | mangle?: boolean | MangleOptions;
|
---|
188 | module?: boolean;
|
---|
189 | nameCache?: object;
|
---|
190 | format?: FormatOptions;
|
---|
191 | /** @deprecated */
|
---|
192 | output?: FormatOptions;
|
---|
193 | parse?: ParseOptions;
|
---|
194 | safari10?: boolean;
|
---|
195 | sourceMap?: boolean | SourceMapOptions;
|
---|
196 | toplevel?: boolean;
|
---|
197 | }
|
---|
198 |
|
---|
199 | export interface MinifyOutput {
|
---|
200 | code?: string;
|
---|
201 | map?: EncodedSourceMap | string;
|
---|
202 | decoded_map?: DecodedSourceMap | null;
|
---|
203 | }
|
---|
204 |
|
---|
205 | export interface SourceMapOptions {
|
---|
206 | /** Source map object, 'inline' or source map file content */
|
---|
207 | content?: SectionedSourceMapInput | string;
|
---|
208 | includeSources?: boolean;
|
---|
209 | filename?: string;
|
---|
210 | root?: string;
|
---|
211 | asObject?: boolean;
|
---|
212 | url?: string | 'inline';
|
---|
213 | }
|
---|
214 |
|
---|
215 | export function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): Promise<MinifyOutput>;
|
---|
216 | export function minify_sync(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): MinifyOutput;
|
---|