@@ -15,11 +15,16 @@ class File {
1515 }
1616
1717 parseFileForImport ( content , isHttpContract , callback ) {
18+ const self = this ;
1819 if ( typeof isHttpContract === 'function' ) {
1920 callback = isHttpContract ;
2021 isHttpContract = false ;
2122 }
22- const self = this ;
23+ if ( self . parsedImports ) {
24+ // We already parsed this file
25+ return callback ( ) ;
26+ }
27+ self . parsedImports = true ;
2328 if ( self . filename . indexOf ( '.sol' ) < 0 ) {
2429 // Only supported in Solidity
2530 return callback ( ) ;
@@ -98,34 +103,25 @@ class File {
98103 content = fs . readFileSync ( this . path ) . toString ( ) ;
99104 } else if ( this . type === File . types . custom ) {
100105 return this . resolver ( ( theContent ) => {
101- if ( ! this . parsedImports ) {
102- this . parsedImports = true ;
103- return this . parseFileForImport ( content , ( ) => {
104- callback ( theContent ) ;
105- } ) ;
106- }
107- callback ( theContent ) ;
106+ this . parseFileForImport ( content , ( ) => {
107+ callback ( theContent ) ;
108+ } ) ;
108109 } ) ;
109110 } else if ( this . type === File . types . http ) {
110111 return this . downloadFile ( this . filename , this . path , ( content ) => {
111112 if ( ! content ) {
112113 return callback ( content ) ;
113114 }
114- this . parsedImports = true ;
115115 this . path = this . filename ;
116116 this . type = File . types . dapp_file ;
117117 callback ( content ) ;
118118 } ) ;
119119 } else {
120120 throw new Error ( "unknown file: " + this . filename ) ;
121121 }
122- if ( ! this . parsedImports ) {
123- this . parsedImports = true ;
124- return this . parseFileForImport ( content , ( ) => {
125- callback ( content ) ;
126- } ) ;
127- }
128- callback ( content ) ;
122+ return this . parseFileForImport ( content , ( ) => {
123+ callback ( content ) ;
124+ } ) ;
129125 }
130126
131127}
0 commit comments