NullVoxPopuli / optional-chaining-codemod

there should be more codemods for mundane stuff like this
16 stars 0 forks source link

Transformation crashes on files that render jsx #4

Open roth-j opened 4 years ago

roth-j commented 4 years ago

I am trying to use this on a react application. I have recreated the issue on a simple file

export const MyComponent = (props) => {
    const x = (props.thing || {}).isTrue;
    return (<h1>hi there</h1>);
}

When I execute the code transformation on any file that has a jsx element in it the command fails and it doesn't change the code.

This is the the command I ran:

optional-chaining-codemod ./Desktop/test-code-mod.js

This is the error I got:

Processing 1 files... 
Spawning 1 workers...
Sending 1 files to free worker...
 ERR ./Desktop/test-code-mod.js Transformation error (Unexpected token, expected "," (3:19))
SyntaxError: Unexpected token, expected "," (3:19)
    at Object._raise (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/location.js:241:45)
    at Object.raiseWithData (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/location.js:236:17)
    at Object.raise (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/location.js:220:17)
    at Object.unexpected (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/util.js:149:16)
    at Object.expect (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/util.js:129:28)
    at Object.parseParenAndDistinguishExpression (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/expression.js:1293:14)
    at Object.parseExprAtom (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/expression.js:1029:21)
    at Object.parseExprSubscripts (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/expression.js:539:23)
    at Object.parseMaybeUnary (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/parser/expression.js:519:21)
    at Object.parseMaybeUnary (/Users/xx/.config/yarn/global/node_modules/@babel/parser/src/plugins/typescript/index.js:2417:22)
All done. 
Results: 
1 errors
0 unmodified
0 skipped
0 ok