ast-transform

WebJar for ast-transform

License

License

MIT
Categories

Categories

ORM Data
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

ast-transform
Last Version

Last Version

0.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

ast-transform
WebJar for ast-transform
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/hughsk/ast-transform

Download ast-transform

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/ast-transform/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>ast-transform</artifactId>
    <version>0.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/ast-transform/
implementation 'org.webjars.npm:ast-transform:0.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/ast-transform/
implementation ("org.webjars.npm:ast-transform:0.0.0")
'org.webjars.npm:ast-transform:jar:0.0.0'
<dependency org="org.webjars.npm" name="ast-transform" rev="0.0.0">
  <artifact name="ast-transform" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='ast-transform', version='0.0.0')
)
libraryDependencies += "org.webjars.npm" % "ast-transform" % "0.0.0"
[org.webjars.npm/ast-transform "0.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm : through jar [2.3.4,2.4)
org.webjars.npm : esprima jar [1.0.4,1.1)
org.webjars.npm : escodegen jar [1.2.0,1.3)

Project Modules

There are no modules declared in this project.

ast-transform Flattr this!experimental

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

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.

Versions

Version
0.0.0