-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypings.d.ts
90 lines (82 loc) · 2.18 KB
/
typings.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// https://github.com/davidbonnet/astring/issues/687
declare module "astring" {
import type { Writable } from "node:stream";
import type { AnyNode } from "acorn";
import type { Mapping, SourceMapGenerator } from "source-map";
/**
* State object passed to generator functions.
*/
export interface State {
output: string;
write(code: string, node?: AnyNode): void;
writeComments: boolean;
indent: string;
lineEnd: string;
indentLevel: number;
line?: number;
column?: number;
lineEndSize?: number;
mapping?: Mapping;
}
/**
* Code generator for each node type.
*/
export type Generator = {
[T in AnyNode["type"]]: (node: AnyNode & { type: T }, state: State) => void;
};
/**
* Code generator options.
*/
export interface Options<Output = null> {
/**
* If present, source mappings will be written to the generator.
*/
sourceMap?: SourceMapGenerator;
/**
* String to use for indentation, defaults to `"␣␣"`.
*/
indent?: string;
/**
* String to use for line endings, defaults to `"\n"`.
*/
lineEnd?: string;
/**
* Indent level to start from, defaults to `0`.
*/
startingIndentLevel?: number;
/**
* Generate comments if `true`, defaults to `false`.
*/
comments?: boolean;
/**
* Output stream to write the render code to, defaults to `null`.
*/
output?: Output;
/**
* Custom code generator logic.
*/
generator?: Generator;
}
/**
* Core Estree Node type to accommodate derived node types from parsers.
*/
interface Node {
type: string;
}
/**
* Returns a string representing the rendered code of the provided AST `node`.
* However, if an `output` stream is provided in the `options`, it writes to that stream and returns it.
*/
export function generate(node: Node, options?: Options<null>): string;
export function generate(node: Node, options?: Options<Writable>): Writable;
/**
* Base code generator.
*/
export const GENERATOR: Generator;
/**
* Base code generator.
*
* @deprecated Use {@link GENERATOR} instead.
*/
export const baseGenerator: Generator;
}