-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Class member has empty decorators array #9024
Description
Describe the bug
We are working on moving into Rspack . To make that happen we have to rewrite our custom TypeScript transformer (AST) into SWC plugin. The plugin for reproductions is available here
What is the problem?
The problem is that class member has as empty array of decorators even if they exists (see example)
In the SWC Playground decorators also exists in as an filled array.
But inside of our code the decorators array is empty:

The prop of member class is ClassProp(ClassProp {
span: 84..118#0,
key: Ident(Ident {
span: 104..108#0,
sym: "test", optional: false
}),
value: None,
type_ann: None,
is_static: false,
==========================
decorators: [],
==========================
accessibility: None,
is_abstract: false,
is_optional: false,
is_override: false,
readonly: false,
declare: false,
definite: false
})
The problem is that all tests are working properly and transforms class property decorator into new value but the example code does not.
How to reproduce?
We've been created an reproduction repository.
The example code is available in example directory. To run the test you have to install all required packages then run build command:
$ pnpm install
$ cd example && pnpm install
$ pnpm build
What is the expected output?
We are trying to make plugin that will add into Prop decorator the annotation type e.g.
Before:
export default class Test {
@Prop()
public firstProp: boolean;
@Prop({ default: boolean })
public secondProp: boolean;
@Prop()
public thirdProp: string;
}After:
export default class Test {
@Prop({ type: Boolean })
public firstProp: boolean;
@Prop({ default: boolean, type: Boolean })
public secondProp: boolean;
@Prop({ type: String })
public thirdProp: string;
}Input code
import { Prop } from "./decorators/Prop";
export default class TestComponent {
@Prop()
private test: boolean;
}Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true
},
"target": "es2019",
"loose": false,
"minify": {
"compress": false,
"mangle": false
},
"experimental": {
"plugins": [
["@enp/swc-plugin-vue-auto-prop", {}],
]
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}Playground link (or link to the minimal reproduction)
SWC Info output
Operating System:
Platform: darwin
Arch: arm64
Machine Type: arm64
Version: Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020
CPU: (10 cores)
Models: Apple M2 Pro
Binaries:
Node: 16.20.2
npm: 8.19.4
Yarn: 1.22.21
pnpm: 9.1.3
Relevant Packages:
@swc/core: 1.5.25
@swc/helpers: N/A
@swc/types: 0.1.7
SWC Config:
output: N/A
.swcrc path: N/A
Next.js info:
output: N/A
Expected behavior
The decorators arrays are filled.
Actual behavior
No response
Version
latest
Additional context
No response