-
Notifications
You must be signed in to change notification settings - Fork 350
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
Extra parens inserted around JSX after attributes are added #1248
Comments
Looks like a fix has been up and ready for review for 2 weeks. Michał did you find a workaround in the meantime? |
#1257 isn't really a fix, is it? A proper fix would be to not add the double parens in the first place, right? |
We haven't upgraded to the broken version. |
Which version of jscodeshift and recast are you using?
It is a workaround, which would be good enough for my use-case. It seems like there are a myriad of issues surrounding parentheses in recast right now, so any path forward is better than nothing imo |
jscodeshift@0.13.1 and recast@0.20.5 |
That worked, thanks! |
looks like it has something to do with the newlines and indentations import * as React from "react";
export default function WrappedLink(props) {
return (<div><a {...props} /></div>);
} ^this produces correct results import * as React from "react";
export default function WrappedLink(props) {
return (<div><a {...props} /></div>
);
} ^ this as well import * as React from "react";
export default function WrappedLink(props) {
return (<div><a {...props} />
</div>
);
} ^ but this gets double parentheses |
We're affected by this issue as well. Thanks for logging it. |
I also encountered it when i was writing an automation script,thanks! |
|
…st produces 1 additional brace thet brokes code (benjamn/recast#1248)
…t produces broken code with additional brace (benjamn/recast#1248)
I've also encountered this error, +1 for a potential fix 🙏 |
Upgrading Specifically, we had code like so: import { Callout, Heading, Link, Stack, Text } from "@airplane/views";
import airplane from "airplane";
const TestView = () => {
return (
<Stack spacing="lg">
<Stack>
<Text>Views make it easy to build UIs in Airplane.</Text>
</Stack>
</Stack>
);
};
export default airplane.view(
{
slug: "test_view",
name: "Test view"
},
TestView
); When using import { Callout, Heading, Link, Stack, Text } from "@airplane/views";
import airplane from "airplane";
const TestView = () => {
return (
(<Stack spacing="lg">
<Stack>
<Text>Views make it easy to build UIs in Airplane.</Text>
</Stack>
</Stack>)
);
};
export default airplane.view(
{
slug: "test_view",
name: "Test view"
},
TestView
); |
+1 just spent way too much time tracking this down and trying to determine it wasn't something goofy with my configuration. |
I believe this is fixed with #1406 |
(This was originally posted in jscodeshift's repo: facebook/jscodeshift#534, but I was redirected to recast)
Context
We're using jscodeshift (and, thus, recast) to provide codemods that help our users migrate to new MUI libraries versions. After updating jscodeshift to 0.14.0 (which updates recast to 0.21.0), our tests started to fail.
It seems that when a codemod adds a JSX attribute, the whole JSX block in a return statement gets wrapped in extra parens (even if it had parens before).
I managed to create a minimal repro:
index.js
source.js
expected output
actual output
The text was updated successfully, but these errors were encountered: