Switch to esm, add #export statement to newt, tweaks to LSP
This commit is contained in:
@@ -7,6 +7,8 @@ export interface Handle {
|
||||
buf: Uint8Array;
|
||||
}
|
||||
|
||||
// Some of this was written for Idris and is not used by newt
|
||||
|
||||
interface Process {
|
||||
argv: string[];
|
||||
platform: string;
|
||||
@@ -49,6 +51,9 @@ export let shim: NodeShim = {
|
||||
},
|
||||
writeSync(fd: number, data: string) {
|
||||
shim.stdout += data;
|
||||
},
|
||||
readSync() {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
process: {
|
||||
|
||||
@@ -14,15 +14,18 @@ const shim = {
|
||||
throw new Error(`${fn} not found`);
|
||||
}
|
||||
},
|
||||
writeSync: (fd: number, msg: string) => console.log(msg)
|
||||
},
|
||||
};
|
||||
// we intercept require to return our fake node modules
|
||||
declare global {
|
||||
interface Window {
|
||||
require: (x: string) => any;
|
||||
fs: any;
|
||||
}
|
||||
}
|
||||
const requireStub: any = (x: string) => (shim as any)[x];
|
||||
self.fs = shim.fs;
|
||||
self.require = requireStub;
|
||||
self.process = {
|
||||
platform: "linux",
|
||||
|
||||
@@ -39,6 +39,12 @@ function mdline2nodes(s: string) {
|
||||
return cs
|
||||
}
|
||||
|
||||
function bundle(js: string) {
|
||||
js = js.replace(/^import.*\n/g, '');
|
||||
js = js.replace(/\nexport /g, '\n');
|
||||
return js;
|
||||
}
|
||||
|
||||
function md2nodes(md: string) {
|
||||
let rval: VNode[] = []
|
||||
let list: VNode[] | undefined
|
||||
@@ -77,7 +83,7 @@ if (!state.javascript.value) {
|
||||
// maybe send fileName, src?
|
||||
await ipc.sendMessage("save", [fileName, src]);
|
||||
let js = await ipc.sendMessage("compile", [fileName]);
|
||||
state.javascript.value = js;
|
||||
state.javascript.value = bundle(js);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +254,7 @@ const language: EditorDelegate = {
|
||||
});
|
||||
}
|
||||
// less flashy version
|
||||
ipc.sendMessage("compile", [fileName]).then(js => state.javascript.value = js);
|
||||
ipc.sendMessage("compile", [fileName]).then(js => state.javascript.value = bundle(js));
|
||||
return diags;
|
||||
} catch (e) {
|
||||
console.log("ERR", e);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { shim } from "./emul";
|
||||
import { API, Message, ResponseMSG } from "./ipc";
|
||||
import { archive, preload } from "./preload";
|
||||
import { Main_main } from './newt';
|
||||
|
||||
const LOG = console.log
|
||||
|
||||
console.log = (m) => {
|
||||
LOG(m)
|
||||
shim.stdout += "\n" + m;
|
||||
};
|
||||
|
||||
@@ -47,4 +50,3 @@ const handleMessage = async function <K extends keyof API>(ev: { data: Message<K
|
||||
// hooks for worker.html to override
|
||||
let sendResponse: <K extends keyof API>(_: ResponseMSG) => void = postMessage;
|
||||
onmessage = handleMessage;
|
||||
importScripts("newt.js");
|
||||
|
||||
Reference in New Issue
Block a user