doc: update README

This commit is contained in:
Michal Szczepanski 2023-05-05 22:57:15 +02:00
parent 2cef033cc0
commit da2cd05723
3 changed files with 11 additions and 14 deletions

View File

@ -5,28 +5,23 @@ javascript interpreter in javascript - poc
I saw that [JS-Interpreter](https://github.com/NeilFraser/JS-Interpreter) is single file so grabbed example fibonacci
and wrote [arcon](https://github.com/acornjs/acorn) parser from scratch.
### Basic test to count fibonacci numbers
### Basic tests
```bash
npm run test
> @szczepano/browser-js@0.0.1 test
> jest
PASS src/decorators/loop.test.ts
PASS src/visitors/array.test.ts
PASS src/js.interpreter.test.ts
js.interpreter.test
✓ calculate fibonacci (5 ms)
✓ array->set-index (1 ms)
✓ array->assign a[0] += 1
✓ array->assign a[0] -= 1 (1 ms)
✓ array->assign - a[0] = a[0] - 1
✓ array->assign - a[0] = 1 - a[0] (1 ms)
✓ array->assign - a[0] = a[0] + a[0]
✓ array->assign - a[0] += a[0]
PASS src/decorators/condition.test.ts
Test Suites: 1 passed, 1 total
Tests: 8 passed, 8 total
Test Suites: 4 passed, 4 total
Tests: 14 passed, 14 total
Snapshots: 0 total
Time: 0.789 s, estimated 1 s
Time: 0.781 s, estimated 1 s
Ran all test suites.
```
### Example that runs in browser with custom global function

View File

@ -31,6 +31,7 @@ export interface VariableDeclarator extends Node {
export interface VariableDeclaration extends Node {
declarations: VariableDeclarator[];
kind?: 'const' | 'var' | 'let';
}
export interface FunctionDeclaration extends Node {

View File

@ -13,7 +13,8 @@ class ConsoleDecorator {
document.getElementById('run-btn').addEventListener('click', () => {
log.innerHTML = '';
const code = (document.getElementById('code') as HTMLTextAreaElement).value;
const ast = acorn.parse(code, { ecmaVersion: 5 });
const ast = acorn.parse(code, { ecmaVersion: 6 });
console.log(ast);
const js = new JsInterpreter();
js.varCache.set('console', new ConsoleDecorator());
js.run((ast as Program).body);