From 93865cb5c4624c5da777c80858a570b4a9647080 Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Fri, 23 Sep 2022 20:58:57 +0800 Subject: [PATCH] Enable emit type assertion in es2abc Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5U2QX Test: test262, parser tests, compiler tests Signed-off-by: xucheng46 Change-Id: Ica5a52d3f8a9aa1d247d9f9164100e3b91914248 --- es2panda/ir/ts/tsAsExpression.cpp | 5 ++++- es2panda/ir/ts/tsAsExpression.h | 2 +- es2panda/ir/ts/tsTypeAssertion.cpp | 5 ++++- es2panda/ir/ts/tsTypeAssertion.h | 2 +- .../ts-test-as-expression-1-expected.txt | 2 ++ .../expressions/ts-test-as-expression-1.ts | 18 ++++++++++++++++++ .../ts-test-type-assertions-1-expected.txt | 2 ++ .../expressions/ts-test-type-assertions-1.ts | 18 ++++++++++++++++++ 8 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-as-expression-1-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-as-expression-1.ts create mode 100644 es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-type-assertions-1-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-type-assertions-1.ts diff --git a/es2panda/ir/ts/tsAsExpression.cpp b/es2panda/ir/ts/tsAsExpression.cpp index c67d15b421..f3589c2286 100644 --- a/es2panda/ir/ts/tsAsExpression.cpp +++ b/es2panda/ir/ts/tsAsExpression.cpp @@ -36,7 +36,10 @@ void TSAsExpression::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSAsExpression"}, {"expression", expression_}, {"typeAnnotation", typeAnnotation_}}); } -void TSAsExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSAsExpression::Compile(compiler::PandaGen *pg) const +{ + expression_->Compile(pg); +} static bool IsValidConstAssertionArgument(checker::Checker *checker, const ir::AstNode *arg) { diff --git a/es2panda/ir/ts/tsAsExpression.h b/es2panda/ir/ts/tsAsExpression.h index ceb6fc2fd1..10a18df7d8 100644 --- a/es2panda/ir/ts/tsAsExpression.h +++ b/es2panda/ir/ts/tsAsExpression.h @@ -57,7 +57,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(checker::Checker *checker) const override; void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; diff --git a/es2panda/ir/ts/tsTypeAssertion.cpp b/es2panda/ir/ts/tsTypeAssertion.cpp index cc09c20103..2b20a6e915 100644 --- a/es2panda/ir/ts/tsTypeAssertion.cpp +++ b/es2panda/ir/ts/tsTypeAssertion.cpp @@ -30,7 +30,10 @@ void TSTypeAssertion::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSTypeAssertion"}, {"typeAnnotation", typeAnnotation_}, {"expression", expression_}}); } -void TSTypeAssertion::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSTypeAssertion::Compile(compiler::PandaGen *pg) const +{ + expression_->Compile(pg); +} checker::Type *TSTypeAssertion::Check([[maybe_unused]] checker::Checker *checker) const { diff --git a/es2panda/ir/ts/tsTypeAssertion.h b/es2panda/ir/ts/tsTypeAssertion.h index afc8ced7fb..583af00c28 100644 --- a/es2panda/ir/ts/tsTypeAssertion.h +++ b/es2panda/ir/ts/tsTypeAssertion.h @@ -48,7 +48,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-as-expression-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-as-expression-1-expected.txt new file mode 100644 index 0000000000..3fb63f8f28 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-as-expression-1-expected.txt @@ -0,0 +1,2 @@ +1 +ts-test-as-expression-1 diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-as-expression-1.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-as-expression-1.ts new file mode 100644 index 0000000000..f74d146f76 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-as-expression-1.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + + +print(1 as number); +print("ts-test-as-expression-1" as string); \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-type-assertions-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-type-assertions-1-expected.txt new file mode 100644 index 0000000000..5a303be25c --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-type-assertions-1-expected.txt @@ -0,0 +1,2 @@ +1 +ts-test-type-assertions-1 diff --git a/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-type-assertions-1.ts b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-type-assertions-1.ts new file mode 100644 index 0000000000..03c54de422 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/expressions/ts-test-type-assertions-1.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + + +print(1); +print("ts-test-type-assertions-1"); \ No newline at end of file -- Gitee