Skip to content

Releases: csstree/csstree

1.0.0-alpha25

09 Oct 23:33
Compare
Choose a tag to compare
  • 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
    • Aligned parseAtrulePrelude behaviour to parseRulePrelude
      • Removed Raw node wraping into AtrulePrelude when parseAtrulePrelude 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)
  • 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)
  • Added support for a single solidus hack for property()
  • Minor fixes for custom errors

1.0.0-alpha24

14 Sep 20:36
Compare
Choose a tag to compare
  • Improved CSSTree to be stable for standart build-in objects extension (#58)
  • Parser
    • Renamed rule's selector to prelude. 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 to Rule.prelude
      • Renamed parseSelector parser option to parseRulePrelude
      • Removed option for selector parse in SelectorList
  • 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

10 Sep 21:01
Compare
Choose a tag to compare
  • 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 to prelude (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

08 Sep 01:12
Compare
Choose a tag to compare
  • 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)
  • Generator
    • Changed generator to produce +n when AnPlusB.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')
  • Walker
    • Added standalone entry point, i.e. default walkers can be used via require('css-tree/lib/walker') (#47)
  • Lexer
    • Added default keyword to the list of invalid values for <custom-ident> (since it reversed per spec)
  • Convertors (toPlainObject() and fromPlainObject()) moved to lib/convertor (entry point is require('css-tree/lib/convertor'))

1.0.0-alpha21 Improved raw consumption, fixes for at-rule parsing and custom errors

05 Sep 00:12
Compare
Choose a tag to compare
  • 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 and balance fields to each token of Tokenizer#dump() method result
  • Parser
    • Added onParseError option
    • Reworked node parsers that consume a Raw node to use a new approach. Since now a Raw node builds in parser#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 into null
    • Changed AtruleExpression handler to always return a node (before it could return a null in some cases)
  • Lexer
    • Fixed comma match node for # multiplier
    • Added reference name to SyntaxReferenceError
  • Additional fixes on custom errors
  • Reduced possible corruption of base config by syntax.fork()

1.0.0-alpha20

28 Aug 14:33
Compare
Choose a tag to compare
  • 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 with Tokenizer#dump() to get all tokens as an array
    • Renamed Tokenizer.TYPE.Whitespace to Tokenizer.TYPE.WhiteSpace
    • Renamed Tokenizer.findWhitespaceEnd() to Tokenizer.findWhiteSpaceEnd()
  • 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 a Raw node. Current safe points: Atrule, AtruleExpression, Rule, Selector and Declaration. Feature is experimental and further improvements are planned.
    • Changed Atrule.expression to contain a AtruleExpression node or null only (other node types is wrapping into a AtruleExpression node)
    • Renamed AttributeSelector.operator to AttributeSelector.matcher
  • 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 for Group node type (Sequence node type removed)
        • Added explicit boolean property for Group
        • 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 to disallowEmpty
        • Added optimisation for syntax tree by dropping redundant root Group when it contains a single Group term (return this Group as a result)
    • Changed lexer's match functionality
      • Changed Lexer#matchProperty() and Lexer#matchType() to return an object instead of match tree. A match tree stores in matched field when AST is matched to grammar successfully, otherwise an error in error field. The result object also has some methods to test AST node against a match tree: getTrace(), isType(), isProperty() and isKeyword()
      • Added Lexer#matchDeclaration() method
      • Removed Lexer#lastMatchError (error stores in match result object in error field)
    • Added initial implementation of search for AST segments (new lexer methods: Lexer#findValueSegments(), Lexer#findDeclarationValueSegments() and Lexer#findAllSegments)
    • Implemented SyntaxReferenceError for unknown property and type references
  • Renamed field in resulting object of property() function: variablecustom
  • Fixed issue with readonly properties (e.g. line and column) of Error and exception on attempt to write in iOS Safari

1.0.0-alpha19

25 Apr 00:12
Compare
Choose a tag to compare
  • 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

03 Apr 21:15
Compare
Choose a tag to compare
  • Added atrule walk context (#39)
  • Changed a result of generate method for AnPlusB, AttributeSelector, Function, MediaFeature and Ratio (1e95877)
  • Fixed typo in List exception messages (@strarsis, #42)
  • Improved tokenizer to convert an input to a string

1.0.0-alpha17 – The first step towards extensibility and test against real Web CSS

13 Mar 20:30
Compare
Choose a tag to compare

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
  • Parser
    • Implemented mediaQueryList and mediaQuery parsing contexts
    • Implemented CDO and CDC 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
    • Changed important clause parsing
      • Allowed any identifier for important (to support hacks like !ie)
      • Store true for important field in case identifier equals to important and string otherwise
    • Fixed parse error formatted message rendering to take into account tabs
    • Removed exposing of Parser class
    • Removed readSelectorSequence(), readSequenceFallback() and readSelectorSequenceFallback methods
    • Used single universal sequence consumer for AtruleExpression, Selector and Value
  • 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 on translateMarkup, 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)
    • Improved mismatch error position
  • Implemented script (gen:syntax) to generate AST format reference page (docs/ast.md) using syntax definition

1.0.0-alpha16

13 Feb 00:01
Compare
Choose a tag to compare
  • Exposed Parser class
  • Added startOffset option to Tokenizer (constructor and setSource() method)
  • Added fallback functions for default (readSequenceFallback) and selector (readSelectorSequenceFallback) sequence readers
  • Fixed edge cases for AnPlusB
  • Fixed wrong whitespace ignoring in Selector consumer