Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

document new signature

  • Loading branch information...
commit 86154f72806200b71b71f51f375551a65624569e 1 parent 1c8ef7c
@substack authored
Showing with 16 additions and 26 deletions.
  1. +15 −25 README.markdown
  2. +1 −1  package.json
View
40 README.markdown
@@ -1,5 +1,4 @@
-falafel
-=======
+# falafel
Transform the [ast](http://en.wikipedia.org/wiki/Abstract_syntax_tree) on a
recursive walk.
@@ -11,11 +10,9 @@ except that it uses [esprima](http://esprima.org) instead of
[uglify](https://github.com/mishoo/UglifyJS)
for friendlier-looking ast nodes.
-example
-=======
+# example
-array.js
---------
+## array.js
Put a function wrapper around all array literals.
@@ -46,15 +43,13 @@ output:
})()
```
-methods
-=======
+# methods
``` js
var falafel = require('falafel')
```
-falafel(src, fn)
-----------------
+## falafel(src, opts={}, fn)
Transform the string source `src` with the function `fn`, returning a
string-like transformed output object.
@@ -69,15 +64,15 @@ The return value is string-like (it defines `.toString()` and `.inspect()`) so
that you can call `node.update()` asynchronously after the function has
returned and still capture the output.
-If `typeof src === 'object'`, then `src.source` will be used for the source and
-the rest of the options will be passed directly along to esprima except for
-`'range'` which is always turned on because falafel needs it.
+Instead of passing a `src` you can also use `opts.source`.
+
+All of the `opts` will be passed directly to esprima except for `'range'` which
+is always turned on because falafel needs it.
Some of the options you might want from esprima includes:
`'loc'`, `'raw'`, `'comments'`, `'tokens'`, and `'tolerant'`.
-nodes
-=====
+# nodes
Aside from the regular [esprima](http://esprima.org) data, you can also call
some inserted methods on nodes.
@@ -85,14 +80,12 @@ some inserted methods on nodes.
Aside from updating the current node, you can also reach into sub-nodes to call
update functions on children from parent nodes.
-node.source()
--------------
+## node.source()
Return the source for the given node, including any modifications made to
children nodes.
-node.update(s)
---------------
+## node.update(s)
Transform the source for the present node to the string `s`.
@@ -100,13 +93,11 @@ Note that in `'ForStatement'` node types, there is an existing subnode called
`update`. For those nodes all the properties are copied over onto the
`node.update()` function.
-node.parent
------------
+## node.parent
Reference to the parent element or `null` at the root element.
-install
-=======
+# install
With [npm](http://npmjs.org) do:
@@ -114,7 +105,6 @@ With [npm](http://npmjs.org) do:
npm install falafel
```
-license
-=======
+# license
MIT
View
2  package.json
@@ -1,7 +1,7 @@
{
"name" : "falafel",
"description" : "transform the ast on a recursive walk",
- "version" : "0.1.2",
+ "version" : "0.1.3",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-falafel.git"
Please sign in to comment.
Something went wrong with that request. Please try again.