Make all the member expressions but the last one part of the first group (#589)

Fixes #587
master
Christopher Chedeau 2017-02-03 13:18:54 -08:00 committed by James Long
parent 57ab92ed33
commit e623668183
3 changed files with 27 additions and 1 deletions

View File

@ -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 = [];

View File

@ -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);
"
`;

View File

@ -0,0 +1,3 @@
const sel = this.connections
.concat(this.activities.concat(this.operators))
.filter(x => x.selected);