Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions postgres/pg-codegen/__tests__/babel.test.ts
Original file line number Diff line number Diff line change
@@ -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;');
});
2 changes: 1 addition & 1 deletion postgres/pg-codegen/src/emit/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const generateCode = (statements: t.Statement[]): string => {

/** Attach a JSDoc block as a leading comment. */
export const withJsDoc = <T extends t.Statement>(node: T, text: string): T => {
t.addComment(node, 'leading', `* ${text} `, false);
t.addComment(node, 'leading', `* ${text.replace(/\*\//g, '*\\/')} `, false);
return node;
};

Expand Down
Loading