asyncLiz / minify-html-literals

Minify HTML template literal strings
MIT License
68 stars 14 forks source link

splitHTMLByPlaceholder fails only if using "unsafeCSS" #45

Open a11delavar opened 2 years ago

a11delavar commented 2 years ago

Hello! I'm using the minify-html-literals-loader in my webpack setup, and basically it throws an error only if I use unsafeCSS inside the styles e.g.

return css`
    :host([type=${unsafeCSS(SomeType.One)}]) {
        color: red;
    }
`

The error is

Error: splitHTMLByPlaceholder() must return same number of strings as template parts
    at Object.ensureHTMLPartsValid (....\node_modules\minify-html-literals\src\minifyHTMLLiterals.js:60:19)
    at ....\node_modules\minify-html-literals\src\minifyHTMLLiterals.js:121:26
    at Array.forEach (<anonymous>)
    at minifyHTMLLiterals (....\node_modules\minify-html-literals\src\minifyHTMLLiterals.js:93:15)
    at module.exports (....\node_modules\minify-html-literals-loader\index.js:7:20)
steverep commented 1 year ago

Does it really matter if you use unsafeCSS or just the bare variable in the expression?

I get this error anytime there is a nested expression, and there's no way to ignore and just have minify abort. Setting validate: false makes no difference.