Skip to content

Commit

Permalink
Always output comment newlines, fix edge case with function param output
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Jan 5, 2017
1 parent 67e2f6d commit 835befe
Show file tree
Hide file tree
Showing 5 changed files with 1,998 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var isObject = types.builtInTypes.object;
var pp = require("./pp");
var fromString = pp.fromString;
var concat = pp.concat;
var line = pp.line;
var hardline = pp.hardline;
var util = require("./util");
var comparePos = util.comparePos;
var childNodesCacheKey = require("private").makeUniqueKey();
Expand Down Expand Up @@ -266,7 +266,7 @@ function printLeadingComment(commentPath, print) {
if (comment.trailing) {
// When we print trailing comments as leading comments, we don't
// want to bring any trailing spaces along.
parts.push(line);
parts.push(hardline);

}

Expand All @@ -288,7 +288,7 @@ function printLeadingComment(commentPath, print) {

// }
else {
parts.push(line);
parts.push(hardline);
}

return concat(parts);
Expand Down
7 changes: 5 additions & 2 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1740,17 +1740,19 @@ function printArgumentsList(path, options, print) {
return "()";
}

const shouldBreak = printed.slice(0, -1).some(hasHardLine);
const lastArg = util.getLast(path.getValue().arguments);
// This is just an optimization; I think we could return the
// conditional group for all function calls, but it's more expensive
// so only do it for specific forms.
const groupLastArg = lastArg.type === "ObjectExpression" ||
lastArg.type === "ArrayExpression" ||
lastArg.type === "FunctionExpression" ||
lastArg.type === "ArrowFunctionExpression";
lastArg.type === "ArrowFunctionExpression" ||
lastArg.type === "CallExpression" ||
lastArg.type === "NewExpression";

if (groupLastArg) {
const shouldBreak = printed.slice(0, -1).some(hasHardLine);
return conditionalGroup(
[
concat([
Expand Down Expand Up @@ -1784,6 +1786,7 @@ function printArgumentsList(path, options, print) {
);
}

const shouldBreak = printed.some(hasHardLine);
return group(
concat([
"(",
Expand Down
Loading

0 comments on commit 835befe

Please sign in to comment.