Skip to content

Commit 0946936

Browse files
committed
JSON
1 parent 63d37f0 commit 0946936

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

packages/deparser/scripts/make-fixtures.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as path from 'path';
33
import * as fs from 'fs';
44
import { sync as globSync } from 'glob';
5+
import { parse } from 'libpg-query';
56
import { splitStatements, generateStatementKey } from '../src/utils/statement-splitter';
67

78
const FIXTURE_DIR = path.join(__dirname, '../../../__fixtures__/kitchen-sink');
@@ -30,7 +31,16 @@ async function main() {
3031

3132
for (const stmt of statements) {
3233
const key = generateStatementKey(relPath, stmt.index);
33-
results[key] = stmt.statement;
34+
35+
// Validate that the extracted statement parses correctly on its own
36+
try {
37+
await parse(stmt.statement);
38+
results[key] = stmt.statement;
39+
} catch (parseErr: any) {
40+
console.error(`Failed to parse extracted statement ${key}:`, parseErr.message);
41+
console.error(`Statement: ${stmt.statement.substring(0, 200)}${stmt.statement.length > 200 ? '...' : ''}`);
42+
// Skip this statement - don't add it to results
43+
}
3444
}
3545
} catch (err: any) {
3646
console.error(`Failed to parse ${relPath}:`, err);

packages/deparser/scripts/make-upstream-diff.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,31 @@ async function main() {
6262
// Get our deparse and its AST
6363
let ourDeparsedSql: string | undefined;
6464
let ourAst: any;
65+
let ourDeParseError = false;
6566
try {
6667
ourDeparsedSql = ourDeparse(rawStmt.stmt);
6768
const ourParsed = await parse(ourDeparsedSql);
6869
ourAst = cleanTree(ourParsed.stmts?.[0]?.stmt);
6970
} catch (err: any) {
7071
console.error(`Failed to process our deparse for statement ${stmt.index + 1} in ${relPath}:`, err);
71-
// Continue with just upstream comparison
72+
ourDeParseError = true;
73+
// Keep ourDeparsedSql so we can still show it in results even if it doesn't parse
7274
}
7375

7476
// Compare ASTs to source of truth only
7577
const upstreamMatches = JSON.stringify(upstreamAst) === JSON.stringify(sourceOfTruthAst);
7678
const ourMatches = ourAst ? JSON.stringify(ourAst) === JSON.stringify(sourceOfTruthAst) : false;
7779

78-
// Only include if either deparser differs from original
79-
if (!upstreamMatches || !ourMatches) {
80+
81+
// Only include if either deparser differs from original OR our deparser failed to parse
82+
if (!upstreamMatches || !ourMatches || ourDeParseError) {
8083
const key = generateStatementKey(relPath, stmt.index);
8184
results[key] = {
8285
original: stmt.statement,
8386
// Show upstream only if it differs from original
8487
...(!upstreamMatches && upstreamSql && { upstream: upstreamSql }),
85-
// Show our deparser only if it differs from original
86-
...(!ourMatches && ourDeparsedSql && { deparsed: ourDeparsedSql })
88+
// Show our deparser if it differs from original OR if it failed to parse (both indicate issues)
89+
...((!ourMatches || ourDeParseError) && ourDeparsedSql && { deparsed: ourDeparsedSql })
8790
};
8891
}
8992
}

0 commit comments

Comments
 (0)