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

add some comments and jsdocs to ExportMap #2981

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/ExportMap.js
Expand Up @@ -23,9 +23,17 @@ let ts;

const log = debug('eslint-plugin-import:ExportMap');

/** @type {Map<string, ExportMap>} */
const exportCache = new Map();
const tsconfigCache = new Map();

/*
* We have prototype methods and static methods
* ExportMap has 2 steps: preparation and rule evaluation
* The static methods use cache keys to run only once for each invocation of ESLint
* The prototype methods run once for each rule for each file
*/

export default class ExportMap {
constructor(path) {
this.path = path;
Expand All @@ -44,7 +52,7 @@ export default class ExportMap {
this.imports = new Map();
this.errors = [];
/**
* type {'ambiguous' | 'Module' | 'Script'}
* @type {'ambiguous' | 'Module' | 'Script'}
*/
this.parseGoal = 'ambiguous';
}
Expand Down Expand Up @@ -296,14 +304,18 @@ function captureTomDoc(comments) {

const supportedImportTypes = new Set(['ImportDefaultSpecifier', 'ImportNamespaceSpecifier']);

ExportMap.get = function (source, context) {
ExportMap.get = /** @returns {ExportMap} */ function (source, context) {
const path = resolve(source, context);
if (path == null) { return null; }

return ExportMap.for(childContext(path, context));
};

ExportMap.for = function (context) {
/**
* Returns an instance of ExportMap *for* the hash key from the context
* (file being linted + specifier)
*/
ExportMap.for = /** @returns {ExportMap} */ function (context) {
const { path } = context;

const cacheKey = context.cacheKey || hashObject(context).digest('hex');
Expand Down Expand Up @@ -359,7 +371,7 @@ ExportMap.for = function (context) {
return exportMap;
};

ExportMap.parse = function (path, content, context) {
ExportMap.parse = /** @returns {ExportMap} */ function (path, content, context) {
const m = new ExportMap(path);
const isEsModuleInteropTrue = isEsModuleInterop();

Expand Down