n-riesco / nel

Node.js module for running a javascript REPL session

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compile 2 JavaScript language support

kebot opened this issue · comments

Thank you for your cool things about iPython Notebook.

I just make two line modify to support CoffeeScript. It works!

  function run(code) {
    var compiledCode = require('coffee-script').compile(code, {bare: true})
    if(DEBUG) { console.log("SM: COMPILED: ```\n", compiledCode, '\n') }
    return vm.runInThisContext(compiledCode);
  }

But I'm not familiar with the architecture, I'm thinking how to make it support any compiler that exists(coffeescript, babel, etc...)

Here are some ways to do it:

  1. build-in compiler ijavascript --compile coffee, compiler can provided as plugins(such as ijavascript-coffee-plugin)
  2. I also see a Cell - Cell Type in the dropdown menubar, maybe add some custom cell-type there
Code(javascript)
Code(CoffeeScript)
Code(babel)
Markdown

To implement that, there are some points

  • async compiler support
  • is Cell Type in iPython pluginable?
  • Source Map Support

Thank you for the interest in this project.

Here's a brief outline of the IJavascript architecture:

  • IJavascript package implements a kernel for the IPython/Jupyter notebook.
  • NEL package runs Javascript on a Node.js session, but also provides auto-completion and documentation functionality.

The kernel in the IJavascript package is already language-agnostic. This means that it is possible to fork the NEL package and make it compile TypeScript, CoffeeScript, ES6, or even use a shell other than Node.js. Note, however, that NEL also provides auto-completion and documentation functionality and those would need updating for the new language.

This is how I suggest that a CoffeeScript kernel could be developed:

  1. Fork the NEL package
  2. Update the run functionality (see http://n-riesco.github.io/nel/module-nel-Session.html#run)
  3. Update the inspect functionality (see http://n-riesco.github.io/nel/module-nel-Session.html#inspect)
  4. Update the auto-completion functionality (see http://n-riesco.github.io/nel/module-nel-Session.html#complete)
  5. Once the forked NEL package is working, I would update IJavascript so that one could run the CoffeeScript kernel.

Note that:

  • your update of the run function in nel_server.js means that Session#run may require no changes.
  • Step 3 and 4 require replacing the list of JavaScript keywords with CoffeeScript keywords
  • Step 3 and 4 may require other changes to account for some of the CoffeeScript operators (e.g. ? and @)

As you see, the changes to get an initial implementation of a CoffeeScript kernel would be few.

I would be happy to help with the fork, so please, let me know if you go ahead.