v3.2.0
3.2.0
Added
- Added `"sideEffects": false` in `package.json`
- Added `list` option to the `parse()` method to specify whether the parser should produce a `List` (by default, `list: true`) or an array (`list: false`) for node's children
- Added support for Functional Notation in definition syntax by wrapping function arguments into an implicit group when necessary
- Added support for stacked multipliers `{A}?` and `{A,B}?` according to spec in definition syntax parsing
- Added math functions support in syntax matching (e.g., `min()`, `max()`, etc.)
- Added `onToken` option to the `parse()` method, which can be either an array or a function for token handling with type, start, end, and index parameters
- Extended `TokenStream` with `getTokenEnd(tokenIndex)` method to return the token's end offset by index
- Extended `TokenStream` with `getTokenType(tokenIndex)` method to return the token's type by index
- Extended `TokenStream` with `isBlockOpenerTokenType(tokenType)` method to identify block opener tokens
- Extended `TokenStream` with `isBlockCloserTokenType(tokenType)` method to identify block closer tokens
- Extended `TokenStream` with `getBlockTokenPairIndex(tokenIndex)` method to return the index of the pair token for a block or `-1` if no pair exists
Changed
- Changed `generate()` to not auto insert whitespaces between tokens for raw values
Fixed
- Fixed `fork()` to extend `node` definitions instead of overriding them
- Added
"sideEffects": falseinpackage.json - Added
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 parsing (#346) - Added math functions support in syntax matching (e.g.,
min(),max(), etc.) (#344) - 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)); } } } });
- When the value is an array, it is populated with objects
- 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 values (#356) - Fixed
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