Skip to content

Commit 663c800

Browse files
committed
init
0 parents  commit 663c800

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
js/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-present Alec Larson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# nebu v0.0.0
2+
3+
Transform your Javascript with [acorn][1] trees.
4+
5+
Source maps included, thanks to [magic-string][2].
6+
7+
Pronounced **nee-boo**.
8+
9+
[1]: https://github.com/acornjs/acorn
10+
[2]: https://github.com/Rich-Harris/magic-string
11+
12+
```js
13+
const nebu = require('nebu');
14+
15+
nebu.walk(code, {
16+
ast: {}, // use an existing ESTree object
17+
plugins: [{
18+
Identifier(node) {
19+
if (node.name == 'foo') {
20+
node.replace('bar')
21+
}
22+
}
23+
}],
24+
})
25+
```
26+
27+
The `walk` function traverses the AST depth-first, which means children are
28+
visited before neighbors, and parents are visited before children.
29+
30+
## Node API
31+
32+
Every node (except the root node) has a `parent` property that points to
33+
the parent node.
34+
35+
Nodes are extended with the following methods.
36+
37+
The `acorn.Node` prototype is temporarily mutated.
38+
39+
Any `code` arguments are parsed appropriately.
40+
41+
### update(prop, code)
42+
43+
Update some property of the node.
44+
45+
The property must support `Node` values.
46+
47+
### insert(prop, code)
48+
49+
Insert a node into an array of child nodes.
50+
51+
### replace(code)
52+
53+
Replace the node.
54+
55+
### remove(prop)
56+
57+
Remove some property of the node.
58+
59+
When `prop` is undefined, remove the node entirely.
60+
61+
Removing the current node's ancestor is *not* supported.
62+
63+
Be careful, this can break your code!

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "nebu",
3+
"version": "0.0.0",
4+
"description": "Transform your acorns",
5+
"license": "MIT",
6+
"main": "js/index",
7+
"scripts": {
8+
"build": "coffee-build src -o js",
9+
"prepublishOnly": "prepv -i || true"
10+
},
11+
"dependencies": {
12+
"acorn": "^5.5.3",
13+
"magic-string": "^0.24.0"
14+
},
15+
"devDependencies": {
16+
"wch-coffee": "^0.2.0"
17+
},
18+
"repository": "https://github.com/aleclarson/nebu.git",
19+
"engines": {
20+
"node": ">= 7.6.0"
21+
}
22+
}

0 commit comments

Comments
 (0)