Skip to content

Commit afd2f5e

Browse files
committed
Use token type not text when detecting keywords after "."
1 parent f96511f commit afd2f5e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lexer/disambiguateTokens.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { isReserved, Token, TokenType } from './token.js';
22

33
/**
4-
* Ensures that no keyword token (RESERVED_*) is preceded by dot (.).
4+
* Ensures that no keyword token (RESERVED_*) is preceded by dot (.)
5+
* or any other property-access operator.
56
*
67
* Ensures that all RESERVED_FUNCTION_NAME tokens are followed by "(".
78
* If they're not, converts the token to RESERVED_KEYWORD.
@@ -17,17 +18,17 @@ import { isReserved, Token, TokenType } from './token.js';
1718
*/
1819
export function disambiguateTokens(tokens: Token[]): Token[] {
1920
return tokens
20-
.map(dotKeywordToIdent)
21+
.map(propertyNameKeywordToIdent)
2122
.map(funcNameToKeyword)
2223
.map(dataTypeToParameterizedDataType)
2324
.map(identToArrayIdent)
2425
.map(dataTypeToArrayKeyword);
2526
}
2627

27-
const dotKeywordToIdent = (token: Token, i: number, tokens: Token[]): Token => {
28+
const propertyNameKeywordToIdent = (token: Token, i: number, tokens: Token[]): Token => {
2829
if (isReserved(token.type)) {
2930
const prevToken = prevNonCommentToken(tokens, i);
30-
if (prevToken && prevToken.text === '.') {
31+
if (prevToken && prevToken.type === TokenType.PROPERTY_ACCESS_OPERATOR) {
3132
return { ...token, type: TokenType.IDENTIFIER, text: token.raw };
3233
}
3334
}

0 commit comments

Comments
 (0)