detective
detective copied to clipboard
speed up by using acorn tokenizer when possible
Add a findFast function that's exactly like detective.find, but doesn't parse the source. detective.find automatically uses findFast if possible.
we cannot do this if a custom isRequire function is provided, because that can check an arbitrarily complex callee. If a custom isRequire function is not provided we only have to check for a single token with name opts.word, so then we can look at only the token stream.
acorn's tokenizer ignores comments so things like require /* xyz */ ('abc') already work.
when opts.nodes is set, detected require calls are parsed using acorn.parseExpressionAt.
opts.fullParse can be set in order to always do a full parse. this can be useful if folks want to make sure that all syntax is correct.
I've so far found only one case where this doesn't work:
detective("(require)('abc')", { fullParse: true }) // → ['abc']
detective("(require)('abc')") // → []
may add a special case for that if there's nothing else.
e;
Before:
➜ node bench/detect.js
147
After:
➜ node bench/detect.js
66
Fixed the merge conflict
yeah not sure about side effects either, might try using it in some more projects first
Well that got a lot more complex to support the scope stuff introduced by #79 :laughing: it looks like it works tho, will do a major bump for this to be safe (+ the scope stuff may technically be breaking as well)