terser.d.ts 6.1 KB

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