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
Is it safe to just simply throw away any instances of Literal "\n " and "\n" when visiting JSXElements, or is there a way to have the parser not pick these up in the first place?
The text was updated successfully, but these errors were encountered:
JSX preserves leading/trailing whitespace as JSXText nodes because JSX is more whitespace-sensitive than most other kinds of JS syntax, and that whitespace needs to be passed as strings to the function calls that JSX is translated to.
I have a theory about what was happening here:
if(1===1){;<h1>OH HAI</h1>;;};
With the original <If> parent node stripped off, those whitespace-only JSXText nodes were ending up without a JSXElement parent, so the printer was treating them as ordinary ExpressionStatements.
So, yes, I think it's safe to throw away those string literals in this case, specifically because JSXText nodes should always have a JSXElement as their parent.
It might make sense, then, to change the printer case for JSXText to print nothing (or throw an exception) if path.getParentNode() is not a JSXElement.
When parsing the following
The top level JSX element (If) has the following children:
Is it safe to just simply throw away any instances of Literal "\n " and "\n" when visiting JSXElements, or is there a way to have the parser not pick these up in the first place?
The text was updated successfully, but these errors were encountered: