diff --git a/es2panda/ir/expressions/callExpression.cpp b/es2panda/ir/expressions/callExpression.cpp index 3c83bbc32eeccdc82008f5e820f11a02887b3df3..2230541625f4ea0712bcaeec5d52fa777b52e716 100644 --- a/es2panda/ir/expressions/callExpression.cpp +++ b/es2panda/ir/expressions/callExpression.cpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include namespace panda::es2panda::ir { @@ -61,8 +64,19 @@ compiler::VReg CallExpression::CreateSpreadArguments(compiler::PandaGen *pg) con void CallExpression::Compile(compiler::PandaGen *pg) const { - if (callee_->IsCallExpression() || callee_->IsNewExpression()) { - if (pg->TryCompileFunctionCallOrNewExpression(callee_)) { + ir::Expression *realCallee = callee_; + while (realCallee->IsTSNonNullExpression() || realCallee->IsTSAsExpression() || realCallee->IsTSTypeAssertion()) { + if (realCallee->IsTSNonNullExpression()) { + realCallee = realCallee->AsTSNonNullExpression()->Expr(); + } else if (realCallee->IsTSAsExpression()) { + realCallee = realCallee->AsTSAsExpression()->Expr(); + } else if (realCallee->IsTSTypeAssertion()) { + realCallee = realCallee->AsTSTypeAssertion()->GetExpression(); + } + } + + if (realCallee->IsCallExpression() || realCallee->IsNewExpression()) { + if (pg->TryCompileFunctionCallOrNewExpression(realCallee)) { return; } } @@ -113,17 +127,17 @@ void CallExpression::Compile(compiler::PandaGen *pg) const bool hasThis = false; compiler::VReg thisReg {}; - if (callee_->IsMemberExpression()) { + if (realCallee->IsMemberExpression()) { hasThis = true; thisReg = pg->AllocReg(); compiler::RegScope mrs(pg); - callee_->AsMemberExpression()->Compile(pg, thisReg); - } else if (callee_->IsChainExpression()) { + realCallee->AsMemberExpression()->Compile(pg, thisReg); + } else if (realCallee->IsChainExpression()) { hasThis = true; - callee_->AsChainExpression()->Compile(pg); + realCallee->AsChainExpression()->Compile(pg); } else { - callee_->Compile(pg); + realCallee->Compile(pg); } pg->StoreAccumulator(this, callee); diff --git a/es2panda/ir/ts/tsNonNullExpression.h b/es2panda/ir/ts/tsNonNullExpression.h index 5d0e858c8379986c2d5f7ec72e2361edaead29ae..a44c9f8b9df3023dc7f6139b0fa10f5810e0c2df 100644 --- a/es2panda/ir/ts/tsNonNullExpression.h +++ b/es2panda/ir/ts/tsNonNullExpression.h @@ -38,6 +38,11 @@ public: return expr_; } + Expression *Expr() + { + return expr_; + } + void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0cfbf08886fca9a91cb753ec8734c84fcbe52c9f --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-1-expected.txt @@ -0,0 +1 @@ +2 diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-1.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-1.ts new file mode 100644 index 0000000000000000000000000000000000000000..abb689feb3514d0f007528cb3e073cebb94e94d9 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-1.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +const deserializeTag = Symbol('[[Deserialize]]'); + +class A { + public propA: number = 1; + public [deserializeTag]() { + this.propA = 2; + } +} + +var a = new A(); +(a[deserializeTag] as any)(); +print(a.propA); diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-2-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0cfbf08886fca9a91cb753ec8734c84fcbe52c9f --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-2-expected.txt @@ -0,0 +1 @@ +2 diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-2.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-2.ts new file mode 100644 index 0000000000000000000000000000000000000000..8c564d2ae61c8135014b376a2b6c25d3f0de74ea --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-2.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +const deserializeTag = Symbol('[[Deserialize]]'); + +class A { + public propA: number = 1; + public [deserializeTag]() { + this.propA = 2; + } +} + +var a = new A(); +((a[deserializeTag]))(); +print(a.propA); diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-3-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0cfbf08886fca9a91cb753ec8734c84fcbe52c9f --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-3-expected.txt @@ -0,0 +1 @@ +2 diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-3.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-3.ts new file mode 100644 index 0000000000000000000000000000000000000000..870cd356460b4cc2447df9a5e2a8a146b48be5a8 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-call-expression-3.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +const deserializeTag = Symbol('[[Deserialize]]'); + +class A { + public propA: number = 1; + public [deserializeTag]() { + this.propA = 2; + } +} + +var a = new A(); +(a[deserializeTag] as any)!(); +print(a.propA); diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-2-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0cfbf08886fca9a91cb753ec8734c84fcbe52c9f --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-2-expected.txt @@ -0,0 +1 @@ +2 diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-2.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-2.ts new file mode 100644 index 0000000000000000000000000000000000000000..0b067ef5d32ff1fd4a04c72b9e5588c15535f927 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-2.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + + +const deserializeTag = Symbol('[[Deserialize]]'); + +class A { + public propA: number = 1; + public [deserializeTag]() { + this.propA = 2; + } +} + +var a = new A(); +a[deserializeTag]!(); +print(a.propA);