Static {analysis,slicing,dicing} of your .coffee
{ bodystitch, parseImportsExports, findSourceFile } = require 'coffeesurgeon'
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: foo bar: bar
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
stitchBodies { main: 'mymainfile' codepath: [ '...' '...' ] }, (e, {coffee, deps_map, deps_chain}) ->
- What about name conflicts?
- TODO: error when they exist
info = parseImportsExports coffee # info: { imports: [[["x", "y"], "misc"], ...] exported_names: ["foo", "bar"] body_coffee: "..." }
findSourceFile {query:"widgets/foo", fromDir:"...", codepath:[...]}, (e, path) -> # not found => path is null # FS error => e is not null