-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversion of React JSX Props on newlines fails #20
Comments
This is a known issue with the extension (see #15 (comment) for background) |
pushing this change soon after doing some more testing @karlhorky |
Looks really good for this example @meganrogge , thanks!! 🙌 |
Another unhandled case is returning to the JavaScript rules once inside of JSX opening tags. Inside of opening tags in JSX, there may be the use of JavaScript expressions (starting with an opening curly bracket and ending with a closing curly). Since we back in regular JavaScript, the special JSX opening tag rules / behavior should not apply. One common example is usage of a <Link
to="/"
style={{
float: 'left',
}}
>
←
</Link> The result of editing Another example would be no prop at all, using object spread: <Link
{...{
a: 'b'
}}
/> The result of editing Both of these examples with objects fail when editing values or also any keys which are in the form of strings (eg. editing Also, an expression as a standalone string (no usage of an object): <Link
href={'abc'}
/> The result of editing This also happens on single lines: <Link href={'abc'} /> The result of editing Or a different expression (an admittedly unusual pattern): <Link
href={href='abc'}
/> The result of editing All of these fail when adding interpolation in the string. New issue again? |
@karlhorky thanks for the examples. reopened this issue and will look into it. |
@karlhorky after re-reading this, I'm kind of confused. Are you saying in the example you provided it shouldn't convert to a JSX prop, even though it's following an |
Sorry, I have updated the examples above to include what happens now and what should happen. The main takeaway here can be the following rules:
The 1st rule above is being applied correctly, but the 2nd - going back to JavaScript rules within that opening tag - is not. In case you're using regex, there are a couple of regular expression implementations for JSX opening tags and JavaScript expression in Prism.js and VS Code that may help: |
Hoping to get to this soon |
Having issues publishing the extension atm, but hopefully will be able to do so soon and thus reflect this fix. |
Great! When there's a new version, I'll test it out :) |
It has been released so lmk @karlhorky |
ok trying on |
<Link
to="/"
style={{
float: 'left',
}}
>
←
</Link> Hm, seems like this one is still open... Just tried in both a didn't test the other cases yet in my comment above |
Worked well for most of your examples when I tested it. Seems like there are a lot of cases to cover |
Hm, interesting... for me, I haven't seen a single one that does work. Maybe the publish didn't work properly? For example, here's another one that fails (which is a very common pattern in React code):
<Link href={'abc'} /> Should this issue be reopened? Or should I create a new issue with the content of my comment above? |
feel free to make a PR @karlhorky i'm quite occupied working on vscode at the moment, so could take me awhile to get to this |
In Template String Converter Kapture.2021-12-29.at.17.00.15.mp4Opened #61 for this. |
I just noticed that in your original example, if you delete the comment line, it will work |
that's a case I don't have time for at the moment, but about to push a fix for the other cases you mention in this issue. Done |
For anyone here looking for what the setting was named:
or in your JSON "template-string-converter.addBracketsToProps": true |
JSX props (React) on their own lines do not convert correctly to template strings:
The text was updated successfully, but these errors were encountered: