0.0.3 • Published 13 years ago

coffeesurgeon v0.0.3

Weekly downloads
11
License
-
Repository
github
Last release
13 years ago

coffeesurgeon

Static {analysis,slicing,dicing} of your .coffee

{
  bodystitch,
  parseImportsExports,
  findSourceFile

} = require 'coffeesurgeon'

Def: prop 1

A .coffee satisfies "Property 1" if ALL of its imports and exports are of the form:

{x, y} = require 'misc'
{...} = require '...'

...body, wherein foo and bar are defined...

module.exports = {foo, bar}

bodystitch

Like stitch, but

  • assumes prop 1
  • stitches bodies directly together in a dependency-satisfying ordering, discarding import/export statements
    • ...thereby being hella minification-friendly
    • ...and letting you expose your stuff (with coffee --bare) to your REPL and unit tests

FAQ

  • What about name conflicts?
    • TODO: error when they exist

parseImportsExports (assumes prop 1)

info = parseImportsExports coffee
# info:
{
  imports: [[["x", "y"], "misc"], ...]
  exported_names: ["foo", "bar"]
  body_coffee: "..."
}

findSourceFile

findSourceFile {query:"widgets/foo", fromDir:"...", codepath:[...]}, (e, path) ->
  # not found => path is null
  # FS error  => e is not null