You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			|  | 4 years ago | |
|---|---|---|
| .. | ||
| node_modules | 4 years ago | |
| LICENSE.md | 4 years ago | |
| README.md | 4 years ago | |
| index.js | 4 years ago | |
| package.json | 4 years ago | |
		
			
				
				README.md
			
		
		
	
	ast-transform 

Convenience wrapper for performing AST transformations with browserify transform streams. Note that it doesn't handle source maps nicely, though pull requests are welcome!
Usage
ast(transform[, opts])
Where transform is a function that takes a filename and returns a function,
e.g.:
var replace = require('replace-method')
var ast = require('ast-transform')
var path = require('path')
module.exports = ast(function (file) {
  if (path.extname(file) !== '.js') return
  return function(ast, done) {
    // replace require calls with
    // strings for some reason
    replace(ast)(['require'], function(node) {
      return { type: 'Literal', value: 'replaced!' }
    })
    done()
  }
})
Note that you can return a falsey value instead of a function to bail the stream early and avoid the parse/deparse overhead. Here's an example of using the above with browserify:
var browserify = require('browserify')
var example = require('./example')
var fs = require('fs')
browserify('./index.js')
  .transform(example)
  .bundle()
  .pipe(fs.createWriteStream(__filename + '/bundle.js'))
License
MIT. See LICENSE.md for details.
