@@ -11,6 +11,8 @@ import {
1111import yaml from "yaml" ;
1212import type { PatchCodeFn } from "./codePatcher" ;
1313
14+ export type * from "@ast-grep/napi" ;
15+
1416/**
1517 * fix has the same meaning as in yaml rules
1618 * see https://ast-grep.github.io/guide/rewrite-code.html#using-fix-in-yaml-rule
@@ -33,7 +35,10 @@ export function applyRule(
3335 rule : string | RuleConfig ,
3436 root : SgNode ,
3537 { once = false } = { } ,
36- ) {
38+ ) : {
39+ edits : Edit [ ] ;
40+ matches : SgNode [ ] ;
41+ } {
3742 const ruleConfig : RuleConfig =
3843 typeof rule === "string" ? yaml . parse ( rule ) : rule ;
3944 if ( ruleConfig . transform ) {
@@ -80,7 +85,7 @@ export function applyRule(
8085 * @param lang The language to parse. Defaults to TypeScript.
8186 * @returns The root for the file.
8287 */
83- export function parseFile ( path : string , lang = Lang . TypeScript ) {
88+ export function parseFile ( path : string , lang = Lang . TypeScript ) : SgNode {
8489 return parse ( lang , readFileSync ( path , { encoding : "utf-8" } ) ) . root ( ) ;
8590}
8691
@@ -106,6 +111,11 @@ export function patchCode(
106111 return node . commitEdits ( edits ) ;
107112}
108113
114+ /**
115+ * @param rule
116+ * @param lang
117+ * @returns a callback applying the the rule.
118+ */
109119export function createPatchCode (
110120 rule : string | RuleConfig ,
111121 lang = Lang . TypeScript ,
0 commit comments