diff --git a/src/printer.js b/src/printer.js index f9327f6a..c61ccf38 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2287,6 +2287,13 @@ function printMemberChain(path, options, print) { if ( hasSeenCallExpression && printedNodes[i].node.type === "MemberExpression" ) { + // [0] should be appended at the end of the group instead of the + // beginning of the next one + if (printedNodes[i].node.computed) { + currentGroup.push(printedNodes[i]); + continue; + } + groups.push(currentGroup); currentGroup = []; hasSeenCallExpression = false; diff --git a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap index 58f38770..604d125a 100644 --- a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap @@ -242,6 +242,21 @@ if (testConfig.ENABLE_ONLINE_TESTS === \\"true\\") { " `; +exports[`square_0.js 1`] = ` +"const version = someLongString + .split('jest version =') + .pop() + .split(EOL)[0] + .trim(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const version = someLongString + .split(\\"jest version =\\") + .pop() + .split(EOL)[0] + .trim(); +" +`; + exports[`test.js 1`] = ` "method().then(x => x) [\\"abc\\"](x => x) diff --git a/tests/method-chain/square_0.js b/tests/method-chain/square_0.js new file mode 100644 index 00000000..89808dfe --- /dev/null +++ b/tests/method-chain/square_0.js @@ -0,0 +1,5 @@ +const version = someLongString + .split('jest version =') + .pop() + .split(EOL)[0] + .trim();