@@ -62,80 +62,78 @@ if (args.help || args._.length < 1) {
62
62
} ) ;
63
63
console . log ( [
64
64
"Version " + version ,
65
- "Syntax: asc [options] [file ...]" ,
65
+ "Syntax: asc [options] [entryFile ...]" ,
66
66
"" ,
67
67
"Examples: asc hello.ts" ,
68
+ " asc hello.ts -b hello.wasm -t hello.wast -a hello.js" ,
69
+ " asc hello.ts -b > hello.wasm" ,
68
70
"" ,
69
71
"Options:"
70
72
] . concat ( options ) . join ( "\n" ) ) ;
71
73
process . exit ( args . help ? 0 : 1 ) ;
72
74
}
73
75
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 ;
86
86
}
87
+ if ( hasErrors )
88
+ process . exit ( 1 ) ;
87
89
}
88
90
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 ;
90
95
91
- var nextPath ;
92
- var nextText ;
93
-
94
- while ( ( nextPath = parser . nextFile ( ) ) != null ) {
95
96
try {
96
- nextText = fs . readFileSync ( nextPath + ".ts" , { encoding : "utf8" } ) ;
97
+ entryText = fs . readFileSync ( entryPath + ".ts" , { encoding : "utf8" } ) ;
97
98
} catch ( e ) {
98
99
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" ;
101
102
} catch ( e ) {
102
- console . error ( "Imported file '" + nextPath + ".ts' not found." ) ;
103
+ console . error ( "File '" + entryPath + ".ts' not found." ) ;
103
104
process . exit ( 1 ) ;
104
105
}
105
106
}
106
- assemblyscript . parseFile ( nextText , nextPath , parser ) ;
107
- }
108
107
109
- var diagnostic ;
110
- var hasErrors = false ;
108
+ parser = assemblyscript . parseFile ( entryText , entryPath , parser , true ) ;
111
109
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 ;
117
112
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
+ } ) ;
120
129
121
130
var options = assemblyscript . createOptions ( ) ;
122
131
assemblyscript . setTarget ( options , 0 ) ;
123
132
assemblyscript . setNoTreeShaking ( options , args . noTreeShaking ) ;
124
133
assemblyscript . setNoDebug ( options , args . noDebug ) ;
125
134
126
135
var 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 ) ;
139
137
140
138
if ( args . validate )
141
139
if ( ! module . validate ( ) ) {
0 commit comments