Replace nodes with CSS-like selectors in aster.
Allows to use CSS-style selectors for finding nodes and replacing them with results of corresponding handlers.
Uses grasp-squery behind the scenes, so check out official documentation for syntax details.
First, install aster-squery
as a development dependency:
npm install --save-dev aster-squery
Then, add it to your build script:
var aster = require('aster'); var squery = require('aster-squery'); aster.src('src/**/*.js') .map(squery({ 'if[then=return][else=return]': function (node) { return { type: 'ReturnStatement', argument: { type: 'ConditionalExpression', test: node.test, consequent: node.consequent.argument, alternate: node.alternate.argument } }; } // , ... })) .map(aster.dest('dist')) .subscribe(aster.runner);
can be also written as:
var aster = require('aster'); var equery = require('aster-equery'); aster.src('src/**/*.js') .map(equery({ 'if[then=return][else=return]': 'return <%= test %> ? <%= consequent.argument %> : <%= alternate.argument %>' // , ... })) .map(aster.dest('dist')) .subscribe(aster.runner);
Type: {pattern: handler}
Replacement mappings.
Type: String
Type: Function(node, named)
Callback to be called on each found match. It will get two arguments - matched node object and hashmap of named subpatterns.
handler (option 2: template)Type: String
estemplate string to be used for generating AST.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4