From 0d5c5518095be9ea6694d78d1ef8ffc77f36c9c1 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Wed, 23 Sep 2026 11:25:58 +0000 Subject: [PATCH] fix(pg-codegen): escape JSDoc terminators in emitted column comments 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. --- postgres/pg-codegen/__tests__/babel.test.ts | 15 +++++++++++++++ postgres/pg-codegen/src/emit/babel.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 postgres/pg-codegen/__tests__/babel.test.ts diff --git a/postgres/pg-codegen/__tests__/babel.test.ts b/postgres/pg-codegen/__tests__/babel.test.ts new file mode 100644 index 0000000000..e5dbedf84c --- /dev/null +++ b/postgres/pg-codegen/__tests__/babel.test.ts @@ -0,0 +1,15 @@ +import * as t from '@babel/types'; + +import { generateCode, withJsDoc } from '../src/emit/babel'; + +it('keeps a comment containing a JSDoc terminator inside its block', () => { + const stmt = withJsDoc( + t.exportNamedDeclaration( + t.variableDeclaration('const', [t.variableDeclarator(t.identifier('x'), t.numericLiteral(1))]) + ), + 'Cron spec: {"rule": "*/5 * * * *"}' + ); + const code = generateCode([stmt]); + expect(code).toContain('/** Cron spec: {"rule": "*\\/5 * * * *"} */'); + expect(code).toContain('export const x = 1;'); +}); diff --git a/postgres/pg-codegen/src/emit/babel.ts b/postgres/pg-codegen/src/emit/babel.ts index 9146a9edd6..ca636e713c 100644 --- a/postgres/pg-codegen/src/emit/babel.ts +++ b/postgres/pg-codegen/src/emit/babel.ts @@ -22,7 +22,7 @@ export const generateCode = (statements: t.Statement[]): string => { /** Attach a JSDoc block as a leading comment. */ export const withJsDoc = (node: T, text: string): T => { - t.addComment(node, 'leading', `* ${text} `, false); + t.addComment(node, 'leading', `* ${text.replace(/\*\//g, '*\\/')} `, false); return node; };