Skip to content

Commit 862f7d3

Browse files
committed
Fix parsing of /** **/ nested block comments
Fixes #747
1 parent 7aee250 commit 862f7d3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/lexer/NestedComment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { RegExpLike } from './TokenizerEngine.js';
33

44
const START = /\/\*/uy; // matches: /*
5-
const MIDDLE = /([^/*]|\*[^/]|\/[^*])+/uy; // matches text NOT containing /* or */
5+
const ANY_CHAR = /[\s\S]/uy; // matches single character
66
const END = /\*\//uy; // matches: */
77

88
/**
@@ -31,7 +31,7 @@ export class NestedComment implements RegExpLike {
3131
} else if ((match = this.matchSection(END, input))) {
3232
result += match;
3333
nestLevel--;
34-
} else if ((match = this.matchSection(MIDDLE, input))) {
34+
} else if ((match = this.matchSection(ANY_CHAR, input))) {
3535
result += match;
3636
} else {
3737
return null;

test/features/comments.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ export default function supportsComments(format: FormatFn, opts: CommentsConfig
239239
`);
240240
});
241241

242+
// Regression test for #747
243+
it('handles block comments with /** and **/ patterns', () => {
244+
const sql = `/** This is a block comment **/`;
245+
expect(format(sql)).toBe(sql);
246+
});
247+
242248
if (opts.hashComments) {
243249
it('supports # line comment', () => {
244250
const result = format('SELECT alpha # commment\nFROM beta');

0 commit comments

Comments
 (0)