asg017 / unofficial-observablehq-compiler

An unofficial compiler for Observable notebook syntax
https://www.npmjs.com/package/@alex.garcia/unofficial-observablehq-compiler
115 stars 22 forks source link

fix(compiler): allow referencing viewof and mutable cells #6

Closed bryangingechen closed 5 years ago

bryangingechen commented 5 years ago

Despite the name of the branch, this PR addresses #2: the compiler should now properly treat regular cells that reference viewof and mutable cells. The tricky part is replacing all the references to "viewof X" and "mutable Y" with placeholders. For that I used the ObservableHQ's parser.walk function with acorn-walk, following some old code.

I've added some examples to test.html; in the future we probably want to have more systematic tests. I also assigned the module object to the window scope in that HTML file to make future debugging a little more convenient.

bryangingechen commented 5 years ago

I now have some commits addressing #1 which sit on top of this branch. If you'd prefer to review everything at once, I can open a new PR with that branch instead.

asg017 commented 5 years ago

Sorry for the delay - was reading up on acorn to understand this more.

This looks good to me! You can send a PR of the other branch and I'll approve that one.

I think ideally, we wouldnt need acorn-walk as a direct dependency, since @observablehq/parser already uses it. Maybe we could send a PR to that parser to re-export simple so we could save some space, but for now it looks good!

Thanks again for working on this, btw - It looks and feels much more cleaner now, and proper viewof/mutable support is just awesome!