Merge computed MemberExpression in member chain (#2670)

master
Lucas Azzola 2017-08-26 22:35:05 +10:00 committed by Christopher Chedeau
parent ab812e2db9
commit dd84559991
3 changed files with 43 additions and 1 deletions

View File

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

View File

@ -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

View File

@ -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'));
});