benjamn / recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator
MIT License
4.91k stars 347 forks source link

fix: TSTypeAnnotation printer when parent is a TSFunction type #1404

Open henryqdineen opened 1 month ago

henryqdineen commented 1 month ago

This is very similar to https://github.com/benjamn/recast/pull/815 but with a test that properly recreates the issue. I ran into the same issue today and needed to use patch-package to fix recast in my project.

It appears that TSTypeAnnotation printer code does not run when you print() a AST with TSTypeAnnotation nodes unless you replace/modify a TSTypeAnnotation and change the typeAnnotation property to be a node of a different type. In my test I switch the typeAnnotation from a TSTypeReference to a TSQualifiedName.

Thanks!