Skip to content

Commit e9a46cf

Browse files
refactor: centralize quote-utils to use generated kwlist.ts
- Remove hardcoded RESERVED_WORDS from quote-utils.ts - Import RESERVED_KEYWORDS and TYPE_FUNC_NAME_KEYWORDS from kwlist.ts - Add explicit Set<string> type annotations to kwlist.ts exports for proper TypeScript compatibility - QuoteUtils.needsQuotes() now uses the centralized keyword sets Co-Authored-By: Dan Lynch <[email protected]>
1 parent 5b34b15 commit e9a46cf

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

packages/deparser/src/kwlist.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ export const kwlist = {
522522
]
523523
} as const;
524524

525-
export const RESERVED_KEYWORDS = new Set(kwlist.RESERVED_KEYWORD ?? []);
526-
export const UNRESERVED_KEYWORDS = new Set(kwlist.UNRESERVED_KEYWORD ?? []);
527-
export const COL_NAME_KEYWORDS = new Set(kwlist.COL_NAME_KEYWORD ?? []);
528-
export const TYPE_FUNC_NAME_KEYWORDS = new Set(kwlist.TYPE_FUNC_NAME_KEYWORD ?? []);
525+
export const RESERVED_KEYWORDS: Set<string> = new Set(kwlist.RESERVED_KEYWORD ?? []);
526+
export const UNRESERVED_KEYWORDS: Set<string> = new Set(kwlist.UNRESERVED_KEYWORD ?? []);
527+
export const COL_NAME_KEYWORDS: Set<string> = new Set(kwlist.COL_NAME_KEYWORD ?? []);
528+
export const TYPE_FUNC_NAME_KEYWORDS: Set<string> = new Set(kwlist.TYPE_FUNC_NAME_KEYWORD ?? []);
529529

530530
export function keywordKindOf(word: string): KeywordKind {
531531
const w = word.toLowerCase();

packages/deparser/src/utils/quote-utils.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
const RESERVED_WORDS = new Set([
2-
'all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric',
3-
'authorization', 'binary', 'both', 'case', 'cast', 'check', 'collate', 'collation',
4-
'column', 'concurrently', 'constraint', 'create', 'cross', 'current_catalog',
5-
'current_date', 'current_role', 'current_schema', 'current_time', 'current_timestamp',
6-
'current_user', 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end',
7-
'except', 'false', 'fetch', 'for', 'foreign', 'freeze', 'from', 'full', 'grant',
8-
'group', 'having', 'ilike', 'in', 'initially', 'inner', 'intersect', 'into', 'is',
9-
'isnull', 'join', 'lateral', 'leading', 'left', 'like', 'limit', 'localtime',
10-
'localtimestamp', 'natural', 'not', 'notnull', 'null', 'offset', 'on', 'only',
11-
'or', 'order', 'outer', 'overlaps', 'placing', 'primary', 'references', 'returning',
12-
'right', 'select', 'session_user', 'similar', 'some', 'symmetric', 'table', 'tablesample',
13-
'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic',
14-
'verbose', 'when', 'where', 'window', 'with'
15-
]);
1+
import { RESERVED_KEYWORDS, TYPE_FUNC_NAME_KEYWORDS } from '../kwlist';
162

173
export class QuoteUtils {
184
static needsQuotes(value: string): boolean {
@@ -22,7 +8,7 @@ export class QuoteUtils {
228

239
const lowerValue = value.toLowerCase();
2410

25-
if (RESERVED_WORDS.has(lowerValue)) {
11+
if (RESERVED_KEYWORDS.has(lowerValue) || TYPE_FUNC_NAME_KEYWORDS.has(lowerValue)) {
2612
return true;
2713
}
2814

@@ -93,4 +79,4 @@ export class QuoteUtils {
9379
return !/^\\x[0-9a-fA-F]+$/i.test(value) && value.includes('\\');
9480
}
9581

96-
}
82+
}

0 commit comments

Comments
 (0)