Skip to content

fix: blank type syntax in computed class field keys before the annotation - #78

Merged
acutmore merged 1 commit into
bloomberg:mainfrom
bardrop:fix-computed-key-field-annotation
Nov 13, 2026
Merged

acutmore merged 1 commit into
bloomberg:mainfrom
bardrop:fix-computed-key-field-annotation

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #77

A class field whose computed key has type syntax (as, satisfies, !, f<T>()) and that also has a type annotation, ? or ! gave invalid JavaScript:

class A {
    [k as "x"]: number = 1;
}

was emitted as [k as "x"] ]: number = 1;.

visitPropertyDeclaration blanked the postfix token and the annotation before it visited the name, so BlankString got its ranges out of source order. This change visits the name first, right after the modifiers. Methods and accessors were not affected (they already visit the name first).

Testing:

  • Added three fields to the class in tests/fixture/cases/b.ts (as + annotation + initializer, static + as + ?, f<T>() + !) and regenerated the fixtures with npm run fixtures. Only b.js changes. The b.ts fixture fails on main and passes with this change.
  • All the inputs from the issue now give the expected output, e.g. [k ] = 1;.
  • npm run check, npm run format:check and npm test (43 tests) pass.

…tion

A class field with type syntax in a computed key and a type annotation,
`?` or `!` after it, produced invalid JavaScript:

    [k as "x"]: number = 1;   // emitted as `[k as "x"]        ]: number = 1;`

visitPropertyDeclaration blanked the postfix token and the annotation
before visiting the name, so BlankString got its ranges out of source
order. Visit the name first.

Fixes #77

Signed-off-by: Mradul Singh <msingh@dealmeridian.com>
@acutmore
acutmore merged commit c68e030 into bloomberg:main Nov 13, 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.

Computed class field key with as/satisfies/type arguments plus a type annotation produces broken output

2 participants