diff --git a/changelog.md b/changelog.md index 87eb034..fcb6d56 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ - Support resolving additional kinds of TypeScript source modules (if the exist) depending on the import specifier path file extension: - `.cjs` resolves `.cts`. - `.js` resolves `.ts` and `.tsx`. +- Use the TypeScript v5.5+ JSDoc tag `@import` to import types in modules. ### Minor diff --git a/findUnusedExports.mjs b/findUnusedExports.mjs index 41039dd..0ecb0a0 100644 --- a/findUnusedExports.mjs +++ b/findUnusedExports.mjs @@ -9,6 +9,8 @@ import isDirectoryPath from "./isDirectoryPath.mjs"; import MODULE_GLOB from "./MODULE_GLOB.mjs"; import scanModuleCode from "./scanModuleCode.mjs"; +/** @import { ModuleExports, ModuleScan } from "./scanModuleCode.mjs" */ + /** * Finds unused * [ECMAScript module exports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) @@ -33,7 +35,7 @@ import scanModuleCode from "./scanModuleCode.mjs"; * `true` might be appropriate. This option only works if the option * `resolveFileExtensions` is used. Defaults to `false`. * @returns {Promise<{ - * [moduleFilePath: string]: import("./scanModuleCode.mjs").ModuleExports, + * [moduleFilePath: string]: ModuleExports, * }>} Map of module file paths and unused module exports. */ export default async function findUnusedExports(options = {}) { @@ -82,7 +84,7 @@ export default async function findUnusedExports(options = {}) { /** * @type {{ - * [moduleFilePath: string]: import("./scanModuleCode.mjs").ModuleScan, + * [moduleFilePath: string]: ModuleScan, * }} */ const scannedModules = {}; @@ -104,7 +106,7 @@ export default async function findUnusedExports(options = {}) { /** * @type {{ - * [moduleFilePath: string]: import("./scanModuleCode.mjs").ModuleExports, + * [moduleFilePath: string]: ModuleExports, * }} */ const possiblyUnusedExports = {}; diff --git a/scanModuleCode.mjs b/scanModuleCode.mjs index 75e3b6d..06a0d7b 100644 --- a/scanModuleCode.mjs +++ b/scanModuleCode.mjs @@ -6,6 +6,8 @@ import babel from "@babel/core"; import getVariableDeclarationIdentifierNames from "./getVariableDeclarationIdentifierNames.mjs"; +/** @import { ParserPlugin } from "@babel/parser" */ + // Babel seems to also support non-standard string literals in place of named // import and export identifiers, perhaps because CJS can have export names // containing dashes, etc. such as `exports["a-b-c"]` and they want to support @@ -42,7 +44,7 @@ export default async function scanModuleCode(code, path) { exports: new Set(), }; - /** @type {Array} */ + /** @type {Array} */ const plugins = [ // Allow parsing code containing modern syntax even if a project doesn’t // have Babel config to handle it.