diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 438ba4940be88ca162694443f01b57208b4b60e6..910b43123c78e91f273b95e332141778aab496ba 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -1002,7 +1002,8 @@ export class Compiler { scope.setLexVar(v, this.scope); } } - pandaGen.loadAccFromLexEnv(node, scope!, level, v); + CmdOptions.isWatchMode() ? pandaGen.loadByNameViaDebugger(node, "this", CacheList.True) + : pandaGen.loadAccFromLexEnv(node, scope!, level, v); } else { throw new Error("\"this\" must be a local variable"); } diff --git a/ts2panda/tests/watch_expression/addWatch.test.ts b/ts2panda/tests/watch_expression/addWatch.test.ts index 189272f5a87e960a1121cbcbf5228538df62bef4..7eacad422c8e907f5a3cd0b631a78cdf3e967afd 100644 --- a/ts2panda/tests/watch_expression/addWatch.test.ts +++ b/ts2panda/tests/watch_expression/addWatch.test.ts @@ -278,17 +278,22 @@ describe("WatchExpressions", function () { }); it("watch ThisKeyword", function () { - let snippetCompiler = new SnippetCompiler(); - snippetCompiler.compile("this"); - let globalScope = snippetCompiler.getGlobalScope(); - let insns = snippetCompiler.getGlobalInsns(); + CmdOptions.parseUserCmd([""]); + CmdOptions.setWatchArgs(['','']); + let insns = compileMainSnippet(` + this + `); let expected = [ - new LdaDyn(new VReg()), + new EcmaLdobjbyname('debuggerGetValue', new VReg()), + new StaDyn(new VReg()), + new LdaStr('this'), + new StaDyn(new VReg()), + new MovDyn(new VReg(), new VReg()), + new EcmaCallargs2dyn(new VReg(), new VReg(), new VReg()), + new ReturnDyn() ]; expect(checkInstructions(insns, expected)).to.be.true; - let thisVar = globalScope!.findLocal("this"); - expect(thisVar instanceof LocalVariable).to.be.true; }); it("watch MetaProperty", function () {