-
-
Notifications
You must be signed in to change notification settings - Fork 75
JSXText nodes are mislabeled as Literal nodes #266
Comments
I could be wrong. But doesn't the JSX AST Spec say that it must be a literal: Does babel do something different? I think JsxText is just used as a token type and not a node type |
Yeah, babylon puts a JSXText node, looks like. I'm guessing the spec is outdated or wrong. Unless people are using something other than babel to compile their JSX? |
Using ASTExplorer I noticed that parsers such as babel-eslint and espree both use Literal as the node type. Both of these parser are used by ESLint and linting rules are expecting this AST tree. If we were to change it then it would be best to change these parsers as well and update any ESLint rules. Babylon v5 used Literal but newer versions use JSXText so its possible there was a change in spec. I will try to dig into this more. @JamesHenry any idea why newer versions of babel have started using JSXText instead of Literal. |
facebook/jsx#50 Seems like there has been discussions about changing the AST psec |
That's probably a mislabeling, I'm not sure what a The use of |
@Kovensky ESTree has a |
So it would allow for literally anything (including a regexp) inside the tags, even though that's not the actual or intended behavior. |
cc @sebmarkbage |
We just changed the JSX spec to use JSXText instead of Literal as this is what all the popular parsers are doing. I think we should follow suite in typescript-eslint-parser. facebook/jsx#50 |
@vjeux Nice. This is a better choice and makes us align with other parsers. Will make the change this weekend. Thanks for taking the time to make it happen |
@vjeux Is a JSXText node going to be defined as well. Flow uses:
|
@soda0289 oh yeah you are totally right. Would you mind sending a PR on the JSX repo to add it? |
No problem |
facebook/jsx#50 is closed. Is there much work to do on this side? |
The change should be straight forward. I think we should convert CRLF line endings for the value property, similar to what esprima does. It will take some time to hit a new release since I need to ensure it will work with current eslint rules. Ill start looking into later today. |
We can make this change. There are lots of rules that this will break and eslint may not be willing to make the change until v5. This means the JSXText node type will not be enabled by default but can be used by enabling a flag. This should allow prettier to use the same node type as other parsers and give eslint and rule authors the time to make the adjustments they need. Will post a PR in the next few days. |
@soda0289 What stops this from being merged and released? This results in false positive on Example: <SomeComponent>
{children}
</SomeComponent> gets parsed as: JSXElement: '<SomeComponent>'
Literal: '\n '
... and tells me to escape the newline character. |
@sompylasar |
@sompylasar I'm pretty sure it's becuase the |
What version of TypeScript are you using?
2.3.2
What version of
typescript-eslint-parser
are you using?a294afa
What code were you trying to parse?
What did you expect to happen?
Program.body[0].expression.children[0]
should be aJSXText
node.What happened?
Program.body[0].expression.children[0]
is aLiteral
node.prettier/prettier#1558
The text was updated successfully, but these errors were encountered: