Add support for source mappings #10

Merged
TopchetoEU merged 22 commits from TopchetoEU/mapping into master 2023-12-18 20:42:38 +00:00
5 changed files with 128 additions and 133 deletions
Showing only changes of commit e8a7ac8da8 - Show all commits

View File

@ -84,14 +84,18 @@
throw new SyntaxError(diagnostics.join("\n")); throw new SyntaxError(diagnostics.join("\n"));
} }
var map = emit.outputFiles[0].text; var map = JSON.parse(emit.outputFiles[0].text);
var result = emit.outputFiles[1].text; var result = emit.outputFiles[1].text;
var declaration = emit.outputFiles[2].text; var declaration = emit.outputFiles[2].text;
log(map);
return { return {
source: result, source: result,
map: log(JSON.stringify({
version: 3,
sources: [ filename ],
file: filename,
mappings: map.mappings
})),
runner: function(func) { runner: function(func) {
return function() { return function() {
var val = func.apply(this, arguments); var val = func.apply(this, arguments);

View File

@ -15,22 +15,13 @@ public class Reading {
} }
public static String streamToString(InputStream in) { public static String streamToString(InputStream in) {
try { try { return new String(in.readAllBytes()); }
StringBuilder out = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
for(var line = br.readLine(); line != null; line = br.readLine()) {
out.append(line).append('\n');
}
br.close();
return out.toString();
}
catch (Throwable e) { throw new UncheckedException(e); } catch (Throwable e) { throw new UncheckedException(e); }
} }
public static InputStream resourceToStream(String name) {
return Reading.class.getResourceAsStream("/assets/" + name);
}
public static String resourceToString(String name) { public static String resourceToString(String name) {
var str = Main.class.getResourceAsStream("/me/topchetoeu/jscript/" + name); return streamToString(resourceToStream(name));
if (str == null) return null;
return streamToString(str);
} }
} }

View File

@ -9,6 +9,7 @@ import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import me.topchetoeu.jscript.Metadata; import me.topchetoeu.jscript.Metadata;
import me.topchetoeu.jscript.Reading;
import me.topchetoeu.jscript.engine.debug.WebSocketMessage.Type; import me.topchetoeu.jscript.engine.debug.WebSocketMessage.Type;
import me.topchetoeu.jscript.events.Notifier; import me.topchetoeu.jscript.events.Notifier;
import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.exceptions.SyntaxException;
@ -232,10 +233,9 @@ public class DebugServer {
public DebugServer() { public DebugServer() {
try { try {
this.favicon = getClass().getClassLoader().getResourceAsStream("assets/favicon.png").readAllBytes(); this.favicon = Reading.resourceToStream("debugger/favicon.png").readAllBytes();
this.protocol = getClass().getClassLoader().getResourceAsStream("assets/protocol.json").readAllBytes(); this.protocol = Reading.resourceToStream("debugger/protocol.json").readAllBytes();
var index = new String(getClass().getClassLoader().getResourceAsStream("assets/index.html").readAllBytes()); this.index = Reading.resourceToString("debugger/index.html")
this.index = index
.replace("${NAME}", Metadata.name()) .replace("${NAME}", Metadata.name())
.replace("${VERSION}", Metadata.version()) .replace("${VERSION}", Metadata.version())
.replace("${AUTHOR}", Metadata.author()) .replace("${AUTHOR}", Metadata.author())