

Javascript AST trickery with burrito - substack
http://substack.net/posts/eed898

======
substack
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.

~~~
snprbob86
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.

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

~~~
bitanarch
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/>

~~~
jmitcheson
Awesome, thank you!

