Skip to content

transformer: param decorator should be executed before metadata injections #13210

@sapphi-red

Description

@sapphi-red
export class Foo {
  @methodDecorator
  method(@paramDecorator param: string): boolean {
    return !!param
  }
}

For the input above, the output of TypeScript (and SWC) runs the code related to paramDecorator before the code related to metadata. But the output of Oxc runs in the opposite order.

// TS output (omitted helpers)
export class Foo {
    method(param) {
        return !!param;
    }
}
__decorate([
    methodDecorator,
    __param(0, paramDecorator),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Boolean)
], Foo.prototype, "method", null);

// Oxc output
export class Foo {
        method(param) {
                return !!param;
        }
}
_decorate([
        methodDecorator,
        _decorateMetadata("design:type", Function),
        _decorateMetadata("design:paramtypes", [String]),
        _decorateMetadata("design:returntype", Boolean),
        _decorateParam(0, paramDecorator)
], Foo.prototype, "method", null);

TS playground
SWC playground
reproduction using transform function exposed from rolldown

Metadata

Metadata

Assignees

Labels

A-transformerArea - Transformer / TranspilerP-highPriority - High

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions