diff --git a/src/printer.js b/src/printer.js index 980be4bf..75779a5e 100644 --- a/src/printer.js +++ b/src/printer.js @@ -3656,7 +3656,8 @@ function printMemberChain(path, options, print) { groups[0].length === 1 && (groups[0][0].node.type === "ThisExpression" || (groups[0][0].node.type === "Identifier" && - groups[0][0].node.name.match(/(^[A-Z])|^[_$]+$/))); + (groups[0][0].node.name.match(/(^[A-Z])|^[_$]+$/) || + (groups[1].length && groups[1][0].node.computed)))); function printGroup(printedGroup) { return concat(printedGroup.map(tuple => tuple.printed)); diff --git a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap index e1b88e5b..85da4ed6 100644 --- a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap @@ -367,6 +367,35 @@ nock(/test/) `; +exports[`computed-merge.js 1`] = ` +[].forEach(key => { + data[key]('foo') + .then(() => console.log('bar')) + .catch(() => console.log('baz')); +}); + +[].forEach(key => { + data('foo') + [key]('bar') + .then(() => console.log('bar')) + .catch(() => console.log('baz')); +}); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[].forEach(key => { + data[key]("foo") + .then(() => console.log("bar")) + .catch(() => console.log("baz")); +}); + +[].forEach(key => { + data("foo") + [key]("bar") + .then(() => console.log("bar")) + .catch(() => console.log("baz")); +}); + +`; + exports[`first_long.js 1`] = ` export default function theFunction(action$, store) { return action$.ofType(THE_ACTION).switchMap(action => Observable diff --git a/tests/method-chain/computed-merge.js b/tests/method-chain/computed-merge.js new file mode 100644 index 00000000..510b9b4d --- /dev/null +++ b/tests/method-chain/computed-merge.js @@ -0,0 +1,12 @@ +[].forEach(key => { + data[key]('foo') + .then(() => console.log('bar')) + .catch(() => console.log('baz')); +}); + +[].forEach(key => { + data('foo') + [key]('bar') + .then(() => console.log('bar')) + .catch(() => console.log('baz')); +});