Just quoting the updated snapshot from #251:
-echo "foo is $foo"; // foo is foobar
+echo "foo is $foo";
-// Using single quotes will print the variable name, not the value
-echo 'foo is $foo'; // foo is $foo
+// Using single quotes will print the variable name, not the value // foo is foobar
+echo 'foo is $foo';
-// If you are not using any other characters, you can just echo variables
-echo $foo; // foobar
-echo $foo,
- $bar; // foobarbarbaz
+// If you are not using any other characters, you can just echo variables // foo is $foo
+echo $foo;
+// foobar
+echo $foo, $bar;
-// Strings can either be passed individually as multiple arguments or
+// Strings can either be passed individually as multiple arguments or // foobarbarbaz
input:
echo "foo is $foo"; // foo is foobar
// Using single quotes will print the variable name, not the value
echo 'foo is $foo';
output:
echo "foo is $foo";
// Using single quotes will print the variable name, not the value // foo is foobar
echo 'foo is $foo';
So I _believe_ this is a problem with how we handle lines in our printer. We basically say each node is responsible for determining if it should be on its own line - to play nicely with prettier core i believe we need to have the parent node dictate line breaks for its children (ie our "program" node). This is how the js printer does it: https://github.com/prettier/prettier/blob/master/src/language-js/printer-estree.js#L335
This is because the core comment logic concatenates leading/trailing comments to the printed result of the node they belong to. But since we're actually printing line breaks with our nodes (rather then the parent node adding linebreaks between its own children), the trailing comments are always coming after the node they're supposed to be attached to
ie at this point (where the trailing comment is printed) https://github.com/prettier/prettier/blob/master/src/main/comments.js#L511 - the node has already been printed, with a line break
I'll try and take a look tomorrow to see how big of a pain this is gonna be to refactor our printing logic around new lines
Fixed with #260
Most helpful comment
I'll try and take a look tomorrow to see how big of a pain this is gonna be to refactor our printing logic around new lines