diff --git a/changelog_unreleased/html/pr-7295.md b/changelog_unreleased/html/pr-7295.md new file mode 100644 index 000000000..7ccb34086 --- /dev/null +++ b/changelog_unreleased/html/pr-7295.md @@ -0,0 +1,27 @@ +#### Fix srcset parse error ([#7295](https://github.com/prettier/prettier/pull/7295) by [@fisker](https://github.com/fisker)) + + +```html + + + + +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) + + + +``` diff --git a/src/language-html/syntax-attribute.js b/src/language-html/syntax-attribute.js index 0389810a8..462fe0ddb 100644 --- a/src/language-html/syntax-attribute.js +++ b/src/language-html/syntax-attribute.js @@ -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"); } diff --git a/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap b/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap index 1a114d12b..56a05d511 100644 --- a/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap @@ -319,6 +319,11 @@ sizes="(max-width: 66rem) 100vw, 66rem" alt=""/> + =====================================output===================================== sizes="(max-width: 66rem) 100vw, 66rem" alt="" /> + ================================================================================ `; diff --git a/tests/html_attributes/srcset.html b/tests/html_attributes/srcset.html index a320c725d..510886cfe 100644 --- a/tests/html_attributes/srcset.html +++ b/tests/html_attributes/srcset.html @@ -7,3 +7,8 @@ sizes="(max-width: 66rem) 100vw, 66rem" alt=""/> +