terser.d.ts 6.4 KB

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