@ast-grep/napi 0.1.4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ast-grep/napi
2
2
 
3
- See https://github.com/HerringtonDarkholme/ast-grep
3
+ See https://github.com/ast-grep/ast-grep
4
4
 
5
5
  ## Support matrix
6
6
 
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
- row: number
8
- col: number
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
- findByString(pattern: string): SgNode | null
26
- findAll(pattern: string): Array<SgNode>
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 type SgRoot = AstGrep
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, AstGrep } = nativeBinding
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.AstGrep = AstGrep
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.4",
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/HerringtonDarkholme/ast-grep",
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.4",
68
- "@ast-grep/napi-darwin-x64": "0.1.4",
69
- "@ast-grep/napi-linux-x64-gnu": "0.1.4",
70
- "@ast-grep/napi-win32-ia32-msvc": "0.1.4",
71
- "@ast-grep/napi-darwin-arm64": "0.1.4",
72
- "@ast-grep/napi-win32-arm64-msvc": "0.1.4"
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
  }