Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

brushtail

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brushtail

JS AST rewriter for tail call elimination

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Brushtail

Tail call optimisation for JavaScript.

Examples

example.js:

function count(from, to) {
    if(from >= to)
        return from;

    return count(from + 1, to);
}

console.log(count(0, 1000000));

Is rewritten into:

function count(from, to) {
    var __tcor;
    tco:
        while (true) {
            if (from >= to) {
                __tcor = from;
                break tco;
            }
            {
                var __from = from + 1, __to = to;
                from = __from;
                to = __to;
                continue tco;
            }
        }
    return __tcor;
}
console.log(count(0, 1000000));

Using the command-line tool:

$ brushtail example.js | node
1000000

For comparison, without the command-line tool:

$ node example.js

brushtail/example.js:1
n (exports, require, module, __filename, __dirname) { function count(from, to)
                                                                    ^
RangeError: Maximum call stack size exceeded

API

brushtail.tco(content)

Takes a JavaScript program as a String. Returns a String with a tail call optimised program.

brushtail.mutateAST(ast)

Takes a Mozilla Parser AST and mutates away tail calls.

brushtail.optimizeFunction(functionDeclaration)

Takes a function declaration in Mozilla Parser AST form and mutates away tail calls.

License

MIT

Keywords

FAQs

Package last updated on 24 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc