diff --git a/es2panda/ir/base/classDefinition.cpp b/es2panda/ir/base/classDefinition.cpp index c34b33f4562b8218595b7fce147bbae0edf11c09..14896cf5f382195cd79d4f8d9393d3600463d9a5 100644 --- a/es2panda/ir/base/classDefinition.cpp +++ b/es2panda/ir/base/classDefinition.cpp @@ -161,6 +161,11 @@ int32_t ClassDefinition::CreateClassStaticProperties(compiler::PandaGen *pg, uti continue; } + if (prop->IsOptional() && prop->Value()->Function()->IsOverload()) { + compiled.Set(i); + continue; + } + util::StringView name = util::Helpers::LiteralToPropName(prop->Key()); compiler::LiteralBuffer *literalBuf = prop->IsStatic() ? &staticBuf : buf; auto &nameMap = prop->IsStatic() ? staticPropNameMap : propNameMap; @@ -237,6 +242,10 @@ void ClassDefinition::CompileMissingProperties(compiler::PandaGen *pg, const uti } const ir::MethodDefinition *prop = properties[i]->AsMethodDefinition(); + if (prop->IsOptional() && prop->Value()->Function()->IsOverload()) { + continue; + } + compiler::VReg dest = prop->IsStatic() ? classReg : protoReg; compiler::RegScope rs(pg); diff --git a/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-20-expected.txt b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-20-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..fe1e163da1becf8bd44ece0f35a201822bc568fb --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-20-expected.txt @@ -0,0 +1,2 @@ +A +Hello diff --git a/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-20.ts b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-20.ts new file mode 100644 index 0000000000000000000000000000000000000000..de37a7f103ae2a23a9277b3fb07aa6b43522805a --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-20.ts @@ -0,0 +1,30 @@ +/* + * 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. + */ + + +class A { + funcA(p: number): void; + funcA(p: any): void { + print("A"); + } +} + +class B { + funcC?(p: number): void; +} + +var a = new A(); +a.funcA(0); +print("Hello"); diff --git a/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-21-expected.txt b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-21-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0cfbf08886fca9a91cb753ec8734c84fcbe52c9f --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-21-expected.txt @@ -0,0 +1 @@ +2 diff --git a/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-21.ts b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-21.ts new file mode 100644 index 0000000000000000000000000000000000000000..43306101c1943f1d45ef5fe5358ac3eecc0a3f24 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-21.ts @@ -0,0 +1,37 @@ +/* + * 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. + */ + + +class B { + a: number = 1; + b?: string; + c(): any { return 2; }; + d?(): string; + get x() { + return false; + } + set x(v: boolean) { + } + e?: number; + f?(): number; +} + +var b = new B(); + +if (b.e) { + print(b.a) +} else { + print(b.c()) +}