Skip to content

Commit

Permalink
write sourceMappingURL custom section
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Apr 1, 2019
1 parent 40fdbaf commit dd9eb4b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void close() throws IOException {
writeExportSection();
writeCodeSection();
writeDebugNames();
writeSourceMappingUrl();
writeProducersSection();

wasm.close();
Expand Down Expand Up @@ -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
*
Expand Down
13 changes: 13 additions & 0 deletions src/de/inetsoftware/jwebassembly/module/WasmTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit dd9eb4b

Please sign in to comment.