csso icon indicating copy to clipboard operation
csso copied to clipboard

Ignore parse errors

Open Ser-Gen opened this issue 8 years ago • 5 comments

csso can't minify some legacy styles because of parse errors.

csso "styles.css" "styles.min.css"

Parse error X:\project\css\styles.css: Unexpected input
 3354 |.Notes {
 3355 | padding:0px
 3356 | display:block;
---------------^
 3357 | width:420px;
 3358 | float:right;

I understand that ignoring could slow parsing and I really need to fix all errors, but right now I don't need linting, my target is only minification.

Is there a way to ignore parse errors?

Ser-Gen avatar Apr 12 '17 15:04 Ser-Gen

It's quite complicated to parse invalid CSS. Unfortunately, I can't say when it will be available. There is a related issue https://github.com/csstree/csstree/issues/16

lahmatiy avatar Apr 12 '17 15:04 lahmatiy

And even if we'll parse broken CSS it's not clear what we should to do with wrong parts – remove, left as is or something else. Broken structure makes optimisations harder as well.

lahmatiy avatar Apr 12 '17 16:04 lahmatiy

Sorry, didn't find that related issue.

it's not clear what we should to do with wrong parts

I think we can remove them, like browsers do. We don't need garbage in optimized code.

Ser-Gen avatar Apr 12 '17 18:04 Ser-Gen

Yep, it looks reasonable. But if optimizer would removes some parts of CSS silently it might be a source of problems. Some parts may to be wrong, but others may to be correct but parser/optimizer just can't understand them. I don't know good enough solution for this problem yet.

lahmatiy avatar Apr 12 '17 19:04 lahmatiy

I would welcome some solution like in clean-css which uses /* clean-css ignore:start */ and /* clean-css ignore:end */.

DanielRuf avatar Apr 20 '20 19:04 DanielRuf