Improve template literal expresions line breaks (#3124)
parent
4a8d52cf35
commit
38b15f7899
|
@ -1934,13 +1934,19 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
tabWidth
|
tabWidth
|
||||||
);
|
);
|
||||||
|
|
||||||
const aligned = addAlignmentToDoc(
|
let printed = expressions[i];
|
||||||
expressions[i],
|
|
||||||
indentSize,
|
|
||||||
tabWidth
|
|
||||||
);
|
|
||||||
|
|
||||||
parts.push("${", aligned, lineSuffixBoundary, "}");
|
if (
|
||||||
|
n.expressions[i].type === "Identifier" ||
|
||||||
|
n.expressions[i].type === "MemberExpression" ||
|
||||||
|
n.expressions[i].type === "ConditionalExpression"
|
||||||
|
) {
|
||||||
|
printed = concat([indent(concat([softline, printed])), softline]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const aligned = addAlignmentToDoc(printed, indentSize, tabWidth);
|
||||||
|
|
||||||
|
parts.push(group(concat(["${", aligned, lineSuffixBoundary, "}"])));
|
||||||
}
|
}
|
||||||
}, "quasis");
|
}, "quasis");
|
||||||
|
|
||||||
|
|
|
@ -1519,15 +1519,17 @@ d //comment
|
||||||
\`
|
\`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
\`
|
\`
|
||||||
\${a // comment
|
\${
|
||||||
|
a // comment
|
||||||
}
|
}
|
||||||
|
|
||||||
\${b /* comment */}
|
\${b /* comment */}
|
||||||
|
|
||||||
\${/* comment */ c /* comment */}
|
\${/* comment */ c /* comment */}
|
||||||
|
|
||||||
\${// comment
|
\${
|
||||||
d //comment
|
// comment
|
||||||
|
d //comment
|
||||||
};
|
};
|
||||||
\`;
|
\`;
|
||||||
|
|
||||||
|
|
|
@ -480,16 +480,18 @@ this_really_should_split_across_lines = (
|
||||||
unstable_before = (
|
unstable_before = (
|
||||||
<div className="yourScore">
|
<div className="yourScore">
|
||||||
Your score:{" "}
|
Your score:{" "}
|
||||||
<span className="score">{\`\${mini.crosstable.users[sessionUserId]} - \${mini
|
<span className="score">{\`\${mini.crosstable.users[sessionUserId]} - \${
|
||||||
.crosstable.users[user.id]}\`}</span>
|
mini.crosstable.users[user.id]
|
||||||
|
}\`}</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
unstable_after_first_run = (
|
unstable_after_first_run = (
|
||||||
<div className="yourScore">
|
<div className="yourScore">
|
||||||
Your score:{" "}
|
Your score:{" "}
|
||||||
<span className="score">{\`\${mini.crosstable.users[sessionUserId]} - \${mini
|
<span className="score">{\`\${mini.crosstable.users[sessionUserId]} - \${
|
||||||
.crosstable.users[user.id]}\`}</span>
|
mini.crosstable.users[user.id]
|
||||||
|
}\`}</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -29,15 +29,17 @@ ExampleStory.getFragment('story')}
|
||||||
\`\${a + a // a
|
\`\${a + a // a
|
||||||
}
|
}
|
||||||
|
|
||||||
\${a // comment
|
\${
|
||||||
|
a // comment
|
||||||
}
|
}
|
||||||
|
|
||||||
\${b /* comment */}
|
\${b /* comment */}
|
||||||
|
|
||||||
\${/* comment */ c /* comment */}
|
\${/* comment */ c /* comment */}
|
||||||
|
|
||||||
\${// comment
|
\${
|
||||||
d //comment
|
// comment
|
||||||
|
d //comment
|
||||||
}
|
}
|
||||||
|
|
||||||
\${// $FlowFixMe found when converting React.createClass to ES6
|
\${// $FlowFixMe found when converting React.createClass to ES6
|
||||||
|
|
|
@ -63,17 +63,19 @@ g
|
||||||
}\`;
|
}\`;
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
\`
|
\`
|
||||||
(?:\${escapeChar}[\\\\S\\\\s]|(?:(?!\${// Using \`XRegExp.union\` safely rewrites backreferences in \`left\` and \`right\`.
|
(?:\${escapeChar}[\\\\S\\\\s]|(?:(?!\${
|
||||||
// Intentionally not passing \`basicFlags\` to \`XRegExp.union\` since any syntax
|
// Using \`XRegExp.union\` safely rewrites backreferences in \`left\` and \`right\`.
|
||||||
// transformation resulting from those flags was already applied to \`left\` and
|
// Intentionally not passing \`basicFlags\` to \`XRegExp.union\` since any syntax
|
||||||
// \`right\` when they were passed through the XRegExp constructor above.
|
// transformation resulting from those flags was already applied to \`left\` and
|
||||||
XRegExp.union([left, right], "", { conjunction: "or" })
|
// \`right\` when they were passed through the XRegExp constructor above.
|
||||||
.source})[^\${escapeChar}])+)+
|
XRegExp.union([left, right], "", { conjunction: "or" }).source
|
||||||
|
})[^\${escapeChar}])+)+
|
||||||
\`;
|
\`;
|
||||||
|
|
||||||
\`a\${/* b */ c /* d */}e\${// f
|
\`a\${/* b */ c /* d */}e\${
|
||||||
g
|
// f
|
||||||
// h
|
g
|
||||||
|
// h
|
||||||
}\`;
|
}\`;
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -1,5 +1,101 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`expressions.js 1`] = `
|
||||||
|
const long = \`long \${a//comment
|
||||||
|
.b} long longlong \${a.b.c.d.e} long longlong \${a.b.c.d.e} long longlong \${a.b.c.d.e} long long\`;
|
||||||
|
const long = \`long \${a.b.c.d.e} long longlong \${loooooooooooooooooong} long longlong \${loooooooooooooooooong} long longlong \${loooooooooooooooooong} long long\`;
|
||||||
|
|
||||||
|
const long = \`long long long long long long long long long long long \${a.b.c.d.e} long long long long long long long long long long long long long\`;
|
||||||
|
|
||||||
|
const description =
|
||||||
|
\`The value of the \${cssName} css of the \${this._name} element\`;
|
||||||
|
|
||||||
|
const foo = \`such a long template string \${foo.bar.baz} that prettier will want to wrap it\`;
|
||||||
|
|
||||||
|
|
||||||
|
x = \`mdl-textfield mdl-js-textfield \${className} \${content.length > 0
|
||||||
|
? 'is-dirty'
|
||||||
|
: ''} combo-box__input\`
|
||||||
|
|
||||||
|
function testing() {
|
||||||
|
const p = {};
|
||||||
|
// faking some tabs since I can't paste my real code in
|
||||||
|
if(true) {
|
||||||
|
if(false) {
|
||||||
|
return \`\${process.env.OPENID_URL}/something/something/something?\${Object.keys(p)
|
||||||
|
.map(k => \`\${encodeURIComponent(k)}=\${encodeURIComponent(p[k])}\`)
|
||||||
|
.join("&")}\`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
\`Trying update appcast for \${app.name} (\${app.cask.appcast}) -> (\${app.cask.appcastGenerated})\`
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(\`brew cask audit --download \${_.map(definitions, 'caskName').join(' ')}\`)
|
||||||
|
|
||||||
|
console.log(\`\\nApparently jetbrains changed the release artifact for \${app.name}@\${app.jetbrains.version}.\\n\`);
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
const long = \`long \${
|
||||||
|
a.b //comment
|
||||||
|
} long longlong \${a.b.c.d.e} long longlong \${a.b.c.d.e} long longlong \${
|
||||||
|
a.b.c.d.e
|
||||||
|
} long long\`;
|
||||||
|
const long = \`long \${a.b.c.d.e} long longlong \${
|
||||||
|
loooooooooooooooooong
|
||||||
|
} long longlong \${loooooooooooooooooong} long longlong \${
|
||||||
|
loooooooooooooooooong
|
||||||
|
} long long\`;
|
||||||
|
|
||||||
|
const long = \`long long long long long long long long long long long \${
|
||||||
|
a.b.c.d.e
|
||||||
|
} long long long long long long long long long long long long long\`;
|
||||||
|
|
||||||
|
const description = \`The value of the \${cssName} css of the \${
|
||||||
|
this._name
|
||||||
|
} element\`;
|
||||||
|
|
||||||
|
const foo = \`such a long template string \${
|
||||||
|
foo.bar.baz
|
||||||
|
} that prettier will want to wrap it\`;
|
||||||
|
|
||||||
|
x = \`mdl-textfield mdl-js-textfield \${className} \${
|
||||||
|
content.length > 0 ? "is-dirty" : ""
|
||||||
|
} combo-box__input\`;
|
||||||
|
|
||||||
|
function testing() {
|
||||||
|
const p = {};
|
||||||
|
// faking some tabs since I can't paste my real code in
|
||||||
|
if (true) {
|
||||||
|
if (false) {
|
||||||
|
return \`\${
|
||||||
|
process.env.OPENID_URL
|
||||||
|
}/something/something/something?\${Object.keys(p)
|
||||||
|
.map(k => \`\${encodeURIComponent(k)}=\${encodeURIComponent(p[k])}\`)
|
||||||
|
.join("&")}\`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
\`Trying update appcast for \${app.name} (\${app.cask.appcast}) -> (\${
|
||||||
|
app.cask.appcastGenerated
|
||||||
|
})\`
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
\`brew cask audit --download \${_.map(definitions, "caskName").join(" ")}\`
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
\`\\nApparently jetbrains changed the release artifact for \${app.name}@\${
|
||||||
|
app.jetbrains.version
|
||||||
|
}.\\n\`
|
||||||
|
);
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`styled-components-with-expressions.js 1`] = `
|
exports[`styled-components-with-expressions.js 1`] = `
|
||||||
const Button = styled.a\`
|
const Button = styled.a\`
|
||||||
/* Comment */
|
/* Comment */
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
const long = `long ${a//comment
|
||||||
|
.b} long longlong ${a.b.c.d.e} long longlong ${a.b.c.d.e} long longlong ${a.b.c.d.e} long long`;
|
||||||
|
const long = `long ${a.b.c.d.e} long longlong ${loooooooooooooooooong} long longlong ${loooooooooooooooooong} long longlong ${loooooooooooooooooong} long long`;
|
||||||
|
|
||||||
|
const long = `long long long long long long long long long long long ${a.b.c.d.e} long long long long long long long long long long long long long`;
|
||||||
|
|
||||||
|
const description =
|
||||||
|
`The value of the ${cssName} css of the ${this._name} element`;
|
||||||
|
|
||||||
|
const foo = `such a long template string ${foo.bar.baz} that prettier will want to wrap it`;
|
||||||
|
|
||||||
|
|
||||||
|
x = `mdl-textfield mdl-js-textfield ${className} ${content.length > 0
|
||||||
|
? 'is-dirty'
|
||||||
|
: ''} combo-box__input`
|
||||||
|
|
||||||
|
function testing() {
|
||||||
|
const p = {};
|
||||||
|
// faking some tabs since I can't paste my real code in
|
||||||
|
if(true) {
|
||||||
|
if(false) {
|
||||||
|
return `${process.env.OPENID_URL}/something/something/something?${Object.keys(p)
|
||||||
|
.map(k => `${encodeURIComponent(k)}=${encodeURIComponent(p[k])}`)
|
||||||
|
.join("&")}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Trying update appcast for ${app.name} (${app.cask.appcast}) -> (${app.cask.appcastGenerated})`
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(`brew cask audit --download ${_.map(definitions, 'caskName').join(' ')}`)
|
||||||
|
|
||||||
|
console.log(`\nApparently jetbrains changed the release artifact for ${app.name}@${app.jetbrains.version}.\n`);
|
Loading…
Reference in New Issue