terser.d.ts 6.0 KB

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