swc
swc copied to clipboard
react-redux used by decorators
Describe the bug
import React from 'react'
import { connect } from 'react-redux'
@connect(
state => {
return xxxx
}
)
class App extends React.Component {}
export default App
if I used react-redux/connect decorators syntax.
or
but if I don't use decorators syntax.
import React from 'react'
import { connect } from 'react-redux'
class App extends React.Component {}
export default connect()(App)
it's worked
Input code
No response
Config
"jsc": {
"target":"es5",
"parser": {
"syntax": "ecmascript",
"jsx": true,
"dynamicImport": true,
"privateMethod": true,
"functionBind": true,
"classPrivateProperty": true,
"exportDefaultFrom": true,
"exportNamespaceFrom": true,
"decorators": true,
"decoratorsBeforeExport": true,
"importMeta": true,
"transform": {
"legacyDecorator": true,
"react": {
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment",
"throwIfNamespace": true,
"development": false,
"useBuiltins": false,
"refresh": true
}
}
}
}
Playground link
No response
Expected behavior
fix decorators syntax
Actual behavior
No response
Version
"@swc/cli": "^0.1.57" "@swc/core": "^1.2.182", "swc-loader": "^0.2.0", "react-redux": "^7.2.2",
Additional context
No response
Can you provide more info?
Did it work previously?
Or, does it work with tsc
?
@kdy1 We can use decorators syntax with react-redux
, like the below code
import React from 'react'
import { connect } from 'react-redux'
@connect(
state =>{xxxx},
dispatch => {xxxx}
)
class App extends React.Component {
render() {
<div>xxxx</div>
}
}
export default App
swc-loader didn't work though at .swcrc
set up decorators config.
when I don't use decorators syntax.
import React from 'react'
import { connect } from 'react-redux'
class App extends React.Component {
render() {
<div>xxxx</div>
}
}
export default connect(fn,fn)(App)
swc-loader worked.
it didn't work previously. the code was written by js not ts, so I didn't test tsc
yet
Oh I think I found the cause.
It's actually https://github.com/swc-project/swc-loader/issues/50
fixed the issue? I update the latest version, try rebuilding, and still error.
It's not released yet
@kdy1 I update v1.2.187, unfortunately, it still didn't work. How can I provide you with more information?
Can you provide a repro?
Can you try the new verison once it's published?
v1.2.189
: https://github.com/swc-project/swc/actions/runs/2363309064
decorator config issue: https://github.com/swc-project/swc/issues/4734 (fixed with v1.2.189
)
@kdy1 https://github.com/wangcongyi/swc-test
you can see index.jsx
, and see code comment.
@kdy1
Seems like this has already been fixed.
Thanks!
@Austaras I still get an error when I run my own project, @swc/cli": "^0.1.57, @swc/core": "^1.3.11, "swc-loader": "^0.2.3",
{
"test": ".jsx?$",
"jsc": {
"target":"es5",
"parser": {
"syntax": "ecmascript",
"jsx": true,
"dynamicImport": true,
"privateMethod": true,
"functionBind": true,
"classPrivateProperty": true,
"exportDefaultFrom": true,
"exportNamespaceFrom": true,
"decorators": true,
"decoratorsBeforeExport": true,
"importMeta": true,
"transform": {
"legacyDecorator": true,
"react": {
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment",
"throwIfNamespace": true,
"development": false,
"useBuiltins": false,
"refresh": true
}
}
}
}
}
You're passing wrong config, it should be
"jsc": {
"target":"es5",
"parser": {
"syntax": "ecmascript",
"jsx": true,
"dynamicImport": true,
"privateMethod": true,
"functionBind": true,
"classPrivateProperty": true,
"exportDefaultFrom": true,
"exportNamespaceFrom": true,
"decorators": true,
"decoratorsBeforeExport": true,
"importMeta": true
},
"transform": {
"legacyDecorator": true,
"react": {
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment",
"throwIfNamespace": true,
"development": false,
"useBuiltins": false,
"refresh": true
}
}
}
oh yes!! thank you so much @Austaras
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.