cloudhead/less.js — Issue #549: LESS should support invalid CSS
Author: matthewdl
Created: 2012-01-05 19:54:15+00:00
State: open

While this may seem crazy at face value, CSS has very clearly-defined rules for how invalid rules should be interpreted. That is, if a curly brace is not closed, or a semi-colon is not missed, the W3C defines exactly how those blocks are closed so that further rules can be interpreted.

Because LESS is CSS extended, it should support someone dropping in their completely bonkers CSS, and having it pass through the parser. However, using the W3C rules, it would close lines / blocks exactly as defined before interpreting the remaining values. In other words, interpret the lines as the browser parser would, and correct (as the browser is required to do) before outputting CSS.

This way, someone can drop in any CSS that has been working "correctly" for them, even if it has an incorrect line somewhere. It would be great to issue a warning at the JavaScript / parser level, but CSS-to-LESS conversion should be absolutely transparent.

Of course, the exception would be in any rules which have been added by LESS. (That is, their invalid CSS code happens to be valid LESS code, such as with nested blocks.)

Here's the rules defined:

http://www.w3.org/TR/CSS2/syndata.html