JavaScript: Keep line breaks when tagged template literal has a single line comment. (#6236)
parent
cfba21f493
commit
74f4d2b3c0
|
@ -195,11 +195,33 @@ Previously, Prettier would incorrectly decode HTML entiites.
|
|||
</p>
|
||||
```
|
||||
|
||||
#### JavaScript: Stop moving comments inside tagged template literals ([#6236] by [@sosukesuzuki])
|
||||
|
||||
Previously, Prettier would move comments after the tag inside the template literal. This version fixes this problem.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
// Input
|
||||
foo //comment
|
||||
`
|
||||
`;
|
||||
|
||||
// Output (Prettier stable)
|
||||
foo` // comment
|
||||
`;
|
||||
|
||||
// Output (Prettier master)
|
||||
foo // comment
|
||||
`
|
||||
`;
|
||||
```
|
||||
|
||||
[#6186]: https://github.com/prettier/prettier/pull/6186
|
||||
[#6206]: https://github.com/prettier/prettier/pull/6206
|
||||
[#6209]: https://github.com/prettier/prettier/pull/6209
|
||||
[#6217]: https://github.com/prettier/prettier/pull/6217
|
||||
[#6234]: https://github.com/prettier/prettier/pull/6234
|
||||
[#6236]: https://github.com/prettier/prettier/pull/6236
|
||||
[@duailibe]: https://github.com/duailibe
|
||||
[@gavinjoyce]: https://github.com/gavinjoyce
|
||||
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
||||
|
|
|
@ -2406,7 +2406,7 @@ function printPathNoParens(path, options, print, args) {
|
|||
);
|
||||
}
|
||||
|
||||
parts.push("`");
|
||||
parts.push(lineSuffixBoundary, "`");
|
||||
|
||||
path.each(childPath => {
|
||||
const i = childPath.getName();
|
||||
|
@ -3914,6 +3914,7 @@ function printJestEachTemplateLiteral(node, expressions, options) {
|
|||
});
|
||||
|
||||
parts.push(
|
||||
lineSuffixBoundary,
|
||||
"`",
|
||||
indent(
|
||||
concat([
|
||||
|
|
|
@ -2012,6 +2012,47 @@ switch (foo) {
|
|||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`tagged-template-literal.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
foo\`\`; // comment
|
||||
|
||||
foo // comment
|
||||
\`\`;
|
||||
|
||||
foo // comment
|
||||
\`
|
||||
\`;
|
||||
|
||||
foo /* comment */\`
|
||||
\`;
|
||||
|
||||
foo /* comment */
|
||||
\`
|
||||
\`;
|
||||
|
||||
=====================================output=====================================
|
||||
foo\`\`; // comment
|
||||
|
||||
foo // comment
|
||||
\`\`;
|
||||
|
||||
foo // comment
|
||||
\`
|
||||
\`;
|
||||
|
||||
foo/* comment */ \`
|
||||
\`;
|
||||
|
||||
foo /* comment */\`
|
||||
\`;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`template-literal.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
foo``; // comment
|
||||
|
||||
foo // comment
|
||||
``;
|
||||
|
||||
foo // comment
|
||||
`
|
||||
`;
|
||||
|
||||
foo /* comment */`
|
||||
`;
|
||||
|
||||
foo /* comment */
|
||||
`
|
||||
`;
|
Loading…
Reference in New Issue