diff --git a/src/printer.js b/src/printer.js index ca6fea22..893664da 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2106,7 +2106,11 @@ function printMemberChain(path, options, print) { // .d() // .e - // The first group is the first node followed by as many CallExpression as possible + // The first group is the first node followed by + // - as many CallExpression as possible + // < fn()()() >.something() + // - then, as many MemberExpression as possible but the last one + // < this.items >.something() var groups = []; var currentGroup = [printedNodes[0]]; var i = 1; @@ -2117,6 +2121,14 @@ function printMemberChain(path, options, print) { break; } } + for (; i + 1 < printedNodes.length; ++i) { + if (printedNodes[i].node.type === "MemberExpression" && + printedNodes[i + 1].node.type === "MemberExpression") { + currentGroup.push(printedNodes[i]); + } else { + break; + } + } groups.push(currentGroup); currentGroup = []; diff --git a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap index 647e4a01..86427b53 100644 --- a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap @@ -166,3 +166,14 @@ method().then(x => x)[\"abc\"](x => x)[abc](x => x); ({}).a().b(); " `; + +exports[`test this.js 1`] = ` +"const sel = this.connections + .concat(this.activities.concat(this.operators)) + .filter(x => x.selected); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const sel = this.connections + .concat(this.activities.concat(this.operators)) + .filter(x => x.selected); +" +`; diff --git a/tests/method-chain/this.js b/tests/method-chain/this.js new file mode 100644 index 00000000..da7fb1ce --- /dev/null +++ b/tests/method-chain/this.js @@ -0,0 +1,3 @@ +const sel = this.connections + .concat(this.activities.concat(this.operators)) + .filter(x => x.selected);