From d5515afbeb9c22aab20289379b290535a5c6d7f7 Mon Sep 17 00:00:00 2001 From: Gavin1012 Date: Thu, 28 Apr 2022 19:30:11 +0800 Subject: [PATCH] fix this keyword in IDE watch Signed-off-by: Gavin1012 Change-Id: I3e392d8e0cf5855ff865d14bc97e42154b9ad31b --- ts2panda/src/compiler.ts | 3 ++- .../tests/watch_expression/addWatch.test.ts | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 438ba4940b..910b43123c 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 189272f5a8..7eacad422c 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 () { -- Gitee