From 9260bfce9606ff909ce44067dae1213ba9f2deed Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Fri, 23 Sep 2022 21:06:02 +0800 Subject: [PATCH] Enable non-null expression in es2abc Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5U2RF Test: test262, parser tests, compiler tests Signed-off-by: xucheng46 Change-Id: Icba218d483b46422c466b9bcb7e4f57c14fbed71 --- es2panda/ir/ts/tsNonNullExpression.cpp | 5 ++++- es2panda/ir/ts/tsNonNullExpression.h | 2 +- ...ts-test-non-null-expression-1-expected.txt | 1 + .../ts-test-non-null-expression-1.ts | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-1-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-1.ts diff --git a/es2panda/ir/ts/tsNonNullExpression.cpp b/es2panda/ir/ts/tsNonNullExpression.cpp index 06f51f77c7..e43b52db35 100644 --- a/es2panda/ir/ts/tsNonNullExpression.cpp +++ b/es2panda/ir/ts/tsNonNullExpression.cpp @@ -29,7 +29,10 @@ void TSNonNullExpression::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSNonNullExpression"}, {"expression", expr_}}); } -void TSNonNullExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSNonNullExpression::Compile(compiler::PandaGen *pg) const +{ + expr_->Compile(pg); +} checker::Type *TSNonNullExpression::Check([[maybe_unused]] checker::Checker *checker) const { diff --git a/es2panda/ir/ts/tsNonNullExpression.h b/es2panda/ir/ts/tsNonNullExpression.h index 9f278f49f7..5d0e858c83 100644 --- a/es2panda/ir/ts/tsNonNullExpression.h +++ b/es2panda/ir/ts/tsNonNullExpression.h @@ -40,7 +40,7 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-1-expected.txt new file mode 100644 index 0000000000..86f1793aff --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-1-expected.txt @@ -0,0 +1 @@ +ts-test-non-null-expression-1 diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-1.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-1.ts new file mode 100644 index 0000000000..f239bef2d8 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-non-null-expression-1.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 C { + a : string = "ts-test-non-null-expression-1"; +} +var x : C = new C(); +print(x!.a) \ No newline at end of file -- Gitee