@@ -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