Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Implementation of Mozilla's Parser API in JavaScript
JavaScript
branch: master

This branch is 5 commits ahead, 18 commits behind zaach:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
dist
examples
lib
scripts
standalone
test
.gitignore
.npmignore
Makefile
README.md
package.json
reflectjs.png

README.md

Reflect.js

Reflect.js is a JavaScript (ES3 compatible) implementation of Mozilla's Parser API. It does not currently support some of Mozilla's extensions, such as generators, list comprehensions, for each, E4X, etc. but may eventually support ones that are, or become Harmony proposals. Builders are also supported.

Parsing really large files can be slow, for reasons articulated by Andy Chu.

Download

You can download a minified-standalone version of reflect.js to embed in web pages here.

Install

Reflect.js is available as a CommonJS module for Node.js. Simply install it with npm:

npm install reflect

Use

var Reflect = require('reflect');

var ast = Reflect.parse("var a = 4 + 7");

console.log(Reflect.stringify(ast, "  "));

Refer to Mozilla's docs for details on the AST interface.

Builders

The optional builder parameter to Reflect.parse() makes it possible to construct user-specified data from the parser, rather than the default Node objects.

The reflect.js module exports the default builder so you can redefine only the node constructors you care about and leave the rest default.

var Reflect = require('reflect');
var builder = Reflect.builder;

// redefine callback for variable declarations
builder["variableDeclaration"] = function (kind, declarators, loc) { ... };

var ast = Reflect.parse("var a = 4 + 7", {builder: builder});

License

MIT X Licensed.

Something went wrong with that request. Please try again.