diff --git a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java index a0794053..60e3a1ce 100644 --- a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java @@ -125,6 +125,7 @@ public void close() throws IOException { writeExportSection(); writeCodeSection(); writeDebugNames(); + writeSourceMappingUrl(); writeProducersSection(); wasm.close(); @@ -272,6 +273,26 @@ private void writeDebugNames() throws IOException { 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 * diff --git a/src/de/inetsoftware/jwebassembly/module/WasmTarget.java b/src/de/inetsoftware/jwebassembly/module/WasmTarget.java index ae8cffc8..1e2a092e 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmTarget.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmTarget.java @@ -73,6 +73,19 @@ public OutputStream getWasmOutput() throws IOException { 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 *