create-element-to-jsx: All files being skipped, even though react is included
not sure why but all my code is being skipped over without explantion
this is how I call the command
jscodeshift -t react-codemod/transforms/create-element-to-jsx.js dealroom/assets/jsx/core/Dialog.js
here is a sample of one of my files that is being skipped
import React from 'react';
import ReactDOM from 'react-dom';
var Dialog = React.createClass({
getInitialState(){
return {
show: false,
onConfirm: null,
onCancel: null,
onBackgroundClick: null,
}
},
render(){
return null;
},
showDialogBox(onConfirm, onCancel, onBackgroundClick){
this.setState({
show: true,
onConfirm: onConfirm,
onCancel: onCancel,
onBackgroundClick: onBackgroundClick,
})
},
hideDialogBox(){
this.setState({
show: false,
onConfirm: null,
onCancel: null
})
},
_onConfirm(){
if(this.state.onConfirm){
this.state.onConfirm()
}
},
_onCancel(){
if(this.state.onCancel){
this.state.onCancel()
}
},
_onBackgroundClick(){
if(this.state.onBackgroundClick){
this.state.onBackgroundClick()
}
},
_renderDialog(){
const {show} = this.state;
var className = 'toast dialog';
var btn1_class = 'btn-primary';
var btn2_class = 'btn-error';
if(this.props.reverseBtnColor){
btn1_class = 'btn-error';
btn2_class = 'btn-primary';
}
ReactDOM.render(
<div className='toast-container dialog-container'>
{show?
<div>
<div className={className}>
<div>
{this.props.children}
</div>
<div className='btns'>
<a className={'btn ' + btn1_class} onClick={this._onConfirm}>
{this.props.confirm_text}
</a>
<a className={'btn ' + btn2_class} onClick={this._onCancel}>
{this.props.cancel_text}
</a>
</div>
</div>
<div className='waiting-overlay' onClick={this._onBackgroundClick}/>
</div>
:null
}
</div>
, this.portal)
},
componentDidMount(){
this.portal = document.createElement('toast');
document.getElementById('portal').appendChild(this.portal);
this._renderDialog(this.props);
},
componentWillReceiveProps(new_props){
this._renderDialog(new_props);
},
componentDidUpdate(){
this._renderDialog();
},
componentWillUnmount(){
ReactDOM.unmountComponentAtNode(this.portal);
}
});
export default Dialog
output
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
All done.
Results:
0 errors
0 unmodified
1 skipped
0 ok
I'm experiencing the same issue with React-PropTypes-to-prop-types.js
@jlmbaka I used the command:
jscodeshift --extensions jsx -t react-codemod/transforms/React-PropTypes-to-prop-types.js <dir-path-with-jsx-files>.
Successfully transformed all my jsx files. I haven't tested it on js files though.
@BossGrand the create-element-to-jsx script returns null when it doesn't make any changes, which jscodeshift interprets as "skipped" rather than "no change", so I guess it's a minor bug in how that script reports its results. In your case, your file had no usage of React.createElement, so there was nothing to transform. If you throw a React.createElement('div') in your code, you should see that the file gets marked as ok and the code changes to <div>.
Maybe you meant to use a different script? React-PropTypes-to-prop-types and class are the two that have recently received a lot of attention as part of the React 15.5.0 release.
@A-Dubz I've followed your advise and it worked for me, thanks
@A-Dubz works for me
adding --extensions jsx worked for me, why is that not in the documentation??
@VictorChen - https://github.com/reactjs/react-codemod/pull/170
I ended up doing this manually. So if people think this is fixed or not an issue feel free to close it
is not fixed on windows os ...
jscodeshift --extensions jsx -t react-codemod/transforms/create-element-to-jsx.js test.jsx
var MyClass = React.createClass({
render() {
return <div>123</div>
}
})
This is happening to me on a typescript project with react/sort-comp, using --extensions did not fix it
I'm going to close this issue, please file fresh issues with specifics and repros if needed.
@sarink and @feonit, How did you fix the issue?