Add support for currying (#1066)

If you write your code in a functional way where you have an arrow function for each argument, it looks better for them to be inline. I can't imagine any case where it would be used in a different way if we limit to a single argument.

Fixes #1065
master
Christopher Chedeau 2017-03-22 13:33:28 -07:00 committed by GitHub
parent dd792a2b22
commit 60816af4ce
3 changed files with 40 additions and 1 deletions

View File

@ -317,7 +317,8 @@ function genericPrintNoParens(path, options, print) {
n.body.type === "BlockStatement" ||
n.body.type === "TaggedTemplateExpression" ||
n.body.type === "TemplateElement" ||
n.body.type === "ClassExpression"
n.body.type === "ClassExpression" ||
n.body.type === "ArrowFunctionExpression"
) {
return group(collapsed);
}

View File

@ -231,6 +231,33 @@ jest.mock(
"
`;
exports[`currying.js 1`] = `
"const fn = b => c => d => {
return 3;
};
const mw = store => next => action => {
return next(action)
}
const middleware = options => (req, res, next) => {
// ...
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const fn = b => c => d => {
return 3;
};
const mw = store => next => action => {
return next(action);
};
const middleware = options => (req, res, next) => {
// ...
};
"
`;
exports[`long-call-no-args.js 1`] = `
"veryLongCall(VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_LONG_CONSTANT, () => {})
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

11
tests/arrows/currying.js Normal file
View File

@ -0,0 +1,11 @@
const fn = b => c => d => {
return 3;
};
const mw = store => next => action => {
return next(action)
}
const middleware = options => (req, res, next) => {
// ...
};