From 20a520dd390ddedc8b437c7855de1cf51b50356a Mon Sep 17 00:00:00 2001 From: Gavin1012 Date: Thu, 28 Apr 2022 21:11:33 +0800 Subject: [PATCH] fixed 380301e from https://gitee.com/gavin1012_hw/ark_ts2abc/pulls/220 fix this keyword in IDE watch Signed-off-by: Gavin1012 Change-Id: I77344ff85852ffa5781b1c1c96a8c83476b6b6b5 --- 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 384613c49e..132ee56efe 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 77edbd0307..05257ebe16 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