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 parsing error where using hyphen prop name #6723
Comments
this works, so I guess it's just again a wrong handling of the jsx mode in the parser. let customDiv = <Div data-a="a" /> |
Indeed, actually I'm working on the * mode in parser, so I'll take a look to fix it. |
Looking at the parser to remove the mode state, I think I understand the underlying reason why we needed a mode list ref type state value. I think it's because the parse* functions all call Parser.next at the end, and why that's a problem is because it affects the parsing of the next token at an earlier, unrelated stage. For example, parsing props, Specifically, to parse the above props correctly without the mode state, we need to do this let parseConstant ?(jsx_mode=false) p ... =
...
Parser.next ~jsx_mode
let parseJsxProps p ...
...
parseConstant ~jsx_mode:true p (* parseConstant should not affect next ident for props *)
... So what I would suggest is to change the implementation so that the parse* function does not call Parser.next at the end for the next operation, but peeks, consumes and returns the expression. @tsnobip Can I have your thoughts about it? |
That is why this issue happens: <div data-a="a" /> // fine
<div name="n" data-a="a" /> // syntax error |
Definitely, I had the same realization, right now modes necessarily "leak" before switching, there are a few util functions that try to mitigate this by retrying the token, but it definitely feels suboptimal! |
Related, https://rescript-lang.org/docs/manual/latest/jsx#hyphens-in-tag-names
|
Yes @predragnikolic, using |
I've tried to use a custom data attribute for lower case jsx.
There are two workaround here.
name
props afterdata-a
, the build is fine.<Div data-a="a" name="div" />
<Div name="div" \"data-a"="a" />
The text was updated successfully, but these errors were encountered: