Prevent breaking MemberExpression inside NewExpression (#3075)

* Test case

* Prevent breaking MemberExpression inside NewExpression
master
Lucas Duailibe 2017-10-21 21:30:05 -02:00 committed by Lucas Azzola
parent 54bdd30595
commit b53a426e15
3 changed files with 38 additions and 2 deletions

View File

@ -418,8 +418,9 @@ function genericPrintNoParens(path, options, print, args) {
const shouldInline =
(firstNonMemberParent &&
((firstNonMemberParent.type === "VariableDeclarator" &&
firstNonMemberParent.id.type !== "Identifier") ||
(firstNonMemberParent.type === "NewExpression" ||
(firstNonMemberParent.type === "VariableDeclarator" &&
firstNonMemberParent.id.type !== "Identifier") ||
(firstNonMemberParent.type === "AssignmentExpression" &&
firstNonMemberParent.left.type !== "Identifier"))) ||
n.computed ||

View File

@ -23,3 +23,28 @@ new (typeof this == "function" ? this : Dict())();
new (createObj()).prop(a());
`;
exports[`with-member-expression.js 1`] = `
function functionName() {
// indent to make the line break
if (true) {
this._aVeryLongVariableNameToForceLineBreak = new this.Promise(
(resolve, reject) => {
// do something
}
);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function functionName() {
// indent to make the line break
if (true) {
this._aVeryLongVariableNameToForceLineBreak = new this.Promise(
(resolve, reject) => {
// do something
}
);
}
}
`;

View File

@ -0,0 +1,10 @@
function functionName() {
// indent to make the line break
if (true) {
this._aVeryLongVariableNameToForceLineBreak = new this.Promise(
(resolve, reject) => {
// do something
}
);
}
}