Prevent breaking MemberExpression inside NewExpression (#3075)

* Test case

* Prevent breaking MemberExpression inside NewExpression
This commit is contained in:
Lucas Duailibe authored and Lucas Azzola committed 2017-10-22 10:30:05 +11:00
1 parent 54bdd30595
commit b53a426e15
3 files changed
+38 -2

No files matched your search

+3 -2
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 ||
@@ -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
}
);
}
}
`;
@@ -0,0 +1,10 @@
function functionName() {
// indent to make the line break
if (true) {
this._aVeryLongVariableNameToForceLineBreak = new this.Promise(
(resolve, reject) => {
// do something
}
);
}
}