Releases: csstree/csstree
1.0.0-alpha25
- Parser
- Added fallback node as argument to
onParseError()
handler - Fixed raw consuming in tolerant mode when selector is invalid (greedy consuming and redundant warnings)
- Fixed exception in tolerant mode caused by unknown at-rule with unclosed block
- Changed handling of semicolons:
- Hanging semicolon inside declaration blocks raises an error or turns into a
Raw
node in tolerant mode instead of being ignored - Semicolon outside of declaration blocks opens a
Rule
node as part of selector instead of being ignored
- Hanging semicolon inside declaration blocks raises an error or turns into a
- Aligned
parseAtrulePrelude
behaviour toparseRulePrelude
- Removed
Raw
node wraping intoAtrulePrelude
whenparseAtrulePrelude
is disabled - Removed error emitting when at-rule has a custom prelude customer but no prelude is found (it should be validated by a lexer later)
- Removed
- Added fallback node as argument to
- Generator
- Fixed performance issue with
translateWithSourceMap()
, flattening the string (because of mixing building string and indexing into it) turned it into a quadratic algorithm (approximate numbers can be found in the quiz created by this case)
- Fixed performance issue with
- Added support for a single solidus hack for
property()
- Minor fixes for custom errors
1.0.0-alpha24
- Improved CSSTree to be stable for standart build-in objects extension (#58)
- Parser
- Renamed rule's
selector
toprelude
. The reasons: spec names this part so, and this branch can contain not a selector only (SelectorList
) but also a raw payload (Raw
). What's changed:- Renamed
Rule.selector
toRule.prelude
- Renamed
parseSelector
parser option toparseRulePrelude
- Removed option for selector parse in
SelectorList
- Renamed
- Renamed rule's
- Lexer
- Fixed undefined positions in a error when match a syntax to empty or white space only value
- Improved
Lexer#checkStructure()
- Return a warning as an object with node reference and message
- No exception on unknown node type, return a warning instead
1.0.0-alpha23
- Fixed
Tokenizer#getRawLength()
's false positive balance match to the end of input in some cases (#56) - Rename walker's entry point methods to be the same as CSSTree exposed methods (i.e.
walk()
,walkUp()
etc) - Rename at-rule's
expression
toprelude
(since spec names it so)AtruleExpression
node type →AtrulePrelude
Atrule.expression
field →Atrule.prelude
parseAtruleExpression
parser's option →parseAtrulePrelude
atruleExpression
parse context →atrulePrelude
atruleExpression
walk context reference →atrulePrelude
1.0.0-alpha22 Separate entry points for key modules
- Parser
- Fixed exception on parsing of unclosed
{}-block
in tolerant mode - Added tolerant mode support for
DeclarationList
- Added standalone entry point, i.e. default parser can be used via
require('css-tree/lib/parser')
(#47)
- Fixed exception on parsing of unclosed
- Generator
- Changed generator to produce
+n
whenAnPlusB.a
is+1
to be "round-trip" with parser - Added standalone entry point, i.e. default generators can be used via
require('css-tree/lib/generator')
- Changed generator to produce
- Walker
- Added standalone entry point, i.e. default walkers can be used via
require('css-tree/lib/walker')
(#47)
- Added standalone entry point, i.e. default walkers can be used via
- Lexer
- Added
default
keyword to the list of invalid values for<custom-ident>
(since it reversed per spec)
- Added
- Convertors (
toPlainObject()
andfromPlainObject()
) moved tolib/convertor
(entry point isrequire('css-tree/lib/convertor')
)
1.0.0-alpha21 Improved raw consumption, fixes for at-rule parsing and custom errors
- Tokenizer
- Added
Raw
token type - Improved tokenization of
url()
with raw as url to be more spec complient - Added
Tokenizer#balance
array computation on token layout - Added
Tokenizer#getRawLength()
to compute a raw length with respect of block balance - Added
Tokenizer#getTokenStart(offset)
method to get token start offset by token index - Added
idx
andbalance
fields to each token ofTokenizer#dump()
method result
- Added
- Parser
- Added
onParseError
option - Reworked node parsers that consume a
Raw
node to use a new approach. Since now aRaw
node builds inparser#Raw()
function onlу - Changed semantic of
parser#Raw()
, it takes 5 parameters now (it might to be changed in future) - Changed
parser#tolerantParse()
to pass a start token index to fallback function instead of source offset - Fixed
AtruleExpression
consumption in tolerant mode - Atrule handler to convert an empty
AtruleExpression
node intonull
- Changed
AtruleExpression
handler to always return a node (before it could return anull
in some cases)
- Added
- Lexer
- Fixed comma match node for
#
multiplier - Added reference name to
SyntaxReferenceError
- Fixed comma match node for
- Additional fixes on custom errors
- Reduced possible corruption of base config by
syntax.fork()
1.0.0-alpha20
- Tokenizer
- Added
Atrule
token type (<at-rule-token>
per spec) - Added
Function
token type (<function-token>
per spec) - Added
Url
token type - Replaced
Tokenizer#getTypes()
method withTokenizer#dump()
to get all tokens as an array - Renamed
Tokenizer.TYPE.Whitespace
toTokenizer.TYPE.WhiteSpace
- Renamed
Tokenizer.findWhitespaceEnd()
toTokenizer.findWhiteSpaceEnd()
- Added
- Parser
- Added initial implementation of tollerant mode (turn on by passing
tolerant: true
option). In this mode parse errors are never occour and any invalid part of CSS turns into aRaw
node. Current safe points:Atrule
,AtruleExpression
,Rule
,Selector
andDeclaration
. Feature is experimental and further improvements are planned. - Changed
Atrule.expression
to contain aAtruleExpression
node ornull
only (other node types is wrapping into aAtruleExpression
node) - Renamed
AttributeSelector.operator
toAttributeSelector.matcher
- Added initial implementation of tollerant mode (turn on by passing
- Generator
translate()
method is now can take a function as second argument, that recieves every generated chunk. When no function is passed, default handler is used, it concats all the chunks and method returns a string.
- Lexer
- Used mdn/data package as source of lexer's grammar instead of local dictionaries
- Added
x
unit to<resolution>
generic type - Improved match tree:
- Omited Group (sequences) match nodes
- Omited empty match nodes (for terms with
zero or more
multipliers) - Added
ASTNode
node type to contain a reference to AST node - Fixed node duplication (uncompleted match were added to tree)
- Added AST node reference in match nodes
- Added comma match node by
#
multiplier
- Grammar
- Changed
translate()
function to get a handler as third argument (optional). That handler recieves result of node traslation and can be used for decoration purposes. See example - Added
SyntaxParseError
to grammar export - Reworked group and multipliers representation in syntax tree:
- Replaced
Sequence
forGroup
node type (Sequence
node type removed) - Added
explicit
boolean property forGroup
- Only groups can have a multiplier now (other node types is wrapping into a single term implicit group when multiplier is applied)
- Renamed
nonEmpty
Group's property todisallowEmpty
- Added optimisation for syntax tree by dropping redundant root
Group
when it contains a singleGroup
term (return thisGroup
as a result)
- Replaced
- Changed
- Changed lexer's match functionality
- Changed
Lexer#matchProperty()
andLexer#matchType()
to return an object instead of match tree. A match tree stores inmatched
field when AST is matched to grammar successfully, otherwise an error inerror
field. The result object also has some methods to test AST node against a match tree:getTrace()
,isType()
,isProperty()
andisKeyword()
- Added
Lexer#matchDeclaration()
method - Removed
Lexer#lastMatchError
(error stores in match result object inerror
field)
- Changed
- Added initial implementation of search for AST segments (new lexer methods:
Lexer#findValueSegments()
,Lexer#findDeclarationValueSegments()
andLexer#findAllSegments
) - Implemented
SyntaxReferenceError
for unknown property and type references
- Renamed field in resulting object of
property()
function:variable
→custom
- Fixed issue with readonly properties (e.g.
line
andcolumn
) ofError
and exception on attempt to write in iOS Safari
1.0.0-alpha19
- Extended
List
class with new methods:List#prepend(item)
List#prependData(data)
List#insertData(data)
List#insertList(list)
List#replace(item, itemOrList)
1.0.0-alpha18
1.0.0-alpha17 – The first step towards extensibility and test against real Web CSS
Extensibility
The main goal of CSSTree is to provide standard CSS parsing as good as possible. However, use cases has shown that it would be useful to easily extend the syntax to make possible experimenting with new CSS modules and features. Therefore, in this release CSSTree is making the first step towards extensibility through a new concept called syntax
.
Syntax
is a set of tools: parser, walkers, lexer, generators and other functions to deal with some variant of CSS syntax. By default it's a standard CSS syntax with implementators features (e.g. hacks and extensions). This syntax may be extended by fork()
method, which returns a new syntax (fork) with modified functionality (when needed) but the same API.
The approach allows to experiment with new CSS features that haven't been implemented yet by browsers, and provide support for CSS extensions (like CSS Modules
, and even SCSS
or Less
syntaxes) at a new level. To reach that goal syntax is described in a declarative way with minimal efforts from the developer. Initial CSS syntax definition speaks for itself. It will be completed and improved in upcoming releases.
Real Web CSS
It's hard enough to understand how good a parser is. There are several problems here, the most notable is the lack of appropriate test suites to test the parser across specs and implementations. As you may know, adoption of CSS is not consistent by browsers, it's changing so fast and don't forget about legacy. Too many things we should care about.
That's the reason why Real Web CSS project was created. The project’s scripts take Alexa Top 250 websites, crawl their CSS, and try to parse and validate them. The results can be found in this table. As you can see there are various issues around the Web, many of websites have a broken CSS and validation warnings. Although this test also has revealed weaknesses of CSSTree and most them were fixed by this release.
This simple test on real Web CSS already showed many problems on sites and CSSTree. And that's just a beginning. We believe it will help to make Web and CSSTree better.
Changes
- Implemented new concept of
syntax
- Changed main
exports
to expose a default syntax - Defined initial CSS syntax
- Implemented
createSyntax()
method to create a new syntax from scratch - Implemented
fork()
method to create a new syntax based on given via extension
- Changed main
- Parser
- Implemented
mediaQueryList
andmediaQuery
parsing contexts - Implemented
CDO
andCDC
node types - Implemented additional declaration property prefix hacks (
#
and+
) - Added support for UTF-16LE BOM
- Added support for
@font-face
at-rule - Added
chroma()
to legacy IE filter functions - Improved
HexColor
to consume hex only - Improved support for
\0
and\9
hacks (#2) - Relaxed number check for
Ratio
terms- Allowed fractal values as a
Ratio
term - Disallowed zero number as a
Ratio
term
- Allowed fractal values as a
- Changed important clause parsing
- Allowed any identifier for important (to support hacks like
!ie
) - Store
true
forimportant
field in case identifier equals toimportant
and string otherwise
- Allowed any identifier for important (to support hacks like
- Fixed parse error formatted message rendering to take into account tabs
- Removed exposing of
Parser
class - Removed
readSelectorSequence()
,readSequenceFallback()
andreadSelectorSequenceFallback
methods - Used single universal sequence consumer for
AtruleExpression
,Selector
andValue
- Implemented
- Generator
- Reworked generator to use auto-generated functions based on syntax definition (additional work to be done in next releases)
- Implemented
translateMarkup(ast, before, after)
method for complex cases - Reworked
translateWithSourceMap
to be more flexible (based ontranslateMarkup
, additional work to be done in next releases)
- Walker
- Reworked walker to use auto-generated function based on syntax definition (additional work to be done in next releases)
- Lexer
- Prepared for better extensibility (additional work to be done in next releases)
- Implemented
checkStructure(ast)
method to check AST structure based on syntax definition - Update syntax dictionaries to latest
mdn/data
- Add missing
<'offset-position'>
syntax - Extended
<position>
property with-webkit-sticky
(@sergejmueller, #37)
- Add missing
- Improved mismatch error position
- Implemented script (
gen:syntax
) to generate AST format reference page (docs/ast.md
) using syntax definition
1.0.0-alpha16
- Exposed
Parser
class - Added
startOffset
option toTokenizer
(constructor andsetSource()
method) - Added fallback functions for default (
readSequenceFallback
) and selector (readSelectorSequenceFallback
) sequence readers - Fixed edge cases for
AnPlusB
- Fixed wrong whitespace ignoring in
Selector
consumer