Skip to content

Instantly share code, notes, and snippets.

@asalant
Last active March 3, 2018 08:22
Show Gist options
  • Save asalant/4155716 to your computer and use it in GitHub Desktop.
Save asalant/4155716 to your computer and use it in GitHub Desktop.
CoffeeScript REPL using Node's REPL
#!/usr/bin/env node
var vm = require('vm');
var repl = require('repl');
var CoffeeScript = require('coffee-script');
repl.start({
prompt: "coffee> ",
eval: function(code, context, file, cb) {
try {
code = CoffeeScript.compile(code, {filename: file, bare: true});
cb(null, vm.runInContext(code, context, file));
}
catch (err) {
cb(err);
}
}
});
@hems
Copy link

hems commented Aug 20, 2017

Thanks for sharing this one!

There is a problem tough which is the auto complete for some reason bugs out once i do that.

For instance:

vm           = require 'vm'
repl         = require 'repl'
CoffeeScript = require 'coffee-script'

server = repl.start
  prompt: '>'
  eval  : (code, context, file, done) ->
    try
      code = CoffeeScript.compile code, { filename: file, bare: true }
      done null, vm.runInContext(code, context, file)

    catch error
      done error

server.context.clock =
  start: 'start'
  stop : 'stop'

then open the repl, type clo<tab> and it will auto complete to clock but once you add the "." and press <tab> it won't auto complete the "start" and "stop" properties.

If you take the "eval" function out, and let it be "javascript" it will auto complete all levels...

any ideas?

@hems
Copy link

hems commented Aug 20, 2017

i found out you can customise the "completer" function but then you have to complete the "globals" as well...

sounds like a lot of work, but in a way a bit of fun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment