@@ -17,7 +17,7 @@ if (!fs.existsSync(moduleRootAbsolute)) {
17
17
}
18
18
19
19
const 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 ;
21
21
const noClassdescRegEx = / @ ( t y p e d e f | m o d u l e | t y p e ) / ;
22
22
const slashRegEx = / \\ / g;
23
23
@@ -79,8 +79,12 @@ exports.astNodeVisitor = {
79
79
const nodes = node . program . body ;
80
80
for ( let i = 0 , ii = nodes . length ; i < ii ; ++ i ) {
81
81
let node = nodes [ i ] ;
82
+ let leadingComments = node . leadingComments ;
82
83
if ( node . type === 'ExportNamedDeclaration' && node . declaration ) {
83
84
node = node . declaration ;
85
+ if ( node . leadingComments ) {
86
+ leadingComments = node . leadingComments ;
87
+ }
84
88
}
85
89
if ( node . type === 'ImportDeclaration' ) {
86
90
node . specifiers . forEach ( specifier => {
@@ -98,6 +102,21 @@ exports.astNodeVisitor = {
98
102
default :
99
103
}
100
104
} ) ;
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
+ }
101
120
} else if ( node . type === 'ClassDeclaration' ) {
102
121
if ( node . id && node . id . name ) {
103
122
identifiers [ node . id . name ] = {
@@ -190,9 +209,9 @@ exports.astNodeVisitor = {
190
209
}
191
210
192
211
// 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 ] ] = {
196
215
value : path . basename ( currentSourceName )
197
216
} ;
198
217
}
@@ -204,7 +223,7 @@ exports.astNodeVisitor = {
204
223
const eventRegex = new RegExp ( `@(event |fires )${ key } ([^A-Za-z])` , 'g' ) ;
205
224
replace ( eventRegex ) ;
206
225
207
- const typeRegex = new RegExp ( `@(.*[{<|,(!?:]\\s*)${ key } ([A-Za-z].*?\}|\})` , 'g' ) ;
226
+ const typeRegex = new RegExp ( `@(.*[{<|,(!?:]\\s*)${ key } ([^ A-Za-z].*?\}|\})` , 'g' ) ;
208
227
replace ( typeRegex ) ;
209
228
210
229
function replace ( regex ) {
0 commit comments