refactor: centralize quote-utils to use generated kwlist.ts #240
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Removes the hardcoded
RESERVED_WORDSSet fromquote-utils.tsand replaces it with imports from the generatedkwlist.ts. This eliminates duplication and ensures quote-utils stays in sync with PostgreSQL's keyword definitions.Changes:
quote-utils.ts: Removed 15-line hardcodedRESERVED_WORDSSet, now importsRESERVED_KEYWORDSandTYPE_FUNC_NAME_KEYWORDSfromkwlist.tskwlist.ts: Added explicitSet<string>type annotations to exported Sets (required for TypeScript compatibility when calling.has()with astringargument)scripts/keywords.ts: Updated the generator script to includeSet<string>type annotations, ensuring they persist when kwlist.ts is regenerateddeparser.ts: RemovedDeparser.RESERVED_WORDSandDeparser.needsQuotes(), replaced withQuoteUtils.quoteString()- all quoting logic is now centralized inQuoteUtilsReview & Testing Checklist for Human
RESERVED_WORDScombined both reserved keywords and type/func name keywords. Confirm thatRESERVED_KEYWORDS.has(x) || TYPE_FUNC_NAME_KEYWORDS.has(x)covers the same set of wordsSELECT "user", "table" FROM foo) to verify quoting behavior is unchangedRecommended test plan: Run the deparser on a variety of SQL statements with reserved word identifiers and compare output before/after this change.
Notes
284 of 285 deparser tests pass. There is one pre-existing test failure (
latest-postgres-create_view.test.ts) related tosystem_userfunction formatting (COERCE_SQL_SYNTAXvsCOERCE_EXPLICIT_CALL) that is unrelated to this change. The pre-existing eslint config issues and proto-parser test failures are also unrelated.Link to Devin run: https://app.devin.ai/sessions/de94b880ef5243deb4a8e76adb6875d6
Requested by: Dan Lynch (@pyramation)