Traverse with aster.
First, install aster-traverse
as a development dependency:
npm install --save-dev aster-traverse
Then, add it to your build script:
var aster = require('aster');
var traverse = require('aster-traverse');
aster.src('src/**/*.js')
.map(traverse({
replace: true,
leave: function (node) {
// Optimizing obvious calculations, concatenations, etc.
if (node.type === 'BinaryExpression' && node.left.type === 'Literal' && node.right.type === 'Literal') {
return {type: 'Literal', value: eval(JSON.stringify(node.left.value) + node.operator + JSON.stringify(node.right.value))};
}
}
}))
.map(aster.dest('dist'))
.subscribe(aster.runner);
Type: Function
Handler functions to be executed on enter/leave of each node.
Type: Boolean
If set, result of enter
/leave
would be used as replacement for node.
If returned from handler, this node would be skipped from processing.
If returned from handler, breaks traversal completely.