fix(HTML, Vue): don't break the template element included in a line shorter than print-width (#6284)
parent
38450587fe
commit
d66c5f82da
|
@ -315,6 +315,30 @@ This version updates the TypeScript parser to correctly handle JSX text with dou
|
||||||
|
|
||||||
Flag used with `--write` to avoid re-checking files that were not changed since they were last written (with the same formatting configuration).
|
Flag used with `--write` to avoid re-checking files that were not changed since they were last written (with the same formatting configuration).
|
||||||
|
|
||||||
|
#### HTML, Vue: Don't break the template element included in a line shorter than print-width([#6284] by [@sosukesuzuki])
|
||||||
|
|
||||||
|
Previously, even if the line length is shorter than print-width is Prettier breaks the line with a template element.
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```html
|
||||||
|
// Input
|
||||||
|
<template>
|
||||||
|
<template>foo</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
// Output (Prettier stable)
|
||||||
|
<template>
|
||||||
|
<template
|
||||||
|
>foo</template
|
||||||
|
>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
// Output (Prettier master)
|
||||||
|
<template>
|
||||||
|
<template>foo</template>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
[#5910]: https://github.com/prettier/prettier/pull/5910
|
[#5910]: https://github.com/prettier/prettier/pull/5910
|
||||||
[#6186]: https://github.com/prettier/prettier/pull/6186
|
[#6186]: https://github.com/prettier/prettier/pull/6186
|
||||||
[#6206]: https://github.com/prettier/prettier/pull/6206
|
[#6206]: https://github.com/prettier/prettier/pull/6206
|
||||||
|
@ -325,6 +349,7 @@ Flag used with `--write` to avoid re-checking files that were not changed since
|
||||||
[#6270]: https://github.com/prettier/prettier/pull/6270
|
[#6270]: https://github.com/prettier/prettier/pull/6270
|
||||||
[#6289]: https://github.com/prettier/prettier/pull/6289
|
[#6289]: https://github.com/prettier/prettier/pull/6289
|
||||||
[#6332]: https://github.com/prettier/prettier/pull/6332
|
[#6332]: https://github.com/prettier/prettier/pull/6332
|
||||||
|
[#6284]: https://github.com/prettier/prettier/pull/6284
|
||||||
[@duailibe]: https://github.com/duailibe
|
[@duailibe]: https://github.com/duailibe
|
||||||
[@gavinjoyce]: https://github.com/gavinjoyce
|
[@gavinjoyce]: https://github.com/gavinjoyce
|
||||||
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
||||||
|
|
|
@ -272,7 +272,7 @@ function forceBreakContent(node) {
|
||||||
forceBreakChildren(node) ||
|
forceBreakChildren(node) ||
|
||||||
(node.type === "element" &&
|
(node.type === "element" &&
|
||||||
node.children.length !== 0 &&
|
node.children.length !== 0 &&
|
||||||
(["body", "template", "script", "style"].indexOf(node.name) !== -1 ||
|
(["body", "script", "style"].indexOf(node.name) !== -1 ||
|
||||||
node.children.some(child => hasNonTextChild(child)))) ||
|
node.children.some(child => hasNonTextChild(child)))) ||
|
||||||
(node.firstChild &&
|
(node.firstChild &&
|
||||||
node.firstChild === node.lastChild &&
|
node.firstChild === node.lastChild &&
|
||||||
|
|
|
@ -332,3 +332,31 @@ printWidth: 80
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`template.html 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["html"]
|
||||||
|
printWidth: 80
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
<template>
|
||||||
|
<template>foo</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<template>foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
<template>
|
||||||
|
<template>foo</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<template
|
||||||
|
>foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</template
|
||||||
|
>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<template>
|
||||||
|
<template>foo</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<template>foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</template>
|
||||||
|
</template>
|
Loading…
Reference in New Issue