Skip to content

Commit

Permalink
Use the TypeScript v5.5+ JSDoc tag @import to import types in modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydenseric committed Jul 2, 2024
1 parent dd6bd9c commit f910da2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions findUnusedExports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = {}) {
Expand Down Expand Up @@ -82,7 +84,7 @@ export default async function findUnusedExports(options = {}) {

/**
* @type {{
* [moduleFilePath: string]: import("./scanModuleCode.mjs").ModuleScan,
* [moduleFilePath: string]: ModuleScan,
* }}
*/
const scannedModules = {};
Expand All @@ -104,7 +106,7 @@ export default async function findUnusedExports(options = {}) {

/**
* @type {{
* [moduleFilePath: string]: import("./scanModuleCode.mjs").ModuleExports,
* [moduleFilePath: string]: ModuleExports,
* }}
*/
const possiblyUnusedExports = {};
Expand Down
4 changes: 3 additions & 1 deletion scanModuleCode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,7 +44,7 @@ export default async function scanModuleCode(code, path) {
exports: new Set(),
};

/** @type {Array<import("@babel/parser").ParserPlugin>} */
/** @type {Array<ParserPlugin>} */
const plugins = [
// Allow parsing code containing modern syntax even if a project doesn’t
// have Babel config to handle it.
Expand Down

0 comments on commit f910da2

Please sign in to comment.