Fix: allow reserved words as property identifiers after optional chaining#378
Open
rbonestell wants to merge 2 commits intotree-sitter:masterfrom
Open
Fix: allow reserved words as property identifiers after optional chaining#378rbonestell wants to merge 2 commits intotree-sitter:masterfrom
rbonestell wants to merge 2 commits intotree-sitter:masterfrom
Conversation
…ning Reserved words like 'delete', 'class', 'return' were producing ERROR nodes when used as property identifiers after '?.' (optional chaining), while working correctly after '.'. This adds a '_keyword_identifier' rule that explicitly lists all reserved words as valid alternatives in the member_expression property field, working around a tree-sitter core issue where the 'reserved()' context wasn't propagated through the '?.' token path. Also extracts RESERVED_WORDS and CONTEXTUAL_KEYWORDS as shared constants to eliminate keyword list duplication across reserved.global, _reserved_identifier, and _keyword_identifier. Fixes tree-sitter#377
Add tree-sitter to devDependencies (required by bindings/node/binding_test.js) and pin node-version to 22 (tree-sitter@0.25.0 cannot compile with Node 24).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fixes #377.
Reserved words (
delete,class,return, etc.) are correctly treated asproperty_identifiernodes after.but produceERRORnodes after?.(optional chaining). This is because thereserved('properties', ...)context is not propagated through the?.token path — likely a tree-sitter core issue.This PR works around it by explicitly listing all reserved words as valid alternatives in the
member_expressionproperty field via a new_keyword_identifierrule.Before:
After:
Changes
RESERVED_WORDSandCONTEXTUAL_KEYWORDSas shared constants to eliminate duplication acrossreserved.global,_reserved_identifier, and the new_keyword_identifierrule. Add_keyword_identifier(inlined) to themember_expressionproperty field alongside$.identifierinside the existingreserved('properties', ...)wrapper.tree-sittertodevDependencies(required bybindings/node/binding_test.js).node-version: 22for Node binding tests (tree-sitter@0.25.0cannot compile with Node 24).tree-sitter generate.Notes
LARGE_STATE_COUNTunchanged.reserved('properties', ...)wrapper is retained for the.path and forward compatibility — when tree-sitter core fixes the propagation issue, the explicit alternatives become redundant but harmless.