feat: allow to invoke compiler with variable encapsulation enabled
This commit is contained in:
parent
138baebacb
commit
814e0d7b7e
@ -253,21 +253,21 @@ public final class JavaScript {
|
|||||||
return !JavaScript.reserved.contains(name);
|
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 = env.child();
|
||||||
env.add(COMPILE_ROOT, env);
|
env.add(COMPILE_ROOT, env);
|
||||||
|
|
||||||
var func = new FunctionValueNode(null, null, Arrays.asList(), new CompoundNode(null, statements), null);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompileResult compile(Environment env, Filename filename, String raw) {
|
public static CompileResult compile(Environment env, Filename filename, String raw, boolean passthrough) {
|
||||||
return JavaScript.compile(env, JavaScript.parse(env, filename, raw));
|
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();
|
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) {
|
public static ParseRes<String> parseLabel(Source src, int i) {
|
||||||
|
@ -15,7 +15,7 @@ import me.topchetoeu.jscript.runtime.values.functions.CodeFunction;
|
|||||||
public interface Compiler {
|
public interface Compiler {
|
||||||
public static final Compiler DEFAULT = (env, filename, raw) -> {
|
public static final Compiler DEFAULT = (env, filename, raw) -> {
|
||||||
try {
|
try {
|
||||||
var res = JavaScript.compile(env, filename, raw);
|
var res = JavaScript.compile(env, filename, raw, true);
|
||||||
var body = res.body();
|
var body = res.body();
|
||||||
DebugContext.get(env).onSource(filename, raw);
|
DebugContext.get(env).onSource(filename, raw);
|
||||||
registerFunc(env, body, res);
|
registerFunc(env, body, res);
|
||||||
|
Loading…
Reference in New Issue
Block a user