Skip to content

Commit edffcbb

Browse files
committed
Treat ASC,DESC as reserved words in "sql" dialect
Fixes #702
1 parent e382659 commit edffcbb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/languages/sql/sql.keywords.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const keywords: string[] = [
66
'ANY', // <- moved over from functions
77
'ARE',
88
'AS',
9+
'ASC', // Not reserved in SQL-2008, but commonly reserved in most dialects
910
'ASENSITIVE',
1011
'ASYMMETRIC',
1112
'AT',
@@ -48,6 +49,7 @@ export const keywords: string[] = [
4849
'DEFAULT',
4950
'DELETE',
5051
'DEREF',
52+
'DESC', // Not reserved in SQL-2008, but commonly reserved in most dialects
5153
'DESCRIBE',
5254
'DETERMINISTIC',
5355
'DISCONNECT',

test/sql.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ describe('SqlFormatter', () => {
7272
).toThrowError('Parse error: Unexpected "{foo};" at line 2 column 3');
7373
});
7474

75+
// Issue #702
76+
it('treats ASC and DESC as reserved keywords', () => {
77+
expect(format(`SELECT foo FROM bar ORDER BY foo asc, zap desc`, { keywordCase: 'upper' }))
78+
.toBe(dedent`
79+
SELECT
80+
foo
81+
FROM
82+
bar
83+
ORDER BY
84+
foo ASC,
85+
zap DESC
86+
`);
87+
});
88+
7589
it('formats ALTER TABLE ... ALTER COLUMN', () => {
7690
expect(
7791
format(

0 commit comments

Comments
 (0)