diff --git a/src/main/java/me/topchetoeu/jscript/compilation/CompoundNode.java b/src/main/java/me/topchetoeu/jscript/compilation/CompoundNode.java index 958b825..9d8bd93 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/CompoundNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/CompoundNode.java @@ -13,7 +13,7 @@ import me.topchetoeu.jscript.common.parsing.Source; public class CompoundNode extends Node { public final Node[] statements; - public final boolean hasScope; + public boolean hasScope; public Location end; @Override public void resolve(CompileResult target) { diff --git a/src/main/java/me/topchetoeu/jscript/compilation/FunctionNode.java b/src/main/java/me/topchetoeu/jscript/compilation/FunctionNode.java index f0ade70..9c369b8 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/FunctionNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/FunctionNode.java @@ -107,6 +107,7 @@ public abstract class FunctionNode extends Node { this.end = end; this.params = params; this.body = body; + this.body.hasScope = false; } public static void compileWithName(Node stm, CompileResult target, boolean pollute, String name) { diff --git a/src/main/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java b/src/main/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java index e935be3..5daf8aa 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/scope/FunctionScope.java @@ -19,6 +19,13 @@ public class FunctionScope extends Scope { public final boolean passtrough; + @Override public boolean hasNonStrict(String name) { + if (functionVarMap.containsKey(name)) return true; + if (blacklistNames.contains(name)) return true; + + return false; + } + @Override public Variable define(Variable var, Location loc) { checkNotEnded(); if (strictVarMap.containsKey(var.name)) throw alreadyDefinedErr(loc, var.name); @@ -32,13 +39,6 @@ public class FunctionScope extends Scope { return variables.add(var); } } - @Override public Variable defineStrict(Variable var, Location loc) { - checkNotEnded(); - if (functionVarMap.containsKey(var.name)) throw alreadyDefinedErr(loc, var.name); - if (blacklistNames.contains(var.name)) throw alreadyDefinedErr(loc, var.name); - - return super.defineStrict(var, loc); - } public Variable defineSpecial(Variable var, Location loc) { checkNotEnded(); if (strictVarMap.containsKey(var.name)) throw alreadyDefinedErr(loc, var.name); diff --git a/src/main/java/me/topchetoeu/jscript/compilation/scope/Scope.java b/src/main/java/me/topchetoeu/jscript/compilation/scope/Scope.java index 206e990..3e210f7 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/scope/Scope.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/scope/Scope.java @@ -86,6 +86,11 @@ public class Scope { return null; } + /** + * Checks if this scope's function parent has a non-strict variable of the given name + */ + public boolean hasNonStrict(String name) { return false; } + /** * Defines an ES2015-style variable * @param readonly True if const, false if let @@ -96,6 +101,7 @@ public class Scope { public Variable defineStrict(Variable var, Location loc) { checkNotEnded(); if (strictVarMap.containsKey(var.name)) throw alreadyDefinedErr(loc, var.name); + if (hasNonStrict(var.name)) throw alreadyDefinedErr(loc, var.name); strictVarMap.put(var.name, var); return variables.add(var);