-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
Describe the bug
Input
class Something extends React.Component<Props, State> {
static defaultProps = {
transitionTime: 500,
};
static meow = 'a';
constructor() {
this.something = 'a';
}
render() {
return null;
}
}Babel with the following config
{
"filename": "repl.tsx",
"presets": [
[
"env",
{
"targets": "node 20",
"modules": false,
"loose": true
}
],
[
"react",
{
"runtime": "automatic"
}
],
[
"typescript",
{
"allowDeclareFields": true,
"allowNamespaces": true
}
]
],
"sourceType": "unambiguous"
}outputs:
class Something extends React.Component {
static defaultProps = {
transitionTime: 500
};
static meow = 'a';
constructor() {
this.something = 'a';
}
render() {
return null;
}
}However SWC outputs
"use strict";
class Something extends React.Component {
static{
this.defaultProps = {
transitionTime: 500
};
}
static{
this.meow = 'a';
}
constructor(){
this.something = 'a';
}
render() {
return null;
}
}I noticed that it will use class static block if I set the loose option to true. When I set it to false, SWC outputs the same as Babel:
"use strict";
class Something extends React.Component {
static defaultProps = {
transitionTime: 500
};
static meow = 'a';
constructor(){
this.something = 'a';
}
render() {
return null;
}
}Which brings to question: why use class static block when loose mode is used? This seem to increase the output size too (like around 10 characters difference when comparing loose=true vs loose=false with compress=true + minify=true)
Input code
class Something extends React.Component<Props, State> {
static defaultProps = {
transitionTime: 500,
};
static meow = 'a';
constructor() {
this.something = 'a';
}
render() {
return null;
}
}Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"loose": true,
"minify": {
"compress": false,
"mangle": false
},"transform": {
},
"experimental": {
"emitIsolatedDts": false
}
},
"module": {
"type": "commonjs"
},
"minify": false,
"isModule": true,
"env": {
"targets": "node 20"
}
}Link to the code that reproduces this issue
SWC Info output
N/A uses playground (1.13.20)
Expected behavior
When using loose = true, shouldn't transform static class property to static block
Actual behavior
When using loose = true, it transform static class property to use static block
Version
1.13.20
Additional context
No response