@@ -92,43 +92,35 @@ exports.definitionFiles = exports.isBundle ? BUNDLE_DEFINITIONS : (() => { // se
92
92
} ) ( ) ;
93
93
94
94
/** Convenience function that parses and compiles source strings directly. */
95
- exports . compileString = async ( sources , options ) => {
95
+ exports . compileString = ( sources , options ) => {
96
96
if ( typeof sources === "string" ) sources = { "input.ts" : sources } ;
97
97
const output = Object . create ( {
98
98
stdout : createMemoryStream ( ) ,
99
99
stderr : createMemoryStream ( ) ,
100
100
binary : null ,
101
101
text : null
102
102
} ) ;
103
- debugger ;
104
- var argv = [ ] ;
103
+ var argv = [
104
+ "--binaryFile" , "binary" ,
105
+ "--textFile" , "text" ,
106
+ ] ;
105
107
Object . keys ( options || { } ) . forEach ( key => {
106
- if ( key != "readFile" && key != 'writeFile' ) {
107
- var val = options [ key ] ;
108
- debugger ;
109
- if ( Array . isArray ( val ) ) val . forEach ( val => argv . push ( "--" + key , String ( val ) ) ) ;
110
- else argv . push ( "--" + key , String ( val ) ) ;
111
- }
108
+ var val = options [ key ] ;
109
+ if ( Array . isArray ( val ) ) val . forEach ( val => argv . push ( "--" + key , String ( val ) ) ) ;
110
+ else argv . push ( "--" + key , String ( val ) ) ;
112
111
} ) ;
113
- await exports . main ( argv . concat ( Object . keys ( sources ) ) , {
112
+ exports . main ( argv . concat ( Object . keys ( sources ) ) , {
114
113
stdout : output . stdout ,
115
114
stderr : output . stderr ,
116
- readFile : async ( name ) => {
117
- try {
118
- return await options . readFile ( name ) ;
119
- } catch ( e ) {
120
- return null ;
121
- }
122
- } ,
123
- writeFile : async ( name , contents ) => await options . writeFile ( name , contents ) ,
115
+ readFile : name => sources . hasOwnProperty ( name ) ? sources [ name ] : null ,
116
+ writeFile : ( name , contents ) => output [ name ] = contents ,
124
117
listFiles : ( ) => [ ]
125
118
} ) ;
126
- debugger ;
127
119
return output ;
128
120
}
129
121
130
122
/** Runs the command line utility using the specified arguments array. */
131
- exports . main = async function main ( argv , options , callback ) {
123
+ exports . main = function main ( argv , options , callback ) {
132
124
if ( typeof options === "function" ) {
133
125
callback = options ;
134
126
options = { } ;
@@ -236,7 +228,7 @@ exports.main = async function main(argv, options, callback) {
236
228
237
229
// Begin parsing
238
230
var parser = null ;
239
- debugger ;
231
+
240
232
// Include library files
241
233
if ( ! args . noLib ) {
242
234
Object . keys ( exports . libraryFiles ) . forEach ( libPath => {
@@ -278,7 +270,7 @@ exports.main = async function main(argv, options, callback) {
278
270
}
279
271
for ( let j = 0 , l = libFiles . length ; j < l ; ++ j ) {
280
272
let libPath = libFiles [ j ] ;
281
- let libText = await readFile ( path . join ( libDir , libPath ) ) ;
273
+ let libText = readFile ( path . join ( libDir , libPath ) ) ;
282
274
if ( libText === null ) return callback ( Error ( "Library file '" + libPath + "' not found." ) ) ;
283
275
stats . parseCount ++ ;
284
276
stats . parseTime += measure ( ( ) => {
@@ -296,14 +288,13 @@ exports.main = async function main(argv, options, callback) {
296
288
// Include entry files
297
289
for ( let i = 0 , k = argv . length ; i < k ; ++ i ) {
298
290
const filename = argv [ i ] ;
299
- if ( filename == "undefined" ) continue ;
300
291
301
292
let sourcePath = String ( filename ) . replace ( / \\ / g, "/" ) . replace ( / ( \. t s | \/ ) $ / , "" ) ;
302
293
303
294
// Try entryPath.ts, then entryPath/index.ts
304
- let sourceText = await readFile ( path . join ( baseDir , sourcePath ) + ".ts" ) ;
295
+ let sourceText = readFile ( path . join ( baseDir , sourcePath ) + ".ts" ) ;
305
296
if ( sourceText === null ) {
306
- sourceText = await readFile ( path . join ( baseDir , sourcePath , "index.ts" ) ) ;
297
+ sourceText = readFile ( path . join ( baseDir , sourcePath , "index.ts" ) ) ;
307
298
if ( sourceText === null ) {
308
299
return callback ( Error ( "Entry file '" + sourcePath + ".ts' not found." ) ) ;
309
300
} else {
@@ -312,7 +303,6 @@ exports.main = async function main(argv, options, callback) {
312
303
} else {
313
304
sourcePath += ".ts" ;
314
305
}
315
- debugger ;
316
306
317
307
stats . parseCount ++ ;
318
308
stats . parseTime += measure ( ( ) => {
@@ -336,12 +326,12 @@ exports.main = async function main(argv, options, callback) {
336
326
} else {
337
327
for ( let i = 0 , k = customLibDirs . length ; i < k ; ++ i ) {
338
328
const dir = customLibDirs [ i ] ;
339
- sourceText = await readFile ( path . join ( dir , plainName + ".ts" ) ) ;
329
+ sourceText = readFile ( path . join ( dir , plainName + ".ts" ) ) ;
340
330
if ( sourceText !== null ) {
341
331
sourcePath = exports . libraryPrefix + plainName + ".ts" ;
342
332
break ;
343
333
} else {
344
- sourceText = await readFile ( path . join ( dir , indexName + ".ts" ) ) ;
334
+ sourceText = readFile ( path . join ( dir , indexName + ".ts" ) ) ;
345
335
if ( sourceText !== null ) {
346
336
sourcePath = exports . libraryPrefix + indexName + ".ts" ;
347
337
break ;
@@ -354,11 +344,11 @@ exports.main = async function main(argv, options, callback) {
354
344
} else {
355
345
const plainName = sourcePath ;
356
346
const indexName = sourcePath + "/index" ;
357
- sourceText = await readFile ( path . join ( baseDir , plainName + ".ts" ) ) ;
347
+ sourceText = readFile ( path . join ( baseDir , plainName + ".ts" ) ) ;
358
348
if ( sourceText !== null ) {
359
349
sourcePath = plainName + ".ts" ;
360
350
} else {
361
- sourceText = await readFile ( path . join ( baseDir , indexName + ".ts" ) ) ;
351
+ sourceText = readFile ( path . join ( baseDir , indexName + ".ts" ) ) ;
362
352
if ( sourceText !== null ) {
363
353
sourcePath = indexName + ".ts" ;
364
354
} else if ( ! plainName . startsWith ( "." ) ) {
@@ -371,12 +361,12 @@ exports.main = async function main(argv, options, callback) {
371
361
} else {
372
362
for ( let i = 0 , k = customLibDirs . length ; i < k ; ++ i ) {
373
363
const dir = customLibDirs [ i ] ;
374
- sourceText = await readFile ( path . join ( dir , plainName + ".ts" ) ) ;
364
+ sourceText = readFile ( path . join ( dir , plainName + ".ts" ) ) ;
375
365
if ( sourceText !== null ) {
376
366
sourcePath = exports . libraryPrefix + plainName + ".ts" ;
377
367
break ;
378
368
} else {
379
- sourceText = await readFile ( path . join ( dir , indexName + ".ts" ) ) ;
369
+ sourceText = readFile ( path . join ( dir , indexName + ".ts" ) ) ;
380
370
if ( sourceText !== null ) {
381
371
sourcePath = exports . libraryPrefix + indexName + ".ts" ;
382
372
break ;
@@ -562,7 +552,7 @@ exports.main = async function main(argv, options, callback) {
562
552
args . binaryFile = args . outFile ;
563
553
}
564
554
}
565
- debugger ;
555
+
566
556
// Write binary
567
557
if ( args . binaryFile != null ) {
568
558
let sourceMapURL = args . sourceMap != null
@@ -578,7 +568,7 @@ exports.main = async function main(argv, options, callback) {
578
568
} ) ;
579
569
580
570
if ( args . binaryFile . length ) {
581
- await writeFile ( path . join ( baseDir , args . binaryFile ) , wasm . output ) ;
571
+ writeFile ( path . join ( baseDir , args . binaryFile ) , wasm . output ) ;
582
572
} else {
583
573
writeStdout ( wasm . output ) ;
584
574
hasStdout = true ;
@@ -590,31 +580,31 @@ exports.main = async function main(argv, options, callback) {
590
580
if ( args . binaryFile . length ) {
591
581
let sourceMap = JSON . parse ( wasm . sourceMap ) ;
592
582
sourceMap . sourceRoot = exports . sourceMapRoot ;
593
- sourceMap . sources . forEach ( async ( name , index ) => {
583
+ sourceMap . sources . forEach ( ( name , index ) => {
594
584
let text = null ;
595
585
if ( name . startsWith ( exports . libraryPrefix ) ) {
596
586
let stdName = name . substring ( exports . libraryPrefix . length ) . replace ( / \. t s $ / , "" ) ;
597
587
if ( exports . libraryFiles . hasOwnProperty ( stdName ) ) {
598
588
text = exports . libraryFiles [ stdName ] ;
599
589
} else {
600
590
for ( let i = 0 , k = customLibDirs . length ; i < k ; ++ i ) {
601
- text = await readFile ( path . join (
591
+ text = readFile ( path . join (
602
592
customLibDirs [ i ] ,
603
593
name . substring ( exports . libraryPrefix . length ) )
604
594
) ;
605
595
if ( text !== null ) break ;
606
596
}
607
597
}
608
598
} else {
609
- text = await readFile ( path . join ( baseDir , name ) ) ;
599
+ text = readFile ( path . join ( baseDir , name ) ) ;
610
600
}
611
601
if ( text === null ) {
612
602
return callback ( Error ( "Source file '" + name + "' not found." ) ) ;
613
603
}
614
604
if ( ! sourceMap . sourceContents ) sourceMap . sourceContents = [ ] ;
615
605
sourceMap . sourceContents [ index ] = text ;
616
606
} ) ;
617
- await writeFile ( path . join (
607
+ writeFile ( path . join (
618
608
baseDir ,
619
609
path . dirname ( args . binaryFile ) ,
620
610
path . basename ( sourceMapURL )
@@ -633,7 +623,7 @@ exports.main = async function main(argv, options, callback) {
633
623
stats . emitTime += measure ( ( ) => {
634
624
asm = module . toAsmjs ( ) ;
635
625
} ) ;
636
- await writeFile ( path . join ( baseDir , args . asmjsFile ) , asm ) ;
626
+ writeFile ( path . join ( baseDir , args . asmjsFile ) , asm ) ;
637
627
} else if ( ! hasStdout ) {
638
628
stats . emitCount ++ ;
639
629
stats . emitTime += measure ( ( ) => {
@@ -653,7 +643,7 @@ exports.main = async function main(argv, options, callback) {
653
643
stats . emitTime += measure ( ( ) => {
654
644
idl = assemblyscript . buildIDL ( program ) ;
655
645
} ) ;
656
- await writeFile ( path . join ( baseDir , args . idlFile ) , idl ) ;
646
+ writeFile ( path . join ( baseDir , args . idlFile ) , idl ) ;
657
647
} else if ( ! hasStdout ) {
658
648
stats . emitCount ++ ;
659
649
stats . emitTime += measure ( ( ) => {
@@ -673,7 +663,7 @@ exports.main = async function main(argv, options, callback) {
673
663
stats . emitTime += measure ( ( ) => {
674
664
tsd = assemblyscript . buildTSD ( program ) ;
675
665
} ) ;
676
- await writeFile ( path . join ( baseDir , args . tsdFile ) , tsd ) ;
666
+ writeFile ( path . join ( baseDir , args . tsdFile ) , tsd ) ;
677
667
} else if ( ! hasStdout ) {
678
668
stats . emitCount ++ ;
679
669
stats . emitTime += measure ( ( ) => {
@@ -693,7 +683,7 @@ exports.main = async function main(argv, options, callback) {
693
683
stats . emitTime += measure ( ( ) => {
694
684
wat = module . toText ( ) ;
695
685
} ) ;
696
- await writeFile ( path . join ( baseDir , args . textFile ) , wat ) ;
686
+ writeFile ( path . join ( baseDir , args . textFile ) , wat ) ;
697
687
} else if ( ! hasStdout ) {
698
688
stats . emitCount ++ ;
699
689
stats . emitTime += measure ( ( ) => {
0 commit comments