oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
9.87k stars 365 forks source link

Unexpected token when using chained decorators #2562

Closed marcus-sa closed 4 months ago

marcus-sa commented 4 months ago

Error

×Unexpected token
    ╭─[apps/server/src/hooks/hooks.controller.ts:14:26]
13 │ 
14 │ @http.controller('hooks').middleware(HooksMiddleware)
    ·                          ─
15 │ export class HooksController {
    ╰────

Reproduction

import { http, HttpMiddleware } from '@deepkit/http';

export class HooksMiddleware implements HttpMiddleware {
  execute(): void | Promise<void> {
    // ...
  }
}

@http.controller('hooks').middleware(HooksMiddleware)
export class HooksController {}
Boshen commented 4 months ago

It seems like I need to rewrite the decorator parsing logic.

If anyone wants to give this a try ...

we need to remove the current code, add a decorator context and mimic what the TypeScript compiler is doing.

https://github.com/microsoft/TypeScript/blob/1d6d962d3132a901f5fb48be4a389c45faf5a74e/src/compiler/parser.ts#L2119-L2121