swc-project / swc-project/swc-node
Unable to use 2022-03 decorators with swc-node/register
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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