From 0b54e86edd6396a34a1307886fcedd65e2b72a13 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 15 Apr 2019 13:03:19 -0400 Subject: [PATCH] Readme: more detailed examples for module code --- README.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0efddf3..576af2b 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 --args $ 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)" @@ -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).