You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make create-element-to-jsx properly transfer comments (#61)
Some non-obvious aspects of this change:
* For the main test, I put a comment between nearly every token. The generated
output is really messy, but the main important thing is that every comment in
the input appears somewhere in the output.
* For closing tags, I had to make a copy of the JSXIdentifier without any
comments. Otherwise, `React.createElement('div' /*foo*/, null, ' ')` would
become `<div /*foo*/> </div /*foo*/>`.
* I had to change the signature of `convertExpressionToJSXAttributes` to also
return an `extraComments` value for any comments that didn't have an obvious
attribute to attach to. This is also necessary since there might be no
attributes, but still some comments.
* JSXText elements seem to ignore any comments you attach to them, so I had to
just use the default behavior of a JSXExpressionContainer for any child
strings that have comments.
* Attaching comments to JSXElement nodes that are children of other JSXElement
nodes causes the comment to be incorrectly printed as a child string, e.g.
`<div><span />/*a comment*/</div>`. To avoid this, whenever the script
generates a child JSXElement, it wraps it in a JSXExpressionContainer if there
are any comments.
* It looks like some comments can be neither leading nor trailing (e.g.
`{/*foo*/}`, and that makes them not print when they're transferred to other
nodes. So in some cases I had to explicitly set the `leading` and `trailing`
booleans when transferring comments. This also makes the comment positioning
look nicer in some situations.
0 commit comments