Skip to content

Commit 63eb0a6

Browse files
committed
docs: update readme
1 parent 84e33ef commit 63eb0a6

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

README.md

+42-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
# nebu v1.2.0
1+
# nebu
22

3-
Fast, extensible, and light Javascript transformer. (pronounced `nee-boo`)
3+
[![npm](https://img.shields.io/npm/v/nebu.svg)](https://www.npmjs.com/package/nebu)
4+
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
5+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/alecdotbiz)
6+
7+
Fast, extensible, statically typed, and light Javascript transformer. (pronounced `nee-boo`)
48

59
**Why bother?** Nebu saves developers from the slow and heavy [Babel][1] compiler. Nebu skips AST-to-code generation, preferring simple string mutations, while keeping sourcemap support. This improves performance, preserves coding style, and makes plugins less clunky.
610

7-
For ES6 support, use [Bublé][2] *after* using Nebu.
11+
If you need to transpile ES6+ to ES5, use [Bublé][2] *after* using Nebu.
812

913
If you believe in Nebu's mission, consider building a Nebu plugin. The ecosystem is practically non-existent. It needs your help! 🤓
1014

@@ -13,6 +17,25 @@ If you believe in Nebu's mission, consider building a Nebu plugin. The ecosystem
1317
[1]: https://github.com/babel/babel
1418
[2]: https://github.com/Rich-Harris/buble
1519

20+
 
21+
22+
## Examples
23+
24+
See the `examples` folder for plugin examples.
25+
26+
You can test these examples like so:
27+
28+
```sh
29+
git clone https://github.com/alloc/nebu
30+
cd nebu && pnpm i
31+
cd examples && pnpm i
32+
./try nebu-strip-dev
33+
```
34+
35+
 
36+
37+
## Usage
38+
1639
```js
1740
const nebu = require('nebu');
1841

@@ -32,37 +55,38 @@ The `process` function traverses the AST depth-first, which means children are
3255
visited before neighbors, and parents are visited before children.
3356

3457
The `process` function has the following options:
35-
- `ast: ?object` pre-existing ESTree object
36-
- `state: ?object` state passed to each visitor
58+
- `ast?: object` pre-existing ESTree object
59+
- `state?: object` state passed to each visitor
3760
- `plugins: object[]` array of visitor maps
38-
- `filename: ?string` path to the source code
39-
- `sourceMaps: ?string|true` sourcemap type
40-
- `generatedFile: ?string` path to the generated code
41-
- `includeContent: ?boolean` include source content in sourcemap
42-
- `parser: ?object` options for the parser
61+
- `filename?: string` path to the source code
62+
- `sourceMap?: boolean | "inline"` sourcemap type
63+
- `sourceMapTarget?: string` sourcemap path (relative to `filename`)
64+
- `generatedFile?: string` path to the generated code
65+
- `includeContent?: boolean` include source content in sourcemap
66+
- `jsx?: boolean` enable JSX parsing
4367

44-
The `plugins` array is required, and must contain at least one plugin. It may contain nested arrays of plugins.
68+
The `plugins` array is required. Plugins are objects whose keys are ESTree node types and each value is a function that receives the node and shared state. The `plugins` array supports a plugin being wrapped in `{default: plugin}` for ESM interop.
4569

4670
The `state` object is useful when a plugin analyzes the structure of your code and needs to communicate this information back to you. Another use case is inter-visitor communication.
4771

48-
The `sourceMaps` option defaults to falsy, which means no sourcemap is generated. Setting `sourceMaps` to `true` or `"both"` will generate a `SourceMap` object and return it as the `map` property of the result object. Setting `sourceMaps` to `"inline"` or `"both"` will append a `//# sourceMappingURL` comment to the generated code. When `sourceMaps` equals `"inline"` or falsy, the `process` function returns a string (the generated code) instead of an object.
72+
The `sourceMap` option defaults to false, so no sourcemap is generated. Setting `sourceMap` to `true` will generate a `SourceMap` object and return it as the `map` property of the result object. Setting `sourceMap` to `"inline"` will append a `//# sourceMappingURL` comment to the generated code.
4973

50-
The `includeContent` option defaults to true, which means you must explicitly specify `false` to exclude source content from the sourcemap.
74+
The `includeContent` option defaults to true. You must explicitly specify `false` to exclude source content from the sourcemap.
5175

52-
The `parser` options object is passed to `acorn.parse`, whose valid options are listed [here](https://github.com/acornjs/acorn#main-parser). The `ecmaVersion` option is always set to `9` (to stay compatible with Bublé). The `sourceType` option is always set to `"module"`.
76+
### Utilities
5377

54-
### nebu.acorn
78+
The `nebu/utils` module exports a few utility functions you may find useful when developing a plugin.
5579

56-
To override the `acorn` module that nebu uses, you can set `nebu.acorn` before calling `nebu.process` for the first time.
80+
```js
81+
import { findParent } from 'nebu/utils'
82+
```
5783

5884
## Node API
5985

6086
Every node (except the root node) has these properties:
6187
- `parent: Node` the nearest container node
6288
- `ref: string` the parent property that contains us
6389

64-
The `acorn.Node` prototype is temporarily extended with the following methods.
65-
6690
NOTE: Methods that take a `code` argument do *not* validate it for syntax errors. So be careful!
6791

6892
### isLiteral(type)

0 commit comments

Comments
 (0)