Repository navigation
fix(transform): normalize nodes under a "constructor" key in normalizeTree - #367
Open
pyramation wants to merge 1 commit into
Open
pyramation wants to merge 1 commit into
pyramation wants to merge 1 commit into
Conversation
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. No issues found — approved ✅. This PR extends the transform package's round-trip validation coverage to PostgreSQL JSON constructor statements:
Reviewed commit: 9aa53d8 |
Contributor
|
Folded into #371 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
normalizeTree(used bycleanTreeandvalidateRoundTrip) found its handler withkeyHandlers?.[key]. For the AST keyconstructor, used byJsonArrayAgg,JsonObjectAggand other SQL/JSON aggregate nodes, that lookup returned the inheritedObject.prototype.constructor. The code then calledObject(node[key], recurse), which returns the subtree without normalizing it. As a result,locationfields underconstructorwere never stripped, sovalidateRoundTrip/transformSql({ roundTrip: true })reported false mismatches whenever whitespace moved them:Fix: look up only the handler's own key (
Object.prototype.hasOwnProperty.call(keyHandlers, key)).Tests
New transform fixture
__fixtures__/input/json-constructors.sql, with its golden output generated bypnpm fixtures:✕ passes round-trip validation (AST1 === AST2)(the mismatch above)Also present in @pgsql/transform 18.18.0, so this is not a regression in 18.18.1.
Link to Devin session: https://app.devin.ai/sessions/f8a1d342fa3b4580a90de9031ed4bd86
Open in Devin Desktop: https://app.devin.ai/desktop/session/f8a1d342fa3b4580a90de9031ed4bd86?variant=devin
Requested by: @pyramation