benjamn / recast

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

printer: Support type parameters on JSX components in TSX #1397

Closed PartMan7 closed 2 months ago

PartMan7 commented 3 months ago

Supports actually parsing cases like <Foo<Bar> /> instead of crashing.

Was unsure how to test this, since the existing code inherits from babel-parser's fixtures, and that doesn't currently have any tests of the sort (though it is a supported format).

Please let me know if there's any changes / modifications needed to the PR!

Demonstration on Babel REPL

eventualbuddha commented 3 months ago

I'd add a test to test/jsx.ts.

PartMan7 commented 3 months ago

test/jsx.ts is currently only running with babel and esprima, which (please correct me if I'm wrong) don't support TypeScript syntax (eg: tests crash even with <b>{'a' as string}</b>, which is valid and supported TSX). From what I could tell, the TSX tests run for recast are limited to those directly taken from babel-parser's fixtures - could you please point me in the right direction?

eventualbuddha commented 3 months ago

I guess I'd probably create a test/tsx.ts file that parses with the typescript option and put the tests in there.

PartMan7 commented 3 months ago

Hope this works!

eventualbuddha commented 2 months ago

Thanks! Published in v0.23.7.