Fix srcset parse error (#7295)
* Fix srcset parse * Don't swallow error * fix srcset parse * Add changelog * Update case * Fix quote style * Make input ugly
This commit is contained in:
1 parent
f93a763f8c
commit
96d419b91a
4 files changed
+39
-1
No files matched your search
@@ -0,0 +1,27 @@
|
||||
#### Fix srcset parse error ([#7295](https://github.com/prettier/prettier/pull/7295) by [@fisker](https://github.com/fisker))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```html
|
||||
<!-- Input -->
|
||||
<img
|
||||
|
||||
srcset="
|
||||
/media/examples/surfer-240-200.jpg
|
||||
">
|
||||
|
||||
<!-- Prettier stable -->
|
||||
Error: Mixed descriptor in srcset is not supported
|
||||
at printImgSrcset (https://prettier.io/lib/standalone.js:20867:13)
|
||||
at printEmbeddedAttributeValue (https://prettier.io/lib/standalone.js:21538:26)
|
||||
at Object.embed$2 [as embed] (https://prettier.io/lib/standalone.js:21009:43)
|
||||
at Object.printSubtree (https://prettier.io/lib/standalone.js:15170:30)
|
||||
at callPluginPrintFunction (https://prettier.io/lib/standalone.js:15288:31)
|
||||
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 https://prettier.io/lib/standalone.js:21285:175
|
||||
at FastPath.map (https://prettier.io/lib/standalone.js:15155:23)
|
||||
|
||||
<!-- Prettier master -->
|
||||
<img srcset="/media/examples/surfer-240-200.jpg" />
|
||||
```
|
||||
@@ -18,7 +18,7 @@ function printImgSrcset(value) {
|
||||
const hasH = srcset.some(src => src.h);
|
||||
const hasX = srcset.some(src => src.d);
|
||||
|
||||
if (hasW + hasH + hasX !== 1) {
|
||||
if (hasW + hasH + hasX > 1) {
|
||||
throw new Error("Mixed descriptor in srcset is not supported");
|
||||
}
|
||||
|
||||
|
||||
@@ -319,6 +319,11 @@ sizes="(max-width: 66rem) 100vw, 66rem" alt=""/>
|
||||
<img src="/assets/visual.png"
|
||||
srcset="/assets/visual@0.5.png 0.5x, /assets/visual.png 1111x, /assets/visual@2x.png 2x, /assets/visual@3x.png 3.3333x"
|
||||
sizes="(max-width: 66rem) 100vw, 66rem" alt=""/>
|
||||
<img
|
||||
|
||||
srcset="
|
||||
/media/examples/surfer-240-200.jpg
|
||||
">
|
||||
|
||||
=====================================output=====================================
|
||||
<img
|
||||
@@ -349,6 +354,7 @@ sizes="(max-width: 66rem) 100vw, 66rem" alt=""/>
|
||||
sizes="(max-width: 66rem) 100vw, 66rem"
|
||||
alt=""
|
||||
/>
|
||||
<img srcset="/media/examples/surfer-240-200.jpg" />
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -7,3 +7,8 @@ sizes="(max-width: 66rem) 100vw, 66rem" alt=""/>
|
||||
<img src="/assets/visual.png"
|
||||
srcset="/assets/visual@0.5.png 0.5x, /assets/visual.png 1111x, /assets/visual@2x.png 2x, /assets/visual@3x.png 3.3333x"
|
||||
sizes="(max-width: 66rem) 100vw, 66rem" alt=""/>
|
||||
<img
|
||||
|
||||
srcset="
|
||||
/media/examples/surfer-240-200.jpg
|
||||
">
|
||||
Reference in new issue
Block a user