Skip to content

fix(pg-codegen): escape JSDoc terminators in emitted column comments - #1858

Merged
pyramation merged 1 commit into
mainfrom
fix/pg-codegen-jsdoc-terminator
Sep 24, 2026
Merged

pyramation merged 1 commit into
mainfrom
fix/pg-codegen-jsdoc-terminator

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

Summary

withJsDoc wrote Postgres column/table comments verbatim into /** … */ blocks. A comment containing */ — found in the wild with a cron example, {"rule": "*/5 * * * *"} on compute_public.function_schedules.schedule_info — terminated the block early and left the remainder as bare tokens, so the generated platform-db-types module failed to parse (SyntaxError: Unexpected token '*', constructive-db #3850 CI).

-t.addComment(node, 'leading', `* ${text} `, false);
+t.addComment(node, 'leading', `* ${text.replace(/\*\//g, '*\\/')} `, false);

Emits *\/, which JSDoc tooling renders as */ and JS parsers ignore. Unit test added in __tests__/babel.test.ts (no DB needed).

constructive-db side-steps the current instance by rewording the comment in #3850; this makes the generator robust for any future comment.

Link to Devin session: https://app.devin.ai/sessions/3c993d055ffb47f6be27862718a9cd42
Open in Devin Desktop: https://app.devin.ai/desktop/session/3c993d055ffb47f6be27862718a9cd42?variant=devin
Requested by: @pyramation

A column comment containing */ (e.g. a cron example "*/5 * * * *") closed
the /** */ block early and left the rest of the comment as bare source,
producing an unparseable module.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@tenki-reviewer

tenki-reviewer Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Escape */ in the property() comment path too · record.ts:83 · file not in diff

// postgres/pg-codegen/src/emit/record.ts
83	  if (comment) t.addComment(prop, 'leading', `* ${comment} `, false);

This PR adds */ → *\/ escaping only in withJsDoc (postgres/pg-codegen/src/emit/babel.ts:25), but the other dynamic comment path, property() at postgres/pg-codegen/src/emit/record.ts:83, still passes raw column.comment text into t.addComment.

A column comment containing */ (e.g. "units */sec") terminates the JSDoc block early, making the generated .ts module syntactically invalid or attaching the remainder as code. The same DB-sourced text is escaped for the module-level comment via withJsDoc but not for per-column comments, so schemas with such comments still produce broken generated modules.


Fixes withJsDoc in pg-codegen to escape */ sequences so comment text cannot prematurely close the emitted block comment, with a focused unit test covering the cron-spec case. Review verified the escaping logic and confirmed no regressions in the touched emit path; one related call site remains unescaped.

Files Change
postgres/pg-codegen/src/emit/babel.ts Escapes */ as *\/ in the withJsDoc leading-comment text before addComment.
postgres/pg-codegen/__tests__/babel.test.ts New test asserting a comment containing */ stays inside its block and the statement still emits.

Reviewed commit: 0d5c551

@pyramation
pyramation merged commit d928379 into main Sep 24, 2026
21 checks passed
@pyramation
pyramation deleted the fix/pg-codegen-jsdoc-terminator branch September 24, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant