@ast-grep/napi 0.27.3 → 0.28.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.
Files changed (3) hide show
  1. package/index.d.ts +8 -4
  2. package/manual.d.ts +78 -0
  3. package/package.json +11 -10
package/index.d.ts CHANGED
@@ -9,12 +9,15 @@
9
9
  */
10
10
  export interface NapiConfig {
11
11
  /** The rule object, see https://ast-grep.github.io/reference/rule.html */
12
- rule: any
12
+ rule: import('./manual').Rule
13
13
  /** See https://ast-grep.github.io/guide/rule-config.html#constraints */
14
- constraints?: any
14
+ constraints?: Record<string, import('./manual').Rule>
15
15
  /** Available languages: html, css, js, jsx, ts, tsx */
16
16
  language?: Lang
17
- /** https://ast-grep.github.io/reference/yaml.html#transform */
17
+ /**
18
+ * transform is NOT useful in JavaScript. You can use JS code to directly transform the result.
19
+ * https://ast-grep.github.io/reference/yaml.html#transform
20
+ */
18
21
  transform?: any
19
22
  /** https://ast-grep.github.io/guide/rule-config/utility-rule.html */
20
23
  utils?: any
@@ -60,7 +63,8 @@ export const enum Lang {
60
63
  Rust = 'Rust',
61
64
  Scala = 'Scala',
62
65
  Sql = 'Sql',
63
- Swift = 'Swift'
66
+ Swift = 'Swift',
67
+ Yaml = 'Yaml'
64
68
  }
65
69
  export interface Edit {
66
70
  /** The start position of the edit */
package/manual.d.ts ADDED
@@ -0,0 +1,78 @@
1
+ export type Strictness =
2
+ | 'cst' | 'smart' | 'ast' | 'relaxed' | 'signature'
3
+
4
+ export interface PatternObject {
5
+ context: string
6
+ selector?: string
7
+ strictness?: Strictness
8
+ }
9
+
10
+ export type PatternStyle = string | PatternObject
11
+
12
+ export interface Relation extends Rule {
13
+ /**
14
+ * Specify how relational rule will stop relative to the target node.
15
+ */
16
+ stopBy?: 'neighbor' | 'end' | Rule
17
+ /** Specify the tree-sitter field in parent node. Only available in has/inside rule. */
18
+ field?: string
19
+ }
20
+
21
+ export interface NthChildObject {
22
+ /** The position in nodes' sibling list. It can be a number of An+B string */
23
+ position: string | number
24
+ ofRule?: Rule
25
+ reverse?: boolean
26
+ }
27
+
28
+ /**
29
+ * NthChild can have these types:
30
+ * * number: the position of the node in the sibling list.
31
+ * * string: An + B style string like CSS nth-child selector.
32
+ * * object: An object with `position` and `ofRule` fields.
33
+ */
34
+ export type NthChild = number | string | NthChildObject
35
+
36
+ export interface Rule {
37
+ /** A pattern string or a pattern object. */
38
+ pattern?: PatternStyle
39
+ /** The kind name of the node to match. You can look up code's kind names in playground. */
40
+ kind?: string
41
+ /** A Rust regular expression to match the node's text. https://docs.rs/regex/latest/regex/#syntax */
42
+ regex?: string
43
+ /**
44
+ * `nthChild` accepts number, string or object.
45
+ * It specifies the position in nodes' sibling list. */
46
+ nthChild?: NthChild
47
+
48
+ // relational
49
+ /**
50
+ * `inside` accepts a relational rule object.
51
+ * the target node must appear inside of another node matching the `inside` sub-rule. */
52
+ inside?: Relation
53
+ /**
54
+ * `has` accepts a relational rule object.
55
+ * the target node must has a descendant node matching the `has` sub-rule. */
56
+ has?: Relation
57
+ /**
58
+ * `precedes` accepts a relational rule object.
59
+ * the target node must appear before another node matching the `precedes` sub-rule. */
60
+ precedes?: Relation
61
+ /**
62
+ * `follows` accepts a relational rule object.
63
+ * the target node must appear after another node matching the `follows` sub-rule. */
64
+ follows?: Relation
65
+ // composite
66
+ /**
67
+ * A list of sub rules and matches a node if all of sub rules match.
68
+ * The meta variables of the matched node contain all variables from the sub-rules. */
69
+ all?: Array<Rule>
70
+ /**
71
+ * A list of sub rules and matches a node if any of sub rules match.
72
+ * The meta variables of the matched node only contain those of the matched sub-rule. */
73
+ any?: Array<Rule>
74
+ /** A single sub-rule and matches a node if the sub rule does not match. */
75
+ not?: Rule
76
+ /** A utility rule id and matches a node if the utility rule matches. */
77
+ matches?: string
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ast-grep/napi",
3
- "version": "0.27.3",
3
+ "version": "0.28.0",
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",
@@ -14,6 +14,7 @@
14
14
  "rewrite"
15
15
  ],
16
16
  "files": [
17
+ "manual.d.ts",
17
18
  "index.d.ts",
18
19
  "index.js"
19
20
  ],
@@ -67,14 +68,14 @@
67
68
  }
68
69
  },
69
70
  "optionalDependencies": {
70
- "@ast-grep/napi-win32-x64-msvc": "0.27.3",
71
- "@ast-grep/napi-darwin-x64": "0.27.3",
72
- "@ast-grep/napi-linux-x64-gnu": "0.27.3",
73
- "@ast-grep/napi-win32-ia32-msvc": "0.27.3",
74
- "@ast-grep/napi-darwin-arm64": "0.27.3",
75
- "@ast-grep/napi-win32-arm64-msvc": "0.27.3",
76
- "@ast-grep/napi-linux-arm64-gnu": "0.27.3",
77
- "@ast-grep/napi-linux-arm64-musl": "0.27.3",
78
- "@ast-grep/napi-linux-x64-musl": "0.27.3"
71
+ "@ast-grep/napi-win32-x64-msvc": "0.28.0",
72
+ "@ast-grep/napi-darwin-x64": "0.28.0",
73
+ "@ast-grep/napi-linux-x64-gnu": "0.28.0",
74
+ "@ast-grep/napi-win32-ia32-msvc": "0.28.0",
75
+ "@ast-grep/napi-darwin-arm64": "0.28.0",
76
+ "@ast-grep/napi-win32-arm64-msvc": "0.28.0",
77
+ "@ast-grep/napi-linux-arm64-gnu": "0.28.0",
78
+ "@ast-grep/napi-linux-arm64-musl": "0.28.0",
79
+ "@ast-grep/napi-linux-x64-musl": "0.28.0"
79
80
  }
80
81
  }