Skip to content

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

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

@matthew-se matthew-se commented Sep 28, 2026 •

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:

interface A {
  a: string
  in_b: number
}

On master this parses as (MISSING "}") followed by a labeled_statement. The same happens for expression statements starting with in_b, in1, in$ or 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, _, $). Real in / instanceof operators across a newline still suppress the semicolon; the new corpus test covers both.

Tests

  • tree-sitter test (0.24.4): 114/114 pass, including the two new cases. Both fail on master.
  • tree-sitter parse --rebuild of the CI example repos (desktop, redux, vscode; 15,190 .ts/.tsx files, same excludes as CI) gives the same 51 failing files before and after.
  • The repro above parses cleanly with both the typescript and tsx grammars.

tree-sitter-javascript's src/scanner.c has the same check. The same fix is in tree-sitter/tree-sitter-javascript#389.

🤖 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 or type member 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