Fast (and loose) require
and import
extractor js-tokens instead of an AST.
- Doesn't handle broken syntax.
- Doesn't look inside embedded expressions in template strings.
- This doesn't work:
// "pretty-ms" will not be found console.log(`time: ${require('pretty-ms')(Date.now())}`);
- See https://github.com/lydell/js-tokens#limitations
$ npm install loose-detect
var detect = require('loose-detect');
console.log(detect('import a from "a"; require("b")'));
// ["a", "b"]
$ find ./bench/nuclide -type f -name '*.js' -print0 | xargs -0 ./bench/bench.js
Looking at 1575 files
babylon & babel-traverse: 5651.09ms
loose-detect: 249.92ms