Skip to content

Commit 4ec73ab

Browse files
committed
types
1 parent 44f9b79 commit 4ec73ab

File tree

5 files changed

+912
-866
lines changed

5 files changed

+912
-866
lines changed

packages/transform/RULES.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,49 @@ This ensures faster feedback loops and prevents dependency on external CI system
235235
## Summary
236236

237237
Always use `@pgsql/parser` for multi-version PostgreSQL AST parsing in the transform package. This is the only way to get accurate version-specific results and build working transformers. Remember that all parser methods are async and must be awaited.
238+
239+
240+
# Transformer Rules
241+
242+
## Core Principles
243+
244+
### 1. Explicit Field Handling (REQUIRED)
245+
**Always explicitly handle each field** rather than using spread operators to copy everything.
246+
247+
#### ✅ GOOD - Explicit field handling
248+
```ts
249+
RoleSpec(node: PG15.RoleSpec, context: TransformerContext): { RoleSpec: PG16.RoleSpec } {
250+
const result: any = {};
251+
252+
if (node.roletype !== undefined) {
253+
result.roletype = node.roletype;
254+
}
255+
256+
if (node.rolename !== undefined) {
257+
result.rolename = node.rolename;
258+
}
259+
260+
if (node.location !== undefined) {
261+
result.location = node.location;
262+
}
263+
264+
return { RoleSpec: result };
265+
}
266+
```
267+
268+
#### ❌ BAD - Blind copying (only acceptable as initial placeholder)
269+
```ts
270+
RoleSpec(node: PG15.RoleSpec, context: TransformerContext): { RoleSpec: PG16.RoleSpec } {
271+
const result: any = { ...node };
272+
return { RoleSpec: result };
273+
}
274+
```
275+
276+
277+
#### No-Change Transformers
278+
For nodes that don't change between versions like this, we should probably just delete them as they should not be visited:
279+
```ts
280+
BooleanTest(node: PG16.BooleanTest, context: TransformerContext): any {
281+
return { BooleanTest: node };
282+
}
283+
```

0 commit comments

Comments
 (0)