You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

790 lines
18 KiB

4 years ago
  1. import { RawSourceMap } from 'source-map';
  2. export type ECMA = 5 | 6 | 7 | 8 | 9;
  3. export interface ParseOptions {
  4. bare_returns?: boolean;
  5. ecma?: ECMA;
  6. html5_comments?: boolean;
  7. shebang?: boolean;
  8. }
  9. export interface CompressOptions {
  10. arguments?: boolean;
  11. arrows?: boolean;
  12. booleans?: boolean;
  13. collapse_vars?: boolean;
  14. comparisons?: boolean;
  15. conditionals?: boolean;
  16. dead_code?: boolean;
  17. defaults?: boolean;
  18. directives?: boolean;
  19. drop_console?: boolean;
  20. drop_debugger?: boolean;
  21. evaluate?: boolean;
  22. expression?: boolean;
  23. global_defs?: object;
  24. hoist_funs?: boolean;
  25. hoist_props?: boolean;
  26. hoist_vars?: boolean;
  27. if_return?: boolean;
  28. inline?: boolean | InlineFunctions;
  29. join_vars?: boolean;
  30. keep_classnames?: boolean | RegExp;
  31. keep_fargs?: boolean;
  32. keep_fnames?: boolean | RegExp;
  33. keep_infinity?: boolean;
  34. loops?: boolean;
  35. negate_iife?: boolean;
  36. passes?: number;
  37. properties?: boolean;
  38. pure_funcs?: string[];
  39. pure_getters?: boolean | 'strict';
  40. reduce_funcs?: boolean;
  41. reduce_vars?: boolean;
  42. sequences?: boolean | number;
  43. side_effects?: boolean;
  44. switches?: boolean;
  45. toplevel?: boolean;
  46. top_retain?: null | string | string[] | RegExp;
  47. typeofs?: boolean;
  48. unsafe?: boolean;
  49. unsafe_arrows?: boolean;
  50. unsafe_comps?: boolean;
  51. unsafe_Function?: boolean;
  52. unsafe_math?: boolean;
  53. unsafe_methods?: boolean;
  54. unsafe_proto?: boolean;
  55. unsafe_regexp?: boolean;
  56. unsafe_undefined?: boolean;
  57. unused?: boolean;
  58. warnings?: boolean;
  59. }
  60. export enum InlineFunctions {
  61. Disabled = 0,
  62. SimpleFunctions = 1,
  63. WithArguments = 2,
  64. WithArgumentsAndVariables = 3
  65. }
  66. export interface MangleOptions {
  67. eval?: boolean;
  68. keep_classnames?: boolean | RegExp;
  69. keep_fnames?: boolean | RegExp;
  70. module?: boolean;
  71. properties?: boolean | ManglePropertiesOptions;
  72. reserved?: string[];
  73. safari10?: boolean;
  74. toplevel?: boolean;
  75. }
  76. export interface ManglePropertiesOptions {
  77. builtins?: boolean;
  78. debug?: boolean;
  79. keep_quoted?: boolean;
  80. regex?: RegExp;
  81. reserved?: string[];
  82. }
  83. export interface OutputOptions {
  84. ascii_only?: boolean;
  85. beautify?: boolean;
  86. braces?: boolean;
  87. comments?: boolean | 'all' | 'some' | RegExp;
  88. ecma?: ECMA;
  89. indent_level?: number;
  90. indent_start?: boolean;
  91. inline_script?: boolean;
  92. ie8?: boolean;
  93. keep_quoted_props?: boolean;
  94. max_line_len?: boolean;
  95. preamble?: string;
  96. quote_keys?: boolean;
  97. quote_style?: OutputQuoteStyle;
  98. safari10?: boolean;
  99. semicolons?: boolean;
  100. shebang?: boolean;
  101. shorthand?: boolean;
  102. source_map?: SourceMapOptions;
  103. webkit?: boolean;
  104. width?: number;
  105. wrap_iife?: boolean;
  106. }
  107. export enum OutputQuoteStyle {
  108. PreferDouble = 0,
  109. AlwaysSingle = 1,
  110. AlwaysDouble = 2,
  111. AlwaysOriginal = 3
  112. }
  113. export interface MinifyOptions {
  114. compress?: boolean | CompressOptions;
  115. ecma?: ECMA;
  116. ie8?: boolean;
  117. keep_classnames?: boolean | RegExp;
  118. keep_fnames?: boolean | RegExp;
  119. mangle?: boolean | MangleOptions;
  120. module?: boolean;
  121. nameCache?: object;
  122. output?: OutputOptions;
  123. parse?: ParseOptions;
  124. safari10?: boolean;
  125. sourceMap?: boolean | SourceMapOptions;
  126. toplevel?: boolean;
  127. warnings?: boolean | 'verbose';
  128. }
  129. export interface MinifyOutput {
  130. ast?: AST_Node;
  131. code?: string;
  132. error?: Error;
  133. map?: string;
  134. warnings?: string[];
  135. }
  136. export interface SourceMapOptions {
  137. content?: RawSourceMap;
  138. includeSources?: boolean;
  139. filename?: string;
  140. root?: string;
  141. url?: string | 'inline';
  142. }
  143. declare function parse(text: string, options?: ParseOptions): AST_Node;
  144. export class TreeWalker {
  145. constructor(callback: (node: AST_Node, descend?: (node: AST_Node) => void) => boolean | undefined);
  146. directives: object;
  147. find_parent(type: AST_Node): AST_Node | undefined;
  148. has_directive(type: string): boolean;
  149. loopcontrol_target(node: AST_Node): AST_Node | undefined;
  150. parent(n: number): AST_Node | undefined;
  151. pop(): void;
  152. push(node: AST_Node): void;
  153. self(): AST_Node | undefined;
  154. stack: AST_Node[];
  155. visit: (node: AST_Node, descend: boolean) => any;
  156. }
  157. export class TreeTransformer extends TreeWalker {
  158. constructor(
  159. before: (node: AST_Node, descend?: (node: AST_Node, tw: TreeWalker) => void, in_list?: boolean) => AST_Node | undefined,
  160. after?: (node: AST_Node, in_list?: boolean) => AST_Node | undefined
  161. );
  162. before: (node: AST_Node) => AST_Node;
  163. after?: (node: AST_Node) => AST_Node;
  164. }
  165. export function push_uniq<T>(array: T[], el: T): void;
  166. type DictEachCallback = (val: any, key: string) => any;
  167. export class Dictionary {
  168. static fromObject(obj: object): Dictionary;
  169. add(key: string, val: any): this;
  170. clone(): Dictionary;
  171. del(key: string): this;
  172. each(fn: DictEachCallback): void;
  173. get(key: string): any;
  174. has(key: string): boolean;
  175. map(fn: DictEachCallback): any[];
  176. set(key: string, val: any): this;
  177. size(): number;
  178. }
  179. export function minify(files: string | string[] | { [file: string]: string } | AST_Node, options?: MinifyOptions): MinifyOutput;
  180. export class AST_Node {
  181. constructor(props?: object);
  182. static BASE?: AST_Node;
  183. static PROPS: string[];
  184. static SELF_PROPS: string[];
  185. static SUBCLASSES: AST_Node[];
  186. static documentation: string;
  187. static propdoc?: Record<string, string>;
  188. static expressions?: AST_Node[];
  189. static warn?: (text: string, props: any) => void;
  190. static from_mozilla_ast?: (node: AST_Node) => any;
  191. walk: (visitor: TreeWalker) => void;
  192. print_to_string: (options?: OutputOptions) => string;
  193. transform: (tt: TreeTransformer, in_list?: boolean) => AST_Node;
  194. TYPE: string;
  195. CTOR: typeof AST_Node;
  196. }
  197. declare class SymbolDef {
  198. constructor(scope?: AST_Scope, orig?: object, init?: object);
  199. name: string;
  200. orig: AST_SymbolRef[];
  201. init: AST_SymbolRef;
  202. eliminated: number;
  203. scope: AST_Scope;
  204. references: AST_SymbolRef[];
  205. replaced: number;
  206. global: boolean;
  207. export: boolean;
  208. mangled_name: null | string;
  209. undeclared: boolean;
  210. id: number;
  211. }
  212. type ArgType = AST_SymbolFunarg | AST_DefaultAssign | AST_Destructuring | AST_Expansion;
  213. declare class AST_Statement extends AST_Node {
  214. constructor(props?: object);
  215. }
  216. declare class AST_Debugger extends AST_Statement {
  217. constructor(props?: object);
  218. }
  219. declare class AST_Directive extends AST_Statement {
  220. constructor(props?: object);
  221. value: string;
  222. quote: string;
  223. }
  224. declare class AST_SimpleStatement extends AST_Statement {
  225. constructor(props?: object);
  226. body: AST_Node[];
  227. }
  228. declare class AST_Block extends AST_Statement {
  229. constructor(props?: object);
  230. body: AST_Node[];
  231. block_scope: AST_Scope | null;
  232. }
  233. declare class AST_BlockStatement extends AST_Block {
  234. constructor(props?: object);
  235. }
  236. declare class AST_Scope extends AST_Block {
  237. constructor(props?: object);
  238. variables: any;
  239. functions: any;
  240. uses_with: boolean;
  241. uses_eval: boolean;
  242. parent_scope: AST_Scope | null;
  243. enclosed: any;
  244. cname: any;
  245. }
  246. declare class AST_Toplevel extends AST_Scope {
  247. constructor(props?: object);
  248. globals: any;
  249. }
  250. declare class AST_Lambda extends AST_Scope {
  251. constructor(props?: object);
  252. name: AST_SymbolDeclaration | null;
  253. argnames: ArgType[];
  254. uses_arguments: boolean;
  255. is_generator: boolean;
  256. async: boolean;
  257. }
  258. declare class AST_Accessor extends AST_Lambda {
  259. constructor(props?: object);
  260. }
  261. declare class AST_Function extends AST_Lambda {
  262. constructor(props?: object);
  263. inlined: boolean;
  264. }
  265. declare class AST_Arrow extends AST_Lambda {
  266. constructor(props?: object);
  267. inlined: boolean;
  268. }
  269. declare class AST_Defun extends AST_Lambda {
  270. constructor(props?: object);
  271. inlined: boolean;
  272. }
  273. declare class AST_Class extends AST_Scope {
  274. constructor(props?: object);
  275. name: AST_SymbolClass | AST_SymbolDefClass | null;
  276. extends: AST_Node | null;
  277. properties: AST_ObjectProperty[];
  278. inlined: boolean;
  279. }
  280. declare class AST_DefClass extends AST_Class {
  281. constructor(props?: object);
  282. }
  283. declare class AST_ClassExpression extends AST_Class {
  284. constructor(props?: object);
  285. }
  286. declare class AST_Switch extends AST_Block {
  287. constructor(props?: object);
  288. expression: AST_Node;
  289. }
  290. declare class AST_SwitchBranch extends AST_Block {
  291. constructor(props?: object);
  292. }
  293. declare class AST_Default extends AST_SwitchBranch {
  294. constructor(props?: object);
  295. }
  296. declare class AST_Case extends AST_SwitchBranch {
  297. constructor(props?: object);
  298. expression: AST_Node;
  299. }
  300. declare class AST_Try extends AST_Block {
  301. constructor(props?: object);
  302. bcatch: AST_Catch;
  303. bfinally: null | AST_Finally;
  304. }
  305. declare class AST_Catch extends AST_Block {
  306. constructor(props?: object);
  307. argname: ArgType;
  308. }
  309. declare class AST_Finally extends AST_Block {
  310. constructor(props?: object);
  311. }
  312. declare class AST_EmptyStatement extends AST_Statement {
  313. constructor(props?: object);
  314. }
  315. declare class AST_StatementWithBody extends AST_Statement {
  316. constructor(props?: object);
  317. body: AST_Node[];
  318. }
  319. declare class AST_LabeledStatement extends AST_StatementWithBody {
  320. constructor(props?: object);
  321. label: AST_Label;
  322. }
  323. declare class AST_IterationStatement extends AST_StatementWithBody {
  324. constructor(props?: object);
  325. block_scope: AST_Scope | null;
  326. }
  327. declare class AST_DWLoop extends AST_IterationStatement {
  328. constructor(props?: object);
  329. condition: AST_Node;
  330. }
  331. declare class AST_Do extends AST_DWLoop {
  332. constructor(props?: object);
  333. }
  334. declare class AST_While extends AST_DWLoop {
  335. constructor(props?: object);
  336. }
  337. declare class AST_For extends AST_IterationStatement {
  338. constructor(props?: object);
  339. init: AST_Node | null;
  340. condition: AST_Node | null;
  341. step: AST_Node | null;
  342. }
  343. declare class AST_ForIn extends AST_IterationStatement {
  344. constructor(props?: object);
  345. init: AST_Node | null;
  346. object: AST_Node;
  347. }
  348. declare class AST_ForOf extends AST_ForIn {
  349. constructor(props?: object);
  350. await: boolean;
  351. }
  352. declare class AST_With extends AST_StatementWithBody {
  353. constructor(props?: object);
  354. expression: AST_Node;
  355. }
  356. declare class AST_If extends AST_StatementWithBody {
  357. constructor(props?: object);
  358. condition: AST_Node;
  359. alternative: AST_Node | null;
  360. }
  361. declare class AST_Jump extends AST_Statement {
  362. constructor(props?: object);
  363. }
  364. declare class AST_Exit extends AST_Jump {
  365. constructor(props?: object);
  366. value: AST_Node | null;
  367. }
  368. declare class AST_Return extends AST_Exit {
  369. constructor(props?: object);
  370. }
  371. declare class AST_Throw extends AST_Exit {
  372. constructor(props?: object);
  373. }
  374. declare class AST_LoopControl extends AST_Jump {
  375. constructor(props?: object);
  376. label: null | AST_LabelRef;
  377. }
  378. declare class AST_Break extends AST_LoopControl {
  379. constructor(props?: object);
  380. }
  381. declare class AST_Continue extends AST_LoopControl {
  382. constructor(props?: object);
  383. }
  384. declare class AST_Definitions extends AST_Statement {
  385. constructor(props?: object);
  386. definitions: AST_VarDef[];
  387. }
  388. declare class AST_Var extends AST_Definitions {
  389. constructor(props?: object);
  390. }
  391. declare class AST_Let extends AST_Definitions {
  392. constructor(props?: object);
  393. }
  394. declare class AST_Const extends AST_Definitions {
  395. constructor(props?: object);
  396. }
  397. declare class AST_Export extends AST_Statement {
  398. constructor(props?: object);
  399. exported_definition: AST_Definitions | AST_Lambda | AST_DefClass | null;
  400. exported_value: AST_Node | null;
  401. is_default: boolean;
  402. exported_names: AST_NameMapping[];
  403. module_name: AST_String;
  404. }
  405. declare class AST_Expansion extends AST_Node {
  406. constructor(props?: object);
  407. expression: AST_Node;
  408. }
  409. declare class AST_Destructuring extends AST_Node {
  410. constructor(props?: object);
  411. names: AST_Node[];
  412. is_array: boolean;
  413. }
  414. declare class AST_PrefixedTemplateString extends AST_Node {
  415. constructor(props?: object);
  416. template_string: AST_TemplateString;
  417. prefix: AST_Node;
  418. }
  419. declare class AST_TemplateString extends AST_Node {
  420. constructor(props?: object);
  421. segments: AST_Node[];
  422. }
  423. declare class AST_TemplateSegment extends AST_Node {
  424. constructor(props?: object);
  425. value: string;
  426. raw: string;
  427. }
  428. declare class AST_NameMapping extends AST_Node {
  429. constructor(props?: object);
  430. foreign_name: AST_Symbol;
  431. name: AST_SymbolExport | AST_SymbolImport;
  432. }
  433. declare class AST_Import extends AST_Node {
  434. constructor(props?: object);
  435. imported_name: null | AST_SymbolImport;
  436. imported_names: AST_NameMapping[];
  437. module_name: AST_String;
  438. }
  439. declare class AST_VarDef extends AST_Node {
  440. constructor(props?: object);
  441. name: AST_Destructuring | AST_SymbolConst | AST_SymbolLet | AST_SymbolVar;
  442. value: AST_Node | null;
  443. }
  444. declare class AST_Call extends AST_Node {
  445. constructor(props?: object);
  446. expression: AST_Node;
  447. args: AST_Node[];
  448. }
  449. declare class AST_New extends AST_Call {
  450. constructor(props?: object);
  451. }
  452. declare class AST_Sequence extends AST_Node {
  453. constructor(props?: object);
  454. expressions: AST_Node[];
  455. }
  456. declare class AST_PropAccess extends AST_Node {
  457. constructor(props?: object);
  458. expression: AST_Node;
  459. property: AST_Node | string;
  460. }
  461. declare class AST_Dot extends AST_PropAccess {
  462. constructor(props?: object);
  463. }
  464. declare class AST_Sub extends AST_PropAccess {
  465. constructor(props?: object);
  466. }
  467. declare class AST_Unary extends AST_Node {
  468. constructor(props?: object);
  469. operator: string;
  470. expression: AST_Node;
  471. }
  472. declare class AST_UnaryPrefix extends AST_Unary {
  473. constructor(props?: object);
  474. }
  475. declare class AST_UnaryPostfix extends AST_Unary {
  476. constructor(props?: object);
  477. }
  478. declare class AST_Binary extends AST_Node {
  479. constructor(props?: object);
  480. operator: string;
  481. left: AST_Node;
  482. right: AST_Node;
  483. }
  484. declare class AST_Assign extends AST_Binary {
  485. constructor(props?: object);
  486. }
  487. declare class AST_DefaultAssign extends AST_Binary {
  488. constructor(props?: object);
  489. }
  490. declare class AST_Conditional extends AST_Node {
  491. constructor(props?: object);
  492. condition: AST_Node;
  493. consequent: AST_Node;
  494. alternative: AST_Node;
  495. }
  496. declare class AST_Array extends AST_Node {
  497. constructor(props?: object);
  498. elements: AST_Node[];
  499. }
  500. declare class AST_Object extends AST_Node {
  501. constructor(props?: object);
  502. properties: AST_ObjectProperty[];
  503. }
  504. declare class AST_ObjectProperty extends AST_Node {
  505. constructor(props?: object);
  506. key: string | number | AST_Node;
  507. value: AST_Node;
  508. }
  509. declare class AST_ObjectKeyVal extends AST_ObjectProperty {
  510. constructor(props?: object);
  511. quote: string;
  512. }
  513. declare class AST_ObjectSetter extends AST_ObjectProperty {
  514. constructor(props?: object);
  515. quote: string;
  516. static: boolean;
  517. }
  518. declare class AST_ObjectGetter extends AST_ObjectProperty {
  519. constructor(props?: object);
  520. quote: string;
  521. static: boolean;
  522. }
  523. declare class AST_ConciseMethod extends AST_ObjectProperty {
  524. constructor(props?: object);
  525. quote: string;
  526. static: boolean;
  527. is_generator: boolean;
  528. async: boolean;
  529. }
  530. declare class AST_Symbol extends AST_Node {
  531. constructor(props?: object);
  532. scope: AST_Scope;
  533. name: string;
  534. thedef: SymbolDef;
  535. }
  536. declare class AST_SymbolDeclaration extends AST_Symbol {
  537. constructor(props?: object);
  538. init: AST_Node | null;
  539. }
  540. declare class AST_SymbolVar extends AST_SymbolDeclaration {
  541. constructor(props?: object);
  542. }
  543. declare class AST_SymbolFunarg extends AST_SymbolVar {
  544. constructor(props?: object);
  545. }
  546. declare class AST_SymbolBlockDeclaration extends AST_SymbolDeclaration {
  547. constructor(props?: object);
  548. }
  549. declare class AST_SymbolConst extends AST_SymbolBlockDeclaration {
  550. constructor(props?: object);
  551. }
  552. declare class AST_SymbolLet extends AST_SymbolBlockDeclaration {
  553. constructor(props?: object);
  554. }
  555. declare class AST_SymbolDefClass extends AST_SymbolBlockDeclaration {
  556. constructor(props?: object);
  557. }
  558. declare class AST_SymbolCatch extends AST_SymbolBlockDeclaration {
  559. constructor(props?: object);
  560. }
  561. declare class AST_SymbolImport extends AST_SymbolBlockDeclaration {
  562. constructor(props?: object);
  563. }
  564. declare class AST_SymbolDefun extends AST_SymbolDeclaration {
  565. constructor(props?: object);
  566. }
  567. declare class AST_SymbolLambda extends AST_SymbolDeclaration {
  568. constructor(props?: object);
  569. }
  570. declare class AST_SymbolClass extends AST_SymbolDeclaration {
  571. constructor(props?: object);
  572. }
  573. declare class AST_SymbolMethod extends AST_Symbol {
  574. constructor(props?: object);
  575. }
  576. declare class AST_SymbolImportForeign extends AST_Symbol {
  577. constructor(props?: object);
  578. }
  579. declare class AST_Label extends AST_Symbol {
  580. constructor(props?: object);
  581. references: AST_LoopControl | null;
  582. }
  583. declare class AST_SymbolRef extends AST_Symbol {
  584. constructor(props?: object);
  585. }
  586. declare class AST_SymbolExport extends AST_SymbolRef {
  587. constructor(props?: object);
  588. }
  589. declare class AST_SymbolExportForeign extends AST_Symbol {
  590. constructor(props?: object);
  591. }
  592. declare class AST_LabelRef extends AST_Symbol {
  593. constructor(props?: object);
  594. }
  595. declare class AST_This extends AST_Symbol {
  596. constructor(props?: object);
  597. }
  598. declare class AST_Super extends AST_This {
  599. constructor(props?: object);
  600. }
  601. declare class AST_NewTarget extends AST_Node {
  602. constructor(props?: object);
  603. }
  604. declare class AST_Constant extends AST_Node {
  605. constructor(props?: object);
  606. }
  607. declare class AST_String extends AST_Constant {
  608. constructor(props?: object);
  609. value: string;
  610. quote: string;
  611. }
  612. declare class AST_Number extends AST_Constant {
  613. constructor(props?: object);
  614. value: number;
  615. literal: string;
  616. }
  617. declare class AST_RegExp extends AST_Constant {
  618. constructor(props?: object);
  619. value: RegExp;
  620. }
  621. declare class AST_Atom extends AST_Constant {
  622. constructor(props?: object);
  623. }
  624. declare class AST_Null extends AST_Atom {
  625. constructor(props?: object);
  626. }
  627. declare class AST_NaN extends AST_Atom {
  628. constructor(props?: object);
  629. }
  630. declare class AST_Undefined extends AST_Atom {
  631. constructor(props?: object);
  632. }
  633. declare class AST_Hole extends AST_Atom {
  634. constructor(props?: object);
  635. }
  636. declare class AST_Infinity extends AST_Atom {
  637. constructor(props?: object);
  638. }
  639. declare class AST_Boolean extends AST_Atom {
  640. constructor(props?: object);
  641. }
  642. declare class AST_False extends AST_Boolean {
  643. constructor(props?: object);
  644. }
  645. declare class AST_True extends AST_Boolean {
  646. constructor(props?: object);
  647. }
  648. declare class AST_Await extends AST_Node {
  649. constructor(props?: object);
  650. expression: AST_Node;
  651. }
  652. declare class AST_Yield extends AST_Node {
  653. constructor(props?: object);
  654. expression: AST_Node;
  655. is_star: boolean;
  656. }