From dd9eb4b049edf3111486875c20cc55e9c0ad2229 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Mon, 1 Apr 2019 16:17:41 +0200 Subject: [PATCH] write sourceMappingURL custom section --- .../binary/BinaryModuleWriter.java | 21 +++++++++++++++++++ .../jwebassembly/module/WasmTarget.java | 13 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java index a079405..60e3a1c 100644 --- a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java @@ -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 * diff --git a/src/de/inetsoftware/jwebassembly/module/WasmTarget.java b/src/de/inetsoftware/jwebassembly/module/WasmTarget.java index ae8cffc..1e2a092 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmTarget.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmTarget.java @@ -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 *