@@ -17,7 +17,7 @@ if (!fs.existsSync(moduleRootAbsolute)) {
1717}
1818
1919const importRegEx = / i m p o r t \( [ " ' ] ( [ ^ " ' ] * ) [ " ' ] \) \. ( [ ^ \. \| \} > < , \) = # \n ] * ) ( [ \. \| \} > < , \) = # \n ] ) / g;
20- const typedefRegEx = / @ t y p e d e f \{ [ ^ \} ] * \} ( \S + ) / ;
20+ const typedefRegEx = / @ t y p e d e f \{ [ ^ \} ] * \} ( \S + ) / g ;
2121const noClassdescRegEx = / @ ( t y p e d e f | m o d u l e | t y p e ) / ;
2222const slashRegEx = / \\ / g;
2323
@@ -79,8 +79,12 @@ exports.astNodeVisitor = {
7979 const nodes = node . program . body ;
8080 for ( let i = 0 , ii = nodes . length ; i < ii ; ++ i ) {
8181 let node = nodes [ i ] ;
82+ let leadingComments = node . leadingComments ;
8283 if ( node . type === 'ExportNamedDeclaration' && node . declaration ) {
8384 node = node . declaration ;
85+ if ( node . leadingComments ) {
86+ leadingComments = node . leadingComments ;
87+ }
8488 }
8589 if ( node . type === 'ImportDeclaration' ) {
8690 node . specifiers . forEach ( specifier => {
@@ -98,6 +102,21 @@ exports.astNodeVisitor = {
98102 default :
99103 }
100104 } ) ;
105+ } else if ( node . type === 'VariableDeclaration' ) {
106+ for ( const declaration of node . declarations ) {
107+ let declarationComments = leadingComments ;
108+ if ( declaration . leadingComments ) {
109+ declarationComments = declaration . leadingComments ;
110+ }
111+ if ( declarationComments && declarationComments . length > 0 ) {
112+ const comment = declarationComments [ declarationComments . length - 1 ] . value ;
113+ if ( / @ e n u m / . test ( comment ) ) {
114+ identifiers [ declaration . id . name ] = {
115+ value : path . basename ( currentSourceName )
116+ } ;
117+ }
118+ }
119+ }
101120 } else if ( node . type === 'ClassDeclaration' ) {
102121 if ( node . id && node . id . name ) {
103122 identifiers [ node . id . name ] = {
@@ -190,9 +209,9 @@ exports.astNodeVisitor = {
190209 }
191210
192211 // Treat `@typedef`s like named exports
193- const typedefMatch = comment . value . replace ( / \s * \* \s * / g, ' ' ) . match ( typedefRegEx ) ;
194- if ( typedefMatch ) {
195- identifiers [ typedefMatch [ 1 ] ] = {
212+ const typedefMatches = comment . value . replace ( / \s * \* \s * / g, ' ' ) . matchAll ( typedefRegEx ) ;
213+ for ( const match of typedefMatches ) {
214+ identifiers [ match [ 1 ] ] = {
196215 value : path . basename ( currentSourceName )
197216 } ;
198217 }
@@ -204,7 +223,7 @@ exports.astNodeVisitor = {
204223 const eventRegex = new RegExp ( `@(event |fires )${ key } ([^A-Za-z])` , 'g' ) ;
205224 replace ( eventRegex ) ;
206225
207- const typeRegex = new RegExp ( `@(.*[{<|,(!?:]\\s*)${ key } ([A-Za-z].*?\}|\})` , 'g' ) ;
226+ const typeRegex = new RegExp ( `@(.*[{<|,(!?:]\\s*)${ key } ([^ A-Za-z].*?\}|\})` , 'g' ) ;
208227 replace ( typeRegex ) ;
209228
210229 function replace ( regex ) {
0 commit comments