Skip to content

Crash in getJSDocTags #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ikonst opened this issue Sep 16, 2023 · 2 comments
Closed

Crash in getJSDocTags #242

ikonst opened this issue Sep 16, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ikonst
Copy link

ikonst commented Sep 16, 2023

Knip: 2.24.1
Node.js v18.16.1

Expected

  1. Better error reporting. It was unclear what file tripped it.
  2. Not crashing.

Reproduction

a.ts

import { f } from "./b"

b.ts

/**
 * @
 */
export function f() {}

Error and stack trace

export const getJSDocTags = (node) => ts.getJSDocTags(node).map(node => node.getText().match(/@\S+/)[0]);
                                                                                                    ^

TypeError: Cannot read properties of null (reading '0')
    at file:///<project>/node_modules/knip/dist/typescript/ast-helpers.js:101:101
    at Array.map (<anonymous>)
    at getJSDocTags (file:///<project>/node_modules/knip/dist/typescript/ast-helpers.js:101:61)
    at addExport (file:///<project>/node_modules/knip/dist/typescript/getImportsAndExports.js:100:27)
    at Array.forEach (<anonymous>)
    at visit (file:///<project>/node_modules/knip/dist/typescript/getImportsAndExports.js:136:38)
    at visitNodes (/<project>/node_modules/knip/node_modules/typescript/lib/typescript.js:27934:24)
    at forEachChildInSourceFile (/<project>/node_modules/knip/node_modules/typescript/lib/typescript.js:28556:18)
    at Object.forEachChild (/<project>/node_modules/knip/node_modules/typescript/lib/typescript.js:28019:37)
    at visit (file:///<project>/node_modules/knip/dist/typescript/getImportsAndExports.js:152:12)
    at getImportsAndExports (file:///<project>/node_modules/knip/dist/typescript/getImportsAndExports.js:154:5)
    at ProjectPrincipal.analyzeSourceFile (file:///<project>/node_modules/knip/dist/ProjectPrincipal.js:114:47)
    at analyzeSourceFile (file:///<project>/node_modules/knip/dist/index.js:185:65)
    at file:///<project>/node_modules/knip/dist/index.js:242:17
    at Array.forEach (<anonymous>)
    at main (file:///<project>/node_modules/knip/dist/index.js:241:19)
    at async run (file:///<project>/node_modules/knip/dist/cli.js:24:73)
    at async file:///<project>/node_modules/knip/dist/cli.js:72:1
@ikonst ikonst added the bug Something isn't working label Sep 16, 2023
@webpro webpro closed this as completed in d17371b Sep 18, 2023
@webpro
Copy link
Member

webpro commented Sep 18, 2023

🚀 This issue has been resolved in v2.25.0. See Release 2.25.0 for release notes.

@webpro
Copy link
Member

webpro commented Sep 18, 2023

Thanks for the report, @ikonst. Agreed that the error reporting could be improved, but for now I only fixed this specific issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants