cfware / babel-plugin-template-html-minifier

Minify HTML in tagged template strings using html-minifier
MIT License
63 stars 4 forks source link

Escaped unicode strings in CSS losing the backslash #8

Closed web-padawan closed 5 years ago

web-padawan commented 5 years ago

The following input is not processed properly:

html`
<style>
  .vaadin-button-container::before {
    content: "\\2003";
  }
</style>
`

The extra slash is removed, which results in "Octal literal in strict mode" parse error. Can be reproduced in web-padawan/polymer3-webpack-starter#18

Note: does not happens when tagged template literals are transpiled to ES5.

coreyfarrell commented 5 years ago

I have seen this, I'm not sure where this is happening. I'll hopefully have a chance to investigate further but right now the work-around I've found is to use JavaScript unicode encoding. So content: "\u2003"; seems to work correctly.

When you say this does not happen for tagged template literals transpiled to ES5, does that transpile prevent babel-plugin-template-html-minifier from running?

web-padawan commented 5 years ago

The code transpiled to ES5 is still minified correctly, and \\2003 remains unchanged. I suspected it could happen in the terser but when I disable minifier, it is not broken. Note: "\u2003" does not seem to work in the CSS pseudo elements.

coreyfarrell commented 5 years ago

@web-padawan Could you test your project using #9? Once you confirm this fixes the issue for you without side effects I'll merge and publish to NPM.