Skip to content

Commit

Permalink
[Update] Add parse & run docs for readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Siubaak committed May 4, 2020
1 parent 83cc851 commit 5b169ef
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -76,7 +76,9 @@ Sval instance has two methods, **import** and **run**.

- **import** is to import modules into your Sval instance scope, expecting a name and a module as arguments like `import(name: string, mod: any)`, or an object which contains the modules as argument like `import({ [name: string]: any })`. The modules will be automatically declared as global variables. This method is more likely to be used in sandbox mode.

- **run** is to evaluate the code inputed, expecting a string as argument like `run(code: string)`. If you want to export something, there is a internal global `exports` object for mounting what you want to export.
- **parse** is to parse the code with internal [Acorn](https://github.com/acornjs/acorn) or custom parser, to get the corresponding AST, like `parse(code: string)` or `parse(code: string, parser: (code: string, options: svalOptions) => estree.Node`

- **run** is to evaluate the code inputed, expecting a string as argument like `run(code: string)`, or an AST followed ESTree Spec as argument like `run(ast: estree.Node)`. If you want to export something, there is a internal global `exports` object for mounting what you want to export.

Sval instance also has a field, **exports**, to get what you exported from runs, merged if several runs have exports.

Expand Down

0 comments on commit 5b169ef

Please sign in to comment.