Skip to content

oxfmt: ignore comment on a decorated class deletes all its decorators #25911

Description

@ubugeeei

Summary

Oxfmt deletes all decorators of a class declaration when an ignore comment (// oxfmt-ignore or // prettier-ignore) is attached to, or placed inside, one of those decorators. The class body itself survives, so the output is still valid TypeScript — the code just silently loses its decorators.

Reproduction

Input (case.ts):

declare function M(o: unknown): ClassDecorator;

@M({
  // oxfmt-ignore
  a: [1],
})
export class A {}

oxfmt case.ts (default config) output:

declare function M(o: unknown): ClassDecorator;

// oxfmt-ignore
export class A {}

The same happens when the ignore comment precedes the decorator:

// oxfmt-ignore
@M({ a: [1] })
export class A {}

becomes

// oxfmt-ignore
export class A {}

With several decorators on one class, all of them are removed.

Expected

The decorators are preserved, as Prettier does. Prettier 3.8.2 leaves the first example untouched.

Notes

  • Reproduces with // prettier-ignore as well as // oxfmt-ignore.
  • Method and property decorators are not affected — only class declarations.
  • Reproduced on oxfmt 0.52.0, 0.62.0 and 0.64.0, so this is not a recent regression.

Impact

I hit this while migrating a NestJS codebase from Prettier to Oxfmt (via Vite+ vp fmt). Three @Module({ ... }) declarations that contained a // prettier-ignore lost their entire dependency-injection wiring. Because the class itself is still there and still compiles, neither tsc nor the unit test suite caught it — the failure would only have surfaced at runtime.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions