Don't removeLines() from TemplateLiteral quasis (#1664)
* Add tests for newlines in template literals These are related to the following issues: * https://github.com/prettier/prettier/issues/1662 * https://github.com/prettier/prettier/issues/821 * https://github.com/prettier/prettier/issues/1183 * https://github.com/prettier/prettier/issues/1626 * Don't removeLines() from TemplateLiteral quasis This fixes https://github.com/prettier/prettier/issues/1662 and fixes https://github.com/prettier/prettier/issues/1626 It also affects https://github.com/prettier/prettier/issues/821 and https://github.com/prettier/prettier/issues/1183master
parent
aeed7840e2
commit
374a68201c
|
@ -1672,11 +1672,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
size = util.getAlignmentSize(value, tabWidth, index + 1);
|
||||
}
|
||||
|
||||
const aligned = addAlignmentToDoc(
|
||||
removeLines(expressions[i]),
|
||||
size,
|
||||
tabWidth
|
||||
);
|
||||
const aligned = addAlignmentToDoc(expressions[i], size, tabWidth);
|
||||
|
||||
parts.push("${", aligned, lineSuffixBoundary, "}");
|
||||
}
|
||||
|
|
|
@ -122,27 +122,176 @@ foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( functi
|
|||
pipe.write(
|
||||
\`\\n \${chalk.dim(\`\\u203A and \${more} more \${more} more \${more} more \${more}\`)}\`,
|
||||
);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1662#issue-230406820
|
||||
const content = \`
|
||||
const env = \${ JSON.stringify({
|
||||
assetsRootUrl: env.assetsRootUrl,
|
||||
env: env.env,
|
||||
role: "client",
|
||||
adsfafa: "sdfsdff",
|
||||
asdfasff: "wefwefw",
|
||||
fefef: "sf sdfs fdsfdsf s dfsfds"
|
||||
}, null, "\\t") });
|
||||
\`;
|
||||
|
||||
// https://github.com/prettier/prettier/issues/821#issue-210557749
|
||||
f(\`\${{
|
||||
a: 4,
|
||||
b: 9,
|
||||
}}\`);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1183#issue-220863505
|
||||
const makeBody = (store, assets, html) =>
|
||||
\`<!doctype html>\${
|
||||
ReactDOMServer.renderToStaticMarkup(
|
||||
<Html
|
||||
headScripts={compact([ assets.javascript.head ])}
|
||||
headStyles={compact([ assets.styles.body, assets.styles.head ])}
|
||||
bodyScripts={compact([ assets.javascript.body ])}
|
||||
bodyStyles={[]}
|
||||
stringScripts={[
|
||||
\`window.__INITIAL_STATE__ = \${
|
||||
JSON.stringify(store.getState(), null, 2)
|
||||
};\`,
|
||||
]}
|
||||
content={[
|
||||
{ id: 'app-container', dangerouslySetInnerHTML: { __html: html } },
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}\`
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1626#issue-229655106
|
||||
const Bar = styled.div\`
|
||||
color: \${props => (props.highlight.length > 0 ? palette(['text', 'dark', 'tertiary'])(props) : palette(['text', 'dark', 'primary'])(props))} !important;
|
||||
\`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
foo(
|
||||
\`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3} with expr\`
|
||||
\`a long string \${1 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3} with expr\`
|
||||
);
|
||||
|
||||
const x = \`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + (function() {
|
||||
const x = \`a long string \${1 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
(function() {
|
||||
return 3;
|
||||
})() + 3 + 2 + 3 + 2 + 3} with expr\`;
|
||||
})() +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3} with expr\`;
|
||||
|
||||
foo(
|
||||
\`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + (function() {
|
||||
\`a long string \${1 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
(function() {
|
||||
const x = 5;
|
||||
|
||||
return x;
|
||||
})() + 3 + 2 + 3 + 2 + 3} with expr\`
|
||||
})() +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3} with expr\`
|
||||
);
|
||||
|
||||
pipe.write(
|
||||
\`\\n \${chalk.dim(\`\\u203A and \${more} more \${more} more \${more} more \${more}\`)}\`
|
||||
\`\\n \${chalk.dim(
|
||||
\`\\u203A and \${more} more \${more} more \${more} more \${more}\`
|
||||
)}\`
|
||||
);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1662#issue-230406820
|
||||
const content = \`
|
||||
const env = \${JSON.stringify(
|
||||
{
|
||||
assetsRootUrl: env.assetsRootUrl,
|
||||
env: env.env,
|
||||
role: "client",
|
||||
adsfafa: "sdfsdff",
|
||||
asdfasff: "wefwefw",
|
||||
fefef: "sf sdfs fdsfdsf s dfsfds"
|
||||
},
|
||||
null,
|
||||
"\\t"
|
||||
)});
|
||||
\`;
|
||||
|
||||
// https://github.com/prettier/prettier/issues/821#issue-210557749
|
||||
f(
|
||||
\`\${{
|
||||
a: 4,
|
||||
b: 9
|
||||
}}\`
|
||||
);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1183#issue-220863505
|
||||
const makeBody = (store, assets, html) =>
|
||||
\`<!doctype html>\${ReactDOMServer.renderToStaticMarkup(
|
||||
<Html
|
||||
headScripts={compact([assets.javascript.head])}
|
||||
headStyles={compact([assets.styles.body, assets.styles.head])}
|
||||
bodyScripts={compact([assets.javascript.body])}
|
||||
bodyStyles={[]}
|
||||
stringScripts={[
|
||||
\`window.__INITIAL_STATE__ = \${JSON.stringify(
|
||||
store.getState(),
|
||||
null,
|
||||
2
|
||||
)};\`
|
||||
]}
|
||||
content={[
|
||||
{ id: "app-container", dangerouslySetInnerHTML: { __html: html } }
|
||||
]}
|
||||
/>
|
||||
)}\`;
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1626#issue-229655106
|
||||
const Bar = styled.div\`
|
||||
color: \${props =>
|
||||
props.highlight.length > 0
|
||||
? palette(["text", "dark", "tertiary"])(props)
|
||||
: palette(["text", "dark", "primary"])(props)} !important;
|
||||
\`;
|
||||
|
||||
`;
|
||||
|
||||
exports[`template-literals.js 2`] = `
|
||||
|
@ -159,25 +308,174 @@ foo(\`a long string \${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( functi
|
|||
pipe.write(
|
||||
\`\\n \${chalk.dim(\`\\u203A and \${more} more \${more} more \${more} more \${more}\`)}\`,
|
||||
);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1662#issue-230406820
|
||||
const content = \`
|
||||
const env = \${ JSON.stringify({
|
||||
assetsRootUrl: env.assetsRootUrl,
|
||||
env: env.env,
|
||||
role: "client",
|
||||
adsfafa: "sdfsdff",
|
||||
asdfasff: "wefwefw",
|
||||
fefef: "sf sdfs fdsfdsf s dfsfds"
|
||||
}, null, "\\t") });
|
||||
\`;
|
||||
|
||||
// https://github.com/prettier/prettier/issues/821#issue-210557749
|
||||
f(\`\${{
|
||||
a: 4,
|
||||
b: 9,
|
||||
}}\`);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1183#issue-220863505
|
||||
const makeBody = (store, assets, html) =>
|
||||
\`<!doctype html>\${
|
||||
ReactDOMServer.renderToStaticMarkup(
|
||||
<Html
|
||||
headScripts={compact([ assets.javascript.head ])}
|
||||
headStyles={compact([ assets.styles.body, assets.styles.head ])}
|
||||
bodyScripts={compact([ assets.javascript.body ])}
|
||||
bodyStyles={[]}
|
||||
stringScripts={[
|
||||
\`window.__INITIAL_STATE__ = \${
|
||||
JSON.stringify(store.getState(), null, 2)
|
||||
};\`,
|
||||
]}
|
||||
content={[
|
||||
{ id: 'app-container', dangerouslySetInnerHTML: { __html: html } },
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}\`
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1626#issue-229655106
|
||||
const Bar = styled.div\`
|
||||
color: \${props => (props.highlight.length > 0 ? palette(['text', 'dark', 'tertiary'])(props) : palette(['text', 'dark', 'primary'])(props))} !important;
|
||||
\`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
foo(
|
||||
\`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3} with expr\`,
|
||||
\`a long string \${1 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3} with expr\`,
|
||||
);
|
||||
|
||||
const x = \`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + (function() {
|
||||
const x = \`a long string \${1 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
(function() {
|
||||
return 3;
|
||||
})() + 3 + 2 + 3 + 2 + 3} with expr\`;
|
||||
})() +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3} with expr\`;
|
||||
|
||||
foo(
|
||||
\`a long string \${1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + (function() {
|
||||
\`a long string \${1 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
(function() {
|
||||
const x = 5;
|
||||
|
||||
return x;
|
||||
})() + 3 + 2 + 3 + 2 + 3} with expr\`,
|
||||
})() +
|
||||
3 +
|
||||
2 +
|
||||
3 +
|
||||
2 +
|
||||
3} with expr\`,
|
||||
);
|
||||
|
||||
pipe.write(
|
||||
\`\\n \${chalk.dim(\`\\u203A and \${more} more \${more} more \${more} more \${more}\`)}\`,
|
||||
\`\\n \${chalk.dim(
|
||||
\`\\u203A and \${more} more \${more} more \${more} more \${more}\`,
|
||||
)}\`,
|
||||
);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1662#issue-230406820
|
||||
const content = \`
|
||||
const env = \${JSON.stringify(
|
||||
{
|
||||
assetsRootUrl: env.assetsRootUrl,
|
||||
env: env.env,
|
||||
role: "client",
|
||||
adsfafa: "sdfsdff",
|
||||
asdfasff: "wefwefw",
|
||||
fefef: "sf sdfs fdsfdsf s dfsfds",
|
||||
},
|
||||
null,
|
||||
"\\t",
|
||||
)});
|
||||
\`;
|
||||
|
||||
// https://github.com/prettier/prettier/issues/821#issue-210557749
|
||||
f(
|
||||
\`\${{
|
||||
a: 4,
|
||||
b: 9,
|
||||
}}\`,
|
||||
);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1183#issue-220863505
|
||||
const makeBody = (store, assets, html) =>
|
||||
\`<!doctype html>\${ReactDOMServer.renderToStaticMarkup(
|
||||
<Html
|
||||
headScripts={compact([assets.javascript.head])}
|
||||
headStyles={compact([assets.styles.body, assets.styles.head])}
|
||||
bodyScripts={compact([assets.javascript.body])}
|
||||
bodyStyles={[]}
|
||||
stringScripts={[
|
||||
\`window.__INITIAL_STATE__ = \${JSON.stringify(
|
||||
store.getState(),
|
||||
null,
|
||||
2,
|
||||
)};\`,
|
||||
]}
|
||||
content={[
|
||||
{ id: "app-container", dangerouslySetInnerHTML: { __html: html } },
|
||||
]}
|
||||
/>,
|
||||
)}\`;
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1626#issue-229655106
|
||||
const Bar = styled.div\`
|
||||
color: \${props =>
|
||||
props.highlight.length > 0
|
||||
? palette(["text", "dark", "tertiary"])(props)
|
||||
: palette(["text", "dark", "primary"])(props)} !important;
|
||||
\`;
|
||||
|
||||
`;
|
||||
|
|
|
@ -11,3 +11,47 @@ foo(`a long string ${ 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + ( function
|
|||
pipe.write(
|
||||
`\n ${chalk.dim(`\u203A and ${more} more ${more} more ${more} more ${more}`)}`,
|
||||
);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1662#issue-230406820
|
||||
const content = `
|
||||
const env = ${ JSON.stringify({
|
||||
assetsRootUrl: env.assetsRootUrl,
|
||||
env: env.env,
|
||||
role: "client",
|
||||
adsfafa: "sdfsdff",
|
||||
asdfasff: "wefwefw",
|
||||
fefef: "sf sdfs fdsfdsf s dfsfds"
|
||||
}, null, "\t") });
|
||||
`;
|
||||
|
||||
// https://github.com/prettier/prettier/issues/821#issue-210557749
|
||||
f(`${{
|
||||
a: 4,
|
||||
b: 9,
|
||||
}}`);
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1183#issue-220863505
|
||||
const makeBody = (store, assets, html) =>
|
||||
`<!doctype html>${
|
||||
ReactDOMServer.renderToStaticMarkup(
|
||||
<Html
|
||||
headScripts={compact([ assets.javascript.head ])}
|
||||
headStyles={compact([ assets.styles.body, assets.styles.head ])}
|
||||
bodyScripts={compact([ assets.javascript.body ])}
|
||||
bodyStyles={[]}
|
||||
stringScripts={[
|
||||
`window.__INITIAL_STATE__ = ${
|
||||
JSON.stringify(store.getState(), null, 2)
|
||||
};`,
|
||||
]}
|
||||
content={[
|
||||
{ id: 'app-container', dangerouslySetInnerHTML: { __html: html } },
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}`
|
||||
|
||||
// https://github.com/prettier/prettier/issues/1626#issue-229655106
|
||||
const Bar = styled.div`
|
||||
color: ${props => (props.highlight.length > 0 ? palette(['text', 'dark', 'tertiary'])(props) : palette(['text', 'dark', 'primary'])(props))} !important;
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue