diff --git a/src/printer.js b/src/printer.js index 5ab5b641..7919480e 100644 --- a/src/printer.js +++ b/src/printer.js @@ -3723,13 +3723,20 @@ function printMemberChain(path, options, print) { // The first group is the first node followed by // - as many CallExpression as possible // < fn()()() >.something() + // - as many array acessors as possible + // < fn()[0][1][2] >.something() // - then, as many MemberExpression as possible but the last one // < this.items >.something() const groups = []; let currentGroup = [printedNodes[0]]; let i = 1; for (; i < printedNodes.length; ++i) { - if (printedNodes[i].node.type === "CallExpression") { + if ( + printedNodes[i].node.type === "CallExpression" || + (printedNodes[i].node.type === "MemberExpression" && + printedNodes[i].node.computed && + isNumericLiteral(printedNodes[i].node.property)) + ) { currentGroup.push(printedNodes[i]); } else { break; diff --git a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap index 471896e5..29f54015 100644 --- a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap @@ -719,6 +719,10 @@ const version = someLongString .pop() .split(EOL)[0] .trim(); + +const component = find('.org-lclp-edit-copy-url-banner__link')[0] + .getAttribute('href') + .indexOf(this.landingPageLink); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ const version = someLongString .split("jest version =") @@ -726,6 +730,10 @@ const version = someLongString .split(EOL)[0] .trim(); +const component = find(".org-lclp-edit-copy-url-banner__link")[0] + .getAttribute("href") + .indexOf(this.landingPageLink); + `; exports[`test.js 1`] = ` diff --git a/tests/method-chain/square_0.js b/tests/method-chain/square_0.js index 89808dfe..9d87dd9b 100644 --- a/tests/method-chain/square_0.js +++ b/tests/method-chain/square_0.js @@ -3,3 +3,7 @@ const version = someLongString .pop() .split(EOL)[0] .trim(); + +const component = find('.org-lclp-edit-copy-url-banner__link')[0] + .getAttribute('href') + .indexOf(this.landingPageLink);