reflect
JavaScript parser adhering to Mozilla's parser API
Last updated 14 years ago by zaach .
Repository · Bugs · Original npm · Tarball · package.json
$ npm install reflect 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.1.3                                ...           latest (14 years ago)

9 Versions

  • 0.1.3                                ...           14 years ago
  • 0.1.2                                ...           14 years ago
  • 0.1.1                                ...           14 years ago
  • 0.0.7                                ...           14 years ago
  • 0.0.6                                ...           14 years ago
  • 0.0.5                                ...           15 years ago
  • 0.0.4                                ...           15 years ago
  • 0.0.3                                ...           15 years ago
  • 0.0.2                                ...           15 years ago
Maintainers (1)
Downloads
Total 27
Today 0
This Week 8
This Month 22
Last Day 0
Last Week 10
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE