MCPcopy Index your code
hub / github.com/LuanRT/Jinter

github.com/LuanRT/Jinter @jintr-v3.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release jintr-v3.3.1 ↗ · + Follow
140 symbols 327 edges 48 files 5 documented · 4%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Jinter

A tiny JavaScript interpreter written in TypeScript

Tests

Note: This project was originally developed for use in YouTube.js.

Table of Contents

Installation

npm install jintr

Usage

Execute some JavaScript code:

// const Jinter = require('jintr').default;
import { Jinter } from 'jintr';

const code = `
  function sayHiTo(person) {
    console.log('Hi ' + person + '!');
  }

  sayHiTo('mom');
`

const jinter = new Jinter();
jinter.evaluate(code);

Inject your own functions, objects, etc:

import { Jinter } from 'jintr';

const jinter = new Jinter();

const code = `
  console.log(new SomeClass().a);
  console.log('hello'.toArray());

  function myFn() {
    console.log('[myFn]: Who called me?');
  }

  myFn();
`;

class SomeClass {
  constructor() {
    this.a = 'this is a test';
  }
}

jinter.defineObject('SomeClass', SomeClass);

// Ex: str.toArray();
jinter.visitor.on('toArray', (node, visitor) => {
  if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression') {
    const obj = visitor.visitNode(node.callee.object);
    return obj.split('');
  }
});

// Intercept function calls
jinter.visitor.on('myFn', (node) => {
  if (node.type == 'CallExpression')
    console.info('myFn was called!');
  return '__continue_exec';
});

jinter.evaluate(code);

For more examples see /test and /examples.

API

evaluate(input: string)

Evaluates the given JavaScript code.

visitor

The node visitor. This is responsible for walking the AST and executing the nodes.

scope

Represents the global scope of the program.

License

Distributed under the MIT License.

(back to top)

Extension points exported contracts — how you extend this code

JSNode (Interface)
(no doc) [37 implementers]
src/utils/index.ts
JSNodeConstructor (Interface)
(no doc)
src/utils/index.ts

Core symbols most depended-on inside this repo

visitNode
called by 79
src/visitor.ts
evaluate
called by 73
src/main.ts
getName
called by 13
src/visitor.ts
defineObject
called by 6
src/main.ts
namedFunction
called by 3
src/utils/index.ts
#throwError
called by 3
src/nodes/CallExpression.ts
run
called by 2
src/utils/index.ts
setAST
called by 1
src/visitor.ts

Shape

Class 78
Method 59
Interface 2
Function 1

Languages

TypeScript100%

Modules by API surface

src/visitor.ts8 symbols
src/utils/index.ts7 symbols
src/nodes/Property.ts6 symbols
src/main.ts6 symbols
src/nodes/CallExpression.ts5 symbols
src/nodes/AssignmentExpression.ts5 symbols
src/nodes/UnaryExpression.ts4 symbols
src/nodes/LogicalExpression.ts4 symbols
src/nodes/ForStatement.ts4 symbols
src/nodes/BaseJSNode.ts4 symbols
src/nodes/WhileStatement.ts3 symbols
src/nodes/VariableDeclaration.ts3 symbols

For agents

$ claude mcp add Jinter \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page