Closed bengourley closed 11 years ago
After a bit more poking around, I've tracked down the source of the inconsistency to https://github.com/substack/node-detective/blob/master/index.js#L49:
if (src.indexOf(word) == -1) return modules;
This short circuit (presumably for performance, to prevent an unnecessary esprima parse) means that sources with the string 'require' anywhere (including in a comment or within a string) will be parsed, but those that don't won't.
Calling detective on this source throws an error:
// I dont require any modules
return
This doesn't:
return
Fixed in 2.1.1.
Thanks!
While tracking down an inconsistency from upgrading to browserify v2, I noticed a discrepancy between what is thrown by
esprima.parse()
anddetective.find()
:I can't see the error being caught anywhere in
detective/index.js
even thoughesprima.parse(str)
is called directly here.Now to the thing I was looking in to that brought me to this module. I hope this is the correct module on which to discuss the issue.
In browserify v1 (and also in node) it is ok to
return
from the main module body, eg:browserify v2 says that this is an illegal return statement, which is presumably in accordance with ES semantics (in that you can't return if you're not in a function), but this introduces a behavioural difference between the browserify environment and the node environment. What do you think?
Cheers