@@ -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
@@ -26,9 +26,6 @@ const fileNodes = {};
2626
2727function getModuleInfo ( moduleId , parser ) {
2828 if ( ! moduleInfos [ moduleId ] ) {
29- const moduleInfo = moduleInfos [ moduleId ] = {
30- namedExports : { }
31- } ;
3229 if ( ! fileNodes [ moduleId ] ) {
3330 const absolutePath = path . join ( process . cwd ( ) , moduleRoot , moduleId + '.js' ) ;
3431 if ( ! fs . existsSync ( absolutePath ) ) {
@@ -37,6 +34,9 @@ function getModuleInfo(moduleId, parser) {
3734 const file = fs . readFileSync ( absolutePath , 'UTF-8' ) ;
3835 fileNodes [ moduleId ] = parser . astBuilder . build ( file , absolutePath ) ;
3936 }
37+ const moduleInfo = moduleInfos [ moduleId ] = {
38+ namedExports : { }
39+ } ;
4040 const node = fileNodes [ moduleId ] ;
4141 if ( node . program && node . program . body ) {
4242 const classDeclarations = { } ;
@@ -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 }
@@ -201,10 +220,10 @@ exports.astNodeVisitor = {
201220 node . comments . forEach ( comment => {
202221 // Replace local types with the full `module:` path
203222 Object . keys ( identifiers ) . forEach ( key => {
204- const eventRegex = new RegExp ( `@(event |fires )${ key } (\\s* )` , 'g' ) ;
223+ const eventRegex = new RegExp ( `@(event |fires )${ key } ([^A-Za-z] )` , 'g' ) ;
205224 replace ( eventRegex ) ;
206225
207- const typeRegex = new RegExp ( `@(.*[{<|,]\\s*[!?]? )${ key } (=?\\s*[}>|,] )` , 'g' ) ;
226+ const typeRegex = new RegExp ( `@(.*[{<|,(!?: ]\\s*)${ key } ([^A-Za-z].*?\}|\} )` , 'g' ) ;
208227 replace ( typeRegex ) ;
209228
210229 function replace ( regex ) {
0 commit comments