1
1
import path from 'path' ;
2
2
import { ContractDefinition , SourceUnit } from 'solidity-ast' ;
3
3
import { SolcOutput , SolcInput } from 'solidity-ast/solc' ;
4
- import { astDereferencer , ASTDereferencer , findAll } from 'solidity-ast/utils' ;
4
+ import { astDereferencer , ASTDereferencer , findAll , isNodeType } from 'solidity-ast/utils' ;
5
5
import { FullConfig } from './config' ;
6
6
import { DocItem , docItemTypes , isDocItem } from './doc-item' ;
7
7
import { Properties } from './templates' ;
@@ -55,7 +55,7 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
55
55
const assign = typeof siteConfig . pages === 'string' ? pageAssigner [ siteConfig . pages ] : siteConfig . pages ;
56
56
57
57
const seen = new Set < string > ( ) ;
58
- const allItems : DocItemWithContext [ ] = [ ] ;
58
+ const items : DocItemWithContext [ ] = [ ] ;
59
59
const pages : Record < string , DocItemWithContext [ ] > = { } ;
60
60
61
61
for ( let { input, output } of builds ) {
@@ -66,8 +66,8 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
66
66
const build = { input, output, deref } ;
67
67
68
68
for ( const { ast : file } of Object . values ( output . sources ) ) {
69
- const isNewItem = ! seen . has ( file . src ) ;
70
- seen . add ( file . src ) ;
69
+ const isNewFile = ! seen . has ( file . absolutePath ) ;
70
+ seen . add ( file . absolutePath ) ;
71
71
72
72
for ( const topLevelItem of file . nodes ) {
73
73
if ( ! isDocItem ( topLevelItem ) ) continue ;
@@ -78,13 +78,18 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
78
78
__item_context : { page, item : topLevelItem as DocItemWithContext , file, build } ,
79
79
} ) ;
80
80
81
- if ( page !== undefined ) {
81
+ if ( isNewFile && page !== undefined ) {
82
82
( pages [ page ] ??= [ ] ) . push ( withContext ) ;
83
+ items . push ( withContext ) ;
83
84
}
84
85
85
- for ( const item of findAll ( docItemTypes , topLevelItem ) ) {
86
- if ( isNewItem ) allItems . push ( item as DocItemWithContext ) ;
87
- if ( item === topLevelItem ) continue ;
86
+ if ( ! isNodeType ( 'ContractDefinition' , topLevelItem ) ) {
87
+ continue ;
88
+ }
89
+
90
+ for ( const item of topLevelItem . nodes ) {
91
+ if ( ! isDocItem ( item ) ) continue ;
92
+ if ( isNewFile && page !== undefined ) items . push ( item as DocItemWithContext ) ;
88
93
const contract = topLevelItem . nodeType === 'ContractDefinition' ? topLevelItem : undefined ;
89
94
const __item_context : DocItemContext = { page, item : item as DocItemWithContext , contract, file, build } ;
90
95
Object . assign ( item , { __item_context } ) ;
@@ -93,16 +98,16 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
93
98
}
94
99
}
95
100
96
- for ( const item of allItems ) {
101
+ for ( const item of items ) {
97
102
for ( const [ prop , fn ] of Object . entries ( properties ) ) {
98
103
const original : unknown = ( item as any ) [ prop ] ;
99
104
defineGetterMemoized ( item as any , prop , ( ) => fn ( item . __item_context , original ) ) ;
100
105
}
101
106
}
102
107
103
108
return {
104
- items : allItems . filter ( i => i [ DOC_ITEM_CONTEXT ] . contract === undefined ) ,
105
- pages : Object . entries ( pages ) . map ( ( [ id , items ] ) => ( { id, items } ) ) ,
109
+ items,
110
+ pages : Object . entries ( pages ) . map ( ( [ id , pageItems ] ) => ( { id, items : pageItems } ) ) ,
106
111
} ;
107
112
}
108
113
0 commit comments