Fix: don't throw on broken html (#7293)

This commit is contained in:
fisker Cheung authored and Evilebot Tnawi committed 2020-01-13 17:31:03 +03:00
1 parent da55719aa4
commit 02c161cf33
4 files changed
+73 -1

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
#### Do not throw on broken html ([#7293](https://github.com/prettier/prettier/pull/7293) by [@fisker](https://github.com/fisker))
<!-- prettier-ignore -->
```html
<!-- Input -->
<div><span>
<
<!-- Prettier stable -->
TypeError: Cannot read property 'start' of null
at hasTrailingLineBreak (https://prettier.io/lib/standalone.js:19694:169)
at forceBreakContent (https://prettier.io/lib/standalone.js:19668:154)
at Object.genericPrint$2 [as print] (https://prettier.io/lib/standalone.js:21068:126)
at callPluginPrintFunction (https://prettier.io/lib/standalone.js:15302:20)
at https://prettier.io/lib/standalone.js:15253:18
at Object.printComments (https://prettier.io/lib/standalone.js:14974:19)
at printGenerically (https://prettier.io/lib/standalone.js:15252:24)
at printChild (https://prettier.io/lib/standalone.js:21227:14)
at https://prettier.io/lib/standalone.js:21211:104
at FastPath.map (https://prettier.io/lib/standalone.js:15155:23)
<!-- Prettier master -->
<div><span> < </span></div>
```
+2 -1
View File
@@ -330,7 +330,8 @@ function hasTrailingLineBreak(node) {
(node.next
? node.next.sourceSpan.start.line > node.sourceSpan.end.line
: node.parent.type === "root" ||
node.parent.endSourceSpan.start.line > node.sourceSpan.end.line)
(node.parent.endSourceSpan &&
node.parent.endSourceSpan.start.line > node.sourceSpan.end.line))
);
}
@@ -1,5 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`broken-html.html 1`] = `
====================================options=====================================
parsers: ["html"]
printWidth: 80
| printWidth
=====================================input======================================
<!--
#7241,
reproduction:
two different element,
linebreak
\`<\`
extra space(s)
-->
<div><span>
<
=====================================output=====================================
<!--
#7241,
reproduction:
two different element,
linebreak
\`<\`
extra space(s)
-->
<div><span> < </span></div>
================================================================================
`;
exports[`comment.html 1`] = `
====================================options=====================================
parsers: ["html"]
+13
View File
@@ -0,0 +1,13 @@
<!--
#7241,
reproduction:
two different element,
linebreak
`<`
extra space(s)
-->
<div><span>
<