Skip to content

fix(scanner): insert semicolon before identifiers starting with in - #389

Closed
matthew-se wants to merge 1 commit into
tree-sitter:masterfrom
matthew-se:asi-before-in-prefixed-identifiers
Closed

matthew-se wants to merge 1 commit into
tree-sitter:masterfrom
matthew-se:asi-before-in-prefixed-identifiers

Conversation

@matthew-se

Copy link
Copy Markdown

A line that starts with an identifier beginning with in followed by a digit, _ or $ (or instanceof followed by one of those) is misread as a continuation of the previous line, so no automatic semicolon is inserted:

a
in_b

On master this parses with an ERROR node. The same happens for in1, in$ and instanceof_.

scan_automatic_semicolon only treats in…/instanceof… as an identifier when the next character satisfies iswalpha. This PR widens both checks to identifier characters (iswalnum, _, $). The four cases are added to the existing "Alphabetical infix operators split across lines" test, which still checks that real in / instanceof operators split across lines suppress the semicolon.

Tests

  • tree-sitter test (0.25.8): 123/123 pass. The extended test fails on master.
  • tree-sitter parse --rebuild over examples/ plus the npm/cli clone from CI (1,554 .js/.jsx files) gives the same single failing file before and after.
  • eslint grammar.js passes.

tree-sitter-typescript has its own copy of this scanner code. The same fix is in tree-sitter/tree-sitter-typescript#372.

🤖 Generated with Claude Code

The automatic semicolon check treats a line starting with `in` or
`instanceof` as a binary operator unless the next character is a letter.
Digits, `_` and `$` also continue an identifier, so a line starting with
`in_b`, `in1`, `in$` or `instanceof_` suppressed the semicolon and the
statement failed to parse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant