Skip to content

Handle ignored files when re-exporting from file #348

Closed

Description

Currently, ignored files return null when you try to get an import from them (see getExports#L79). However, this causes the import/export rule to throw an exception when you try to re-export everything from a file who is re-exporting from an ignored file, because ExportMap's forEach expects each of its re-exports to be able to get their imports (see getExports#L331).

For example, running ESLint with import/exports turned on throws on these files:

// test.js
export { default as x } from 'your-package'; // your-package is in the ignored settings (eg. in node_modules)

// reexport.js
export * from './test';

Exception:

Cannot read property 'get' of null
TypeError: Cannot read property 'get' of null
    at .../node_modules/eslint-plugin-import/lib/core/getExports.js:422:48
    at Map.forEach (native)
    at ExportMap.forEach (.../node_modules/eslint-plugin-import/lib/core/getExports.js:419:20)
    at EventEmitter.ExportAllDeclaration (.../node_modules/eslint-plugin-import/lib/rules/export.js:82:21)
    at emitOne (events.js:82:20)
    at EventEmitter.emit (events.js:169:7)
    at NodeEventGenerator.enterNode (.../node_modules/eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (.../node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
    at CommentEventGenerator.enterNode (.../node_modules/eslint/lib/util/comment-event-generator.js:97:23)
    at Controller.traverser.traverse.enter (.../node_modules/eslint/lib/eslint.js:886:36)

It seems like the simplest thing to fix this would be to just check that getImport() exists before trying to use .get() on it (although I'm not really sure what the first argument to the callback represents -- would null as a possibility make sense there?), but from a cursory glance, I also feel that using null to represent ignored files seems somewhat brittle?

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

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions