Skip to content

TypeScript decorators lose context values. #20206

@ZQH123196

Description

@ZQH123196

What version of Bun is running?

1.2.15

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

The decorator seems to lose context information.
When executing "bun xxx.ts" with decorators, it shows different results from "bun xxx.js" compiled by tsc.
note: "originalMethod" also gets the same problem.

my test code: tmp.zip

function loggedMethod(originalMethod: any, context: ClassMethodDecoratorContext) {
    const methodName = String(context.name);
    console.log(`🔍 自动日志装饰器应用于方法: ${methodName}`);
    function replacementMethod(this: any, ...args: any[]) {
        console.log(`LOG: Entering method '${methodName}'.`)
        const result = originalMethod.call(this, ...args);
        console.log(`LOG: Exiting method '${methodName}'.`)
        return result;
    }
    return replacementMethod;
}

class ExampleClass {
    @loggedMethod
    foo() {
        console.log("foo 方法执行完毕");
    }
}

new ExampleClass().foo();

What is the expected behavior?

Hope "bun xxx.ts" can correctly process decorator context values.

In ".ts" file, "methodName" should be log correctly like ".js" files.

What do you see instead?

Image

Additional information

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtypescriptSomething for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions