From cde322bff8b5edac041a8e1ca8f81541be2d29d1 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 26 Jan 2017 14:24:50 -0800 Subject: [PATCH] Add CallExpression to the last argument expansion whitelist (#470) Fixes #274 --- src/printer.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 38 +++++++++++++++++++ tests/last_argument_expansion/arrow.js | 15 ++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/last_argument_expansion/arrow.js diff --git a/src/printer.js b/src/printer.js index 2d39ab7db..becef22a8 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1748,6 +1748,7 @@ function printArgumentsList(path, options, print) { lastArg.body.type === "ArrowFunctionExpression" || lastArg.body.type === "ObjectExpression" || lastArg.body.type === "ArrayExpression" || + lastArg.body.type === "CallExpression" || lastArg.body.type === "JSXElement") || lastArg.type === "NewExpression"; diff --git a/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap b/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap index 0304387da..3359789c6 100644 --- a/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap +++ b/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap @@ -1,3 +1,41 @@ +exports[`test arrow.js 1`] = ` +"export default function searchUsers(action$) { + return action$.ofType(ActionTypes.SEARCHED_USERS) + .map(action => action.payload.query) + .filter(q => !!q) + .switchMap(q => + Observable.timer(800) // debounce + .takeUntil(action$.ofType(ActionTypes.CLEARED_SEARCH_RESULTS)) + .mergeMap(() => Observable.merge( + Observable.of(replace(\`?q=\${q}\`)), + ajax.getJSON(\`https://api.github.com/search/users?q=\${q}\`) + .map(res => res.items) + .map(receiveUsers) + )) + ); +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export default function searchUsers(action$) { + return action$ + .ofType(ActionTypes.SEARCHED_USERS) + .map(action => action.payload.query) + .filter(q => !!q) + .switchMap(q => + Observable + .timer(800) + .takeUntil(action$.ofType(ActionTypes.CLEARED_SEARCH_RESULTS)) + .mergeMap(() => + Observable.merge( + Observable.of(replace(\`?q=\${q}\`)), + ajax + .getJSON(\`https://api.github.com/search/users?q=\${q}\`) + .map(res => res.items) + .map(receiveUsers) + ))); +} +" +`; + exports[`test jsx.js 1`] = ` "const els = items.map(item => (
diff --git a/tests/last_argument_expansion/arrow.js b/tests/last_argument_expansion/arrow.js new file mode 100644 index 000000000..faa21f628 --- /dev/null +++ b/tests/last_argument_expansion/arrow.js @@ -0,0 +1,15 @@ +export default function searchUsers(action$) { + return action$.ofType(ActionTypes.SEARCHED_USERS) + .map(action => action.payload.query) + .filter(q => !!q) + .switchMap(q => + Observable.timer(800) // debounce + .takeUntil(action$.ofType(ActionTypes.CLEARED_SEARCH_RESULTS)) + .mergeMap(() => Observable.merge( + Observable.of(replace(`?q=${q}`)), + ajax.getJSON(`https://api.github.com/search/users?q=${q}`) + .map(res => res.items) + .map(receiveUsers) + )) + ); +};