@@ -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 \{ [ ^ \} ] * \} ( [ ^ \r ? \n ? ] * ) / ;
20+ const typedefRegEx = / @ t y p e d e f \{ [ ^ \} ] * \} ( \S + ) / ;
2121const noClassdescRegEx = / @ ( t y p e d e f | m o d u l e | t y p e ) / ;
2222const slashRegEx = / \\ / g;
2323
@@ -180,7 +180,7 @@ exports.astNodeVisitor = {
180180 const moduleId = path . relative ( path . join ( process . cwd ( ) , moduleRoot ) , rel ) . replace ( / \. j s $ / , '' ) ;
181181 if ( getModuleInfo ( moduleId , parser ) ) {
182182 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 ) ;
184184 replacement = `module:${ moduleId . replace ( slashRegEx , '/' ) } ${ exportName ? delimiter + exportName : '' } ` ;
185185 }
186186 }
@@ -190,25 +190,34 @@ exports.astNodeVisitor = {
190190 }
191191
192192 // 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 ) ;
194194 if ( typedefMatch ) {
195195 identifiers [ typedefMatch [ 1 ] ] = {
196196 value : path . basename ( currentSourceName )
197197 } ;
198198 }
199+ } ) ;
199200
201+ node . comments . forEach ( comment => {
200202 // Replace local types with the full `module:` path
201203 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+ }
212221 }
213222 }
214223 } ) ;
0 commit comments