terser.d.ts 6.3 KB

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