@@ -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 \{ [ ^ \} ] * \} ( [ ^ \r ? \n ? ] * ) / ;
20
+ const typedefRegEx = / @ t y p e d e f \{ [ ^ \} ] * \} ( \S + ) / ;
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
@@ -180,7 +180,7 @@ exports.astNodeVisitor = {
180
180
const moduleId = path . relative ( path . join ( process . cwd ( ) , moduleRoot ) , rel ) . replace ( / \. j s $ / , '' ) ;
181
181
if ( getModuleInfo ( moduleId , parser ) ) {
182
182
const exportName = importMatch [ 2 ] === 'default' ? getDefaultExportName ( moduleId , parser ) : importMatch [ 2 ] ;
183
- const delimiter = importMatch [ 2 ] === 'default' ? '~' : getDelimiter ( moduleId , exportName , parser ) ;
183
+ const delimiter = importMatch [ 2 ] === 'default' ? '~' : getDelimiter ( moduleId , exportName , parser ) ;
184
184
replacement = `module:${ moduleId . replace ( slashRegEx , '/' ) } ${ exportName ? delimiter + exportName : '' } ` ;
185
185
}
186
186
}
@@ -190,25 +190,34 @@ exports.astNodeVisitor = {
190
190
}
191
191
192
192
// Treat `@typedef`s like named exports
193
- const typedefMatch = comment . value . replace ( / \r ? \n ? \ s* \* \s / g, ' ' ) . match ( typedefRegEx ) ;
193
+ const typedefMatch = comment . value . replace ( / \s * \* \s * / g, ' ' ) . match ( typedefRegEx ) ;
194
194
if ( typedefMatch ) {
195
195
identifiers [ typedefMatch [ 1 ] ] = {
196
196
value : path . basename ( currentSourceName )
197
197
} ;
198
198
}
199
+ } ) ;
199
200
201
+ node . comments . forEach ( comment => {
200
202
// Replace local types with the full `module:` path
201
203
Object . keys ( identifiers ) . forEach ( key => {
202
- const regex = new RegExp ( `@(event |fires |.*[\{<\|,] ?!?)${ key } ` , 'g' ) ;
203
- if ( regex . test ( comment . value ) ) {
204
- const identifier = identifiers [ key ] ;
205
- const absolutePath = path . resolve ( path . dirname ( currentSourceName ) , identifier . value ) ;
206
- const moduleId = path . relative ( path . join ( process . cwd ( ) , moduleRoot ) , absolutePath ) . replace ( / \. j s $ / , '' ) ;
207
- if ( getModuleInfo ( moduleId , parser ) ) {
208
- const exportName = identifier . defaultImport ? getDefaultExportName ( moduleId , parser ) : key ;
209
- const delimiter = identifier . defaultImport ? '~' : getDelimiter ( moduleId , exportName , parser ) ;
210
- const replacement = `module:${ moduleId . replace ( slashRegEx , '/' ) } ${ exportName ? delimiter + exportName : '' } ` ;
211
- comment . value = comment . value . replace ( regex , '@$1' + replacement ) ;
204
+ const eventRegex = new RegExp ( `@(event |fires )${ key } (\\s*)` , 'g' ) ;
205
+ replace ( eventRegex ) ;
206
+
207
+ const typeRegex = new RegExp ( `@(.*[{<|,]\\s*[!?]?)${ key } (=?\\s*[}>|,])` , 'g' ) ;
208
+ replace ( typeRegex ) ;
209
+
210
+ function replace ( regex ) {
211
+ if ( regex . test ( comment . value ) ) {
212
+ const identifier = identifiers [ key ] ;
213
+ const absolutePath = path . resolve ( path . dirname ( currentSourceName ) , identifier . value ) ;
214
+ const moduleId = path . relative ( path . join ( process . cwd ( ) , moduleRoot ) , absolutePath ) . replace ( / \. j s $ / , '' ) ;
215
+ if ( getModuleInfo ( moduleId , parser ) ) {
216
+ const exportName = identifier . defaultImport ? getDefaultExportName ( moduleId , parser ) : key ;
217
+ const delimiter = identifier . defaultImport ? '~' : getDelimiter ( moduleId , exportName , parser ) ;
218
+ let replacement = `module:${ moduleId . replace ( slashRegEx , '/' ) } ${ exportName ? delimiter + exportName : '' } ` ;
219
+ comment . value = comment . value . replace ( regex , '@$1' + replacement + '$2' ) ;
220
+ }
212
221
}
213
222
}
214
223
} ) ;
0 commit comments