1.0.0-alpha.27 Rework generator and walker
lahmatiy
released this
14 Jan 16:45
·
467 commits
to master
since this release
Most of the changes of this release relate to rework of generator and walker. Instead of plenty methods there just single method for each one: generate()
for the generator and walk()
for the walker. Both methods take two arguments ast
and options
(optional for the generator). This makes API much simpler (see details about API in Translate AST to string and AST traversal):
Also List
class API was extended, and some utils methods such as keyword()
and property()
were changed to be more useful.
Generator
- Changed node's
generate()
methods invocation, methods now take a node as a single argument and context (i.e.this
) that have methods:chunk()
,node()
andchildren()
- Renamed
translate()
togenerate()
and changed to takeoptions
argument - Removed
translateMarkup(ast, enter, leave)
method, usegenerate(ast, { decorator: (handlers) => { ... }})
instead - Removed
translateWithSourceMap(ast)
, usegenerate(ast, { sourceMap: true })
instead - Changed to support for children as an array
Walker
- Changed
walk()
to take anoptions
argument instead of handler, withenter
,leave
,visit
andreverse
options (walk(ast, fn)
is still works and equivalent towalk(ast, { enter: fn })
) - Removed
walkUp(ast, fn)
, usewalk(ast, { leave: fn })
- Removed
walkRules(ast, fn)
, usewalk(ast, { visit: 'Rule', enter: fn })
instead - Removed
walkRulesRight(ast, fn)
, usewalk(ast, { visit: 'Rule', reverse: true, enter: fn })
instead - Removed
walkDeclarations(ast, fn)
, usewalk(ast, { visit: 'Declaration', enter: fn })
instead - Changed to support for children as array in most cases (
reverse: true
will fail on arrays since they have noforEachRight()
method)
Misc
- List
- Added
List#forEach()
method - Added
List#forEachRight()
method - Added
List#filter()
method - Changed
List#map()
method to return aList
instance instead ofArray
- Added
List#push()
method, similar toList#appendData()
but returns nothing - Added
List#pop()
method - Added
List#unshift()
method, similar toList#prependData()
but returns nothing - Added
List#shift()
method - Added
List#prependList()
method - Changed
List#insert()
,List#insertData()
,List#appendList()
andList#insertList()
methods to return a list that performed an operation
- Added
- Changed
keyword()
method- Changed
name
field to include a vendor prefix - Added
basename
field to contain a name without a vendor prefix - Added
custom
field that contain atrue
when keyword is a custom property reference
- Changed
- Changed
property()
method- Changed
name
field to include a vendor prefix - Added
basename
field to contain a name without any prefixes, i.e. a hack and a vendor prefix
- Changed
- Added
vendorPrefix()
method - Added
isCustomProperty()
method