Coffeescript

Is it possible to evaluate coffeescript inside cells? like you can use coffeescript/require from js files?

We don’t currently support transpilers, but you could evaluate JavaScript dynamically (using eval or the Function constructor).

Could you show us how?

Probably would be a hundred times better if we packaged it with template literals like

coffee`(x) -> x * x`

but here is the coffeescript compiler running in observable https://observablehq.com/@tomlarkworthy/coffeescript-demo

2 Likes

Tks!

Adding to your contribution: https://observablehq.com/@fernandortdias/coffeescript-proof-of-concept

2 Likes

You could also remove the parentheses from your implementation doing this

cs = (str, ...args) => compiler.eval(str[0])

and this would work

square = cs`(x) -> x * x`

the arguments could also be used, but don’t have an example now in coffeescript context. you can read more about it here

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates

3 Likes

Putting CoffeeScript into named Markdown cells makes this a little more straightforward than the proofs of concept I’ve seen so far: CoffeeScript Markdown in Observable.