Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use 2022-03 decorators with swc-node/register #773

Open
alberteddu opened this issue May 5, 2024 · 1 comment
Open

Unable to use 2022-03 decorators with swc-node/register #773

alberteddu opened this issue May 5, 2024 · 1 comment

Comments

@alberteddu
Copy link

alberteddu commented May 5, 2024

Hey! I am trying to use the new decorators in this way:

.swcrc

{
    "$schema": "https://json.schemastore.org/swcrc",
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "decorators": true
        },
        "transform": {
            "decoratorVersion": "2022-03",
        }
    }
}

test.ts

function one(_target: unknown, context: ClassFieldDecoratorContext) {
    context.addInitializer(function () {
        const instance = this as { prop: number };
        instance.prop = 1;
    });
}

class Example {
    @one
    prop: number;
}

const instance = new Example();
console.log(instance.prop); // Output: undefined instead of 1

Using this command: SWCRC=true node --require @swc-node/register test.ts

The output is expected to be 1 (that is the output I get with ts-node) but is undefined with @swc-node/register.
I have looked around and I am not sure if this is supposed to work yet.
Am I doing something wrong?

@yeliex
Copy link
Contributor

yeliex commented May 27, 2024

swc-project/swc#8922

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants