js.spec icon indicating copy to clipboard operation
js.spec copied to clipboard

Function specification idea

Open roman01la opened this issue 8 years ago • 3 comments

I can think of an AST transform that could instrument functions. Here's some ideas:

  • Define specs in separate files/modules (with .spec extension, similar to .d.ts in TypeScript)
  • Find a way to map spec modules to JS modules
    • /* @spec path/to/spec.spec */ in JS files?
    • import from "path/to/spec.spec";
  • Match specs with function by name?
  • Use Webpack loader and Babel AST transform to load specs and instrument JS code

roman01la avatar Nov 30 '16 13:11 roman01la

I'd be careful prescribing an extension for this, since a lot of people uses *spec* to match test files, but I'm sure there will be a way to have whatever test-runner or bootstrapping script you use to specify where to find the right files.

scotttrinh avatar Nov 30 '16 17:11 scotttrinh

Wow, that's an interesting suggestion. I don't understand how this would work yet, but worth looking into 👍

prayerslayer avatar Nov 30 '16 18:11 prayerslayer

You might want to consider ES Decorators to do this instead of magic places and names. Decorator would create the instrumented code you would need to spec the function params before calling the actual function. See https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841#.khz5wclld

mattbishop avatar Mar 13 '17 19:03 mattbishop