swc-project / swc-project/swc-node

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

Open
#773 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2k
Forks
95
Avg merge
14d 11h
Merged PRs (30d)
1

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example from test.ts using the shown .swcrc configuration and the SWCRC=true node --require @swc-node/register test.ts command. Compare the result with ts-node and trace how @swc-node/register handles the 2022-03 decorator configuration; done means the example prints 1 or the supported limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.