Skip to content

Commit e0e6a4a

Browse files
committed
docs: add tsdoc
1 parent 749f17b commit e0e6a4a

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

packages/tree-shaking-plugin/src/lib/transform/mutate.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ const traverse =
1515
traverseModule
1616
);
1717

18+
/**
19+
* Apply a previously created transform plan by rewriting call sites, inserting
20+
* imports, emitting optimized clients, and removing declarations that became
21+
* dead after the rewrite.
22+
*
23+
* @example
24+
* ```ts
25+
* const plan = await createTransformPlan(source, id, options);
26+
*
27+
* applyTransformPlan(plan, plan.runtimeLocalNames);
28+
*
29+
* // `plan.ast` is now mutated in place and ready for code generation.
30+
* ```
31+
*/
1832
export function applyTransformPlan(
1933
plan: TransformPlan,
2034
runtimeLocalNames: RuntimeLocalNames

packages/tree-shaking-plugin/src/lib/transform/plan.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,47 @@ type ExportedDeclarationResolution = {
7979
importBindings: Map<string, { imported: string; resolvedId: string | null }>;
8080
};
8181

82+
/**
83+
* Parse the source, resolve the configured clients, and collect everything the
84+
* mutation phase needs without changing the AST.
85+
*
86+
* The returned plan separates the discovered work into concrete buckets:
87+
* - `clients`: bindings for discovered client variables
88+
* - `namedUsages`: matched client method calls that already have a local client
89+
* - `inlineUsages`: inline `createAPIClient(...)` call sites that need rewrite
90+
*
91+
* The plan also carries the bookkeeping needed by the mutator to insert
92+
* imports, generate optimized clients, and clean up dead declarations.
93+
*
94+
* @example
95+
* ```ts
96+
* const plan = await createTransformPlan(source, id, options);
97+
*
98+
* plan.clients[0]
99+
* // {
100+
* // name: 'api',
101+
* // mode: { type: 'context' },
102+
* // ...
103+
* // }
104+
*
105+
* plan.namedUsages[0]
106+
* // {
107+
* // client: { name: 'api' },
108+
* // serviceName: 'pets',
109+
* // operationName: 'getPets',
110+
* // callbackName: 'useQuery',
111+
* // ...
112+
* // }
113+
*
114+
* plan.inlineUsages[0]
115+
* // {
116+
* // callbackName: 'invalidateQueries',
117+
* // callbackLocalName: 'invalidateQueries',
118+
* // operationImport: { importPath: './api/services/PetsService' },
119+
* // ...
120+
* // }
121+
* ```
122+
*/
82123
export async function createTransformPlan(
83124
code: string,
84125
id: string,

0 commit comments

Comments
 (0)