1 | // Type definitions for babel-generator 6.25
|
2 | // Project: https://github.com/babel/babel/tree/master/packages/babel-generator, https://babeljs.io
|
3 | // Definitions by: Troy Gerwien <https://github.com/yortus>
|
4 | // Johnny Estilles <https://github.com/johnnyestilles>
|
5 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
6 | // TypeScript Version: 2.8
|
7 |
|
8 | import * as t from 'babel-types';
|
9 |
|
10 | /**
|
11 | * Turns an AST into code, maintaining sourcemaps, user preferences, and valid output.
|
12 | * @param ast - the abstract syntax tree from which to generate output code.
|
13 | * @param opts - used for specifying options for code generation.
|
14 | * @param code - the original source code, used for source maps.
|
15 | * @returns - an object containing the output code and source map.
|
16 | */
|
17 | export default function generate(ast: t.Node, opts?: GeneratorOptions, code?: string | {[filename: string]: string}): GeneratorResult;
|
18 |
|
19 | export interface GeneratorOptions {
|
20 | /**
|
21 | * Optional string to add as a block comment at the start of the output file.
|
22 | */
|
23 | auxiliaryCommentBefore?: string;
|
24 |
|
25 | /**
|
26 | * Optional string to add as a block comment at the end of the output file.
|
27 | */
|
28 | auxiliaryCommentAfter?: string;
|
29 |
|
30 | /**
|
31 | * Function that takes a comment (as a string) and returns true if the comment should be included in the output.
|
32 | * By default, comments are included if `opts.comments` is `true` or if `opts.minifed` is `false` and the comment
|
33 | * contains `@preserve` or `@license`.
|
34 | */
|
35 | shouldPrintComment?(comment: string): boolean;
|
36 |
|
37 | /**
|
38 | * Attempt to use the same line numbers in the output code as in the source code (helps preserve stack traces).
|
39 | * Defaults to `false`.
|
40 | */
|
41 | retainLines?: boolean;
|
42 |
|
43 | /**
|
44 | * Should comments be included in output? Defaults to `true`.
|
45 | */
|
46 | comments?: boolean;
|
47 |
|
48 | /**
|
49 | * Set to true to avoid adding whitespace for formatting. Defaults to the value of `opts.minified`.
|
50 | */
|
51 | compact?: boolean | 'auto';
|
52 |
|
53 | /**
|
54 | * Should the output be minified. Defaults to `false`.
|
55 | */
|
56 | minified?: boolean;
|
57 |
|
58 | /**
|
59 | * Set to true to reduce whitespace (but not as much as opts.compact). Defaults to `false`.
|
60 | */
|
61 | concise?: boolean;
|
62 |
|
63 | /**
|
64 | * The type of quote to use in the output. If omitted, autodetects based on `ast.tokens`.
|
65 | */
|
66 | quotes?: 'single' | 'double';
|
67 |
|
68 | /**
|
69 | * Used in warning messages
|
70 | */
|
71 | filename?: string;
|
72 |
|
73 | /**
|
74 | * Enable generating source maps. Defaults to `false`.
|
75 | */
|
76 | sourceMaps?: boolean;
|
77 |
|
78 | /**
|
79 | * The filename of the generated code that the source map will be associated with.
|
80 | */
|
81 | sourceMapTarget?: string;
|
82 |
|
83 | /**
|
84 | * A root for all relative URLs in the source map.
|
85 | */
|
86 | sourceRoot?: string;
|
87 |
|
88 | /**
|
89 | * The filename for the source code (i.e. the code in the `code` argument).
|
90 | * This will only be used if `code` is a string.
|
91 | */
|
92 | sourceFileName?: string;
|
93 |
|
94 | /**
|
95 | * Set to true to run jsesc with "json": true to print "\u00A9" vs. "©";
|
96 | */
|
97 | jsonCompatibleStrings?: boolean;
|
98 | }
|
99 |
|
100 | export interface GeneratorResult {
|
101 | map: {};
|
102 | code: string;
|
103 | }
|