benjamn / recast

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

prettyPrint renders HTML entities in JSX #213

Open chandlerprall opened 9 years ago

chandlerprall commented 9 years ago

When pretty printing JSX with HTML entities, the entities are rendered as their display character instead of the source.

print works as expected -

recast.print(recast.parse('<strong>&lt;</strong>'));
// <strong>&lt;</strong>'

prettyPrint breaks the output -

recast.prettyPrint(recast.parse('<strong>&lt;</strong>'));
// '<strong><</strong>;'

We are using recast to make AST transforms and convert back to code using prettyPrint. Having lt; transformed to < breaks the subsequent JSX parsing.

chandlerprall commented 9 years ago

It appears that prettyPrint also strips out spaces from JSXElements.

<span>text <a href="#">link</a><span>

becomes

<span>text<a href="#">link</a><span>

where there's no longer a space between text and the a tag

tatermelon commented 7 years ago

I am seeing the same issue <div>&#10003;</div> becomes <div>✓</div>