feat: allow to invoke compiler with variable encapsulation enabled

This commit is contained in:
TopchetoEU 2024-12-10 00:44:18 +02:00
parent 138baebacb
commit 814e0d7b7e
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
2 changed files with 7 additions and 7 deletions

View File

@ -253,21 +253,21 @@ public final class JavaScript {
return !JavaScript.reserved.contains(name);
}
public static CompileResult compile(Environment env, Node ...statements) {
public static CompileResult compile(Environment env, boolean passthrough, Node ...statements) {
env = env.child();
env.add(COMPILE_ROOT, env);
var func = new FunctionValueNode(null, null, Arrays.asList(), new CompoundNode(null, statements), null);
var res = func.compileBody(env, new FunctionScope(true), true, null);
var res = func.compileBody(env, new FunctionScope(passthrough), true, null);
return res;
}
public static CompileResult compile(Environment env, Filename filename, String raw) {
return JavaScript.compile(env, JavaScript.parse(env, filename, raw));
public static CompileResult compile(Environment env, Filename filename, String raw, boolean passthrough) {
return JavaScript.compile(env, passthrough, JavaScript.parse(env, filename, raw));
}
public static CompileResult compile(Filename filename, String raw) {
public static CompileResult compile(Filename filename, String raw, boolean passthrough) {
var env = new Environment();
return JavaScript.compile(env, JavaScript.parse(env, filename, raw));
return JavaScript.compile(env, passthrough, JavaScript.parse(env, filename, raw));
}
public static ParseRes<String> parseLabel(Source src, int i) {

View File

@ -15,7 +15,7 @@ import me.topchetoeu.jscript.runtime.values.functions.CodeFunction;
public interface Compiler {
public static final Compiler DEFAULT = (env, filename, raw) -> {
try {
var res = JavaScript.compile(env, filename, raw);
var res = JavaScript.compile(env, filename, raw, true);
var body = res.body();
DebugContext.get(env).onSource(filename, raw);
registerFunc(env, body, res);