write sourceMappingURL custom section

This commit is contained in:
Volker Berlin 2019-04-01 16:17:41 +02:00
parent 40fdbaffc5
commit dd9eb4b049
2 changed files with 34 additions and 0 deletions

View File

@ -125,6 +125,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
writeExportSection();
writeCodeSection();
writeDebugNames();
writeSourceMappingUrl();
writeProducersSection();
wasm.close();
@ -272,6 +273,26 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
wasm.writeSection( SectionType.Custom, stream );
}
/**
* Write the source mapping url
*
* @throws IOException
* if any I/O error occur
*/
private void writeSourceMappingUrl() throws IOException {
if( !createSourceMap ) {
return;
}
String url = target.getSourceMappingURL();
if( url == null ) {
return;
}
WasmOutputStream stream = new WasmOutputStream();
stream.writeString( "sourceMappingURL" ); // Custom Section name "sourceMappingURL", content is part of the section length
stream.writeString( url );
wasm.writeSection( SectionType.Custom, stream );
}
/**
* Write producer information to wasm
*

View File

@ -73,6 +73,19 @@ public class WasmTarget implements Closeable {
return output;
}
/**
* Get the URL for the source mapping that should be write into the assembly.
*
* @return the URL string or null.
*/
@Nonnull
public String getSourceMappingURL() {
if( file != null ) {
return file.getName() + ".map";
}
return null;
}
/**
* Get the source map OutputStream
*