@ast-grep/napi 0.32.3 → 0.33.1
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 +3 -1
- package/index.js +2 -1
- package/lang/Css.d.ts +48 -6
- package/package.json +12 -12
- package/types/api.d.ts +7 -7
- package/types/config.d.ts +4 -4
- package/types/lang.d.ts +4 -0
- package/types/registerDynamicLang.d.ts +27 -0
- package/types/sgnode.d.ts +5 -5
- package/types/staticTypes.d.ts +1 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//-----Type Only Export!-----//
|
|
2
2
|
export type { Pos, Edit, Range } from './types/sgnode'
|
|
3
3
|
export type { NapiConfig, FindConfig, FileOption } from './types/config'
|
|
4
|
+
export type { DynamicLangRegistrations } from './types/registerDynamicLang'
|
|
4
5
|
// Only Rule here. User can use Rule['pattern'], e.g., to get the type of subfield.
|
|
5
6
|
export type { Rule } from './types/rule'
|
|
6
7
|
|
|
@@ -15,5 +16,6 @@ export {
|
|
|
15
16
|
pattern,
|
|
16
17
|
findInFiles,
|
|
17
18
|
} from './types/api'
|
|
19
|
+
export { registerDynamicLanguage } from './types/registerDynamicLang'
|
|
18
20
|
// deprecated
|
|
19
|
-
export * from './types/deprecated'
|
|
21
|
+
export * from './types/deprecated'
|
package/index.js
CHANGED
|
@@ -310,7 +310,7 @@ if (!nativeBinding) {
|
|
|
310
310
|
throw new Error(`Failed to load native binding`)
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
const { parseFiles, Lang, SgNode, SgRoot, parse, parseAsync, kind, pattern, findInFiles, html, js, jsx, ts, tsx, css } = nativeBinding
|
|
313
|
+
const { parseFiles, Lang, SgNode, SgRoot, parse, parseAsync, kind, pattern, findInFiles, registerDynamicLanguage, html, js, jsx, ts, tsx, css } = nativeBinding
|
|
314
314
|
|
|
315
315
|
module.exports.parseFiles = parseFiles
|
|
316
316
|
module.exports.Lang = Lang
|
|
@@ -321,6 +321,7 @@ module.exports.parseAsync = parseAsync
|
|
|
321
321
|
module.exports.kind = kind
|
|
322
322
|
module.exports.pattern = pattern
|
|
323
323
|
module.exports.findInFiles = findInFiles
|
|
324
|
+
module.exports.registerDynamicLanguage = registerDynamicLanguage
|
|
324
325
|
module.exports.html = html
|
|
325
326
|
module.exports.js = js
|
|
326
327
|
module.exports.jsx = jsx
|
package/lang/Css.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Auto-generated from tree-sitter Css v0.23.
|
|
1
|
+
// Auto-generated from tree-sitter Css v0.23.2
|
|
2
2
|
type CssTypes = {
|
|
3
3
|
"adjacent_sibling_selector": {
|
|
4
4
|
"type": "adjacent_sibling_selector",
|
|
@@ -661,6 +661,25 @@ type CssTypes = {
|
|
|
661
661
|
]
|
|
662
662
|
}
|
|
663
663
|
},
|
|
664
|
+
"class_name": {
|
|
665
|
+
"type": "class_name",
|
|
666
|
+
"named": true,
|
|
667
|
+
"fields": {},
|
|
668
|
+
"children": {
|
|
669
|
+
"multiple": true,
|
|
670
|
+
"required": false,
|
|
671
|
+
"types": [
|
|
672
|
+
{
|
|
673
|
+
"type": "escape_sequence",
|
|
674
|
+
"named": true
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
"type": "identifier",
|
|
678
|
+
"named": true
|
|
679
|
+
}
|
|
680
|
+
]
|
|
681
|
+
}
|
|
682
|
+
},
|
|
664
683
|
"class_selector": {
|
|
665
684
|
"type": "class_selector",
|
|
666
685
|
"named": true,
|
|
@@ -1845,11 +1864,26 @@ type CssTypes = {
|
|
|
1845
1864
|
"string_value": {
|
|
1846
1865
|
"type": "string_value",
|
|
1847
1866
|
"named": true,
|
|
1848
|
-
"fields": {}
|
|
1867
|
+
"fields": {},
|
|
1868
|
+
"children": {
|
|
1869
|
+
"multiple": true,
|
|
1870
|
+
"required": false,
|
|
1871
|
+
"types": [
|
|
1872
|
+
{
|
|
1873
|
+
"type": "escape_sequence",
|
|
1874
|
+
"named": true
|
|
1875
|
+
},
|
|
1876
|
+
{
|
|
1877
|
+
"type": "string_content",
|
|
1878
|
+
"named": true
|
|
1879
|
+
}
|
|
1880
|
+
]
|
|
1881
|
+
}
|
|
1849
1882
|
},
|
|
1850
1883
|
"stylesheet": {
|
|
1851
1884
|
"type": "stylesheet",
|
|
1852
1885
|
"named": true,
|
|
1886
|
+
"root": true,
|
|
1853
1887
|
"fields": {},
|
|
1854
1888
|
"children": {
|
|
1855
1889
|
"multiple": true,
|
|
@@ -1977,14 +2011,14 @@ type CssTypes = {
|
|
|
1977
2011
|
"type": "at_keyword",
|
|
1978
2012
|
"named": true
|
|
1979
2013
|
},
|
|
1980
|
-
"class_name": {
|
|
1981
|
-
"type": "class_name",
|
|
1982
|
-
"named": true
|
|
1983
|
-
},
|
|
1984
2014
|
"comment": {
|
|
1985
2015
|
"type": "comment",
|
|
1986
2016
|
"named": true
|
|
1987
2017
|
},
|
|
2018
|
+
"escape_sequence": {
|
|
2019
|
+
"type": "escape_sequence",
|
|
2020
|
+
"named": true
|
|
2021
|
+
},
|
|
1988
2022
|
"feature_name": {
|
|
1989
2023
|
"type": "feature_name",
|
|
1990
2024
|
"named": true
|
|
@@ -2001,6 +2035,10 @@ type CssTypes = {
|
|
|
2001
2035
|
"type": "id_name",
|
|
2002
2036
|
"named": true
|
|
2003
2037
|
},
|
|
2038
|
+
"identifier": {
|
|
2039
|
+
"type": "identifier",
|
|
2040
|
+
"named": true
|
|
2041
|
+
},
|
|
2004
2042
|
"important": {
|
|
2005
2043
|
"type": "important",
|
|
2006
2044
|
"named": true
|
|
@@ -2033,6 +2071,10 @@ type CssTypes = {
|
|
|
2033
2071
|
"type": "property_name",
|
|
2034
2072
|
"named": true
|
|
2035
2073
|
},
|
|
2074
|
+
"string_content": {
|
|
2075
|
+
"type": "string_content",
|
|
2076
|
+
"named": true
|
|
2077
|
+
},
|
|
2036
2078
|
"tag_name": {
|
|
2037
2079
|
"type": "tag_name",
|
|
2038
2080
|
"named": true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ast-grep/napi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"description": "Search and Rewrite code at large scale using precise AST pattern",
|
|
5
5
|
"homepage": "https://ast-grep.github.io",
|
|
6
6
|
"main": "index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"typegen": "ts-node scripts/generateTypes.ts"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@ast-grep/napi": "0.
|
|
55
|
+
"@ast-grep/napi": "0.33.0",
|
|
56
56
|
"@biomejs/biome": "1.9.4",
|
|
57
57
|
"@napi-rs/cli": "2.18.4",
|
|
58
58
|
"@types/node": "^22.10.2",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"chalk": "5.4.1",
|
|
61
61
|
"smol-toml": "^1.3.1",
|
|
62
62
|
"ts-node": "10.9.2",
|
|
63
|
-
"typescript": "5.7.
|
|
63
|
+
"typescript": "5.7.3"
|
|
64
64
|
},
|
|
65
65
|
"ava": {
|
|
66
66
|
"require": [
|
|
@@ -76,14 +76,14 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"optionalDependencies": {
|
|
79
|
-
"@ast-grep/napi-win32-x64-msvc": "0.
|
|
80
|
-
"@ast-grep/napi-darwin-x64": "0.
|
|
81
|
-
"@ast-grep/napi-linux-x64-gnu": "0.
|
|
82
|
-
"@ast-grep/napi-win32-ia32-msvc": "0.
|
|
83
|
-
"@ast-grep/napi-darwin-arm64": "0.
|
|
84
|
-
"@ast-grep/napi-win32-arm64-msvc": "0.
|
|
85
|
-
"@ast-grep/napi-linux-arm64-gnu": "0.
|
|
86
|
-
"@ast-grep/napi-linux-arm64-musl": "0.
|
|
87
|
-
"@ast-grep/napi-linux-x64-musl": "0.
|
|
79
|
+
"@ast-grep/napi-win32-x64-msvc": "0.33.1",
|
|
80
|
+
"@ast-grep/napi-darwin-x64": "0.33.1",
|
|
81
|
+
"@ast-grep/napi-linux-x64-gnu": "0.33.1",
|
|
82
|
+
"@ast-grep/napi-win32-ia32-msvc": "0.33.1",
|
|
83
|
+
"@ast-grep/napi-darwin-arm64": "0.33.1",
|
|
84
|
+
"@ast-grep/napi-win32-arm64-msvc": "0.33.1",
|
|
85
|
+
"@ast-grep/napi-linux-arm64-gnu": "0.33.1",
|
|
86
|
+
"@ast-grep/napi-linux-arm64-musl": "0.33.1",
|
|
87
|
+
"@ast-grep/napi-linux-x64-musl": "0.33.1"
|
|
88
88
|
}
|
|
89
89
|
}
|
package/types/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SgNode, SgRoot } from './sgnode'
|
|
2
2
|
import type { NapiConfig, FindConfig, FileOption } from './config'
|
|
3
|
-
import type {
|
|
3
|
+
import type { NapiLang } from './lang'
|
|
4
4
|
import type { NamedKinds, TypesMap } from './staticTypes'
|
|
5
5
|
|
|
6
6
|
export declare function parseFiles<M extends TypesMap>(
|
|
@@ -9,7 +9,7 @@ export declare function parseFiles<M extends TypesMap>(
|
|
|
9
9
|
): Promise<number>
|
|
10
10
|
/** Parse a string to an ast-grep instance */
|
|
11
11
|
export declare function parse<M extends TypesMap>(
|
|
12
|
-
lang:
|
|
12
|
+
lang: NapiLang,
|
|
13
13
|
src: string,
|
|
14
14
|
): SgRoot<M>
|
|
15
15
|
/**
|
|
@@ -20,17 +20,17 @@ export declare function parse<M extends TypesMap>(
|
|
|
20
20
|
* for its default behavior and performance tuning tricks.
|
|
21
21
|
*/
|
|
22
22
|
export declare function parseAsync<M extends TypesMap>(
|
|
23
|
-
lang:
|
|
23
|
+
lang: NapiLang,
|
|
24
24
|
src: string,
|
|
25
25
|
): Promise<SgRoot<M>>
|
|
26
26
|
/** Get the `kind` number from its string name. */
|
|
27
27
|
export declare function kind<M extends TypesMap>(
|
|
28
|
-
lang:
|
|
28
|
+
lang: NapiLang,
|
|
29
29
|
kindName: NamedKinds<M>,
|
|
30
30
|
): number
|
|
31
31
|
/** Compile a string to ast-grep Pattern. */
|
|
32
32
|
export declare function pattern<M extends TypesMap>(
|
|
33
|
-
lang:
|
|
33
|
+
lang: NapiLang,
|
|
34
34
|
pattern: string,
|
|
35
35
|
): NapiConfig<M>
|
|
36
36
|
/**
|
|
@@ -40,7 +40,7 @@ export declare function pattern<M extends TypesMap>(
|
|
|
40
40
|
* `callback` will receive matching nodes found in a file.
|
|
41
41
|
*/
|
|
42
42
|
export declare function findInFiles<M extends TypesMap>(
|
|
43
|
-
lang:
|
|
43
|
+
lang: NapiLang,
|
|
44
44
|
config: FindConfig<M>,
|
|
45
45
|
callback: (err: null | Error, result: SgNode<M>[]) => void,
|
|
46
|
-
): Promise<number>
|
|
46
|
+
): Promise<number>
|
package/types/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Rule } from './rule'
|
|
2
|
-
import type {
|
|
2
|
+
import type { NapiLang } from './lang'
|
|
3
3
|
import type { TypesMap } from './staticTypes'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,8 +11,8 @@ export interface NapiConfig<M extends TypesMap = TypesMap> {
|
|
|
11
11
|
rule: Rule<M>
|
|
12
12
|
/** See https://ast-grep.github.io/guide/rule-config.html#constraints */
|
|
13
13
|
constraints?: Record<string, Rule<M>>
|
|
14
|
-
/**
|
|
15
|
-
language?:
|
|
14
|
+
/** Builtin Language or custom language */
|
|
15
|
+
language?: NapiLang
|
|
16
16
|
/**
|
|
17
17
|
* transform is NOT useful in JavaScript. You can use JS code to directly transform the result.
|
|
18
18
|
* https://ast-grep.github.io/reference/yaml.html#transform
|
|
@@ -36,4 +36,4 @@ export interface FindConfig<M extends TypesMap = TypesMap> {
|
|
|
36
36
|
* It is slightly different from https://ast-grep.github.io/reference/sgconfig.html#languageglobs
|
|
37
37
|
*/
|
|
38
38
|
languageGlobs?: Array<string>
|
|
39
|
-
}
|
|
39
|
+
}
|
package/types/lang.d.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** The JSON object to register dynamic languages */
|
|
2
|
+
interface LangRegistration {
|
|
3
|
+
/** the path to the dynamic library */
|
|
4
|
+
libraryPath: string
|
|
5
|
+
/** the file extensions of the language. e.g. mojo */
|
|
6
|
+
extensions: string[]
|
|
7
|
+
/** the dylib symbol to load ts-language, default is `tree_sitter_{name}` */
|
|
8
|
+
languageSymbol?: string
|
|
9
|
+
/** the meta variable leading character, default is $ */
|
|
10
|
+
metaVarChar?: string
|
|
11
|
+
/**
|
|
12
|
+
* An optional char to replace $ in your pattern.
|
|
13
|
+
* See https://ast-grep.github.io/advanced/custom-language.html#register-language-in-sgconfig-yml
|
|
14
|
+
*/
|
|
15
|
+
expandoChar?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A map of language names to their registration information */
|
|
19
|
+
export interface DynamicLangRegistrations {
|
|
20
|
+
[langName: string]: LangRegistration
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @experimental
|
|
25
|
+
* Register dynamic languages. This function should be called exactly once in the program.
|
|
26
|
+
*/
|
|
27
|
+
export declare function registerDynamicLanguage(langs: DynamicLangRegistrations): void
|
package/types/sgnode.d.ts
CHANGED
|
@@ -46,11 +46,11 @@ export declare class SgNode<
|
|
|
46
46
|
isNamed(): boolean
|
|
47
47
|
isNamedLeaf(): boolean
|
|
48
48
|
text(): string
|
|
49
|
-
matches(m: string): boolean
|
|
50
|
-
inside(m: string): boolean
|
|
51
|
-
has(m: string): boolean
|
|
52
|
-
precedes(m: string): boolean
|
|
53
|
-
follows(m: string): boolean
|
|
49
|
+
matches(m: string | number | NapiConfig<M>): boolean
|
|
50
|
+
inside(m: string | number | NapiConfig<M>): boolean
|
|
51
|
+
has(m: string | number | NapiConfig<M>): boolean
|
|
52
|
+
precedes(m: string | number | NapiConfig<M>): boolean
|
|
53
|
+
follows(m: string | number | NapiConfig<M>): boolean
|
|
54
54
|
/** Returns the string name of the node kind */
|
|
55
55
|
kind(): T
|
|
56
56
|
readonly kindToRefine: T
|
package/types/staticTypes.d.ts
CHANGED