doc: update README
This commit is contained in:
parent
2cef033cc0
commit
da2cd05723
21
README.md
21
README.md
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue