terser.d.ts 5.7 KB

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