ikorni

1.0.0 • Public • Published

ikorni

ikorni

A wrapper for acorn allowing for easy mutation of Node values.

Installation

npm install --save ikorni

Usage

var ikorni = require('./index.js');
var ast = ikorni.parse('var x = 0;');
ast.replace(ast.body[0].declarations[0].id, 'y');
console.log(ast.generate);
var y = 0;

API

var ast = ikorni.parse(source, opts)

Same as acorn.parse(input, opts)

ast.replace(node, value)

Update the source code representing the provided node in the AST with value.

A few notes:

  • Strings must include quotes, example: ast.replace(node, '\'foo.js\'').
  • node will be left unchanged. If you need to update the AST with your changes, you will need to generate the new source and re-parse. You can get the current value of the node as it would be written out via generate with getValue.

var source = ast.getValue(node)

Returns the current source represented by node, based on the changes made by all of the replace invocations.

var source = ast.generate()

Returns a new source file updated with everything that has been mutated with ast.replace.

Package Sidebar

Install

npm i ikorni

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

4.96 kB

Total Files

5

Last publish

Collaborators

  • retrohack3r