Skip to content

fix(asi): add semicolon when erasing a class index signature - #84

Open
Lotion-3 wants to merge 1 commit into
bloomberg:mainfrom
Lotion-3:index-signature-asi
Open

Lotion-3 wants to merge 1 commit into
bloomberg:mainfrom
Lotion-3:index-signature-asi

Conversation

@Lotion-3

@Lotion-3 Lotion-3 commented Nov 23, 2026 •

Copy link
Copy Markdown

A class index signature with a modifier can follow a field whose initializer has no ;. It was erased with blankExact, so the next member could continue the initializer:

class C {
    f = a
    static [key: string]: any
    [x] = 1     // -> `f = a[x] = 1`: one field `f`, and `a[x]` is assigned
}

With readonly [key: number]: any followed by ["m"]() {} or *gen() {}, the output is a SyntaxError. TypeScript reports no diagnostics for these inputs, and onError isn't called.

Index signatures are now erased with blankStatement, like the erased method signatures in #74.

Testing:

  • New cases in tests/fixture/cases/asi.ts. They fail on main and pass with the fix.
  • The index signature in a.ts follows a method body, so it now also starts with a ;, as an erased method signature already does in that position.
  • npm run check passes. npm test: 41/43; the two loader tests fail the same way on main on my Windows machine.
  • I also compared the output with tsc's on about 52,000 generated class bodies (previous member × erased member × modifiers × next member) that TypeScript accepts without errors. On main, 447 differ, all with index signatures; with this change, none do.

An index signature with a modifier can follow a field initializer that
has no `;`. Erasing it left the next member able to continue the
initializer:

    f = a
    static [key: string]: any
    [x] = 1               ->  f = a[x] = 1  (valid JS, wrong fields)

Index signatures are now blanked like other erased class members, so a
`;` is inserted when the previous member needs one.

Signed-off-by: Laksh Agarwal <184763813+Lotion-3@users.noreply.github.com>

This branch has not been deployed

No deployments
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