-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jsx_element
nodes on different line being parsed as start on the same line.
#329
Comments
jsx_element
nodes on different line shown as start on the same line.jsx_element
nodes on different line being parsed as start on the same line.
It seems like adding token.immediate to had an effect on the outer We could explicitly allow whitespace with something like _jsx_child: $ => choice(
$.jsx_text,
/[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]+/,
$.html_character_reference,
$._jsx_element,
$.jsx_expression,
), But TBH, this feels downstream of #328 upholding #221 . This is starting to feel like the wrong call, its not what estree-compatible parsers do but theres no spec requiring it either way. what i mean is having <div>
<div/>
</div> result in
would also solve this problem (and be helpful for babel/acorn compatibility) but would go back on #221 what do you think @amaanq |
What if we just forbid newlines in the first regex group? The problem is (and this is a somewhat known issue) the spaces get consumed when parsing the author's original example, and then get lumped in with the parsing of the Log output showing what I mean: The @jackschu a question I have is, are these spaces after a newline rendered in React as literal spaces? I'm no React/JSX expert, but if they are, we should consider going back on 221 then imo, since real syntactic info about the code is lost. If it is not rendered as spaces, then we can either go with what I proposed. |
Kind of. If newlines are separating text nodes then React will render these as literal spaces. My best understanding is that this is the current ruleset for react facebook/react#480 (comment)
This means that these examples will include whitespace in what react emits let x = (<div> <Button/> </div>)
// OR
let y = (<div>
hi
bye
</div>) But this example will not <div>
<Button/>
</div> (for more detail see the JS emitted by this playground link) So babel, acorn, etc decide to just always emit jsx_text nodes containing newlines and let downstream tooling figure it out. This is the direction id lean especially given that the ruleset that react seems to use is not really codified by any spec. But I'm not sure if this would be bad for @lucario387 's use-case. |
From what I can see of both of the examples, and from the playground link let x = (<div> <Button/> </div>)
// OR
let y = (<div>
hi
bye
</div>) They both do contain whitespaces, but they do not consider it part of the child element, but rather as separate, actual <p>
Foo
Bar
</p> creates |
Agreed, I think this is what @amaanq and I are talking about w.r.t. 'going back on 221' |
I'm fine with that, it makes more sense imo, though might be slightly annoying for some consumers |
From v0.21.4, I experienced the jsx elements to be captured too widely. Here's an example of it
The output of
tree-sitter parse
is the following:While this is the parsed result from commit c4739fe
And the diff of the two parsed trees:
As can be seen from the file above. despite
<></>
and<Button></Button>
be on different lines, the<Button>
element starts at[2, 6]
instead of[3, 6]
like in v0.21.3I think the changes in 99be62f may have lead to this being affected.
The text was updated successfully, but these errors were encountered: