kudzu

0.0.1 • Public • Published

kudzu

Fast evaluation on ESTree-compatible ASTs

Features

  • Comprehensive tests
  • Fully asynchronous API and internals
  • Esprima and Cherow compatible
  • ECMA 3 and IE8 compatible
  • ESNext support

Install

npm install esprima-eval

Usage

var esEval   = require('esprima-eval'),
    esprima  = require('esprima');
 
var ast   = esprima.parseScript(' ... '),
    scope = new esEval.Scope(globals);
 
scope.on('get', function () {
  // supports custom scope data handlers
});
 
scope.on('ConditionalExpression', function () {
  // supports custom lexical node handlers
});
 
scope.walk(ast, function (returnValue) {
  // done
});

Support

Runtime

  • Strict mode
  • Error handling
  • Error skipping/resolution
  • Protected global objects/prototypes

Globals

  • Array
  • Function
  • Object
  • Date
  • Number
  • RegExp
  • String
  • Proxy
  • Symbol
  • Math

Scope

  • Scope chain
  • Function scope (var)
  • Block scope (let)

Operations

  • Binary (&, |, ^)
  • Mathematical (+, -, /, *, %)
  • Increment before (++i, --i)
  • Increment after (i++, i--)
  • Add assignment
  • Subtract assignment
  • Multiply assignment
  • Divide assignment
  • typeof

Conditionals

  • And/or
  • Strict/non-strict equality
  • <, >, <=, >=
  • instanceof
  • If statements

Loops

  • For loops
  • While loops
  • break
  • continue
  • return

Functions

  • Function declarations
  • Anonymous closures
  • Arrow functions
  • Async functions
  • Spread operator
  • Object identity

Proxies

  • Proxy constructor
  • Has/get/set/delete property
  • Get/set property descriptor
  • Get/set prototype
  • Apply

Promises

  • Promise constructor
  • Promise.then
  • Promise.catch

Symbols

Errors

  • Error constructor
  • Stack traces
  • Try/catch

# Prior Art

https://www.npmjs.com/package/esper.js https://www.npmjs.com/package/sandboxr https://github.com/NeilFraser/JS-Interpreter https://github.com/mozilla/narcissus/

Package Sidebar

Install

npm i kudzu

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

78.2 kB

Total Files

30

Last publish

Collaborators

  • rchipka