jscodeshift icon indicating copy to clipboard operation
jscodeshift copied to clipboard

JS Doc type annotation moved inside of object after v0.13

Open michielpauw opened this issue 11 months ago • 2 comments

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'
});

michielpauw avatar Feb 26 '25 11:02 michielpauw

Which parser are you using?

Daniel15 avatar Jul 29 '25 22:07 Daniel15

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.

ElonVolo avatar Jul 29 '25 22:07 ElonVolo