reflect

JavaScript parser adhering to Mozilla's parser API

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 articulatedby 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 docsfor details on the AST interface.

Builders

The optional builderparameter 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 builderso 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.

Repository

https://github.com/zaach/reflect.js


上一篇:evolve
下一篇:esfuzz

相关推荐

  • 【资源集合】 ES6 元编程(Proxy & Reflect & Symbol)

    导读 几年前 ES6 刚出来的时候接触过 元编程(Metaprogramming)的概念,不过当时还没有深究。今天在应用和学习中不断接触到这概念,比如 mobx 5() 中就用到了 Proxy 重...

    2 年前
  • 【ES6入门10】:Proxy和Reflect

    Proxy代理 Reflect反射 反射的是 object,Reflect的方法跟Proxy一样,都有get,set,has... 数据校验例子 ...

    2 年前
  • reflective-bind

    Eliminate wasteful rerendering in React components caused by inline functions Build Status(https://...

    23 天前
  • reflect.ownkeys

    ES2015 speccompliant shim for Reflect.ownKeys reflect.ownkeys Version Badgenpmversionsvgpackageurl...

    1 年前
  • reflect-own-keys-x

    Sham for Reflect.ownKeys reflectownkeysx Sham for Reflect.ownKeys ⇒...

    7 个月前
  • reflect-metadata

    Polyfill for Metadata Reflection API Metadata Reflection API Detailed proposalMetadataSpec Ins...

    2 年前
  • p-reflect

    Make a promise always fulfill with its actual fulfillment value or rejection reason preflect Build...

    1 年前
  • has-reflect-support-x

    Tests if ES6 Reflect is supported. hasreflectsupportx Tests if ES6 Reflec...

    7 个月前
  • harmony-reflect

    ES5 shim for ES6 (ECMAScript 6) Reflect and Proxy objects NPM version(https://badge.fury.io/js/harm...

    2 年前
  • glsl-extract-reflect

    turn glslextract into a JSON tree glslextractreflect stable(http://badges.github.io/stabilitybadg...

    1 年前

官方社区

扫码加入 JavaScript 社区