From 41d2e7198432549bd1b1009b315ada38bebe1fc9 Mon Sep 17 00:00:00 2001 From: sverweij Date: Sun, 1 Dec 2024 17:25:20 +0100 Subject: [PATCH] more nits --- src/extract/tsc/extract-typescript-deps.mjs | 12 ++++------ .../tsc/jsdoc-bracket-imports.spec.mjs | 24 ++++++++++++++++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/extract/tsc/extract-typescript-deps.mjs b/src/extract/tsc/extract-typescript-deps.mjs index 6bafd154c..e9b19868a 100644 --- a/src/extract/tsc/extract-typescript-deps.mjs +++ b/src/extract/tsc/extract-typescript-deps.mjs @@ -287,7 +287,7 @@ function isJSDocImport(pTypeNode) { ); } -function keyIsBoring(pKey) { +function keyInJSDocIsIgnorable(pKey) { return [ "parent", "pos", @@ -303,10 +303,6 @@ function keyIsBoring(pKey) { ].includes(pKey); } -/** - * Walks the given object, that can have both arrays and objects as values, and returns a new object with the same structure, but with all the values replaced by the result of the given function. - * @param {Object} obj The object to walk. - */ export function walkJSDoc(pObject, pCollection = new Set()) { if (isJSDocImport(pObject)) { pCollection.add(pObject.argument.literal.text); @@ -314,16 +310,16 @@ export function walkJSDoc(pObject, pCollection = new Set()) { pObject.forEach((pValue) => walkJSDoc(pValue, pCollection)); } else if (typeof pObject === "object") { for (const lKey in pObject) { - if (!keyIsBoring(lKey) && pObject[lKey]) { + if (!keyInJSDocIsIgnorable(lKey) && pObject[lKey]) { walkJSDoc(pObject[lKey], pCollection); } } } } -export function getJSDocImports(pObject) { +export function getJSDocImports(pTagNode) { const lCollection = new Set(); - walkJSDoc(pObject, lCollection); + walkJSDoc(pTagNode, lCollection); return Array.from(lCollection); } diff --git a/test/extract/tsc/jsdoc-bracket-imports.spec.mjs b/test/extract/tsc/jsdoc-bracket-imports.spec.mjs index a63dfec9d..e880d3431 100644 --- a/test/extract/tsc/jsdoc-bracket-imports.spec.mjs +++ b/test/extract/tsc/jsdoc-bracket-imports.spec.mjs @@ -114,7 +114,6 @@ describe("[U] ast-extractors/extract-typescript - jsdoc 'bracket' imports", () = ); }); - /* eslint mocha/no-skipped-tests: "off" */ it("extracts @type whole module even when wrapped in type shenanigans (Partial)", () => { deepEqual( extractTypescript( @@ -222,6 +221,29 @@ describe("[U] ast-extractors/extract-typescript - jsdoc 'bracket' imports", () = ], ); }); + it("extracts @return wrapped in type shenanigans)", () => { + deepEqual( + extractTypescript( + "/** @return {Promise} */", + [], + true, + ), + [ + { + module: "./types.js", + moduleSystem: "es6", + dynamic: false, + exoticallyRequired: false, + dependencyTypes: [ + "type-only", + "import", + "jsdoc", + "jsdoc-bracket-import", + ], + }, + ], + ); + }); it("leaves @type things alone that are not imports (but that look a bit like them)", () => { deepEqual(