jscodeshift
jscodeshift copied to clipboard
JS Doc type annotation moved inside of object after v0.13
Hi! I noticed a strange change of behaviour from v0.14 onwards when using jscodeshift on this code snippet:
export default /** @type {SomeType} */ ({
someProp: 'someProp',
});
I'm "transforming" this file as such:
const root = j.(fs.readFileSync(filepath, 'utf-8'));
return root.toSource();
Expected output
The code should not have changed
export default /** @type {SomeType} */ ({
someProp: 'someProp',
});
This seems to be the case in v0.13 and before.
Actual output (from v0.14 onward)
export default ({
/** @type {SomeType} */ someProp: 'someProp'
});
Which parser are you using?
Haven’t looked at the code or anything, but it would be at 80% likelyhood it’s recast issue (with possibly some amount of changes needed in ast-types library). So filing a bug with recast may be your best bet.
With most codemod-related thing you’ll get more reliable and repeatable output if you avoid inlining things (especially comments) and give something its own line.