-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Failing cases in JSX mode #3745
Comments
Use it to enable value-less attributes in the JSX mode Issue #3745
Kludge the xml indentation to ignore inside-tag positions, and properly set start indentation state in javascript mode. Issue #3745
I pushed some patches that take care of most of these (though getting indentation right across language boundaries is always tricky, and I'm not sure if the result is what you consider the right way to indent these). But...
What? I saw something like that in the grammar and assumed it was a typo. I guess we're no longer in XML Kansas anymore here, huh? What does this even do? That's going to be somewhat tricky to support since it does not correspond to the XML mode's expectations of what XML looks like. |
Awesome, thanks for fixing these so quickly! I'll test and confirm they're fixed. As far as style goes, I'm trusting what facebook shows on the reactjs site as the "proper" way to indent. Yeah, I dunno, I've never seen anyone write elements as attributes in any JSX code I've ever seen in the wild over the past year... I believe it's exactly the same as writing It's in the spec as:
IMO, not worth the effort. |
I agree that direct |
1: Boolean attributes ✅ 2 & 3: Comments are correct for the list of attributes 4: Won't fix, IMO. 5: Much much better. Still a few weird points. I'm not really sure how to systematically describe these other than as random one-offs of how they do/don't behave like I expect... Fixed (although, should the closing Better, but indents one spot too far, I think. Good (also, closing Here I expect the closing Three more things I found! 6: Attribute indentation doesn't behave as I would expect. I would set 7: Fat arrow => expression doesn't parse correctly. If surrounded by () it's ok. Fat array => {statements} is also ok. 8: Very minor, but something's a little off about the demo page https://codemirror.net/mode/jsx/index.html. The tab character inserts the equivalent of 4 spaces, but adding a newline after a |
This is CodeMirror's default behavior. You can configure it with the I fixed comments only being comments inside of tags, and also added support for tag attributes (which, if you see them as a shorthand for |
1: ✅ Boolean attributes |
This one's just a general javascript mode issue I found while testing jsx mode. Object destructuring with a trailing comma was throwing off the rest of the parsing: Fixed in #3748: It's here in the spec. (I thought maybe I was just writing weird code!)
|
So that addModeClass sees the right mode for the token Issue #3745
The brackets are fed to the correct mode, but the way |
I tweaked the indentation within I'm pretty much handling each case specially. I don't know if there's a better overarching rule that these follow that I haven't noticed. One thing I wasn't sure how to handle: I want to indent differently, depending on whether a |
Great. Anything left before we can close this? |
One last thing I found: currently the JS within the E.g. each property in this object is parsed as variable, and it's one long continued statement I took a stab at fixing by adding a hook expectExpression: function(state) {
state.cc.push(expressionNoComma)
} to JS mode. Which mostly works, except that the curly braces are getting parsed by the JS mode also. So I tried:
or
In both cases I would still need to tweak indentation a bit more. Or maybe theres a better way entirely. What do you think? |
I think parsing the braces in the JSX mode is a sane approach (they aren't really part of the JS, anyway). You could set the JS mode to JSON to get it to parse the top-level as an expression, but that'll have some undesirable effect (such as turning off the comment info), so I think there it would make sense to extend the JS mode to also have a configuration that says 'expect an expression', without it being full-on JSON mode. |
Pasting that code into http://codemirror.net/mode/jsx/ yields different results than what you screenshotted, and actually looks fine. |
Ah right, I just used Codemirror's home page's demo, so likely was in HTML mode... Sorry about the disturbance... Is there any drawback using JSX mode for all JS code ? |
JSX is a superset, so probably not. |
Thanks ! Maybe it's not the right location to ask this, but why don't you merge JS and JSX modes, then ? |
What do you mean by merging? If you're talking about code, |
I don't really understand why, if there's already all this. I'm not saying the code should be physically copied, but enabling the Javascript syntax should IMO also enable JSX... especially if TypeScript and others are also already enabled. |
If you select JavaScript mode, you get JavaScript, not TypeScript or JSX. These are different languages, they just happen to share a lot. |
Following up on: #3742
Three from the jsx/index.html page:
/>
)/>
)Two other things I've found:
4 . Elements should be allowed as attributes
5 . Indentation in JS expressions should be relative to the indentation level of JSX elements. I believe currently they get indented to prior JS indentation level. (this issue is highest priority, if I had to choose)
Current behavior gif here:
Correct position here:
Another example of current behavior (not followed by } char):
Correct position here:
@parisk @petetnt
The text was updated successfully, but these errors were encountered: