terser.d.ts 6.3 KB

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