From ec914747176bb6441d0551608ff6973ce550d702 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Tue, 28 Jun 2022 14:32:01 +0800 Subject: [PATCH] Fix incorrect column number of CallExpression Fix incorrect column number of CallExpression when callee is MemberAccessExpression Signed-off-by: ctw-ian Change-Id: I46ec7d50fa191cb2cb7d25e3fd5b04d00eb7ee48 --- ts2panda/src/expression/callExpression.ts | 21 ++++++++++++++++++--- ts2panda/tests/scope.test.ts | 13 +++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ts2panda/src/expression/callExpression.ts b/ts2panda/src/expression/callExpression.ts index 837b1126a0..03347cc8fe 100644 --- a/ts2panda/src/expression/callExpression.ts +++ b/ts2panda/src/expression/callExpression.ts @@ -109,17 +109,32 @@ function emitCallArguments(compiler: Compiler, expr: ts.CallExpression, args: VR export function emitCall(expr: ts.CallExpression, args: VReg[], passThis: boolean, compiler: Compiler) { let pandaGen = compiler.getPandaGen(); let hasSpread = emitCallArguments(compiler, expr, args); + let callee = expr.expression; + let debugNode = undefined; + switch (callee.kind) { + case ts.SyntaxKind.ElementAccessExpression: { + debugNode = (callee).argumentExpression; + break; + } + case ts.SyntaxKind.PropertyAccessExpression: { + debugNode = (callee).name; + break; + } + default: { + debugNode = expr; + } + } if (!hasSpread) { - pandaGen.call(expr, [...args], passThis); + pandaGen.call(debugNode, [...args], passThis); return; } // spread argument exist - let callee = args[0]; + let calleeReg = args[0]; let thisReg = passThis ? args[1] : getVregisterCache(pandaGen, CacheList.undefined); let argArray = pandaGen.getTemp(); createArrayFromElements(expr, compiler, >expr.arguments, argArray); - pandaGen.callSpread(expr, callee, thisReg, argArray); + pandaGen.callSpread(debugNode, calleeReg, thisReg, argArray); pandaGen.freeTemps(argArray); } \ No newline at end of file diff --git a/ts2panda/tests/scope.test.ts b/ts2panda/tests/scope.test.ts index 85ef72aa12..077c531211 100644 --- a/ts2panda/tests/scope.test.ts +++ b/ts2panda/tests/scope.test.ts @@ -126,18 +126,15 @@ describe("ScopeTest", function () { }); it("test add 'none' variable to LocalScope", function () { - let parent = new FunctionScope(); + let parent = new GlobalScope(); let scope = new LocalScope(parent); let variable = scope.add("x", VarDeclarationKind.NONE); - expect(variable).to.be.equal(undefined); + expect(variable instanceof GlobalVariable).to.be.true; let { scope: sp, level: lv, v: outVariable } = scope.find("x"); - expect(outVariable).to.be.equal(undefined); - expect(lv).to.be.equal(0); - expect(sp).to.be.equal(undefined); + expect(outVariable === variable).to.be.true; let { scope: spParent, level: lvParent, v: outVariableParent } = parent.find("x"); - expect(outVariableParent).to.be.equal(undefined); - expect(lvParent).to.be.equal(0); - expect(spParent).to.be.equal(undefined); + expect(outVariableParent === variable).to.be.true; + expect(spParent instanceof GlobalScope).to.be.true; }); it("test add 'var' variable to LocalScope", function () { -- Gitee