asyncLiz / minify-html-literals

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

Error when interpolating variables as a substring of an attribute #1

Closed acarapetis closed 5 years ago

acarapetis commented 5 years ago

If I run this test:

require('minify-html-literals').minifyHTMLLiterals(
    'html`<p style="color: ${color}"></p>`'
);

Then I get this error:

Error: splitHTMLByPlaceholder() must return same number of strings as template parts

Replacing "color: ${color}" with "${color}" makes the error go away.

acarapetis commented 5 years ago

Setting removeAttributeQuotes: false in minifyOptions would fix this if not for the presence of a semicolon in defaultStrategy.getPlaceholder(), which is stripped out by html-minifier's inline CSS minification.

asyncLiz commented 5 years ago

Thanks for finding that bug! I added a test case for it and published 1.1.2 that fixes it.

neuronetio commented 3 years ago

I still have this issue in 1.2.5 but I've got multiple style properties in style tag.

HTML:

<div style="left: ${left}px; top: ${top}px;"></div>

But this code works:

<div style="left: ${left+'px'}; top: ${top+'px'};"></div>
davidfilkins commented 3 years ago

I still have this issue in 1.2.5 but I've got multiple style properties in style tag.

HTML:

<div style="left: ${left}px; top: ${top}px;"></div>

But this code works:

<div style="left: ${left+'px'}; top: ${top+'px'};"></div>

This saved me hours of digging. Thanks @neuronetio!