Flatten function expression parameters in hugged last argument (#9662)
Fixes #3376 This was done for arrow functions in #1305 ("Avoid breaking arguments for last arg expansion"). This PR enables the same for function expressions unless the function expression is the only argument.
This commit is contained in:
1 parent
8046841978
commit
e721ef30ea
4 files changed
+158
-48
No files matched your search
@@ -0,0 +1,29 @@
|
||||
#### Flatten function expression parameters in hugged last argument (#9662 by @thorn0)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
// Prettier stable
|
||||
function* mySagas() {
|
||||
yield effects.takeEvery(rexpress.actionTypes.REQUEST_START, function* ({
|
||||
id
|
||||
}) {
|
||||
console.log(id);
|
||||
yield rexpress.actions(store).writeHead(id, 400);
|
||||
yield rexpress.actions(store).end(id, "pong");
|
||||
console.log("pong");
|
||||
});
|
||||
}
|
||||
|
||||
// Prettier master
|
||||
function* mySagas() {
|
||||
yield effects.takeEvery(
|
||||
rexpress.actionTypes.REQUEST_START,
|
||||
function* ({ id }) {
|
||||
console.log(id);
|
||||
yield rexpress.actions(store).writeHead(id, 400);
|
||||
yield rexpress.actions(store).end(id, "pong");
|
||||
console.log("pong");
|
||||
}
|
||||
);
|
||||
}
|
||||
```
|
||||
@@ -644,7 +644,16 @@ function printPathNoParens(path, options, print, args) {
|
||||
]);
|
||||
case "FunctionDeclaration":
|
||||
case "FunctionExpression":
|
||||
parts.push(printFunctionDeclaration(path, print, options));
|
||||
parts.push(
|
||||
printFunctionDeclaration(
|
||||
path,
|
||||
print,
|
||||
options,
|
||||
args &&
|
||||
args.expandLastArg &&
|
||||
getCallArguments(path.getParentNode()).length > 1
|
||||
)
|
||||
);
|
||||
if (!n.body) {
|
||||
parts.push(semi);
|
||||
}
|
||||
@@ -3736,7 +3745,7 @@ function canPrintParamsWithoutParens(node) {
|
||||
);
|
||||
}
|
||||
|
||||
function printFunctionDeclaration(path, print, options) {
|
||||
function printFunctionDeclaration(path, print, options, expandArg) {
|
||||
const n = path.getValue();
|
||||
const parts = [];
|
||||
|
||||
@@ -3758,7 +3767,7 @@ function printFunctionDeclaration(path, print, options) {
|
||||
printFunctionTypeParameters(path, options, print),
|
||||
group(
|
||||
concat([
|
||||
printFunctionParameters(path, print, options),
|
||||
printFunctionParameters(path, print, options, expandArg),
|
||||
printReturnType(path, print, options),
|
||||
])
|
||||
),
|
||||
|
||||
@@ -186,26 +186,26 @@ a(
|
||||
|
||||
exports.examples = [
|
||||
{
|
||||
render: withGraphQLQuery("node(1234567890){image{uri}}", function (
|
||||
container,
|
||||
data
|
||||
) {
|
||||
return (
|
||||
<div>
|
||||
<InlineBlock>
|
||||
<img
|
||||
src={data[1234567890].image.uri}
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "0",
|
||||
left: "0",
|
||||
zIndex: "-1",
|
||||
}}
|
||||
/>
|
||||
</InlineBlock>
|
||||
</div>
|
||||
);
|
||||
}),
|
||||
render: withGraphQLQuery(
|
||||
"node(1234567890){image{uri}}",
|
||||
function (container, data) {
|
||||
return (
|
||||
<div>
|
||||
<InlineBlock>
|
||||
<img
|
||||
src={data[1234567890].image.uri}
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "0",
|
||||
left: "0",
|
||||
zIndex: "-1",
|
||||
}}
|
||||
/>
|
||||
</InlineBlock>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -217,32 +217,32 @@ someReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReal
|
||||
]
|
||||
);
|
||||
|
||||
(function webpackUniversalModuleDefinition() {})(this, function (
|
||||
__WEBPACK_EXTERNAL_MODULE_85__,
|
||||
__WEBPACK_EXTERNAL_MODULE_115__
|
||||
) {
|
||||
return /******/ (function (modules) {
|
||||
// webpackBootstrap
|
||||
/******/
|
||||
})(
|
||||
/************************************************************************/
|
||||
/******/ [
|
||||
/* 0 */
|
||||
/***/ function (module, exports, __webpack_require__) {
|
||||
/***/
|
||||
},
|
||||
/* 1 */
|
||||
/***/ function (module, exports, __webpack_require__) {
|
||||
/***/
|
||||
},
|
||||
/* 2 */
|
||||
/***/ function (module, exports, __webpack_require__) {
|
||||
/***/
|
||||
},
|
||||
(function webpackUniversalModuleDefinition() {})(
|
||||
this,
|
||||
function (__WEBPACK_EXTERNAL_MODULE_85__, __WEBPACK_EXTERNAL_MODULE_115__) {
|
||||
return /******/ (function (modules) {
|
||||
// webpackBootstrap
|
||||
/******/
|
||||
]
|
||||
);
|
||||
});
|
||||
})(
|
||||
/************************************************************************/
|
||||
/******/ [
|
||||
/* 0 */
|
||||
/***/ function (module, exports, __webpack_require__) {
|
||||
/***/
|
||||
},
|
||||
/* 1 */
|
||||
/***/ function (module, exports, __webpack_require__) {
|
||||
/***/
|
||||
},
|
||||
/* 2 */
|
||||
/***/ function (module, exports, __webpack_require__) {
|
||||
/***/
|
||||
},
|
||||
/******/
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -309,6 +309,58 @@ func(
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`function-expression.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
function* mySagas() {
|
||||
yield effects.takeEvery(
|
||||
rexpress.actionTypes.REQUEST_START,
|
||||
function*({ id }) {
|
||||
console.log(id);
|
||||
yield rexpress.actions(store).writeHead(id, 400);
|
||||
yield rexpress.actions(store).end(id, 'pong');
|
||||
console.log('pong');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function mySagas2() {
|
||||
return effects.takeEvery(
|
||||
rexpress.actionTypes.REQUEST_START,
|
||||
function({ id }) {
|
||||
console.log(id);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
function* mySagas() {
|
||||
yield effects.takeEvery(
|
||||
rexpress.actionTypes.REQUEST_START,
|
||||
function* ({ id }) {
|
||||
console.log(id);
|
||||
yield rexpress.actions(store).writeHead(id, 400);
|
||||
yield rexpress.actions(store).end(id, "pong");
|
||||
console.log("pong");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function mySagas2() {
|
||||
return effects.takeEvery(
|
||||
rexpress.actionTypes.REQUEST_START,
|
||||
function ({ id }) {
|
||||
console.log(id);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`jsx.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow"]
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
function* mySagas() {
|
||||
yield effects.takeEvery(
|
||||
rexpress.actionTypes.REQUEST_START,
|
||||
function*({ id }) {
|
||||
console.log(id);
|
||||
yield rexpress.actions(store).writeHead(id, 400);
|
||||
yield rexpress.actions(store).end(id, 'pong');
|
||||
console.log('pong');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function mySagas2() {
|
||||
return effects.takeEvery(
|
||||
rexpress.actionTypes.REQUEST_START,
|
||||
function({ id }) {
|
||||
console.log(id);
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user