Skip to content

asterjs/aster-traverse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aster-traverse

NPM version Build Status

Traverse with aster.

Usage

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);

API

traverse(options)

options.enter, options.leave

Type: Function

Handler functions to be executed on enter/leave of each node.

options.replace

Type: Boolean

If set, result of enter/leave would be used as replacement for node.

Special values

traverse.Skip

If returned from handler, this node would be skipped from processing.

traverse.Break

If returned from handler, breaks traversal completely.

License

MIT License

Releases

No releases published

Packages

No packages published