diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 384613c49ebef2a49fe4544adc6375c06537f8b1..132ee56efee06fd942496ed58a752d73fcd4d60c 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -1020,7 +1020,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 77edbd03078639be9b17e9c18aecf4b3a1ac4355..05257ebe16d6645ed257643201ec3133f7b2a653 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 () {