Browse Source

Fixed dynamic variable resolution when a parent lexical binding exists

Dmitry Panov 4 years ago
parent
commit
8f81471d5d
2 changed files with 19 additions and 0 deletions
  1. 2 0
      compiler.go
  2. 17 0
      compiler_test.go

+ 2 - 0
compiler.go

@@ -476,6 +476,8 @@ func (s *scope) finaliseVarAlloc(stackOffset int) (stashSize, stackSize int) {
 						*ap = initStash(idx)
 					case *loadMixed:
 						i.idx = idx
+					case *loadMixedLex:
+						i.idx = idx
 					case *resolveMixed:
 						i.idx = idx
 					}

+ 17 - 0
compiler_test.go

@@ -3462,6 +3462,23 @@ func TestArgAccessFromDynamicStash(t *testing.T) {
 	testScript1(SCRIPT, valueTrue, t)
 }
 
+func TestLoadMixedLex(t *testing.T) {
+	const SCRIPT = `
+	function f() {
+		let a = 1;
+		{
+			function inner() {
+				eval("var a = true");
+				return a;
+			}
+			return inner();
+		}
+	}
+	f();
+	`
+	testScript1(SCRIPT, valueTrue, t)
+}
+
 /*
 func TestBabel(t *testing.T) {
 	src, err := ioutil.ReadFile("babel7.js")