Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

monotone

0.1.0 • Public • Published

monotone

An implementation of the monotone framework for JavaScript

Install

npm install monotone --save

Usage

import { monotone, runString, Direction, TransferResult } from "monotone";
 
const instance = monotone((files, checker) => {
    return {
        direction: Direction.Backward,    // Or Direction.Forward
        
        bottom: undefined,                // Bottom value
        entry() {
            return undefined;             // Initial value for entry points
        },
        union(a, b) {
            return undefined;             // Combine two values
        },
        isLessOrEqual(a, b) {
            return true;                  // Compare two value
        },
        
        kinds: [GraphNodeKind.Begin],     // The positions of nodes in the AST that have a transfer function
        filter(node) {
            return true;                  // Filter nodes that have a transfer function
        }
        transfer(node, kind, state, get) {
            return TransferResult(state); // The transfer function of the monotone framework
        },
        result(get) {
            return undefined;             // Extract the information from the final state
        }
    };
});
const result = runString(instance, `function(a, b) { return a + b }`);

You can find a complete example, which implements live variable analysis, in src/test/monotone-example.ts.

This project uses the TypeScript compiler for parsing and scope analysis, which can parse both JavaScript and TypeScript.

Build

You can build this project with npm run build and test it with npm test.

License

Monotone is licensed under the MIT license.

Install

npm i monotone

DownloadsWeekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • avatar