Skip to content

Commit 30027a7

Browse files
committed
Preserve ------- comments
Fixes #67
1 parent ad48054 commit 30027a7

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/printComment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { Whitespace } from "sql-parser-cst";
44
export const printComment = (path: AstPath<Whitespace>): string => {
55
const node = path.node;
66
if (node.type === "line_comment") {
7-
if (/^--[^ \t]/.test(node.text)) {
7+
if (/^--[^ \t-]/.test(node.text)) {
88
return node.text.replace(/^--/, "-- ");
99
}
10-
if (/^#[^ \t!]/.test(node.text)) {
10+
if (/^#[^ \t!#]/.test(node.text)) {
1111
return node.text.replace(/^#/, "# ");
1212
}
1313
}

test/comments.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,29 @@ describe("comments", () => {
170170
`);
171171
});
172172

173+
// Issue #67
174+
it(`preserves ------ comments as-is`, async () => {
175+
rawTest(dedent`
176+
SELECT 1;
177+
---------------------
178+
-- Start main block
179+
---------------------
180+
SELECT 1;
181+
182+
`);
183+
});
184+
185+
it(`preserves ######### comments as-is`, async () => {
186+
rawTest(dedent`
187+
SELECT 1;
188+
#####################
189+
# Start main block
190+
#####################
191+
SELECT 1;
192+
193+
`);
194+
});
195+
173196
// Issue #9
174197
it.skip(`keeps separate-line line-comments on a separate line (not moving them to line end)`, async () => {
175198
rawTest(dedent`

0 commit comments

Comments
 (0)