From d92b5f261bad9df715d84d9306eb07ff86d59220 Mon Sep 17 00:00:00 2001 From: songqi Date: Tue, 10 Oct 2023 10:35:31 +0800 Subject: [PATCH] Fix compiler of abstract accessor Donot generate any bytecode of abstract accessor methods Issue: I86PWV Tests: test_es2abc Signed-off-by: songqi Change-Id: I700275359fec100b67a221cb28e00b8ee9e8411a --- es2panda/ir/base/classDefinition.cpp | 4 +++ .../classes/test-ts-classes-25-expected.txt | 2 ++ .../conformance/classes/test-ts-classes-25.ts | 35 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-25-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-25.ts diff --git a/es2panda/ir/base/classDefinition.cpp b/es2panda/ir/base/classDefinition.cpp index 1dcd5c4edd..3a6290291e 100644 --- a/es2panda/ir/base/classDefinition.cpp +++ b/es2panda/ir/base/classDefinition.cpp @@ -246,6 +246,10 @@ void ClassDefinition::CompileMissingProperties(compiler::PandaGen *pg, const uti continue; } + if (prop->IsAbstract()) { + 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-25-expected.txt b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-25-expected.txt new file mode 100644 index 0000000000..680e53d55e --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-25-expected.txt @@ -0,0 +1,2 @@ +derived derived +ok ok diff --git a/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-25.ts b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-25.ts new file mode 100644 index 0000000000..00e2896f42 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/classes/test-ts-classes-25.ts @@ -0,0 +1,35 @@ +/* + * 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. + */ + + +abstract class Base { + abstract name: string; + abstract get Name(); + abstract set Name(value: string); +} + +class Divied extends Base { + name = "derived"; + get Name() { + return 'ok'; + } + set Name(value: string) { + this.name = value; + } +} + +let d = new Divied(); +print(d.name, "derived"); +print(d.Name, "ok"); -- Gitee