Skip to content

fix(codegen): sanitize */ in JSDoc comments to prevent syntax errors#1084

Merged
pyramation merged 1 commit intomainfrom
fix/jsdoc-comment-sanitization
May 9, 2026
Merged

fix(codegen): sanitize */ in JSDoc comments to prevent syntax errors#1084
pyramation merged 1 commit intomainfrom
fix/jsdoc-comment-sanitization

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

Summary

When codegen.comments: true is enabled, addJSDocComment() in both babel-ast.ts and hooks-ast.ts embeds field descriptions directly into /* ... */ block comments without sanitizing. If a description contains a literal */ sequence (common in PostGraphile-generated descriptions like "Reads and enables pagination through a set of ..."), it prematurely closes the JSDoc comment block and produces invalid JavaScript/TypeScript.

This PR applies */*\/ sanitization to both addJSDocComment implementations and adds unit tests to prevent regression.

Changes:

  • babel-ast.ts: sanitize */ in lines before building comment text
  • hooks-ast.ts: same sanitization applied
  • New test file jsdoc-comment.test.ts: 6 tests covering single-line, multi-line, and safe descriptions for both implementations

Closes constructive-io/constructive-planning#820

Review & Testing Checklist for Human

  • Verify generated JSDoc output looks correct when codegen.comments: true is used with a schema containing */ in field descriptions
  • Confirm the *\/ escape renders acceptably in IDE tooltips and documentation generators

Notes

The downstream workaround (comments: false in constructive-db's codegen-helper.ts) can be reverted once this fix is merged.

Link to Devin session: https://app.devin.ai/sessions/2ddfbe8d8fc04675af6e2540decbafe1
Requested by: @pyramation

When codegen.comments is enabled, field descriptions containing literal
*/ sequences would prematurely close the JSDoc comment block, producing
invalid JavaScript/TypeScript output.

Apply the same *\/ sanitization to both babel-ast.ts and hooks-ast.ts
addJSDocComment functions, and add unit tests to prevent regression.

Closes constructive-io/constructive-planning#820
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 6080749 into main May 9, 2026
55 checks passed
@pyramation pyramation deleted the fix/jsdoc-comment-sanitization branch May 9, 2026 17:16
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