css-tree
3.2.1 · 5 Mar 2026MIT183.3M / weekRepositoryHomepagenpmAtom feed
21 stable releases, newest first, by release line. Notes are quoted as the maintainers published them.
- 3.x · latest line
3.2.1
5 Mar 2026Fixed parsing of nested function in a group in definition syntax
3.2.0
5 Mar 2026Added
"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
"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
3.1.0
6 Dec 2024Added support for boolean expression multiplier in syntax definition, i.e.
<boolean-expr[ test ]>Added
source,startOffset,startLine, andstartColumnparameters toOffsetToLocationconstructor, eliminating the need to callsetSource()after creating a newOffsetToLocationinstanceExposed
OffsetToLocationclass in the main entry point, which was previously accessible only viacss-tree/tokenizer
Added support for boolean expression multiplier in syntax definition, i.e.
<boolean-expr[ test ]>Added
source,startOffset,startLine, andstartColumnparameters toOffsetToLocationconstructor, eliminating the need to callsetSource()after creating a newOffsetToLocationinstanceExposed
OffsetToLocationclass in the main entry point, which was previously accessible only viacss-tree/tokenizerFixed
Rawnode value consumption by ignoring stop tokens inside blocks, resolving an issue whereRawvalue consumption stopped prematurely. This fix also enables parsing of functions whose content includes stop characters (e.g., semicolons and curly braces) within declaration values, aligning with the latest draft of CSS Values and Units L5.Fixed
TokenStream#balancecomputation to handle unmatched brackets correctly. Previously, when encountering a closing bracket, theTokenStreamwould prioritize it over unmatched opening brackets, leading to improper parsing. For example, the parser would incorrectly consume the declaration value of.a { prop: ([{); }as([{)instead of consuming it until all opened brackets were closed (([{); }). Now, unmatched closing brackets are discarded unless they match the most recent opening bracket on the stack. This change aligns CSSTree with CSS specifications and browser behavior.Fixed syntax definition parser to allow a token to be followed by a multiplier
Fixed location for
LayernodeBumped
mdn/datato 2.12.2
3.0.1
2 Nov 2024- Removed
Removed second parameter (
assign) for the callback in thefork()method (e.g.,syntax.fork((config, assign) => { ... })), as it simply refers toObject.assign() Bumped
mdn/datato 2.12.1Added
errorsarray to theLexer#validate()method result, providing details on problematic syntax.
Bumped
mdn/datato 2.12.1Added
errorsarray to theLexer#validate()method result, providing details on problematic syntax.Added CSS wide keyword customization and introspection:
Added a
Lexer#cssWideKeywordsdictionary to list CSS-wide keywordsUpdated the Lexer's constructor to consider
config.cssWideKeywordsfor overriding the default listExpanded the lexer's dump output to include the
cssWideKeywordsdictionaryModified the
fork()method to accept acssWideKeywordsoption, allowing the addition of new keywords to the existing list
Reverted changes to
Blockto include{and}, andAtruleandRuleto exclude{and}for ablock- Removed
Removed second parameter (
assign) for the callback in thefork()method (e.g.,syntax.fork((config, assign) => { ... })), as it simply refers toObject.assign() Fixes in syntaxes:
<basic-shapes>,<absolute-color-function>and<'stroke-opacity'>
3.0.0
11 Sep 2024Added support for the
@containerat-ruleAdded support for the
@starting-styleat-ruleAdded support for the
@scopeat-rule
Added support for the
@containerat-ruleAdded support for the
@starting-styleat-ruleAdded support for the
@scopeat-ruleAdded support for the
@position-tryat-ruleAdded support for the
@layerat-ruleAdded support for
layer,layer()andsupports()in the@mediaat-rule (according to the @import rule in Cascading and Inheritance 5)Added
LayerandLayerListnode typesAdded
TokenStream#lookupTypeNonSC()methodAdded
<dashed-ident>to generic typesBumped
mdn/datato2.10.0Aligned
<'font'>to CSS Fonts 4Aligned
<color>to CSS Color 5Fixed initialization when
Object.prototypeis extended or pollutedFixed
fork()method to consider thegenericoption when creating a Lexer instanceFixed crash on parse error when custom
lineoroffsetis specified via optionsFixed
speaksyntax patchFixed
:lang()to accept a list of<ident>or<string>per specFixed lexer matching for syntaxes referred to as
<'property'>, when the syntax has a top-level#-multiplierRelaxed parsing of syntax definition to allow whitespaces in range multiplier
Changed
parseWithFallback()to rollbacktokenIndexbefore calling a fallbackChanged
Blockto not include{and}Changed
AtruleandRuleto include{and}for a blockChanged
Ratioparsing:Left and right parts contain nodes instead of strings
Both left and right parts of a ratio can now be any number; validation of number range is no longer within the parser's scope.
Both parts can now be functions. Although not explicitly mentioned in the specification, mathematical functions can replace numbers, addressing potential use cases (#162).
As per the CSS Values and Units Level 4 specification, the right part of
Ratiocan be omitted. While this can't be a parser output (which would produce aNumbernode), it's feasible duringRationode construction or transformation.
Changes to query-related at-rules:
Added new node types:
Feature: represents features like(feature)and(feature: value), fundamental for both@mediaand@containerat-rulesFeatureRange: represents features in a range contextFeatureFunction: represents functional features such as@supports'sselector()or@container'sstyle()Condition: used across all query-like at-rules, encapsulating queries with features and thenot,and, andoroperatorsGeneralEnclosure: represents the<general-enclosed>production, which caters to unparsed parentheses or functional expressions
Note: All new nodes include a
kindproperty to define the at-rule type. Supported kinds aremedia,supports, andcontainerAdded support for functions for features and features in a range context, e.g.
(width: calc(100cm / 6))Added a
conditionvalue for the parser's context option to parse queries. Use thekindoption to specify the condition type, e.g.,parse('...', { context: 'condition', kind: 'media' })Introduced a
featuressection in the syntax configuration for defining functional features of at-rules. Expand definitions using thefork()method. The current definition is as follows:features: { supports: { selector() { /* ... */ } }, container: { style() { /* ... */ } } }Changes for
@mediaat-rule:Enhanced prelude parsing for complex queries. Parentheses with errors will be parsed as
GeneralEnclosedAdded support for features in a range context, e.g.
(width > 100px)or(100px < height < 400px)Transitioned from
MediaFeaturenode type to theFeaturenode type withkind: "media"Changed
MediaQuerynode structure into the following form:type MediaQuery = { type: "MediaQuery"; modifier: string | null; // e.g. "not", "only", etc. mediaType: string | null; // e.g. "all", "screen", etc. condition: Condition | null; }
Changes for
@supportsat-rule:Enhanced prelude parsing for complex queries. Parentheses with errors will be parsed as
GeneralEnclosedAdded support for features in a range context, e.g.
(width > 100px)or(100px < height < 400px)Added
SupportsDeclarationnode type to encapsulate a declaration in a query, replacingParenthesesParsing now employs
ConditionorSupportsDeclarationnodes of kindsupportsinstead ofParenthesesAdded support for the
selector()feature via theFeatureFunctionnode (configured infeatures.supports.selector)
- 2.x
2.3.1
14 Dec 2022Reading the note…
2.3.0
30 Nov 2022Reading the note…
2.2.1
14 Aug 2022Reading the note…
2.2.0
10 Aug 2022Reading the note…
2.1.0
27 Feb 2022Reading the note…
2.0.4
17 Dec 2021Reading the note…
2.0.3
15 Dec 2021Reading the note…
2.0.2
10 Dec 2021Reading the note…
2.0.1
4 Dec 2021Reading the note…
2.0.0
3 Dec 2021Reading the note…
- 1.x
1.1.3
31 Mar 2021Reading the note…
1.1.2
26 Nov 2020Reading the note…
1.1.1
18 Nov 2020Reading the note…
1.1.0
18 Nov 2020Reading the note…
1.0.1
11 Nov 2020Reading the note…
1.0.0
27 Oct 2020Reading the note…
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.