-
-
Notifications
You must be signed in to change notification settings - Fork 157
/
index.d.ts
232 lines (230 loc) · 8.96 KB
/
index.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* tslint:disable */
/* eslint-disable */
/* auto-generated by NAPI-RS */
/**
* Rule configuration similar to YAML
* See https://ast-grep.github.io/reference/yaml.html
*/
export interface NapiConfig {
/** The rule object, see https://ast-grep.github.io/reference/rule.html */
rule: any
/** See https://ast-grep.github.io/guide/rule-config.html#constraints */
constraints?: any
/** Available languages: html, css, js, jsx, ts, tsx */
language?: FrontEndLanguage
/** https://ast-grep.github.io/reference/yaml.html#transform */
transform?: any
/** https://ast-grep.github.io/guide/rule-config/utility-rule.html */
utils?: any
}
export const enum FrontEndLanguage {
Html = 0,
JavaScript = 1,
Tsx = 2,
Css = 3,
TypeScript = 4
}
export interface Pos {
/** line number starting from 0 */
line: number
/** column number starting from 0 */
column: number
/** byte offset of the position */
index: number
}
export interface Range {
/** starting position of the range */
start: Pos
/** ending position of the range */
end: Pos
}
export interface FileOption {
paths: Array<string>
languageGlobs: Record<string, Array<string>>
}
export function parseFiles(paths: Array<string> | FileOption, callback: (err: null | Error, result: SgRoot) => void): Promise<number>
export interface FindConfig {
/** specify the file paths to recursively find files */
paths: Array<string>
/** a Rule object to find what nodes will match */
matcher: NapiConfig
/**
* An list of pattern globs to treat of certain files in the specified language.
* eg. ['*.vue', '*.svelte'] for html.findFiles, or ['*.ts'] for tsx.findFiles.
* It is slightly different from https://ast-grep.github.io/reference/sgconfig.html#languageglobs
*/
languageGlobs?: Array<string>
}
export class SgNode {
range(): Range
isLeaf(): boolean
isNamed(): boolean
isNamedLeaf(): boolean
/** Returns the string name of the node kind */
kind(): string
text(): string
matches(m: string): boolean
inside(m: string): boolean
has(m: string): boolean
precedes(m: string): boolean
follows(m: string): boolean
getMatch(m: string): SgNode | null
getMultipleMatches(m: string): Array<SgNode>
getTransformed(m: string): string | null
/** Returns the node's SgRoot */
getRoot(): SgRoot
children(): Array<SgNode>
find(matcher: string | number | NapiConfig): SgNode | null
findAll(matcher: string | number | NapiConfig): Array<SgNode>
/** Finds the child node in the `field` */
field(name: string): SgNode | null
parent(): SgNode | null
child(nth: number): SgNode | null
ancestors(): Array<SgNode>
next(): SgNode | null
nextAll(): Array<SgNode>
prev(): SgNode | null
prevAll(): Array<SgNode>
}
/** Represents the parsed tree of code. */
export class SgRoot {
/** Returns the root SgNode of the ast-grep instance. */
root(): SgNode
/**
* Returns the path of the file if it is discovered by ast-grep's `findInFiles`.
* Returns `"anonymous"` if the instance is created by `lang.parse(source)`.
*/
filename(): string
}
export namespace html {
/** Parse a string to an ast-grep instance */
export function parse(src: string): SgRoot
/**
* Parse a string to an ast-grep instance asynchronously in threads.
* It utilize multiple CPU cores when **concurrent processing sources**.
* However, spawning excessive many threads may backfire.
* Please refer to libuv doc, nodejs' underlying runtime
* for its default behavior and performance tuning tricks.
*/
export function parseAsync(src: string): Promise<SgRoot>
/** Get the `kind` number from its string name. */
export function kind(kindName: string): number
/** Compile a string to ast-grep Pattern. */
export function pattern(pattern: string): NapiConfig
/**
* Discover and parse multiple files in Rust.
* `config` specifies the file path and matcher.
* `callback` will receive matching nodes found in a file.
*/
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
}
export namespace js {
/** Parse a string to an ast-grep instance */
export function parse(src: string): SgRoot
/**
* Parse a string to an ast-grep instance asynchronously in threads.
* It utilize multiple CPU cores when **concurrent processing sources**.
* However, spawning excessive many threads may backfire.
* Please refer to libuv doc, nodejs' underlying runtime
* for its default behavior and performance tuning tricks.
*/
export function parseAsync(src: string): Promise<SgRoot>
/** Get the `kind` number from its string name. */
export function kind(kindName: string): number
/** Compile a string to ast-grep Pattern. */
export function pattern(pattern: string): NapiConfig
/**
* Discover and parse multiple files in Rust.
* `config` specifies the file path and matcher.
* `callback` will receive matching nodes found in a file.
*/
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
}
export namespace jsx {
/** Parse a string to an ast-grep instance */
export function parse(src: string): SgRoot
/**
* Parse a string to an ast-grep instance asynchronously in threads.
* It utilize multiple CPU cores when **concurrent processing sources**.
* However, spawning excessive many threads may backfire.
* Please refer to libuv doc, nodejs' underlying runtime
* for its default behavior and performance tuning tricks.
*/
export function parseAsync(src: string): Promise<SgRoot>
/** Get the `kind` number from its string name. */
export function kind(kindName: string): number
/** Compile a string to ast-grep Pattern. */
export function pattern(pattern: string): NapiConfig
/**
* Discover and parse multiple files in Rust.
* `config` specifies the file path and matcher.
* `callback` will receive matching nodes found in a file.
*/
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
}
export namespace ts {
/** Parse a string to an ast-grep instance */
export function parse(src: string): SgRoot
/**
* Parse a string to an ast-grep instance asynchronously in threads.
* It utilize multiple CPU cores when **concurrent processing sources**.
* However, spawning excessive many threads may backfire.
* Please refer to libuv doc, nodejs' underlying runtime
* for its default behavior and performance tuning tricks.
*/
export function parseAsync(src: string): Promise<SgRoot>
/** Get the `kind` number from its string name. */
export function kind(kindName: string): number
/** Compile a string to ast-grep Pattern. */
export function pattern(pattern: string): NapiConfig
/**
* Discover and parse multiple files in Rust.
* `config` specifies the file path and matcher.
* `callback` will receive matching nodes found in a file.
*/
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
}
export namespace tsx {
/** Parse a string to an ast-grep instance */
export function parse(src: string): SgRoot
/**
* Parse a string to an ast-grep instance asynchronously in threads.
* It utilize multiple CPU cores when **concurrent processing sources**.
* However, spawning excessive many threads may backfire.
* Please refer to libuv doc, nodejs' underlying runtime
* for its default behavior and performance tuning tricks.
*/
export function parseAsync(src: string): Promise<SgRoot>
/** Get the `kind` number from its string name. */
export function kind(kindName: string): number
/** Compile a string to ast-grep Pattern. */
export function pattern(pattern: string): NapiConfig
/**
* Discover and parse multiple files in Rust.
* `config` specifies the file path and matcher.
* `callback` will receive matching nodes found in a file.
*/
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
}
export namespace css {
/** Parse a string to an ast-grep instance */
export function parse(src: string): SgRoot
/**
* Parse a string to an ast-grep instance asynchronously in threads.
* It utilize multiple CPU cores when **concurrent processing sources**.
* However, spawning excessive many threads may backfire.
* Please refer to libuv doc, nodejs' underlying runtime
* for its default behavior and performance tuning tricks.
*/
export function parseAsync(src: string): Promise<SgRoot>
/** Get the `kind` number from its string name. */
export function kind(kindName: string): number
/** Compile a string to ast-grep Pattern. */
export function pattern(pattern: string): NapiConfig
/**
* Discover and parse multiple files in Rust.
* `config` specifies the file path and matcher.
* `callback` will receive matching nodes found in a file.
*/
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
}