diff --git a/src/ExportMap.js b/src/ExportMap.js index f61d3c170..1012b65cc 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -23,9 +23,17 @@ let ts; const log = debug('eslint-plugin-import:ExportMap'); +/** @type {Map} */ 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; @@ -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'; } @@ -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'); @@ -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();