From caa62647e886d64f38f2da38c323b4407e494959 Mon Sep 17 00:00:00 2001 From: Ivan Rubinson Date: Wed, 13 Mar 2024 18:25:15 +0200 Subject: [PATCH 1/3] fix invalid jsdoc --- src/ExportMap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExportMap.js b/src/ExportMap.js index f61d3c170..57c9e696b 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -44,7 +44,7 @@ export default class ExportMap { this.imports = new Map(); this.errors = []; /** - * type {'ambiguous' | 'Module' | 'Script'} + * @type {'ambiguous' | 'Module' | 'Script'} */ this.parseGoal = 'ambiguous'; } From ca5c12f404c2715987a9a8f91208b263755295e7 Mon Sep 17 00:00:00 2001 From: Ivan Rubinson Date: Wed, 13 Mar 2024 18:26:01 +0200 Subject: [PATCH 2/3] add explaination comments --- src/ExportMap.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ExportMap.js b/src/ExportMap.js index 57c9e696b..eb570e235 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -26,6 +26,13 @@ const log = debug('eslint-plugin-import: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; @@ -303,6 +310,10 @@ ExportMap.get = function (source, context) { return ExportMap.for(childContext(path, context)); }; +/** + * Returns an instance of ExportMap *for* the hash key from the context + * (file being linted + specifier) + */ ExportMap.for = function (context) { const { path } = context; From 201cc21c06b9c5c8b000b3ab005946f6d625f626 Mon Sep 17 00:00:00 2001 From: Ivan Rubinson Date: Wed, 13 Mar 2024 18:26:16 +0200 Subject: [PATCH 3/3] add jsdoc --- src/ExportMap.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ExportMap.js b/src/ExportMap.js index eb570e235..1012b65cc 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -23,6 +23,7 @@ let ts; const log = debug('eslint-plugin-import:ExportMap'); +/** @type {Map} */ const exportCache = new Map(); const tsconfigCache = new Map(); @@ -303,7 +304,7 @@ 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; } @@ -314,7 +315,7 @@ ExportMap.get = function (source, context) { * Returns an instance of ExportMap *for* the hash key from the context * (file being linted + specifier) */ -ExportMap.for = function (context) { +ExportMap.for = /** @returns {ExportMap} */ function (context) { const { path } = context; const cacheKey = context.cacheKey || hashObject(context).digest('hex'); @@ -370,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();