fix(formatter): stop line comments swallowing following tokens

This commit is contained in:
zipg authored and GitHub committed 2026-09-26 01:33:32 +08:00
1 parent c224b3c972
commit 08773d93f7
5 files changed
+119 -7

No files matched your search

+10
View File
@@ -75,6 +75,16 @@ describe("sqlFormatter", () => {
expect(formatted).toContain('"ACTIVE_USERS"');
});
it("keeps a view's trailing line comment from swallowing the next column (issue #10278)", async () => {
// A `--` comment consumes the rest of its line, so the column that follows
// it in the view text has to start a new line; appending it to the comment
// would silently drop it from the DDL shown to the user.
const viewDdl = `CREATE VIEW "TEMP_TEST_VIEW" AS SELECT trunc(sysdate) AS dates, -- 测试\n(SELECT sysdate FROM dual t) AS nows\nFROM dual;`;
const formatted = await formatSqlForDisplay(viewDdl, sqlFormatDialectForDbType("oracle"));
expect(formatted).toBe('CREATE VIEW "TEMP_TEST_VIEW" AS\nSELECT trunc(sysdate) AS dates,\n -- 测试\n (SELECT sysdate FROM dual t) AS nows\nFROM dual;');
});
it("collapses a short OceanBase Oracle view DDL onto one line (issue #7540)", async () => {
// The default style joins a statement that fits the line width onto one
// line, so a short view body comes back with its keywords cased rather