@@ -104,13 +104,22 @@ function checkDiagnostics(parser) {
104
104
process . exit ( 1 ) ;
105
105
}
106
106
107
- // Include standard library
108
- var stdlibDir = path . join ( __dirname , ".." , "std" , "assembly" ) ;
109
- if ( ! args . noLib ) {
107
+ // Include standard library if --noLib isn't set
108
+ var libDirs = args . noLib ? [ ] : [ path . join ( __dirname , ".." , "std" , "assembly" ) ] ;
109
+
110
+ // Include custom library components (with or without stdlib)
111
+ if ( args . lib ) {
112
+ if ( Array . isArray ( args . lib ) )
113
+ Array . prototype . push . apply ( libDirs , args . lib . map ( dir ) ) ;
114
+ else
115
+ libDirs . push ( args . lib ) ;
116
+ }
117
+
118
+ libDirs . forEach ( libDir => {
110
119
var notIoTime = 0 ;
111
120
readTime += measure ( ( ) => {
112
- glob . sync ( "*.ts" , { cwd : stdlibDir } ) . forEach ( file => {
113
- var nextText = fs . readFileSync ( path . join ( stdlibDir , file ) , { encoding : "utf8" } ) ;
121
+ glob . sync ( "*.ts" , { cwd : libDir } ) . forEach ( file => {
122
+ var nextText = fs . readFileSync ( path . join ( libDir , file ) , { encoding : "utf8" } ) ;
114
123
++ readCount ;
115
124
var time = measure ( ( ) => {
116
125
parser = assemblyscript . parseFile ( nextText , "std:" + file , parser , false ) ;
@@ -119,7 +128,7 @@ if (!args.noLib) {
119
128
notIoTime += time ;
120
129
} ) ;
121
130
} ) - notIoTime ;
122
- }
131
+ } ) ;
123
132
124
133
// Include entry files
125
134
args . _ . forEach ( filename => {
@@ -154,26 +163,41 @@ args._.forEach(filename => {
154
163
} ) ;
155
164
156
165
while ( ( nextPath = parser . nextFile ( ) ) != null ) {
157
- try {
166
+ var found = false ;
167
+ if ( nextPath . startsWith ( "std:" ) ) {
168
+ for ( var i = 0 ; i < libDirs . length ; ++ i ) {
169
+ readTime += measure ( ( ) => {
170
+ try {
171
+ nextText = fs . readFileSync ( libDirs [ i ] + "/" + nextPath . substring ( 4 ) + ".ts" , { encoding : "utf8" } ) ;
172
+ found = true ;
173
+ } catch ( e ) { }
174
+ } ) ;
175
+ ++ readCount ;
176
+ if ( found )
177
+ break ;
178
+ }
179
+ } else {
158
180
readTime += measure ( ( ) => {
159
- if ( nextPath . startsWith ( "std:" ) )
160
- nextText = fs . readFileSync ( stdlibDir + "/" + nextPath . substring ( 4 ) + ".ts" , { encoding : "utf8" } ) ;
161
- else
162
- nextText = fs . readFileSync ( nextPath + ".ts" , { encoding : "utf8" } ) ;
181
+ try {
182
+ nextText = fs . readFileSync ( nextPath + "/index .ts" , { encoding : "utf8" } ) ;
183
+ found = true ;
184
+ } catch ( e ) { }
163
185
} ) ;
164
186
++ readCount ;
165
- } catch ( e ) {
166
- try {
187
+ if ( ! found ) {
167
188
readTime += measure ( ( ) => {
168
- nextText = fs . readFileSync ( nextPath + "/index.ts" , { encoding : "utf8" } ) ;
189
+ try {
190
+ nextText = fs . readFileSync ( nextPath + ".ts" , { encoding : "utf8" } ) ;
191
+ found = true ;
192
+ } catch ( e ) { }
169
193
} ) ;
170
194
++ readCount ;
171
- nextPath = nextPath + "/index" ;
172
- } catch ( e ) {
173
- console . error ( "Imported file '" + nextPath + ".ts' not found." ) ;
174
- process . exit ( 1 ) ;
175
195
}
176
196
}
197
+ if ( ! found ) {
198
+ console . error ( "Imported file '" + nextPath + ".ts' not found." ) ;
199
+ process . exit ( 1 ) ;
200
+ }
177
201
parseTime += measure ( ( ) => {
178
202
assemblyscript . parseFile ( nextText , nextPath , parser ) ;
179
203
} ) ;
0 commit comments