Support inline template for new calls (#2222)
I merged the implementation of new and call expressions in this PR. Fixes #2215
This commit is contained in:
1 parent
63c47c85e0
commit
aac0d1dda0
3 files changed
+25
-15
No files matched your search
+10
-15
@@ -801,16 +801,21 @@ function genericPrintNoParens(path, options, print, args) {
|
||||
parts.push(semi);
|
||||
|
||||
return concat(parts);
|
||||
case "NewExpression":
|
||||
case "CallExpression": {
|
||||
const isNew = n.type === "NewExpression";
|
||||
if (
|
||||
// We want to keep require calls as a unit
|
||||
(n.callee.type === "Identifier" && n.callee.name === "require") ||
|
||||
(!isNew &&
|
||||
n.callee.type === "Identifier" &&
|
||||
n.callee.name === "require") ||
|
||||
// Template literals as single arguments
|
||||
(n.arguments.length === 1 &&
|
||||
isTemplateOnItsOwnLine(n.arguments[0], options.originalText)) ||
|
||||
// Keep test declarations on a single line
|
||||
// e.g. `it('long name', () => {`
|
||||
(n.callee.type === "Identifier" &&
|
||||
(!isNew &&
|
||||
n.callee.type === "Identifier" &&
|
||||
(n.callee.name === "it" ||
|
||||
n.callee.name === "test" ||
|
||||
n.callee.name === "describe") &&
|
||||
@@ -824,6 +829,7 @@ function genericPrintNoParens(path, options, print, args) {
|
||||
n.arguments[1].params.length <= 1)
|
||||
) {
|
||||
return concat([
|
||||
isNew ? "new " : "",
|
||||
path.call(print, "callee"),
|
||||
path.call(print, "typeParameters"),
|
||||
concat(["(", join(", ", path.map(print, "arguments")), ")"])
|
||||
@@ -832,11 +838,12 @@ function genericPrintNoParens(path, options, print, args) {
|
||||
|
||||
// We detect calls on member lookups and possibly print them in a
|
||||
// special chain format. See `printMemberChain` for more info.
|
||||
if (n.callee.type === "MemberExpression") {
|
||||
if (!isNew && n.callee.type === "MemberExpression") {
|
||||
return printMemberChain(path, options, print);
|
||||
}
|
||||
|
||||
return concat([
|
||||
isNew ? "new " : "",
|
||||
path.call(print, "callee"),
|
||||
printFunctionTypeParameters(path, options, print),
|
||||
printArgumentsList(path, options, print)
|
||||
@@ -1216,18 +1223,6 @@ function genericPrintNoParens(path, options, print, args) {
|
||||
])
|
||||
);
|
||||
}
|
||||
case "NewExpression":
|
||||
parts.push(
|
||||
"new ",
|
||||
path.call(print, "callee"),
|
||||
printFunctionTypeParameters(path, options, print)
|
||||
);
|
||||
|
||||
if (n.arguments) {
|
||||
parts.push(printArgumentsList(path, options, print));
|
||||
}
|
||||
|
||||
return concat(parts);
|
||||
case "VariableDeclaration": {
|
||||
const printed = path.map(childPath => {
|
||||
return print(childPath);
|
||||
|
||||
@@ -27,6 +27,11 @@ insertRule(\`*, *:before, *:after {
|
||||
insertRule\`*, *:before, *:after {
|
||||
box-sizing: inherit;
|
||||
}\`;
|
||||
|
||||
new Error(formatErrorMessage\`
|
||||
This a really bad error.
|
||||
Which has more than one line.
|
||||
\`);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
insertRule(\`*, *:before, *:after {
|
||||
box-sizing: inherit;
|
||||
@@ -36,6 +41,11 @@ insertRule\`*, *:before, *:after {
|
||||
box-sizing: inherit;
|
||||
}\`;
|
||||
|
||||
new Error(formatErrorMessage\`
|
||||
This a really bad error.
|
||||
Which has more than one line.
|
||||
\`);
|
||||
|
||||
`;
|
||||
|
||||
exports[`comment.js 1`] = `
|
||||
|
||||
@@ -5,3 +5,8 @@ insertRule(`*, *:before, *:after {
|
||||
insertRule`*, *:before, *:after {
|
||||
box-sizing: inherit;
|
||||
}`;
|
||||
|
||||
new Error(formatErrorMessage`
|
||||
This a really bad error.
|
||||
Which has more than one line.
|
||||
`);
|
||||
Reference in new issue
Block a user