Hacker News new | past | comments | ask | show | jobs | submit login
Javascript AST trickery with burrito (substack.net)
64 points by substack on July 7, 2011 | hide | past | web | favorite | 6 comments



Oh I forgot to mention in the article, but I'm also using burrito for node-detective (https://github.com/substack/node-detective) to find all the require()s in a javascript file. Using detective made browserify (https://github.com/substack/node-browserify) much easier to use.


Cool!

The concatenation in Stitch and Sprockets is generally pretty great and reminds me a lot of Python modules. Unfortunately, I really missed the auto-loading `const_missing` behavior from Rails.

To minimize imports, we export most of our classes to `window` and simply `require` static class dependancies to enforce sequencing. Then we loop over every module & make sure they were all required at least once before instantiating any classes.

In CoffeeScript, exporting to `window` is as easy prepending '@' to the class name. We then `require` base classes and other statically needed modules for sequencing. Example:

  require 'model'
  require 'static_thing'

  class @User extends @Model

    # Explicit requirement needed as the class is being defined
    @foo = StaticThing.bar()

    # But not here, if we `require` everything before kicking off the app
    x: -> new DynamicThing()

I wonder if burrito could be used to automatically add those require statements for Model and StaticThing to the top of the file. Then, it would be nice to wrap DynamicThing in `require('dynamic_thing').DynamicThing`. That would be super awesome.


Why not simply adding that to the article?


This is pretty cool. Are there any other libraries out there that can parse / manipulate js source?


Narcissus https://github.com/mozilla/narcissus/

It's been used as part of the Narrative JavaScript project to parse the JavaScript-like njs language and compile it back to JavaScript. http://www.neilmix.com/narrativejs/doc/


Awesome, thank you!




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: