UNPKG

7.43 kBTypeScriptView Raw
1// Modified and inlined to avoid extra dependency
2// Source: https://github.com/terser/terser/blob/master/tools/terser.d.ts
3// BSD Licensed https://github.com/terser/terser/blob/master/LICENSE
4
5/*
6Terser is released under the BSD license:
7
8Copyright 2012-2018 (c) Mihai Bazon <mihai.bazon@gmail.com>
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions
12are met:
13
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the following
16 disclaimer.
17
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the following
20 disclaimer in the documentation and/or other materials
21 provided with the distribution.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
24EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
32TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
33THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34SUCH DAMAGE.
35*/
36
37export namespace Terser {
38 export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
39
40 export interface ParseOptions {
41 bare_returns?: boolean
42 /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
43 ecma?: ECMA
44 html5_comments?: boolean
45 shebang?: boolean
46 }
47
48 export interface CompressOptions {
49 arguments?: boolean
50 arrows?: boolean
51 booleans_as_integers?: boolean
52 booleans?: boolean
53 collapse_vars?: boolean
54 comparisons?: boolean
55 computed_props?: boolean
56 conditionals?: boolean
57 dead_code?: boolean
58 defaults?: boolean
59 directives?: boolean
60 drop_console?: boolean
61 drop_debugger?: boolean
62 ecma?: ECMA
63 evaluate?: boolean
64 expression?: boolean
65 global_defs?: object
66 hoist_funs?: boolean
67 hoist_props?: boolean
68 hoist_vars?: boolean
69 ie8?: boolean
70 if_return?: boolean
71 inline?: boolean | InlineFunctions
72 join_vars?: boolean
73 keep_classnames?: boolean | RegExp
74 keep_fargs?: boolean
75 keep_fnames?: boolean | RegExp
76 keep_infinity?: boolean
77 loops?: boolean
78 module?: boolean
79 negate_iife?: boolean
80 passes?: number
81 properties?: boolean
82 pure_funcs?: string[]
83 pure_getters?: boolean | 'strict'
84 reduce_funcs?: boolean
85 reduce_vars?: boolean
86 sequences?: boolean | number
87 side_effects?: boolean
88 switches?: boolean
89 toplevel?: boolean
90 top_retain?: null | string | string[] | RegExp
91 typeofs?: boolean
92 unsafe_arrows?: boolean
93 unsafe?: boolean
94 unsafe_comps?: boolean
95 unsafe_Function?: boolean
96 unsafe_math?: boolean
97 unsafe_symbols?: boolean
98 unsafe_methods?: boolean
99 unsafe_proto?: boolean
100 unsafe_regexp?: boolean
101 unsafe_undefined?: boolean
102 unused?: boolean
103 }
104
105 export enum InlineFunctions {
106 Disabled = 0,
107 SimpleFunctions = 1,
108 WithArguments = 2,
109 WithArgumentsAndVariables = 3
110 }
111
112 export interface MangleOptions {
113 eval?: boolean
114 keep_classnames?: boolean | RegExp
115 keep_fnames?: boolean | RegExp
116 module?: boolean
117 nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
118 properties?: boolean | ManglePropertiesOptions
119 reserved?: string[]
120 safari10?: boolean
121 toplevel?: boolean
122 }
123
124 /**
125 * An identifier mangler for which the output is invariant with respect to the source code.
126 */
127 export interface SimpleIdentifierMangler {
128 /**
129 * Obtains the nth most favored (usually shortest) identifier to rename a variable to.
130 * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
131 * This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
132 * @param n - The ordinal of the identifier.
133 */
134 get(n: number): string
135 }
136
137 /**
138 * An identifier mangler that leverages character frequency analysis to determine identifier precedence.
139 */
140 export interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
141 /**
142 * Modifies the internal weighting of the input characters by the specified delta.
143 * Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
144 * @param chars - The characters to modify the weighting of.
145 * @param delta - The numeric weight to add to the characters.
146 */
147 consider(chars: string, delta: number): number
148 /**
149 * Resets character weights.
150 */
151 reset(): void
152 /**
153 * Sorts identifiers by character frequency, in preparation for calls to get(n).
154 */
155 sort(): void
156 }
157
158 export interface ManglePropertiesOptions {
159 builtins?: boolean
160 debug?: boolean
161 keep_quoted?: boolean | 'strict'
162 nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
163 regex?: RegExp | string
164 reserved?: string[]
165 }
166
167 export interface FormatOptions {
168 ascii_only?: boolean
169 /** @deprecated Not implemented anymore */
170 beautify?: boolean
171 braces?: boolean
172 comments?:
173 | boolean
174 | 'all'
175 | 'some'
176 | RegExp
177 | ((
178 node: any,
179 comment: {
180 value: string
181 type: 'comment1' | 'comment2' | 'comment3' | 'comment4'
182 pos: number
183 line: number
184 col: number
185 }
186 ) => boolean)
187 ecma?: ECMA
188 ie8?: boolean
189 keep_numbers?: boolean
190 indent_level?: number
191 indent_start?: number
192 inline_script?: boolean
193 keep_quoted_props?: boolean
194 max_line_len?: number | false
195 preamble?: string
196 preserve_annotations?: boolean
197 quote_keys?: boolean
198 quote_style?: OutputQuoteStyle
199 safari10?: boolean
200 semicolons?: boolean
201 shebang?: boolean
202 shorthand?: boolean
203 source_map?: SourceMapOptions
204 webkit?: boolean
205 width?: number
206 wrap_iife?: boolean
207 wrap_func_args?: boolean
208 }
209
210 export enum OutputQuoteStyle {
211 PreferDouble = 0,
212 AlwaysSingle = 1,
213 AlwaysDouble = 2,
214 AlwaysOriginal = 3
215 }
216
217 export interface MinifyOptions {
218 compress?: boolean | CompressOptions
219 ecma?: ECMA
220 enclose?: boolean | string
221 ie8?: boolean
222 keep_classnames?: boolean | RegExp
223 keep_fnames?: boolean | RegExp
224 mangle?: boolean | MangleOptions
225 module?: boolean
226 nameCache?: object
227 format?: FormatOptions
228 /** @deprecated deprecated */
229 output?: FormatOptions
230 parse?: ParseOptions
231 safari10?: boolean
232 sourceMap?: boolean | SourceMapOptions
233 toplevel?: boolean
234 }
235
236 export interface MinifyOutput {
237 code?: string
238 map?: object | string
239 decoded_map?: object | null
240 }
241
242 export interface SourceMapOptions {
243 /** Source map object, 'inline' or source map file content */
244 content?: object | string
245 includeSources?: boolean
246 filename?: string
247 root?: string
248 url?: string | 'inline'
249 }
250}