diff --git a/ts2panda/src/expression/callExpression.ts b/ts2panda/src/expression/callExpression.ts index 837b1126a0813d8b5e2a36fc288fd4d75d2a99bc..03347cc8fe28246e766ab842ff14f3c304cf7cc1 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 85ef72aa12f4d374754159f3b406c591619b7950..077c531211909ca134e4d4e269b038681f2040a3 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 () {