Experimental module to wrap the traceur-compiler cli to add REPL and functionality for doing string evaluations.
You can still use the original features as you'd expect.
npm install -g traceur-cli
➜ traceur-cli
traceur> var f = (a) => a * 2;
undefined
traceur> f(2)
4
traceur>
➜ traceur-cli
traceur> var f = () => {
... return "Hello, World!";
... };
undefined
traceur> f()
'Hello, World!'
traceur>
➜ traceur-cli
traceur> var foo = (for (x of [1, 2, 3, 4]) "Foo: " + x);
undefined
traceur> foo.next();
{ value: 'Foo: 1', done: false }
traceur> foo.next();
{ value: 'Foo: 2', done: false }
traceur> foo.next();
{ value: 'Foo: 3', done: false }
➜ traceur-cli
traceur> [for (x of [1, 2, 3, 4]) "Foo: " + x]
[ 'Foo: 1',
'Foo: 2',
'Foo: 3',
'Foo: 4' ]
➜ traceur-cli
traceur> var { user, age } = { user: "mikaelbr", url: "https://github.com/mikaelbr" };
undefined
traceur> user
'mikaelbr'
traceur> url
https://github.com/mikaelbr
traceur>
➜ traceur-cli
traceur> import { username, url } from './b';
undefined
traceur> username
'mikaelbr'
traceur> url
'https://github.com/mikaelbr/traceur-cli'
➜ traceur-cli
traceur> var { readFileSync } = require('fs');
undefined
traceur> readFileSync
[Function]
traceur>
➜ traceur-cli
traceur> var x = 0;
undefined
traceur> var obj = { [x]: "Foo"; };
<unknown file>:1:23: Unexpected token ;,<unknown file>:1:25: Unexpected token }
traceur> var obj = { [x]: "Foo" };
undefined
traceur> obj
{ '0': 'Foo' }
traceur>
You can use regular Node repl functions as .save
and .load
.
➜ traceur-cli
traceur> .help
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.exit Exit the repl
.help Show repl options
.load Load JS from a file into the REPL session
.save Save all evaluated commands in this REPL session to a file
traceur> var f = () => "hello, world";
undefined
traceur> f
[Function]
traceur> f()
'hello, world'
traceur> .save test
Session saved to:test
traceur> .exit
➜ traceur-cli
traceur> .load test
traceur> var f = () => "hello, world";
undefined
traceur> f
[Function]
traceur> f()
'hello, world'
traceur> .exit
➜ traceur-cli -e '({ foo: "bar", bar: "bat" });'
{ foo: 'bar', bar: 'bat' }
➜ traceur-cli -e 'var { foo, bar } = {foo: "Some", bar: "Data"}; console.log(foo + " " + bar)'
Some Data
undefined
➜ traceur-cli -e '({ foo: "bar", bar: "bat" });' > test.txt
➜ cat test.txt
{ foo: 'bar', bar: 'bat' }
➜ traceur-cli -e 'console.log("hello"); var foo = "Bar"; console.log(foo); foo;'
hello
Bar
Bar
➜ traceur-cli -e '(for (x of [1, 2, 3, 4]) "Foo: " + x).next()'
{ value: 'Foo: 1', done: false }
➜ echo '({ foo: "bar", bar: "bat" });' | traceur-cli
traceur> ({ foo: "bar", bar: "bat" });
{ foo: 'bar', bar: 'bat' }
traceur> %
➜
You can use the traceur-cli as a wrapper for the original functionality of traceur.
For instance by using -h
:
➜ traceur-cli -h
Usage: traceur-cli [options] [files]
Commands:
# [...etc]
Or compiling files:
➜ traceur-cli --script example.js --out compiled.js
➜ node compiled.js
{ '0': 'Foo' }
Make it work with iterators.Add support for multiline/blocks- ~~Add support for modules/requires in repl. (Has now basic support.)~
- Tests