@@ -112,14 +112,22 @@ export default iterateJsdoc(({
112112 . filter ( Boolean ) ) ;
113113 }
114114
115- const comments = sourceCode . getAllComments ( )
115+ const allComments = sourceCode . getAllComments ( ) ;
116+ const comments = allComments
116117 . filter ( ( comment ) => {
117118 return ( / ^ \* \s / u) . test ( comment . value ) ;
118119 } )
119120 . map ( ( commentNode ) => {
120121 return parseComment ( commentNode , '' ) ;
121122 } ) ;
122123
124+ const globals = allComments
125+ . filter ( ( comment ) => {
126+ return ( / ^ \s * g l o b a l s / u) . test ( comment . value ) ;
127+ } ) . flatMap ( ( commentNode ) => {
128+ return commentNode . value . replace ( / ^ \s * g l o b a l s / u, '' ) . trim ( ) . split ( / , \s * / u) ;
129+ } ) ;
130+
123131 const typedefDeclarations = comments
124132 . flatMap ( ( doc ) => {
125133 return doc . tags . filter ( ( {
@@ -242,6 +250,12 @@ export default iterateJsdoc(({
242250 return result ;
243251 } ;
244252
253+ /**
254+ * We treat imports differently as we can't introspect their children.
255+ * @type {string[] }
256+ */
257+ const imports = [ ] ;
258+
245259 const allDefinedTypes = new Set ( globalScope . variables . map ( ( {
246260 name,
247261 } ) => {
@@ -256,8 +270,22 @@ export default iterateJsdoc(({
256270 } ) => {
257271 return variables ;
258272 } ) . map ( ( {
273+ identifiers,
259274 name,
260275 } ) => {
276+ if (
277+ [
278+ 'ImportDefaultSpecifier' ,
279+ 'ImportNamespaceSpecifier' ,
280+ 'ImportSpecifier' ,
281+ ] . includes (
282+ /** @type {import('estree').Identifier & {parent: {type: string}} } */ (
283+ identifiers ?. [ 0 ] ) ?. parent ?. type ,
284+ )
285+ ) {
286+ imports . push ( name ) ;
287+ }
288+
261289 return name ;
262290 /* c8 ignore next */
263291 } ) : [ ] ,
@@ -408,7 +436,12 @@ export default iterateJsdoc(({
408436 * _parent?: import('jsdoc-type-pratt-parser').NonRootResult
409437 * }}
410438 */ ( currNode ) . _parent ;
411- if ( currNode && 'right' in currNode && currNode . right ?. type === 'JsdocTypeProperty' ) {
439+ if (
440+ // Avoid appending for imports and globals since we don't want to
441+ // check their properties which may or may not exist
442+ ! imports . includes ( val ) && ! globals . includes ( val ) &&
443+ currNode && 'right' in currNode &&
444+ currNode . right ?. type === 'JsdocTypeProperty' ) {
412445 val = val + '.' + currNode . right . value ;
413446 }
414447 } while ( currNode ?. type === 'JsdocTypeNamePath' ) ;
0 commit comments