Closed jonathanong closed 10 years ago
It is a controlled throw. As you can see in line 78-80 we are pushing the type of module into the result array, and successive, we throw an error that is controlled thru a try/catch.
The reason why I decided to throw instead of letting the modules to be executed is because we are executing the code in a new context with new globals to avoid polluting the current runtime (where you just really want to detect the type). In the case of the require
statement, there are problems that I want to control:
process.cwd()
there is not guarantee that it will work.Ah ok. This module might be too crazy for me haha. I just want to know if something is es6 without executing code
@jonathanong I have the exact same discussion with @ericf, I think for now I managed to convince him to stick to the current implementation. I think it is irrelevant if we execute the code or not since it happens in a sandbox.
You could split it up into two modules. One basically just does regexp checks, then this one executes the code as well.
yes, that was the center of the discussion between @ericf and myself, so it is on the table, let see if the time comes.
https://github.com/yahoo/js-module-formats/blob/master/index.js#L81
not sure what's the point of throwing o.O