Does not work with functions not in global scope
But you knew that already :)
It actually does. See the new example on the readme. Though I agree that the syntax for making the declaration is not ideal:
MyObj = {
//+ MyObj.test_fun :: Number -> Number -> Number
test_fun:function(num1, num2){
return num1 + num2;
}
}
Also, if you are looking through your fork, you may want to update things... I've already pushed some fairly significant changes/fixes.
Oh no I saw that in examples/test.js I'm talking about the private functions inside a closure.
Example:
(function () {
// no way to access concat automatically :(
// but TypedJS throws an error!
//+ concat :: String -> String -> String
function concat(a, b) {
return a + b;
}
}());
I was thinking about this and perhaps there's two ways to attack this problem.
- Use TypedJS along with your unit tests.
- Allow one to call a single automated test from wherever.
This is especially an issue for people who write JavaScript programs that don't leak any global variables and their public interface is limited.
Oh, ok. That's a thornier problem. And the private scoping pattern is pretty common... I'll give it some thought.
A crazy idea to have automated tests and private functions:
- You parse the JS
- Turn all the functions global in a typedjs sandbox
- Assign them new names (in case of collisions)
- Find/replace all references to those functions with their new names
- Create the test suite with the new functions and signatures mapped to them
- Run the automated tests
- return results
That's not so crazy, really. Proxino's error-detection product did something similar. We got a lot of flack for it from developers, but people might not care so much in this case (since TypedJS is for testing, not production code).
I wrote it and it's working pretty ok. I haven't done the assigning of new names or find/replace all references yet but for now it works for functions which don't call other functions.