Skip to content

Commit

Permalink
Inline the arguments of an arrow function in the body is conditional …
Browse files Browse the repository at this point in the history
…expression (#5209)
  • Loading branch information
duailibe committed Oct 8, 2018
1 parent ce952fc commit b5fd382
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/language-js/printer-estree.js
Expand Up @@ -3420,6 +3420,7 @@ function couldGroupArg(arg) {
arg.body.type === "ArrayExpression" ||
arg.body.type === "CallExpression" ||
arg.body.type === "OptionalCallExpression" ||
arg.body.type === "ConditionalExpression" ||
isJSXNode(arg.body)))
);
}
Expand Down
30 changes: 27 additions & 3 deletions tests/arrow-call/__snapshots__/jsfmt.spec.js.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`arrow_call.js - flow-verify 1`] = `
exports[`arrow_call.js - babylon-verify 1`] = `
const testResults = results.testResults.map(testResult =>
formatResult(testResult, formatter, reporter)
);
Expand Down Expand Up @@ -43,6 +43,8 @@ const composition = (ViewComponent, ContainerComponent) =>
class extends React.Component {
static propTypes = {};
};
promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const testResults = results.testResults.map(testResult =>
formatResult(testResult, formatter, reporter)
Expand Down Expand Up @@ -93,9 +95,15 @@ const composition = (ViewComponent, ContainerComponent) =>
static propTypes = {};
};
promise.then(result =>
result.veryLongVariable.veryLongPropertyName > someOtherVariable
? "ok"
: "fail"
);
`;

exports[`arrow_call.js - flow-verify 2`] = `
exports[`arrow_call.js - babylon-verify 2`] = `
const testResults = results.testResults.map(testResult =>
formatResult(testResult, formatter, reporter)
);
Expand Down Expand Up @@ -138,6 +146,8 @@ const composition = (ViewComponent, ContainerComponent) =>
class extends React.Component {
static propTypes = {};
};
promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const testResults = results.testResults.map(testResult =>
formatResult(testResult, formatter, reporter),
Expand Down Expand Up @@ -188,9 +198,15 @@ const composition = (ViewComponent, ContainerComponent) =>
static propTypes = {};
};
promise.then(result =>
result.veryLongVariable.veryLongPropertyName > someOtherVariable
? "ok"
: "fail",
);
`;

exports[`arrow_call.js - flow-verify 3`] = `
exports[`arrow_call.js - babylon-verify 3`] = `
const testResults = results.testResults.map(testResult =>
formatResult(testResult, formatter, reporter)
);
Expand Down Expand Up @@ -233,6 +249,8 @@ const composition = (ViewComponent, ContainerComponent) =>
class extends React.Component {
static propTypes = {};
};
promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const testResults = results.testResults.map((testResult) =>
formatResult(testResult, formatter, reporter)
Expand Down Expand Up @@ -283,4 +301,10 @@ const composition = (ViewComponent, ContainerComponent) =>
static propTypes = {};
};
promise.then((result) =>
result.veryLongVariable.veryLongPropertyName > someOtherVariable
? "ok"
: "fail"
);
`;
2 changes: 2 additions & 0 deletions tests/arrow-call/arrow_call.js
Expand Up @@ -40,3 +40,5 @@ const composition = (ViewComponent, ContainerComponent) =>
class extends React.Component {
static propTypes = {};
};

promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
10 changes: 7 additions & 3 deletions tests/arrow-call/jsfmt.spec.js
@@ -1,3 +1,7 @@
run_spec(__dirname, ["flow", "typescript"]);
run_spec(__dirname, ["flow", "typescript"], { trailingComma: "all" });
run_spec(__dirname, ["flow", "typescript"], { arrowParens: "always" });
run_spec(__dirname, ["babylon", "flow", "typescript"]);
run_spec(__dirname, ["babylon", "flow", "typescript"], {
trailingComma: "all"
});
run_spec(__dirname, ["babylon", "flow", "typescript"], {
arrowParens: "always"
});
60 changes: 28 additions & 32 deletions tests/ternaries/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -22,14 +22,13 @@ const funnelSnapshotCard =
) : null;
room = room.map((row, rowIndex) =>
row.map(
(col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
row.map((col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
)
);
Expand Down Expand Up @@ -57,14 +56,13 @@ const funnelSnapshotCard =
) : null;
room = room.map((row, rowIndex) =>
row.map(
(col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
row.map((col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
)
);
Expand Down Expand Up @@ -92,14 +90,13 @@ const funnelSnapshotCard =
) : null;
room = room.map((row, rowIndex) =>
row.map(
(col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
row.map((col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
)
);
Expand Down Expand Up @@ -127,14 +124,13 @@ const funnelSnapshotCard =
) : null;
room = room.map((row, rowIndex) =>
row.map(
(col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
row.map((col, colIndex) =>
rowIndex === 0 ||
colIndex === 0 ||
rowIndex === height ||
colIndex === width
? 1
: 0
)
);
Expand Down

0 comments on commit b5fd382

Please sign in to comment.