1 | export interface FormatOptions {
|
2 | /**
|
3 | * The indent options
|
4 | */
|
5 | indent?: IndentOptions | undefined;
|
6 | /**
|
7 | * New line string. Default is '\n'.
|
8 | */
|
9 | newline?: string | undefined;
|
10 | /**
|
11 | * White space string. Default is standard ' ' (\x20).
|
12 | */
|
13 | space?: string | undefined;
|
14 | /**
|
15 | * Enforce JSON format of numeric and string literals. This option takes precedence over option.format.hexadecimal and option.format.quotes. Default is false.
|
16 | */
|
17 | json?: boolean | undefined;
|
18 | /**
|
19 | * Try to generate shorter numeric literals than toString() (9.8.1). Default is false.
|
20 | */
|
21 | renumber?: boolean | undefined;
|
22 | /**
|
23 | * Generate hexadecimal a numeric literal if it is shorter than its equivalents. Requires option.format.renumber. Default is false.
|
24 | */
|
25 | hexadecimal?: boolean | undefined;
|
26 | /**
|
27 | * Delimiter to use for string literals. Accepted values are: 'single', 'double', and 'auto'. When 'auto' is specified, escodegen selects a delimiter that results in a shorter literal. Default is 'single'.
|
28 | */
|
29 | quotes?: string | undefined;
|
30 | /**
|
31 | * Escape as few characters in string literals as necessary. Default is false.
|
32 | */
|
33 | escapeless?: boolean | undefined;
|
34 | /**
|
35 | * Do not include superfluous whitespace characters and line terminators. Default is false.
|
36 | */
|
37 | compact?: boolean | undefined;
|
38 | /**
|
39 | * Preserve parentheses in new expressions that have no arguments. Default is true.
|
40 | */
|
41 | parentheses?: boolean | undefined;
|
42 | /**
|
43 | * Preserve semicolons at the end of blocks and programs. Default is true.
|
44 | */
|
45 | semicolons?: boolean | undefined;
|
46 | safeConcatenation?: boolean | undefined;
|
47 | preserveBlankLines?: boolean | undefined;
|
48 | }
|
49 |
|
50 | export interface IndentOptions {
|
51 | /**
|
52 | * Indent string. Default is 4 spaces (' ').
|
53 | */
|
54 | style?: string | undefined;
|
55 | /**
|
56 | * Base indent level. Default is 0.
|
57 | */
|
58 | base?: number | undefined;
|
59 | /**
|
60 | * Adjust the indentation of multiline comments to keep asterisks vertically aligned. Default is false.
|
61 | */
|
62 | adjustMultilineComment?: boolean | undefined;
|
63 | }
|
64 |
|
65 | export interface MozillaOptions {
|
66 | /**
|
67 | * Default: false
|
68 | */
|
69 | starlessGenerator?: boolean | undefined;
|
70 | /**
|
71 | * Default: false
|
72 | */
|
73 | parenthesizedComprehensionBlock?: boolean | undefined;
|
74 | /**
|
75 | * Default: false
|
76 | */
|
77 | comprehensionExpressionStartsWithAssignment?: boolean | undefined;
|
78 | }
|
79 |
|
80 | export interface GenerateOptions {
|
81 | /**
|
82 | * The format options
|
83 | */
|
84 | format?: FormatOptions | undefined;
|
85 | moz?: MozillaOptions | undefined;
|
86 | /**
|
87 | * Mozilla Parser API compatible parse function, e.g., the parse function exported by esprima. If it is provided, generator tries to use the 'raw' representation. See esprima raw information. Default is null.
|
88 | */
|
89 | parse?: Function | undefined;
|
90 | /**
|
91 | * If comments are attached to AST, escodegen is going to emit comments to output code. Default is false.
|
92 | */
|
93 | comment?: boolean | undefined;
|
94 | /**
|
95 | * sourceMap is the source maps's source filename, that's a name that will show up in the browser debugger for the generated source (if source-maps is enabled).
|
96 | * If a non-empty string value is provided, generate a source map.
|
97 | */
|
98 | sourceMap?: string | undefined;
|
99 | /**
|
100 | * . If sourceMapWithCode is true generator returns output hash, where output.map is a source-map representation, which can be serialized as output.map.toString(). output.code is a string with generated JS code (note that it's not going to have //@ sourceMappingURL comment in it).
|
101 | */
|
102 | sourceMapWithCode?: boolean | undefined;
|
103 | /**
|
104 | * Optionally option.sourceContent string can be passed (which represents original source of the file, for example it could be a source of coffeescript from which JS is being generated), if provided generated source map will have original source embedded in it.
|
105 | */
|
106 | sourceContent?: string | undefined;
|
107 | sourceCode?: string | undefined;
|
108 | /**
|
109 | * Optionally option.sourceMapRoot can be provided, in which case option.sourceMap will be treated as relative to it. For more information about source map itself, see source map library document, V3 draft and HTML5Rocks introduction. Default is undefined
|
110 | * sourceMapRoot is the source root for the source map (see the Mozilla documentation). If sourceMapWithCode is truthy, an object is returned from generate() of the form: { code: .. , map: .. }. If file is provided, it will be used as file property of generated source map.
|
111 | */
|
112 | sourceMapRoot?: string | undefined;
|
113 | /**
|
114 | * Recognize DirectiveStatement and distinguish it from ExpressionStatement. Default: false
|
115 | */
|
116 | directive?: boolean | undefined;
|
117 | /**
|
118 | * If file is provided, it will be used as file property of generated source map.
|
119 | */
|
120 | file?: string | undefined;
|
121 | /**
|
122 | * Providing verbatim code generation option to Expression nodes.
|
123 | * verbatim option is provided by user as string. When generating Expression code,
|
124 | * looking up node[option.verbatim] value and dump it instead of normal code generation.
|
125 | *
|
126 | * @example
|
127 | */
|
128 | verbatim?: string | undefined;
|
129 | }
|
130 |
|
131 | /**
|
132 | * https://github.com/estools/escodegen/commit/adf113333cd4888cf59bfc4f957df98bf7db82b6
|
133 | */
|
134 | export enum Precedence {
|
135 | Sequence,
|
136 | Yield,
|
137 | Await,
|
138 | Assignment,
|
139 | Conditional,
|
140 | ArrowFunction,
|
141 | LogicalOR,
|
142 | LogicalAND,
|
143 | BitwiseOR,
|
144 | BitwiseXOR,
|
145 | BitwiseAND,
|
146 | Equality,
|
147 | Relational,
|
148 | BitwiseSHIFT,
|
149 | Additive,
|
150 | Multiplicative,
|
151 | Unary,
|
152 | Postfix,
|
153 | Call,
|
154 | New,
|
155 | TaggedTemplate,
|
156 | Member,
|
157 | Primary,
|
158 | }
|
159 |
|
160 | /**
|
161 | * Produces given Abstract Syntax Tree as javascript code
|
162 | * @param ast The Abstract Syntax Tree to generate code from
|
163 | * @param options The generation options
|
164 | */
|
165 | export function generate(ast: any, options?: GenerateOptions): string;
|
166 | /**
|
167 | * Attaching the comments is needed to keep the comments and to allow blank lines to be preserved.
|
168 | */
|
169 | export function attachComments(ast: any, comments: any, tokens: any): any;
|