@ast-grep/napi 0.1.4 → 0.1.6
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 +8 -2
- package/package.json +11 -11
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
|
@@ -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.6",
|
|
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",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@napi-rs/cli": "2.11.4",
|
|
47
|
-
"@swc-node/register": "1.5.1",
|
|
48
47
|
"ava": "4.3.3",
|
|
49
48
|
"chalk": "5.0.1",
|
|
50
|
-
"
|
|
49
|
+
"ts-node": "10.9.1",
|
|
50
|
+
"typescript": "4.8.4"
|
|
51
51
|
},
|
|
52
52
|
"ava": {
|
|
53
53
|
"require": [
|
|
54
|
-
"
|
|
54
|
+
"ts-node/register"
|
|
55
55
|
],
|
|
56
56
|
"extensions": [
|
|
57
57
|
"ts"
|
|
@@ -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.6",
|
|
68
|
+
"@ast-grep/napi-darwin-x64": "0.1.6",
|
|
69
|
+
"@ast-grep/napi-linux-x64-gnu": "0.1.6",
|
|
70
|
+
"@ast-grep/napi-win32-ia32-msvc": "0.1.6",
|
|
71
|
+
"@ast-grep/napi-darwin-arm64": "0.1.6",
|
|
72
|
+
"@ast-grep/napi-win32-arm64-msvc": "0.1.6"
|
|
73
73
|
}
|
|
74
74
|
}
|