Skip to content

fix(asi): add semicolon before class members named in or instanceof - #80

Merged
acutmore merged 1 commit into
bloomberg:mainfrom
bardrop-oss:fix-asi-in-instanceof-member-names
Nov 18, 2026
Merged

acutmore merged 1 commit into
bloomberg:mainfrom
bardrop-oss:fix-asi-in-instanceof-member-names

Conversation

@bardrop

@bardrop bardrop commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #79

A class member named in or instanceof with a removed modifier in front of it could continue the previous field's initializer when that field has no ;:

class C {
    f = a
    private in = 1   // -> `f = a in = 1`, SyntaxError
}

With private in followed by a field b, the output was valid JS but read as one field f = (a in b).

The fix treats these two names like computed names and generator methods: the first removed modifier is replaced by a ;. This is done in both visitPropertyDeclaration and visitFunctionLikeDeclaration (methods named in() / instanceof() have the same problem).

Testing:

  • New cases in tests/fixture/cases/asi.ts (field with initializer, field with type annotation, two methods). npm test fails on main (expected: ' ; in = 1') and passes with the fix (43/43).
  • npm run check and npm run format:check pass.
  • Checked that inputs which are not hazards are unchanged, e.g. public 'in' = 1 (string name) gets no ;.

When a removed modifier (private, public, protected, readonly, override)
is in front of a member named `in` or `instanceof`, and the previous
field has an initializer without a semicolon, the member name was read
as a binary operator that continues that initializer:

    f = a
    private in = 1    ->  f = a in = 1  (SyntaxError)

    f = a
    private in
    b                 ->  f = a in b    (valid JS, wrong fields)

Treat these names like computed names and generator methods and start
the blanked modifier with a semicolon.

Signed-off-by: Mradul Singh <msingh@dealmeridian.com>
@acutmore

Copy link
Copy Markdown
Collaborator

thanks @bardrop!

@acutmore
acutmore merged commit cb639a8 into bloomberg:main Nov 18, 2026
4 checks passed
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.

ASI hazard: class member named in or instanceof after a removed modifier continues the previous field

2 participants