fix(plpgsql): bump @libpg-query/parser to 17.8.0 + OUT-param RETURN NEXT, EXCEPTION wrapper block, and comment-reinjection fixes#307
Merged
Conversation
…e function's OUT parameters libpg-query now emits retvarno and out_param_varno in the PL/pgSQL JSON. With OUT parameters, RETURN NEXT must stay bare (PostgreSQL rejects an expression there), so suppress the variable when retvarno equals out_param_varno; likewise treat the compiler's implicit final RETURN (retvarno == out_param_varno) as implicit.
…ound top-level EXCEPTION blocks
…h newlines, skip DECLARE sections during statement matching
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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
Bumps
@libpg-query/parserto^17.8.0(built fromconstructive-io/libpg_query@17-constructive, which now serializesretvarnoandout_param_varno) and fixes the deparser bugs that surface once those fields — and a single unified WASM instance — actually flow through the stack.1. plpgsql-deparser: keep
RETURN NEXTbare when retvarno targets the OUT parametersWith
retvarnonow emitted by the parser,RETURN NEXT;in an OUT-param function would deparse asRETURN NEXT x— invalid SQL (with OUT params it must stay bare). The deparser now threadsfunc.out_param_varnothrough the context:Same rule applied to implicit-final-
RETURNstripping. Fixtures 57–58.2. plpgsql-deparser: unwrap the compiler-generated EXCEPTION wrapper block
When a function's top-level block has an
EXCEPTIONclause, the PL/pgSQL compiler wraps it in a synthetic outer block (nolineno) whose body is just the user's block + implicit return. Deparsing that verbatim emitted a redundantBEGIN BEGIN … END; END.deparseFunctionnow unwraps viaunwrapCompilerWrapperBlock: only when the outer block has nolineno, nolabel, noexceptions, and exactly onePLpgSQL_stmt_blockchild — so explicit user-written nested blocks (which carry alineno) are preserved. Fixtures 59–60 cover both cases.3. plpgsql-parse: comment-reinjection fixes
The comment-preserving deparse path in
plpgsql-parsehad never actually executed: the workspace previously resolved two@libpg-query/parserinstances (^17.6.10in plpgsql-parse vs^17.6.3in plpgsql-deparser), so hydration always threw "WASM not initialized" into the silent fallback (Deparser.deparseof the raw statement, which prints the original body verbatim). The old snapshots captured that fallback. With one unified version the path runs for real, exposing two bugs now fixed:stitchBodyIntoAstpads the rebuilt body with newlines so output isAS $$\n<body>\n$$instead ofAS $$DECLARE…reinjectBodyCommentsnow skips DECLARE sections, so a declaration likev_x int;no longer consumes the keyword match for a laterv_x := …assignment (which misplaced comments on the first pass and dropped them on the second — the idempotency failure)Snapshots regenerated to the real enhanced output; all fixture round-trips are idempotent.
Test results
deparser 713, transform 1126, plpgsql-deparser 106, plpgsql-parser 285, plpgsql-parse 57, parse 68, parser 9, quotes 57, traverse 12, utils 4, proto-parser 42 — all passing against the published
@libpg-query/parser@17.8.0.Note:
pnpm-lock.yamlhas large formatting churn from lockfile regeneration (quote style); the substantive change is only the parser version.Link to Devin session: https://app.devin.ai/sessions/eeb8deba0c04475091df703c88877302
Requested by: @pyramation