@@ -719,7 +719,11 @@ exports.main = function main(argv, options, callback) {
719
719
// Prepare output
720
720
if ( ! args . noEmit ) {
721
721
let hasStdout = false ;
722
- let hasOutput = false ;
722
+ let hasOutput = args . textFile != null
723
+ || args . binaryFile != null
724
+ || args . jsFile != null
725
+ || args . tsdFile != null
726
+ || args . idlFile != null ;
723
727
724
728
if ( args . outFile != null ) {
725
729
if ( / \. w a s ? t $ / . test ( args . outFile ) && args . textFile == null ) {
@@ -752,7 +756,6 @@ exports.main = function main(argv, options, callback) {
752
756
writeStdout ( wasm . output ) ;
753
757
hasStdout = true ;
754
758
}
755
- hasOutput = true ;
756
759
757
760
// Post-process source map
758
761
if ( wasm . sourceMap != null ) {
@@ -776,24 +779,22 @@ exports.main = function main(argv, options, callback) {
776
779
}
777
780
}
778
781
779
- // Write JS
780
- if ( args . jsFile != null ) {
781
- let js ;
782
- if ( args . jsFile . length ) {
782
+ // Write text (also fallback)
783
+ if ( args . textFile != null || ! hasOutput ) {
784
+ let wat ;
785
+ if ( args . textFile != null && args . textFile . length ) {
783
786
stats . emitCount ++ ;
784
787
stats . emitTime += measure ( ( ) => {
785
- js = module . toAsmjs ( ) ;
788
+ wat = module . toText ( ) ;
786
789
} ) ;
787
- writeFile ( args . jsFile , js , baseDir ) ;
790
+ writeFile ( args . textFile , wat , baseDir ) ;
788
791
} else if ( ! hasStdout ) {
789
792
stats . emitCount ++ ;
790
793
stats . emitTime += measure ( ( ) => {
791
- js = module . toAsmjs ( ) ;
794
+ wat = module . toText ( ) ;
792
795
} ) ;
793
- writeStdout ( js ) ;
794
- hasStdout = true ;
796
+ writeStdout ( wat ) ;
795
797
}
796
- hasOutput = true ;
797
798
}
798
799
799
800
// Write WebIDL
@@ -813,7 +814,6 @@ exports.main = function main(argv, options, callback) {
813
814
writeStdout ( idl ) ;
814
815
hasStdout = true ;
815
816
}
816
- hasOutput = true ;
817
817
}
818
818
819
819
// Write TypeScript definition
@@ -833,24 +833,23 @@ exports.main = function main(argv, options, callback) {
833
833
writeStdout ( tsd ) ;
834
834
hasStdout = true ;
835
835
}
836
- hasOutput = true ;
837
836
}
838
837
839
- // Write text ( must be last)
840
- if ( args . textFile != null || ! hasOutput ) {
841
- let wat ;
842
- if ( args . textFile && args . textFile . length ) {
838
+ // Write JS (modifies the binary, so must be last)
839
+ if ( args . jsFile != null ) {
840
+ let js ;
841
+ if ( args . jsFile . length ) {
843
842
stats . emitCount ++ ;
844
843
stats . emitTime += measure ( ( ) => {
845
- wat = module . toText ( ) ;
844
+ js = module . toAsmjs ( ) ;
846
845
} ) ;
847
- writeFile ( args . textFile , wat , baseDir ) ;
846
+ writeFile ( args . jsFile , js , baseDir ) ;
848
847
} else if ( ! hasStdout ) {
849
848
stats . emitCount ++ ;
850
849
stats . emitTime += measure ( ( ) => {
851
- wat = module . toText ( ) ;
850
+ js = module . toAsmjs ( ) ;
852
851
} ) ;
853
- writeStdout ( wat ) ;
852
+ writeStdout ( js ) ;
854
853
}
855
854
}
856
855
}
0 commit comments