cjs-module-lexer icon indicating copy to clipboard operation
cjs-module-lexer copied to clipboard

Expose requires

Open developit opened this issue 5 years ago • 2 comments

This adds a third requires[] property to the output object in both modes. It's an Array of {s:number,e:number} start/end offsets, like those of es-module-lexer. All require() calls are added to the Array, including re-exports, and are not de-duplicated since the value is their source position.

const source = `foo=require("foo")`;
const { requires } = parse(source);
requires; // [{ s: 13, e: 16 }]
source.substring(requires[0].s, requires[0].e);  // foo

developit avatar Oct 04 '20 00:10 developit

@guybedford I’ve made a fork of this and now begin the process of catching the fork up with changes that have occurred here since. This is of course an absurdly expensive exercise in comparison to pooling our effort here. To the upside of pooling our effort, I did find and fix bugs in the process of linting and providing the minimal TypeScript annotations for our purposes. I don’t doubt that the slope might slip a little, but I would expect it to be a shallow slope with a near bottom. For one, we will certainly never need to analyze __dirname and __filename. https://github.com/endojs/endo/pull/666

kriskowal avatar Apr 13 '21 22:04 kriskowal

@kriskowal nice to hear. es-module-lexer is a fork to also keep in sync and so far it hasn't been too bad at all to maintain that. If you hit any cases worth upstreaming please do consider it! Would be great to collaborate on keeping this project up to date. Also, if you feel like tipping the old GitHub sponsors account that would always be very much appreciated :)

guybedford avatar Apr 14 '21 12:04 guybedford