[K/JS] Move ES modules logic to a new transformer with IC
This commit is contained in:
@@ -9,6 +9,7 @@ import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
private val LINE_SEPARATOR = System.getProperty("line.separator")!!
|
||||
private val END_MARKER = "<END>$LINE_SEPARATOR"
|
||||
private val ESM_EXTENSION = ".mjs"
|
||||
|
||||
abstract class ProcessBasedScriptEngine(
|
||||
private val executablePath: String
|
||||
@@ -58,6 +59,7 @@ abstract class ProcessBasedScriptEngine(
|
||||
}
|
||||
|
||||
override fun loadFile(path: String) {
|
||||
if (path.endsWith(ESM_EXTENSION)) return
|
||||
eval("load('${path.replace('\\', '/')}');")
|
||||
}
|
||||
|
||||
|
||||
@@ -75,27 +75,31 @@ function restoreGlobalState() {
|
||||
resetRealm();
|
||||
|
||||
// noinspection InfiniteLoopJS
|
||||
while (true) {
|
||||
let code = readline().replace(/\\n/g, '\n');
|
||||
async function loop() {
|
||||
while (true) {
|
||||
let code = readline().replace(/\\n/g, '\n');
|
||||
|
||||
try {
|
||||
switch (code) {
|
||||
case "!reset":
|
||||
resetRealm()
|
||||
break;
|
||||
case "!saveGlobalState":
|
||||
saveGlobalState();
|
||||
break;
|
||||
case "!restoreGlobalState":
|
||||
restoreGlobalState();
|
||||
break;
|
||||
default:
|
||||
print(Realm.eval(currentRealmIndex, code));
|
||||
try {
|
||||
switch (code) {
|
||||
case "!reset":
|
||||
resetRealm()
|
||||
break;
|
||||
case "!saveGlobalState":
|
||||
saveGlobalState();
|
||||
break;
|
||||
case "!restoreGlobalState":
|
||||
restoreGlobalState();
|
||||
break;
|
||||
default:
|
||||
print(await Realm.eval(currentRealmIndex, code));
|
||||
}
|
||||
} catch(e) {
|
||||
printErr(e.stack != null ? e.stack : e.toString());
|
||||
printErr('\nCODE:\n' + code);
|
||||
}
|
||||
} catch(e) {
|
||||
printErr(e.stack != null ? e.stack : e.toString());
|
||||
printErr('\nCODE:\n' + code);
|
||||
}
|
||||
|
||||
print('<END>');
|
||||
print('<END>');
|
||||
}
|
||||
}
|
||||
|
||||
loop()
|
||||
Reference in New Issue
Block a user