@@ -201,17 +201,23 @@ exports.astNodeVisitor = {
201
201
node . comments . forEach ( comment => {
202
202
// Replace local types with the full `module:` path
203
203
Object . keys ( identifiers ) . forEach ( key => {
204
- const regex = new RegExp ( `@(event |fires |.*[{<|,] ?!?)${ key } ([}>|,\\s])` , 'g' ) ;
204
+ const eventRegex = new RegExp ( `@(event |fires )${ key } (\\s*)` , 'g' ) ;
205
+ replace ( eventRegex ) ;
205
206
206
- if ( regex . test ( comment . value ) ) {
207
- const identifier = identifiers [ key ] ;
208
- const absolutePath = path . resolve ( path . dirname ( currentSourceName ) , identifier . value ) ;
209
- const moduleId = path . relative ( path . join ( process . cwd ( ) , moduleRoot ) , absolutePath ) . replace ( / \. j s $ / , '' ) ;
210
- if ( getModuleInfo ( moduleId , parser ) ) {
211
- const exportName = identifier . defaultImport ? getDefaultExportName ( moduleId , parser ) : key ;
212
- const delimiter = identifier . defaultImport ? '~' : getDelimiter ( moduleId , exportName , parser ) ;
213
- const replacement = `module:${ moduleId . replace ( slashRegEx , '/' ) } ${ exportName ? delimiter + exportName : '' } ` ;
214
- comment . value = comment . value . replace ( regex , '@$1' + replacement + '$2' ) ;
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
+ }
215
221
}
216
222
}
217
223
} ) ;
0 commit comments