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

fix: check exports exist before access to it #2990

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

headfire94
Copy link

while this issue exist #2866, this fix helps to prevent eslint from crashing.

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.81%. Comparing base (2de78c1) to head (fa07557).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2990   +/-   ##
=======================================
  Coverage   81.81%   81.81%           
=======================================
  Files          77       77           
  Lines        3795     3795           
  Branches     1257     1260    +3     
=======================================
  Hits         3105     3105           
  Misses        690      690           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -534,15 +534,15 @@ module.exports = {
}

// special case: export * from
const exportAll = exports.get(EXPORT_ALL_DECLARATION);
const exportAll = exports && exports.get(EXPORT_ALL_DECLARATION);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need to report from line 567 to be shown:

context.report(
          node,
          `exported declaration '${value}' not used within other modules`,
        );

At the end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error console says the file has no exports then why it should report any export error? Or that just means an internal bug?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scenario is following:

  1. create new file and define export it in
  2. see eslint error that export is not used anywhere.

Without this PR we see eslint crash and no longer provide other checks and autofixes.
I assume this is internal bug mentioned in console warning, file has export, so this should be fixed somehow. till then this fix works as well

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can’t fix a bug without a regression test. Can you add one?

@headfire94
Copy link
Author

headfire94 commented Mar 27, 2024

@ljharb

  1. Use webstorm
  2. create new js file and define variable and export it 'export default someVar'.
  3. see eslint error that export is not used anywhere.

Without PR eslint process crashes

@ljharb
Copy link
Member

ljharb commented Mar 27, 2024

I understand the repro, but we need a code regression test.

@headfire94
Copy link
Author

Is there an example in this repo of regression test with dynamically added code to mirror for this case?

@ljharb
Copy link
Member

ljharb commented Mar 27, 2024

Not that I know of. Unfortunately this is a really difficult failure case to reproduce in tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants