@@ -67,9 +67,6 @@ exports.version = exports.isBundle ? BUNDLE_VERSION : require("../package.json")
67
67
/** Available CLI options. */
68
68
exports . options = require ( "./asc.json" ) ;
69
69
70
- /** Common root used in source maps. */
71
- exports . sourceMapRoot = "assemblyscript:///" ;
72
-
73
70
/** Prefix used for library files. */
74
71
exports . libraryPrefix = assemblyscript . LIBRARY_PREFIX ;
75
72
@@ -767,16 +764,17 @@ exports.main = function main(argv, options, callback) {
767
764
768
765
// Write binary
769
766
if ( args . binaryFile != null ) {
767
+ let basename = path . basename ( args . binaryFile ) ;
770
768
let sourceMapURL = args . sourceMap != null
771
769
? args . sourceMap . length
772
770
? args . sourceMap
773
- : path . basename ( args . binaryFile ) + ".map"
771
+ : "./" + basename + ".map"
774
772
: null ;
775
773
776
774
let wasm ;
777
775
stats . emitCount ++ ;
778
776
stats . emitTime += measure ( ( ) => {
779
- wasm = module . toBinary ( sourceMapURL )
777
+ wasm = module . toBinary ( sourceMapURL ) ;
780
778
} ) ;
781
779
782
780
if ( args . binaryFile . length ) {
@@ -790,18 +788,19 @@ exports.main = function main(argv, options, callback) {
790
788
// Post-process source map
791
789
if ( wasm . sourceMap != null ) {
792
790
if ( args . binaryFile . length ) {
793
- let sourceMap = JSON . parse ( wasm . sourceMap ) ;
794
- sourceMap . sourceRoot = exports . sourceMapRoot ;
795
- sourceMap . sources . forEach ( ( name , index ) => {
791
+ let map = JSON . parse ( wasm . sourceMap ) ;
792
+ map . sourceRoot = "./" + basename ;
793
+ let contents = [ ] ;
794
+ map . sources . forEach ( ( name , index ) => {
796
795
let text = assemblyscript . getSource ( program , name . replace ( / \. t s $ / , "" ) ) ;
797
796
if ( text == null ) return callback ( Error ( "Source of file '" + name + "' not found." ) ) ;
798
- if ( ! sourceMap . sourceContents ) sourceMap . sourceContents = [ ] ;
799
- sourceMap . sourceContents [ index ] = text ;
797
+ contents [ index ] = text ;
800
798
} ) ;
799
+ map . sourcesContent = contents ;
801
800
writeFile ( path . join (
802
801
path . dirname ( args . binaryFile ) ,
803
802
path . basename ( sourceMapURL )
804
- ) . replace ( / ^ \. \/ / , "" ) , JSON . stringify ( sourceMap ) , baseDir ) ;
803
+ ) . replace ( / ^ \. \/ / , "" ) , JSON . stringify ( map ) , baseDir ) ;
805
804
} else {
806
805
stderr . write ( "Skipped source map (stdout already occupied)" + EOL ) ;
807
806
}
0 commit comments