metajs
metajs copied to clipboard
Hoisting fails
The following test throws an exception, but shouldn't: x(); function x() { console.log(1); }
Yeah, I was lazy about implementing another AST traversal to extract out the function declarations. We should do that. This also throws when it shouldn't, because we don't hoist var declarations either: console.log(a); var a;. I think it'd be nice to use an existing traversal library like estraverse rather than writing another huge switch-case statement.
@int3: I recommend both Constellation/estraverse and Constellation/escope. My favourite program doesn't work:
(function(){
try { throw 0; } catch(a) { var a = 1; }
console.log(a);
}());
@michaelficarra I actually have another interpreter that implements hoisting (and several other features) correctly. It does use estraverse, but not escope -- I'll definitely have a look at the latter the next time I write another JS interpreter / tool. closure-interpreter isn't in CPS at the moment, but I think it should be quite easy to hack it into shape, and then hook it up to metajs' frontend. Maybe this weekend.
+1