asyncLiz / minify-html-literals

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

CSS minify produces invalid css templates #20

Closed gerriet-hinrichs closed 4 years ago

gerriet-hinrichs commented 4 years ago

Due to the way the splitting after minification works, some required semicolons are removed, giving invalid css as the result.

Code to reproduce:

const { minifyHTMLLiterals } = require('minify-html-literals');
const assert = require('assert');

const source = `
    const fontSize = '12px';
    const style = css\`
        body {
            font-size: \${fontSize};
            font-color: black;
        }\`;
`;

const expected = `
    const fontSize = '12px';
    const style = css\`body{font-size:\${fontSize};font-color:#000}\`;
`;

const result = minifyHTMLLiterals(source, { fileName: 'test.js' });
console.log(result.code);

// the semicolon after the ${fontSize} template part gets removed during splitting
assert(source == expected);
asyncLiz commented 4 years ago

Fixed in https://github.com/asyncLiz/minify-html-literals/pull/22