Skip to content

Commit

Permalink
Readme: more detailed examples for module code
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Apr 15, 2019
1 parent 4c78ea7 commit 0b54e86
Showing 1 changed file with 71 additions and 9 deletions.
80 changes: 71 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ eshost-cli makes it easy to run and compare ECMAScript code uniformly across a n

See eshost's [supported hosts](https://github.com/bterlson/eshost#supported-hosts) for a list of hosts, download/build locations, and other information.

### Usage
## Usage

See `--help` output for the full details. Basic usage:

Expand All @@ -22,29 +22,33 @@ See `--help` output for the full details. Basic usage:
- `eshost -mx "foo = 42; print(foo);"` (this example should result in errors!)
* Execute a source file as module code by saving the file with an `.mjs` extension: `eshost file.mjs`; or by using the `-m` option: `eshost -m file.js`

#### Examples
### Examples

```
$ npm install -g eshost-cli
$ eshost --help
$ eshost --add <name> <type> <path to host executable> --args <optional arguments>
$ eshost -e "Map.length"
#### Chakra
0
## chakra-es6
#### engine262
0
## d8
#### JavaScriptCore
0
## chakra
#### SpiderMonkey
0
## spidermonkey
1
#### V8
0
## node
#### XS
0
```

```
$ eshost --configure-jsvu --jsvu-prefix jsvu
$ eshost --tags jsvu-web -itsx "let a = 40+2; print(a)"
Expand All @@ -59,7 +63,65 @@ let a = 40+2; print(a)
└──────────┴────┘
```

### Managing Hosts
### Rules For Module Code

Files containing the imported modules must be located in the same directory that the "entry point" file is located. Please read and accept the following examples.

1. Executing a program with module dependencies, where the entry point is a ".mjs" file:

```
mkdir entry-point-mjs;
cd entry-point-mjs;
echo "export var a = 1;" >> export.mjs
echo "import {a} from './export.mjs'; print(a);" >> import.mjs
eshost --host="engine262,JavaScriptCore,SpiderMonkey,V8,XS" import.mjs
#### engine262
1
#### JavaScriptCore
1
#### SpiderMonkey
1
#### V8
1
#### XS
1
```

2. Executing a program with module dependencies, where the entry point is a ".js" file:

(Notice the use of the `-m` flag, **this is required for ".js" files**)
```
mkdir entry-point-js;
cd entry-point-js;
echo "export var a = 1;" >> export.mjs
echo "import {a} from './export.mjs'; print(a);" >> import.js
eshost --host="engine262,JavaScriptCore,SpiderMonkey,V8,XS" -m import.js
#### engine262
1
#### JavaScriptCore
1
#### SpiderMonkey
1
#### V8
1
#### XS
1
```

**Executing a multi-line program with module dependencies is not yet supported. Support is in progress.**


## Managing Hosts

You can `--list`, `--add`, `--edit`, and `--delete` hosts. Adding a host requires a name, type, and path to the runtime executable. You can optionally pass arguments using `--args`. The same host can be added multiple times with different `--args` which makes it easy to compare the output of runtimes given different options (e.g. by turning language features on and off).

Expand Down

0 comments on commit 0b54e86

Please sign in to comment.