Hygienic Macros for JavaScript!
- Read a tutorial on macros.
- Read the documentation at sweetjs.org.
- Play with the editor.
- Hang out on IRC #sweet.js at irc.mozilla.org.
- Try out other macros.
Install sweet.js with npm:
$ npm install -g sweet.js
And compile your sweet macro enhanced code:
$ sjs --output compiled.js my_sweet_code.js
You can collect your macros into a single module file to share with your other code or on npm. Full details here but the basic idea is to define your macros in a file macros.js
and use the export
keyword:
// macros.js
macro m { ... }
export m;
Then compile using the --module
flag:
sjs --module /macros.js my_sweet_code.js
The --module
also looks up along the npm
path so you can install macro modules from npm
(using lambda-chop as an example):
npm install lambda-chop
sjs --module lambda-chop/macros my_sweet_code.js
If you want to share your macros on npm we recommend using the sweet-macros keyword to make macros easy to find.
Install the dev dependencies:
$ npm install
Build and run the tests:
$ grunt
Sweet.js is self hosted so you hack on the files in src/
using the version of sweet.js already built in lib/
. When you are happy with your hacking, grunt dist
will build a new version of sweet.js and put it into lib/
.
Slightly confusing but the process goes like this:
<hack hack hack>
$ grunt
<tests fail!>
<hack hack hack>
$ grunt
<tests pass!>
$ grunt dist
$ git add lib/
$ git commit -m "sweet!"
Built on top of esprima and escodegen. Contributors are awesome!