From 2c541207201520462280d806a8410f45ef7a3b43 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Sat, 21 Dec 2024 11:46:14 +0200 Subject: [PATCH] Never detect words in foo.bar constructs as keywords Refs #812 --- src/lexer/disambiguateTokens.ts | 4 ++++ test/options/keywordCase.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/lexer/disambiguateTokens.ts b/src/lexer/disambiguateTokens.ts index 41af6c7135..939fb3ffc5 100644 --- a/src/lexer/disambiguateTokens.ts +++ b/src/lexer/disambiguateTokens.ts @@ -31,6 +31,10 @@ const propertyNameKeywordToIdent = (token: Token, i: number, tokens: Token[]): T if (prevToken && prevToken.type === TokenType.PROPERTY_ACCESS_OPERATOR) { return { ...token, type: TokenType.IDENTIFIER, text: token.raw }; } + const nextToken = nextNonCommentToken(tokens, i); + if (nextToken && nextToken.type === TokenType.PROPERTY_ACCESS_OPERATOR) { + return { ...token, type: TokenType.IDENTIFIER, text: token.raw }; + } } return token; }; diff --git a/test/options/keywordCase.ts b/test/options/keywordCase.ts index 15bc72e619..37e6f6a4cc 100644 --- a/test/options/keywordCase.ts +++ b/test/options/keywordCase.ts @@ -62,6 +62,18 @@ export default function supportsKeywordCase(format: FormatFn) { `); }); + it('treats dot-seperated keywords as plain identifiers', () => { + const result = format('select table.and from set.select', { + keywordCase: 'upper', + }); + expect(result).toBe(dedent` + SELECT + table.and + FROM + set.select + `); + }); + // regression test for #356 it('formats multi-word reserved clauses into single line', () => { const result = format(