fix(pgpm): fix AST round-trip diff comparison bug and add --outputDiff flag #529
+25
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug in the
pgpm packagecommand where the AST round-trip diff check was always reporting a mismatch due to comparing incompatible types. Also adds a new--outputDiffflag to export the AST diff files for debugging.Bug fix: The original code compared
tree1(an array ofRawStmt[]) totree2(a fullParseResultobject), which would always show a diff even when the ASTs were identical. The fix now correctly comparestree1toreparsed.stmtswith the samefilterStatementsapplied to both.New feature: Added
--outputDiffflag that writesorig.*.tree.jsonandparsed.*.tree.jsonfiles when a diff is detected, making it easier to debug AST mismatches.Review & Testing Checklist for Human
tree2 = filterStatements(reparsed.stmts as any, extension)properly mirrors the filtering applied totree1at line 62pgpm package --outputDiffon a module and verify the JSON files are written correctly when a diff exists--outputDiffwhen a diff is detectedRecommended test plan:
pgpm packageand verify you see the new warning message suggesting--outputDiffpgpm package --outputDiffand verify the JSON files are written to thesql/folderNotes
@pgpmjs/*module declarations - these are unrelated to this changeLink to Devin run: https://app.devin.ai/sessions/369b1b00cb84494d93307674f0b9fb0e
Requested by: Dan Lynch (@pyramation)