@ast-grep/napi 0.1.3 → 0.1.5
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/README.md +1 -1
- package/index.d.ts +47 -10
- package/index.js +21 -15
- package/package.json +8 -8
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -3,14 +3,29 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
+
export const enum FrontEndLanguage {
|
|
7
|
+
Html = 0,
|
|
8
|
+
JavaScript = 1,
|
|
9
|
+
Tsx = 2,
|
|
10
|
+
TypeScript = 3
|
|
11
|
+
}
|
|
6
12
|
export interface Pos {
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
/** line number starting from 1 */
|
|
14
|
+
line: number
|
|
15
|
+
/** column number starting from 1 */
|
|
16
|
+
column: number
|
|
17
|
+
/** byte offset of the position */
|
|
18
|
+
index: number
|
|
9
19
|
}
|
|
10
20
|
export interface Range {
|
|
11
21
|
start: Pos
|
|
12
22
|
end: Pos
|
|
13
23
|
}
|
|
24
|
+
export interface NapiConfig {
|
|
25
|
+
rule: any
|
|
26
|
+
constraints?: any
|
|
27
|
+
language?: FrontEndLanguage
|
|
28
|
+
}
|
|
14
29
|
export class SgNode {
|
|
15
30
|
range(): Range
|
|
16
31
|
isLeaf(): boolean
|
|
@@ -21,9 +36,11 @@ export class SgNode {
|
|
|
21
36
|
has(m: string): boolean
|
|
22
37
|
precedes(m: string): boolean
|
|
23
38
|
follows(m: string): boolean
|
|
39
|
+
getMatch(m: string): SgNode | null
|
|
40
|
+
getMultipleMatches(m: string): Array<SgNode>
|
|
24
41
|
children(): Array<SgNode>
|
|
25
|
-
|
|
26
|
-
findAll(
|
|
42
|
+
find(matcher: string | number | NapiConfig): SgNode | null
|
|
43
|
+
findAll(matcher: string | number | NapiConfig): Array<SgNode>
|
|
27
44
|
field(name: string): SgNode | null
|
|
28
45
|
parent(): SgNode | null
|
|
29
46
|
child(nth: number): SgNode | null
|
|
@@ -33,11 +50,31 @@ export class SgNode {
|
|
|
33
50
|
prev(): SgNode | null
|
|
34
51
|
prevAll(): Array<SgNode>
|
|
35
52
|
}
|
|
36
|
-
export
|
|
37
|
-
export class AstGrep {
|
|
38
|
-
static html(src: string): SgRoot
|
|
39
|
-
static js(src: string): SgRoot
|
|
40
|
-
static ts(src: string): SgRoot
|
|
41
|
-
static tsx(src: string): SgRoot
|
|
53
|
+
export class SgRoot {
|
|
42
54
|
root(): SgNode
|
|
43
55
|
}
|
|
56
|
+
export namespace html {
|
|
57
|
+
export function parse(src: string): SgRoot
|
|
58
|
+
export function kind(kindName: string): number
|
|
59
|
+
export function pattern(pattern: string): NapiConfig
|
|
60
|
+
}
|
|
61
|
+
export namespace js {
|
|
62
|
+
export function parse(src: string): SgRoot
|
|
63
|
+
export function kind(kindName: string): number
|
|
64
|
+
export function pattern(pattern: string): NapiConfig
|
|
65
|
+
}
|
|
66
|
+
export namespace jsx {
|
|
67
|
+
export function parse(src: string): SgRoot
|
|
68
|
+
export function kind(kindName: string): number
|
|
69
|
+
export function pattern(pattern: string): NapiConfig
|
|
70
|
+
}
|
|
71
|
+
export namespace ts {
|
|
72
|
+
export function parse(src: string): SgRoot
|
|
73
|
+
export function kind(kindName: string): number
|
|
74
|
+
export function pattern(pattern: string): NapiConfig
|
|
75
|
+
}
|
|
76
|
+
export namespace tsx {
|
|
77
|
+
export function parse(src: string): SgRoot
|
|
78
|
+
export function kind(kindName: string): number
|
|
79
|
+
export function pattern(pattern: string): NapiConfig
|
|
80
|
+
}
|
package/index.js
CHANGED
|
@@ -30,7 +30,7 @@ switch (platform) {
|
|
|
30
30
|
if (localFileExisted) {
|
|
31
31
|
nativeBinding = require('./ast-grep-napi.android-arm64.node')
|
|
32
32
|
} else {
|
|
33
|
-
nativeBinding = require('ast-grep
|
|
33
|
+
nativeBinding = require('@ast-grep/napi-android-arm64')
|
|
34
34
|
}
|
|
35
35
|
} catch (e) {
|
|
36
36
|
loadError = e
|
|
@@ -42,7 +42,7 @@ switch (platform) {
|
|
|
42
42
|
if (localFileExisted) {
|
|
43
43
|
nativeBinding = require('./ast-grep-napi.android-arm-eabi.node')
|
|
44
44
|
} else {
|
|
45
|
-
nativeBinding = require('ast-grep
|
|
45
|
+
nativeBinding = require('@ast-grep/napi-android-arm-eabi')
|
|
46
46
|
}
|
|
47
47
|
} catch (e) {
|
|
48
48
|
loadError = e
|
|
@@ -62,7 +62,7 @@ switch (platform) {
|
|
|
62
62
|
if (localFileExisted) {
|
|
63
63
|
nativeBinding = require('./ast-grep-napi.win32-x64-msvc.node')
|
|
64
64
|
} else {
|
|
65
|
-
nativeBinding = require('ast-grep
|
|
65
|
+
nativeBinding = require('@ast-grep/napi-win32-x64-msvc')
|
|
66
66
|
}
|
|
67
67
|
} catch (e) {
|
|
68
68
|
loadError = e
|
|
@@ -76,7 +76,7 @@ switch (platform) {
|
|
|
76
76
|
if (localFileExisted) {
|
|
77
77
|
nativeBinding = require('./ast-grep-napi.win32-ia32-msvc.node')
|
|
78
78
|
} else {
|
|
79
|
-
nativeBinding = require('ast-grep
|
|
79
|
+
nativeBinding = require('@ast-grep/napi-win32-ia32-msvc')
|
|
80
80
|
}
|
|
81
81
|
} catch (e) {
|
|
82
82
|
loadError = e
|
|
@@ -90,7 +90,7 @@ switch (platform) {
|
|
|
90
90
|
if (localFileExisted) {
|
|
91
91
|
nativeBinding = require('./ast-grep-napi.win32-arm64-msvc.node')
|
|
92
92
|
} else {
|
|
93
|
-
nativeBinding = require('ast-grep
|
|
93
|
+
nativeBinding = require('@ast-grep/napi-win32-arm64-msvc')
|
|
94
94
|
}
|
|
95
95
|
} catch (e) {
|
|
96
96
|
loadError = e
|
|
@@ -108,7 +108,7 @@ switch (platform) {
|
|
|
108
108
|
if (localFileExisted) {
|
|
109
109
|
nativeBinding = require('./ast-grep-napi.darwin-x64.node')
|
|
110
110
|
} else {
|
|
111
|
-
nativeBinding = require('ast-grep
|
|
111
|
+
nativeBinding = require('@ast-grep/napi-darwin-x64')
|
|
112
112
|
}
|
|
113
113
|
} catch (e) {
|
|
114
114
|
loadError = e
|
|
@@ -122,7 +122,7 @@ switch (platform) {
|
|
|
122
122
|
if (localFileExisted) {
|
|
123
123
|
nativeBinding = require('./ast-grep-napi.darwin-arm64.node')
|
|
124
124
|
} else {
|
|
125
|
-
nativeBinding = require('ast-grep
|
|
125
|
+
nativeBinding = require('@ast-grep/napi-darwin-arm64')
|
|
126
126
|
}
|
|
127
127
|
} catch (e) {
|
|
128
128
|
loadError = e
|
|
@@ -141,7 +141,7 @@ switch (platform) {
|
|
|
141
141
|
if (localFileExisted) {
|
|
142
142
|
nativeBinding = require('./ast-grep-napi.freebsd-x64.node')
|
|
143
143
|
} else {
|
|
144
|
-
nativeBinding = require('ast-grep
|
|
144
|
+
nativeBinding = require('@ast-grep/napi-freebsd-x64')
|
|
145
145
|
}
|
|
146
146
|
} catch (e) {
|
|
147
147
|
loadError = e
|
|
@@ -158,7 +158,7 @@ switch (platform) {
|
|
|
158
158
|
if (localFileExisted) {
|
|
159
159
|
nativeBinding = require('./ast-grep-napi.linux-x64-musl.node')
|
|
160
160
|
} else {
|
|
161
|
-
nativeBinding = require('ast-grep
|
|
161
|
+
nativeBinding = require('@ast-grep/napi-linux-x64-musl')
|
|
162
162
|
}
|
|
163
163
|
} catch (e) {
|
|
164
164
|
loadError = e
|
|
@@ -171,7 +171,7 @@ switch (platform) {
|
|
|
171
171
|
if (localFileExisted) {
|
|
172
172
|
nativeBinding = require('./ast-grep-napi.linux-x64-gnu.node')
|
|
173
173
|
} else {
|
|
174
|
-
nativeBinding = require('ast-grep
|
|
174
|
+
nativeBinding = require('@ast-grep/napi-linux-x64-gnu')
|
|
175
175
|
}
|
|
176
176
|
} catch (e) {
|
|
177
177
|
loadError = e
|
|
@@ -187,7 +187,7 @@ switch (platform) {
|
|
|
187
187
|
if (localFileExisted) {
|
|
188
188
|
nativeBinding = require('./ast-grep-napi.linux-arm64-musl.node')
|
|
189
189
|
} else {
|
|
190
|
-
nativeBinding = require('ast-grep
|
|
190
|
+
nativeBinding = require('@ast-grep/napi-linux-arm64-musl')
|
|
191
191
|
}
|
|
192
192
|
} catch (e) {
|
|
193
193
|
loadError = e
|
|
@@ -200,7 +200,7 @@ switch (platform) {
|
|
|
200
200
|
if (localFileExisted) {
|
|
201
201
|
nativeBinding = require('./ast-grep-napi.linux-arm64-gnu.node')
|
|
202
202
|
} else {
|
|
203
|
-
nativeBinding = require('ast-grep
|
|
203
|
+
nativeBinding = require('@ast-grep/napi-linux-arm64-gnu')
|
|
204
204
|
}
|
|
205
205
|
} catch (e) {
|
|
206
206
|
loadError = e
|
|
@@ -215,7 +215,7 @@ switch (platform) {
|
|
|
215
215
|
if (localFileExisted) {
|
|
216
216
|
nativeBinding = require('./ast-grep-napi.linux-arm-gnueabihf.node')
|
|
217
217
|
} else {
|
|
218
|
-
nativeBinding = require('ast-grep
|
|
218
|
+
nativeBinding = require('@ast-grep/napi-linux-arm-gnueabihf')
|
|
219
219
|
}
|
|
220
220
|
} catch (e) {
|
|
221
221
|
loadError = e
|
|
@@ -236,7 +236,13 @@ if (!nativeBinding) {
|
|
|
236
236
|
throw new Error(`Failed to load native binding`)
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
const { SgNode,
|
|
239
|
+
const { FrontEndLanguage, SgNode, SgRoot, html, js, jsx, ts, tsx } = nativeBinding
|
|
240
240
|
|
|
241
|
+
module.exports.FrontEndLanguage = FrontEndLanguage
|
|
241
242
|
module.exports.SgNode = SgNode
|
|
242
|
-
module.exports.
|
|
243
|
+
module.exports.SgRoot = SgRoot
|
|
244
|
+
module.exports.html = html
|
|
245
|
+
module.exports.js = js
|
|
246
|
+
module.exports.jsx = jsx
|
|
247
|
+
module.exports.ts = ts
|
|
248
|
+
module.exports.tsx = tsx
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ast-grep/napi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Search and Rewrite code at large scale using precise AST pattern",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"repository": "https://github.com/
|
|
6
|
+
"repository": "https://github.com/ast-grep/ast-grep",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"ast",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
},
|
|
65
65
|
"packageManager": "yarn@3.2.3",
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@ast-grep/napi-win32-x64-msvc": "0.1.
|
|
68
|
-
"@ast-grep/napi-darwin-x64": "0.1.
|
|
69
|
-
"@ast-grep/napi-linux-x64-gnu": "0.1.
|
|
70
|
-
"@ast-grep/napi-win32-ia32-msvc": "0.1.
|
|
71
|
-
"@ast-grep/napi-darwin-arm64": "0.1.
|
|
72
|
-
"@ast-grep/napi-win32-arm64-msvc": "0.1.
|
|
67
|
+
"@ast-grep/napi-win32-x64-msvc": "0.1.5",
|
|
68
|
+
"@ast-grep/napi-darwin-x64": "0.1.5",
|
|
69
|
+
"@ast-grep/napi-linux-x64-gnu": "0.1.5",
|
|
70
|
+
"@ast-grep/napi-win32-ia32-msvc": "0.1.5",
|
|
71
|
+
"@ast-grep/napi-darwin-arm64": "0.1.5",
|
|
72
|
+
"@ast-grep/napi-win32-arm64-msvc": "0.1.5"
|
|
73
73
|
}
|
|
74
74
|
}
|