reactjs / react-docgen

A CLI and library to extract information from React component files for documentation generation purposes.

Home Page:https://react-docgen.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting `TypeError: Cannot read properties of undefined (reading 'end')` on a function parameter

matyasf opened this issue · comments

This is the code on in the component that triggers the exception:

onUpdate?: ({ visibleItemsCount }: { visibleItemsCount: number }) => void

(this is in the type of the props for a class based component)

The full stack trace is:

TypeError: Cannot read properties of undefined (reading 'end')
    at NodePath.getSource (/Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/node_modules/@babel/traverse/lib/path/introspection.js:136:12)
    at printValue (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/printValue.js:12:23)
    at file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTSType.js:233:28
    at Array.forEach (<anonymous>)
    at Object.handleTSFunctionType [as TSFunctionType] (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTSType.js:212:28)
    at getTSTypeWithResolvedTypes (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTSType.js:347:37)
    at getTSType (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTSType.js:370:18)
    at setPropDescriptor (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/handlers/codeTypeHandler.js:50:22)
    at file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/handlers/codeTypeHandler.js:74:9
    at file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTypeFromReactComponent.js:58:40
    at Array.forEach (<anonymous>)
    at applyToTypeProperties (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTypeFromReactComponent.js:58:14)
    at applyToTypeProperties (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTypeFromReactComponent.js:83:13)
    at file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTypeFromReactComponent.js:76:50
    at Array.forEach (<anonymous>)
    at applyToTypeProperties (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTypeFromReactComponent.js:76:27)
    at applyToTypeProperties (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/utils/getTypeFromReactComponent.js:83:13)
    at codeTypeHandler (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/handlers/codeTypeHandler.js:73:5)
    at file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/parse.js:10:39
    at Array.forEach (<anonymous>)
    at file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/parse.js:10:18
    at Array.map (<anonymous>)
    at executeHandlers (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/parse.js:8:33)
    at parse (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/parse.js:43:12)
    at defaultParse (file:///Users/matyas.szabo/CODE/instructure-ui/node_modules/react-docgen/dist/main.js:26:12)
    at getReactDoc (file:///Users/matyas.szabo/CODE/instructure-ui/packages/__docs__/lib/utils/getReactDoc.mjs:30:18)
    at parseDoc (file:///Users/matyas.szabo/CODE/instructure-ui/packages/__docs__/lib/utils/parseDoc.mjs:36:15)
    at processFile (file:///Users/matyas.szabo/CODE/instructure-ui/packages/__docs__/lib/processFile.mjs:34:17)
    at processSingleFile (file:///Users/matyas.szabo/CODE/instructure-ui/packages/__docs__/lib/build-docs.mjs:154:21)
    at file:///Users/matyas.szabo/CODE/instructure-ui/packages/__docs__/lib/build-docs.mjs:117:20
    at Array.map (<anonymous>)
    at file:///Users/matyas.szabo/CODE/instructure-ui/packages/__docs__/lib/build-docs.mjs:115:30

Thanks for reporting this. 💙

I fixed this and it is released in version 6.0.3

This went undetected, because the types of babel in that case were wrong: babel/babel#15867