-
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
Recast is adding extra newlines in ObjectExpressions #242
Comments
Thinking about this a little, I'm inclined to believe that this is also related to #240. Essentially, the printer is forcefully adding one extra newline after each property in an objectExpression. So, if there is none, then there will be one. If there's one, then there will be two. But if there's two or more, then nothing happens. |
This comes from Lines 624 to 627 in 827ae9f
From what I've seen, the practice of writing code as I've given in the first code snippet above is quite common and, at risk of sounding too narrow-minded, no one writes an extra newline in their code separating the properties of an objectExpression, not even Facebook. |
+1 |
I found a ton of examples of cases where this happens. I originally filed a bug here: zxbodya/flowts#11 It seems any property that spans multiple lines causes extra newlines, even if it's just because it has a comment. |
It is happening something similar to me. This code, for example: const shortProperty = (j, identifier) => {
return { ...j.objectProperty(identifier, identifier), shorthand: true };
};
export default function (file, api) {
const j = api.jscodeshift;
const call = j.variableDeclaration("const", [
j.variableDeclarator(
j.objectPattern([shortProperty(j,j.identifier("__"))]),
j.callExpression(j.identifier("usePulyglot"), [
j.identifier("phrases")
])
)
])
return j(call).toSource();
} Produces this output: const {
__
} = usePulyglot(phrases); = 99 But I expected this instead: const { __ } = usePulyglot(phrases); = 99 Here is a playground: https://astexplorer.net/#/gist/eeee224efd6c389deb8a82a338e4fbe7/latest |
Made a fix for this: #1262 |
Refer to the following fiddle: http://astexplorer.net/#/27xKOBJJGN
When I have an object with a structure such as this:
and I do anything with the body of the ObjectExpression like this:
then the following output is gotten:
see that extra newline after
base
and beforeribbon
. These lines are added after every property, which is adding unnecessary changes to my codebase. Is there a way to suppress that? or is that a bug?The text was updated successfully, but these errors were encountered: