@@ -67,9 +67,6 @@ exports.version = exports.isBundle ? BUNDLE_VERSION : require("../package.json")
6767/** Available CLI options. */
6868exports . options = require ( "./asc.json" ) ;
6969
70- /** Common root used in source maps. */
71- exports . sourceMapRoot = "assemblyscript:///" ;
72-
7370/** Prefix used for library files. */
7471exports . libraryPrefix = assemblyscript . LIBRARY_PREFIX ;
7572
@@ -767,16 +764,17 @@ exports.main = function main(argv, options, callback) {
767764
768765 // Write binary
769766 if ( args . binaryFile != null ) {
767+ let basename = path . basename ( args . binaryFile ) ;
770768 let sourceMapURL = args . sourceMap != null
771769 ? args . sourceMap . length
772770 ? args . sourceMap
773- : path . basename ( args . binaryFile ) + ".map"
771+ : "./" + basename + ".map"
774772 : null ;
775773
776774 let wasm ;
777775 stats . emitCount ++ ;
778776 stats . emitTime += measure ( ( ) => {
779- wasm = module . toBinary ( sourceMapURL )
777+ wasm = module . toBinary ( sourceMapURL ) ;
780778 } ) ;
781779
782780 if ( args . binaryFile . length ) {
@@ -790,18 +788,19 @@ exports.main = function main(argv, options, callback) {
790788 // Post-process source map
791789 if ( wasm . sourceMap != null ) {
792790 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 ) => {
796795 let text = assemblyscript . getSource ( program , name . replace ( / \. t s $ / , "" ) ) ;
797796 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 ;
800798 } ) ;
799+ map . sourcesContent = contents ;
801800 writeFile ( path . join (
802801 path . dirname ( args . binaryFile ) ,
803802 path . basename ( sourceMapURL )
804- ) . replace ( / ^ \. \/ / , "" ) , JSON . stringify ( sourceMap ) , baseDir ) ;
803+ ) . replace ( / ^ \. \/ / , "" ) , JSON . stringify ( map ) , baseDir ) ;
805804 } else {
806805 stderr . write ( "Skipped source map (stdout already occupied)" + EOL ) ;
807806 }
0 commit comments