diff --git a/es2panda/ir/expressions/callExpression.cpp b/es2panda/ir/expressions/callExpression.cpp index 0956850bfca8c928745a350df25ba39bc51f39cd..2d3370bb805cf7c0c35644b38058fe33296d8162 100644 --- a/es2panda/ir/expressions/callExpression.cpp +++ b/es2panda/ir/expressions/callExpression.cpp @@ -65,7 +65,7 @@ compiler::VReg CallExpression::CreateSpreadArguments(compiler::PandaGen *pg) con void CallExpression::Compile(compiler::PandaGen *pg) const { - ir::Expression *realCallee = callee_; + const ir::Expression *realCallee = callee_; while (realCallee->IsTSNonNullExpression() || realCallee->IsTSAsExpression() || realCallee->IsTSTypeAssertion()) { if (realCallee->IsTSNonNullExpression()) { realCallee = realCallee->AsTSNonNullExpression()->Expr(); @@ -146,7 +146,7 @@ void CallExpression::Compile(compiler::PandaGen *pg) const compiler::RegScope mrs(pg); realCallee->AsMemberExpression()->Compile(pg, thisReg); } else if (realCallee->IsChainExpression()) { - hasThis = true; + hasThis = realCallee->AsChainExpression()->GetExpression()->IsMemberExpression(); realCallee->AsChainExpression()->Compile(pg); } else { realCallee->Compile(pg); diff --git a/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee-expected.txt b/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee.js b/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee.js new file mode 100644 index 0000000000000000000000000000000000000000..d19c4bafc03b9f9213a76b5086a7d256d910a1e1 --- /dev/null +++ b/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let a = { + A() { + return ()=>{print(1)}; + } +}; + +(a?.A())?.(); \ No newline at end of file