@@ -67,19 +67,30 @@ let color = ast // the Root node
6767 .first ; // a Word node, containing the color value.
6868```
6969
70- ## CSS-Like Languages
70+ ## Loose Mode
7171
72- If your intent is to use this parser with a CSS-like language (eg. SASS, LESS)
73- then you can instruct the parser ** _ not to adhere to strict CSS _ ** parsing rules as
74- per [ the spec ] ( https://drafts.csswg.org/css-values-3/ ) . For example, the parser
75- will throw an error by default if ` calc ` parameters [ don't adhere to the spec ] ( https://drafts.csswg.org/css-values-3/#calc-syntax ) .
72+ Loose mode was introduced to support adherence to the W3C CSS Specification as
73+ well as the ability to parse noncompliant CSS for variants like LESS, SCSS, and
74+ CSSNext. If you're working with a noncompliant or CSS-like variant, then loose
75+ mode is for you .
7676
77- We call this ` loose ` mode. To enable ` loose ` mode, pass an options object to the
78- ` parser ` method:
77+ For example, the parser
78+ will throw an error by default if ` calc ` parameters [ don't adhere to the spec] ( https://www.w3.org/TR/css-values/#calc-syntax ) .
79+ However, with loose mode enabled, the parse will ignore spec rules and succeed.
80+
81+ In-draft features, or CSS features in modules not yet finalized, often cause parser
82+ errors. eg. ` url(var(--somevar)) ` . Loose mode supports parsing of these features.
83+
84+ Loose Mode is enabled by passing an option of ` loose: true ` to the ` parser ` method.
7985
8086``` js
87+ const less = ' calc(2+2)' ; // not valid per spec, but valid in LESS
88+ const cssnext = ' url(var(--somevar))' ; // not valid per spec, but in spec draft
89+
8190const parser = require (' postcss-values-parser' );
82- const ast = parser (' #fff' , { loose: true }).parse ();
91+ const ast = parser (less, { loose: true }).parse ();
92+
93+ // parse will succeed
8394```
8495
8596## Acknowledgements
0 commit comments