@@ -62,80 +62,78 @@ if (args.help || args._.length < 1) {
6262 } ) ;
6363 console . log ( [
6464 "Version " + version ,
65- "Syntax: asc [options] [file ...]" ,
65+ "Syntax: asc [options] [entryFile ...]" ,
6666 "" ,
6767 "Examples: asc hello.ts" ,
68+ " asc hello.ts -b hello.wasm -t hello.wast -a hello.js" ,
69+ " asc hello.ts -b > hello.wasm" ,
6870 "" ,
6971 "Options:"
7072 ] . concat ( options ) . join ( "\n" ) ) ;
7173 process . exit ( args . help ? 0 : 1 ) ;
7274}
7375
74- var entryPath = args . _ [ 0 ] . replace ( / \\ / g, "/" ) . replace ( / ( \. t s | \/ ) $ / , "" ) ;
75- var entryDir = path . dirname ( entryPath ) ;
76- var entryText ;
77- try {
78- entryText = fs . readFileSync ( entryPath + ".ts" , { encoding : "utf8" } ) ;
79- } catch ( e ) {
80- try {
81- entryText = fs . readFileSync ( entryPath + "/index.ts" , { encoding : "utf8" } ) ;
82- entryPath = entryPath + "/index" ;
83- } catch ( e ) {
84- console . error ( "File '" + entryPath + ".ts' not found." ) ;
85- process . exit ( 1 ) ;
76+ var parser = null ;
77+
78+ function checkDiagnostics ( parser ) {
79+ var diagnostic ;
80+ var hasErrors = false ;
81+
82+ while ( ( diagnostic = assemblyscript . nextDiagnostic ( parser ) ) != null ) {
83+ console . error ( assemblyscript . formatDiagnostic ( diagnostic , process . stderr . isTTY , true ) ) ;
84+ if ( assemblyscript . isError ( diagnostic ) )
85+ hasErrors = true ;
8686 }
87+ if ( hasErrors )
88+ process . exit ( 1 ) ;
8789}
8890
89- var parser = assemblyscript . parseFile ( entryText , entryPath ) ;
91+ args . _ . forEach ( filename => {
92+ var entryPath = filename . replace ( / \\ / g, "/" ) . replace ( / ( \. t s | \/ ) $ / , "" ) ;
93+ var entryDir = path . dirname ( entryPath ) ;
94+ var entryText ;
9095
91- var nextPath ;
92- var nextText ;
93-
94- while ( ( nextPath = parser . nextFile ( ) ) != null ) {
9596 try {
96- nextText = fs . readFileSync ( nextPath + ".ts" , { encoding : "utf8" } ) ;
97+ entryText = fs . readFileSync ( entryPath + ".ts" , { encoding : "utf8" } ) ;
9798 } catch ( e ) {
9899 try {
99- nextText = fs . readFileSync ( nextPath + "/index.ts" , { encoding : "utf8" } ) ;
100- nextPath = nextPath + "/index" ;
100+ entryText = fs . readFileSync ( entryPath + "/index.ts" , { encoding : "utf8" } ) ;
101+ entryPath = entryPath + "/index" ;
101102 } catch ( e ) {
102- console . error ( "Imported file '" + nextPath + ".ts' not found." ) ;
103+ console . error ( "File '" + entryPath + ".ts' not found." ) ;
103104 process . exit ( 1 ) ;
104105 }
105106 }
106- assemblyscript . parseFile ( nextText , nextPath , parser ) ;
107- }
108107
109- var diagnostic ;
110- var hasErrors = false ;
108+ parser = assemblyscript . parseFile ( entryText , entryPath , parser , true ) ;
111109
112- while ( ( diagnostic = assemblyscript . nextDiagnostic ( parser ) ) != null ) {
113- console . error ( assemblyscript . formatDiagnostic ( diagnostic , process . stderr . isTTY , true ) ) ;
114- if ( assemblyscript . isError ( diagnostic ) )
115- hasErrors = true ;
116- }
110+ var nextPath ;
111+ var nextText ;
117112
118- if ( hasErrors )
119- process . exit ( 1 ) ;
113+ while ( ( nextPath = parser . nextFile ( ) ) != null ) {
114+ try {
115+ nextText = fs . readFileSync ( nextPath + ".ts" , { encoding : "utf8" } ) ;
116+ } catch ( e ) {
117+ try {
118+ nextText = fs . readFileSync ( nextPath + "/index.ts" , { encoding : "utf8" } ) ;
119+ nextPath = nextPath + "/index" ;
120+ } catch ( e ) {
121+ console . error ( "Imported file '" + nextPath + ".ts' not found." ) ;
122+ process . exit ( 1 ) ;
123+ }
124+ }
125+ assemblyscript . parseFile ( nextText , nextPath , parser ) ;
126+ }
127+ checkDiagnostics ( parser ) ;
128+ } ) ;
120129
121130var options = assemblyscript . createOptions ( ) ;
122131assemblyscript . setTarget ( options , 0 ) ;
123132assemblyscript . setNoTreeShaking ( options , args . noTreeShaking ) ;
124133assemblyscript . setNoDebug ( options , args . noDebug ) ;
125134
126135var module = assemblyscript . compile ( parser , options ) ;
127-
128- hasErrors = false ;
129- while ( ( diagnostic = assemblyscript . nextDiagnostic ( parser ) ) != null ) {
130- console . error ( assemblyscript . formatDiagnostic ( diagnostic , process . stderr . isTTY , true ) ) ;
131- if ( assemblyscript . isError ( diagnostic ) )
132- hasErrors = true ;
133- }
134-
135- if ( hasErrors ) {
136- module . dispose ( ) ;
137- process . exit ( 1 ) ;
138- }
136+ checkDiagnostics ( parser ) ;
139137
140138if ( args . validate )
141139 if ( ! module . validate ( ) ) {
0 commit comments