Open aaronjensen opened 9 years ago
Probably related: https://github.com/benjamn/recast/issues/147
same here
works for assign breaks for return
function App(props) {
//const div = ( // good
return ( // bad
<div className="app">
hello {props.name}
</div>
);
//return div;
}
but only when i transform the AST
good result: assign
function App(props) {
const div = (
<div class="app">
hello {props.name}
</div>
);
return div;
}
bad result: return
function App(props) {
return (
(<div class="app">hello{props.name}
</div>)
);
}
note: also whitespace in hello {props.name}
is lost
demo
bug seems to be in
child.type = "JSXText"
child.value = "\n hello "
line 1314: "hello"
from
return (
<div class="app">
hello {props.name}
</div>
);
the whitespace before </div>
child.value: "\n "
line 1316: "\n"
https://github.com/benjamn/recast/blob/f41dd8b53fe25839b0866fec5dad4232c6ed21b8/lib/printer.ts#L1326
openingLines = ' <div class="app">'
childLines = "hello{props.name}\n"
closingLines = "</div>"
in the "good" case, this code is not reached instead, print seems to use the fast path
i guess the slow path is caused by adding parens at return ( ... )
but we already have parens around that expression
when parens are missing
return <div>
asdf
</div>
then it should create a parens-block, indented by 2 spaces
return (
<div>
asdf
</div>
)
nevermind. im moving on to eslint as its more popular
Is it currently possible to print JSX nodes like so:
They seem to always print like:
http://felix-kling.de/esprima_ast_explorer/#/984sneJJn2
Thanks!