@ast-grep/napi 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +77 -0
- package/index.js +2 -1
- package/package.json +9 -9
package/index.d.ts
CHANGED
|
@@ -19,19 +19,32 @@ export interface Pos {
|
|
|
19
19
|
index: number
|
|
20
20
|
}
|
|
21
21
|
export interface Range {
|
|
22
|
+
/** starting position of the range */
|
|
22
23
|
start: Pos
|
|
24
|
+
/** ending position of the range */
|
|
23
25
|
end: Pos
|
|
24
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Rule configuration similar to YAML
|
|
29
|
+
* See https://ast-grep.github.io/reference/yaml.html
|
|
30
|
+
*/
|
|
25
31
|
export interface NapiConfig {
|
|
32
|
+
/** The rule object, see https://ast-grep.github.io/reference/rule.html */
|
|
26
33
|
rule: any
|
|
34
|
+
/** See https://ast-grep.github.io/guide/rule-config.html#constraints */
|
|
27
35
|
constraints?: any
|
|
36
|
+
/** Available languages: html, css, js, jsx, ts, tsx */
|
|
28
37
|
language?: FrontEndLanguage
|
|
38
|
+
/** https://ast-grep.github.io/reference/yaml.html#transform */
|
|
29
39
|
transform?: any
|
|
40
|
+
/** https://ast-grep.github.io/guide/rule-config/utility-rule.html */
|
|
30
41
|
utils?: any
|
|
31
42
|
}
|
|
32
43
|
export function parseFiles(paths: string[], callback: (err: null | Error, result: SgRoot) => void): Promise<number>
|
|
33
44
|
export interface FindConfig {
|
|
45
|
+
/** specify the file paths to recursively find files */
|
|
34
46
|
paths: Array<string>
|
|
47
|
+
/** a Rule object to find what nodes will match */
|
|
35
48
|
matcher: NapiConfig
|
|
36
49
|
}
|
|
37
50
|
export class SgNode {
|
|
@@ -39,6 +52,7 @@ export class SgNode {
|
|
|
39
52
|
isLeaf(): boolean
|
|
40
53
|
isNamed(): boolean
|
|
41
54
|
isNamedLeaf(): boolean
|
|
55
|
+
/** Returns the string name of the node kind */
|
|
42
56
|
kind(): string
|
|
43
57
|
text(): string
|
|
44
58
|
matches(m: string): boolean
|
|
@@ -48,9 +62,12 @@ export class SgNode {
|
|
|
48
62
|
follows(m: string): boolean
|
|
49
63
|
getMatch(m: string): SgNode | null
|
|
50
64
|
getMultipleMatches(m: string): Array<SgNode>
|
|
65
|
+
/** Returns the node's SgRoot */
|
|
66
|
+
getRoot(): SgRoot
|
|
51
67
|
children(): Array<SgNode>
|
|
52
68
|
find(matcher: string | number | NapiConfig): SgNode | null
|
|
53
69
|
findAll(matcher: string | number | NapiConfig): Array<SgNode>
|
|
70
|
+
/** Finds the child node in the `field` */
|
|
54
71
|
field(name: string): SgNode | null
|
|
55
72
|
parent(): SgNode | null
|
|
56
73
|
child(nth: number): SgNode | null
|
|
@@ -60,37 +77,97 @@ export class SgNode {
|
|
|
60
77
|
prev(): SgNode | null
|
|
61
78
|
prevAll(): Array<SgNode>
|
|
62
79
|
}
|
|
80
|
+
/** Represents the parsed tree of code. */
|
|
63
81
|
export class SgRoot {
|
|
82
|
+
/** Returns the root SgNode of the ast-grep instance. */
|
|
64
83
|
root(): SgNode
|
|
84
|
+
/**
|
|
85
|
+
* Returns the path of the file if it is discovered by ast-grep's `findInFiles`.
|
|
86
|
+
* Returns `"anonymous"` if the instance is created by `lang.parse(source)`.
|
|
87
|
+
*/
|
|
65
88
|
filename(): string
|
|
66
89
|
}
|
|
67
90
|
export namespace html {
|
|
91
|
+
/** Parse a string to an ast-grep instance */
|
|
68
92
|
export function parse(src: string): SgRoot
|
|
93
|
+
/** Get the `kind` number from its string name. */
|
|
69
94
|
export function kind(kindName: string): number
|
|
95
|
+
/** Compile a string to ast-grep Pattern. */
|
|
70
96
|
export function pattern(pattern: string): NapiConfig
|
|
97
|
+
/**
|
|
98
|
+
* Discover and parse multiple files in Rust.
|
|
99
|
+
* `config` specifies the file path and matcher.
|
|
100
|
+
* `callback` will receive matching nodes found in a file.
|
|
101
|
+
*/
|
|
71
102
|
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
|
|
72
103
|
}
|
|
73
104
|
export namespace js {
|
|
105
|
+
/** Parse a string to an ast-grep instance */
|
|
74
106
|
export function parse(src: string): SgRoot
|
|
107
|
+
/** Get the `kind` number from its string name. */
|
|
75
108
|
export function kind(kindName: string): number
|
|
109
|
+
/** Compile a string to ast-grep Pattern. */
|
|
76
110
|
export function pattern(pattern: string): NapiConfig
|
|
111
|
+
/**
|
|
112
|
+
* Discover and parse multiple files in Rust.
|
|
113
|
+
* `config` specifies the file path and matcher.
|
|
114
|
+
* `callback` will receive matching nodes found in a file.
|
|
115
|
+
*/
|
|
77
116
|
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
|
|
78
117
|
}
|
|
79
118
|
export namespace jsx {
|
|
119
|
+
/** Parse a string to an ast-grep instance */
|
|
80
120
|
export function parse(src: string): SgRoot
|
|
121
|
+
/** Get the `kind` number from its string name. */
|
|
81
122
|
export function kind(kindName: string): number
|
|
123
|
+
/** Compile a string to ast-grep Pattern. */
|
|
82
124
|
export function pattern(pattern: string): NapiConfig
|
|
125
|
+
/**
|
|
126
|
+
* Discover and parse multiple files in Rust.
|
|
127
|
+
* `config` specifies the file path and matcher.
|
|
128
|
+
* `callback` will receive matching nodes found in a file.
|
|
129
|
+
*/
|
|
83
130
|
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
|
|
84
131
|
}
|
|
85
132
|
export namespace ts {
|
|
133
|
+
/** Parse a string to an ast-grep instance */
|
|
86
134
|
export function parse(src: string): SgRoot
|
|
135
|
+
/** Get the `kind` number from its string name. */
|
|
87
136
|
export function kind(kindName: string): number
|
|
137
|
+
/** Compile a string to ast-grep Pattern. */
|
|
88
138
|
export function pattern(pattern: string): NapiConfig
|
|
139
|
+
/**
|
|
140
|
+
* Discover and parse multiple files in Rust.
|
|
141
|
+
* `config` specifies the file path and matcher.
|
|
142
|
+
* `callback` will receive matching nodes found in a file.
|
|
143
|
+
*/
|
|
89
144
|
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
|
|
90
145
|
}
|
|
91
146
|
export namespace tsx {
|
|
147
|
+
/** Parse a string to an ast-grep instance */
|
|
92
148
|
export function parse(src: string): SgRoot
|
|
149
|
+
/** Get the `kind` number from its string name. */
|
|
93
150
|
export function kind(kindName: string): number
|
|
151
|
+
/** Compile a string to ast-grep Pattern. */
|
|
94
152
|
export function pattern(pattern: string): NapiConfig
|
|
153
|
+
/**
|
|
154
|
+
* Discover and parse multiple files in Rust.
|
|
155
|
+
* `config` specifies the file path and matcher.
|
|
156
|
+
* `callback` will receive matching nodes found in a file.
|
|
157
|
+
*/
|
|
158
|
+
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
|
|
159
|
+
}
|
|
160
|
+
export namespace css {
|
|
161
|
+
/** Parse a string to an ast-grep instance */
|
|
162
|
+
export function parse(src: string): SgRoot
|
|
163
|
+
/** Get the `kind` number from its string name. */
|
|
164
|
+
export function kind(kindName: string): number
|
|
165
|
+
/** Compile a string to ast-grep Pattern. */
|
|
166
|
+
export function pattern(pattern: string): NapiConfig
|
|
167
|
+
/**
|
|
168
|
+
* Discover and parse multiple files in Rust.
|
|
169
|
+
* `config` specifies the file path and matcher.
|
|
170
|
+
* `callback` will receive matching nodes found in a file.
|
|
171
|
+
*/
|
|
95
172
|
export function findInFiles(config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number>
|
|
96
173
|
}
|
package/index.js
CHANGED
|
@@ -252,7 +252,7 @@ if (!nativeBinding) {
|
|
|
252
252
|
throw new Error(`Failed to load native binding`)
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
const { FrontEndLanguage, SgNode, SgRoot, parseFiles, html, js, jsx, ts, tsx } = nativeBinding
|
|
255
|
+
const { FrontEndLanguage, SgNode, SgRoot, parseFiles, html, js, jsx, ts, tsx, css } = nativeBinding
|
|
256
256
|
|
|
257
257
|
module.exports.FrontEndLanguage = FrontEndLanguage
|
|
258
258
|
module.exports.SgNode = SgNode
|
|
@@ -263,3 +263,4 @@ module.exports.js = js
|
|
|
263
263
|
module.exports.jsx = jsx
|
|
264
264
|
module.exports.ts = ts
|
|
265
265
|
module.exports.tsx = tsx
|
|
266
|
+
module.exports.css = css
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ast-grep/napi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Search and Rewrite code at large scale using precise AST pattern",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "https://github.com/ast-grep/ast-grep",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@napi-rs/cli": "2.16.1",
|
|
47
47
|
"ava": "5.3.1",
|
|
48
|
-
"chalk": "5.
|
|
48
|
+
"chalk": "5.3.0",
|
|
49
49
|
"ts-node": "10.9.1",
|
|
50
|
-
"typescript": "5.1.
|
|
50
|
+
"typescript": "5.1.6"
|
|
51
51
|
},
|
|
52
52
|
"ava": {
|
|
53
53
|
"require": [
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
},
|
|
65
65
|
"packageManager": "yarn@3.2.3",
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@ast-grep/napi-win32-x64-msvc": "0.
|
|
68
|
-
"@ast-grep/napi-darwin-x64": "0.
|
|
69
|
-
"@ast-grep/napi-linux-x64-gnu": "0.
|
|
70
|
-
"@ast-grep/napi-win32-ia32-msvc": "0.
|
|
71
|
-
"@ast-grep/napi-darwin-arm64": "0.
|
|
72
|
-
"@ast-grep/napi-win32-arm64-msvc": "0.
|
|
67
|
+
"@ast-grep/napi-win32-x64-msvc": "0.8.0",
|
|
68
|
+
"@ast-grep/napi-darwin-x64": "0.8.0",
|
|
69
|
+
"@ast-grep/napi-linux-x64-gnu": "0.8.0",
|
|
70
|
+
"@ast-grep/napi-win32-ia32-msvc": "0.8.0",
|
|
71
|
+
"@ast-grep/napi-darwin-arm64": "0.8.0",
|
|
72
|
+
"@ast-grep/napi-win32-arm64-msvc": "0.8.0"
|
|
73
73
|
}
|
|
74
74
|
}
|