Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependent uses #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

goto-bus-stop
Copy link
Contributor

This patch adds dependency tracking to individual exports. If an export A is only used inside another exported function B that is not used, the A export will also be marked as unused.

To detect whether an export is used inside another export, I copied the ancestor() walker from Acorn, so the siftMember method can check if any of the ancestors of the current node also assign an export.

I added a parameter to Module#isUsed() when checking dependent uses, which tracks which dependencies have already been visited, to address recursive dependencies like:

// a.js
exports.a = function () { return require('./b').b }
// b.js
exports.b = function () { return require('./a').a }

(Initially I used a this.computingDependents array for this purpose but that didn't work when a recursive dependency crossed module boundaries.)

Verified

This commit was signed with the committer’s verified signature. The key has expired.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
I added a parameter to `isUsed()` to track which dependencies had
already been visited, to address recursive dependencies:

```js
// a.js
exports.a = function () { return require('./b').b }
// b.js
exports.b = function () { return require('./a').a }
```

Hopefully nobody uses it...

Verified

This commit was signed with the committer’s verified signature. The key has expired.
This is a little easier to read, I think, and it looks like it's not
necessary to do it simultaneously.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant