mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
use "sourceRoot" in map instead to concatenate it to every source file name
This commit is contained in:
parent
7fa099298f
commit
515123d4e1
@ -63,8 +63,6 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
|
||||
private final boolean createSourceMap;
|
||||
|
||||
private final String javaSourceMapBase;
|
||||
|
||||
private WasmOutputStream codeStream = new WasmOutputStream();
|
||||
|
||||
private List<TypeEntry> functionTypes = new ArrayList<>();
|
||||
@ -104,7 +102,6 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
this.target = target;
|
||||
// for now we build the source map together with debug names
|
||||
createSourceMap = options.debugNames();
|
||||
javaSourceMapBase = options.getSourceMapBase();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,7 +291,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
}
|
||||
wasm.writeSection( SectionType.Code, stream );
|
||||
|
||||
SourceMapWriter sourceMap = createSourceMap ? new SourceMapWriter() : null;
|
||||
SourceMapWriter sourceMap = createSourceMap ? new SourceMapWriter( options.getSourceMapBase() ) : null;
|
||||
if( sourceMap != null ) {
|
||||
int offset = wasm.size() - start - stream.size();
|
||||
for( Function func : functions.values() ) {
|
||||
@ -563,7 +560,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
protected void writeMethodStart( FunctionName name, String sourceFile ) throws IOException {
|
||||
if( createSourceMap ) {
|
||||
int idx = name.className.lastIndexOf( '/' );
|
||||
this.javaSourceFile = javaSourceMapBase + name.className.substring( 0, idx + 1 ) + sourceFile;
|
||||
this.javaSourceFile = name.className.substring( 0, idx + 1 ) + sourceFile;
|
||||
}
|
||||
codeStream.reset();
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Generates Source Map version 3.
|
||||
*
|
||||
@ -28,11 +30,23 @@ import java.util.Map.Entry;
|
||||
*/
|
||||
public class SourceMapWriter {
|
||||
|
||||
private List<SourceMapping> mappings = new ArrayList<>();
|
||||
private final String sourceRoot;
|
||||
|
||||
private LinkedHashMap<String, Integer> sourceFileNames = new LinkedHashMap<String, Integer>();
|
||||
private final List<SourceMapping> mappings = new ArrayList<>();
|
||||
|
||||
private int nextSourceFileNameIndex;
|
||||
private final LinkedHashMap<String, Integer> sourceFileNames = new LinkedHashMap<String, Integer>();
|
||||
|
||||
private int nextSourceFileNameIndex;
|
||||
|
||||
/**
|
||||
* Create a new instance of the writer for a single map file.
|
||||
*
|
||||
* @param sourceRoot
|
||||
* optional absolute or relative path to the sources
|
||||
*/
|
||||
public SourceMapWriter( @Nullable String sourceRoot ) {
|
||||
this.sourceRoot = sourceRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a mapping for the given node. Mappings must be added in order.
|
||||
@ -61,6 +75,11 @@ public class SourceMapWriter {
|
||||
out.append( "{\n" );
|
||||
appendJsonField( out, "version", "3" );
|
||||
|
||||
// sourceRoot
|
||||
if( sourceRoot != null && !sourceRoot.isEmpty() ) {
|
||||
appendJsonField( out, "sourceRoot", sourceRoot );
|
||||
}
|
||||
|
||||
// the source file names
|
||||
out.append( ",\n" );
|
||||
appendJsonField( out, "sources", "[" );
|
||||
|
@ -10,7 +10,7 @@ public class SourceMapWriterTest {
|
||||
|
||||
@Test
|
||||
public void simple() throws IOException {
|
||||
SourceMapWriter map = new SourceMapWriter();
|
||||
SourceMapWriter map = new SourceMapWriter( null );
|
||||
|
||||
map.addMapping( new SourceMapping( 0, 1, "Test1.java" ) );
|
||||
map.addMapping( new SourceMapping( 5, 2, "Test1.java" ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user