tsup ignores useDefineForClassFields, and always generates definitions for class fields
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
When compiling with the typescript compiler (`tsc`), how class fields are transformed depends on the value of `useDefineForClassFields`, but the `tsup` is currently ignoring this setting.
This causes problems with field decorators.
Original typescript code:
```
export class Foo {
@customDecorator()
public readonly value!: string;
}
```
Result of `tsc` with `useDefineForClassFields = false`
```
class Foo {
}
```
Result of `tsc` with `useDefineForClassFields = true`
```
class Foo {
constructor() {
Object.defineProperty(this, "value", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
}
}
```
Result of `tsup` regardless of `useDefineForClassFields` value
```
var Foo = class {
constructor() {
__publicField(this, "value");
}
}
```
The issue here is that the `__publicField()` logic which is being added, prevents processing of field decorators.
Contributor guide
Research direction
Start by reproducing the issue with the TypeScript example and compare tsup output against tsc with useDefineForClassFields set to both false and true. Trace where tsup handles this compiler setting and field decorators; done means the generated output respects the setting and no longer prevents decorator processing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100