css-tree
3.2.1 · 5 Mar 2026MIT183.3M / weekRepositoryHomepagenpmAtom feed
3.2.1 is the newest release of 3.x.
In short
7 new1 fixed7 changed
Release note
Added
"sideEffects": falseinpackage.jsonAdded
listoption to theparse()method to specify whether the parser should produce aList(by default,list: true) or an array (list: false) for node's children (e.g.,SelectorList,Block, etc.)Added support for Functional Notation in definition syntax (for now by wrapping function arguments into an implicit group when necessary, see #292)
Added support for stacked multipliers
{A}?and{A,B}?according to spec in definition syntax parsingAdded math functions support in syntax matching (e.g.,
min(),max(), etc.)Added
onTokenoption to theparse()method, which can be either an array or a function:When the value is an array, it is populated with objects
{ type, start, end }(token type, and its start and end offsets).When the value is a function, it accepts
type,start,end, andindexparameters, and is invoked with a token API asthis, enabling advanced token handling (see onToken). For example, the following demonstrates checking if all block tokens have matching pairs:parse(css, { onToken(type, start, end, index) { if (this.isBlockOpenerTokenType(type)) { if (this.getBlockPairTokenIndex(index) === -1) { console.warn('No closing pair for', this.getTokenValue(index), this.getRangeLocation(start, end)); } } else if (this.isBlockCloserTokenType(type)) { if (this.getBlockPairTokenIndex(index) === -1) { console.warn('No opening pair for', this.getTokenValue(index), this.getRangeLocation(start, end)); } } } });
Extended
TokenStreamwith the following methods:getTokenEnd(tokenIndex)– returns the token's end offset by index, complementinggetTokenStart(tokenIndex)getTokenType(tokenIndex)– returns the token's type by indexisBlockOpenerTokenType(tokenType)– returnstruefor<function-token>,<(-token>,<[-token>, and<{-token>isBlockCloserTokenType(tokenType)– returnstruefor<)-token>,<]-token>, and<}-token>getBlockTokenPairIndex(tokenIndex)– returns the index of the pair token for a block, or-1if no pair exists
Changed
generate()to not auto insert whitespaces between tokens for raw valuesFixed
fork()to extendnodedefinitions instead of overriding them. For example,fork({ node: { Dimension: { generate() { /* ... */ } } } })will now update only thegenerate()method on theDimensionnode, while inheriting all other properties from the previous syntax definition.Bumped
mdn/datato 2.27.1 and various fixes in syntaxes
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.