diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 0eb85b5cbcd5d02f51c8f515a85640fefc2ea53e..05f4a2d0d7bf351834cef5ac4ae1ee4632958d52 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -1693,7 +1693,8 @@ void PandaGen::LoadExternalModuleVariable(const ir::AstNode *node, const binder: auto index = variable->Index(); if (Context()->IsTypeExtractorEnabled()) { const ir::Identifier *identifier = nullptr; - const ir::AstNode *declareNode = Context()->TypeExtractor()->GetDeclNodeFromIdentifier(node->AsIdentifier(), &identifier); + const ir::AstNode *declareNode = + Context()->TypeExtractor()->GetDeclNodeFromIdentifier(node->AsIdentifier(), &identifier); int64_t typeIndex = Context()->TypeRecorder()->GetNodeTypeIndex(declareNode); if (typeIndex != extractor::TypeRecorder::PRIMITIVETYPE_ANY) { index <= util::Helpers::MAX_INT8 ? ra_.EmitWithType(node, typeIndex, index) : diff --git a/es2panda/ir/expressions/chainExpression.cpp b/es2panda/ir/expressions/chainExpression.cpp index d2656c05ac78ce57eadf7be05652bd865fda59c9..27c0d429879f75f0a9bc05bdc56b36d41e74007f 100644 --- a/es2panda/ir/expressions/chainExpression.cpp +++ b/es2panda/ir/expressions/chainExpression.cpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace panda::es2panda::ir { @@ -39,6 +40,8 @@ void ChainExpression::Compile(compiler::PandaGen *pg) const if (expression_->IsMemberExpression()) { expression_->AsMemberExpression()->Compile(pg); + } else if (expression_->IsTSNonNullExpression()) { + expression_->AsTSNonNullExpression()->Expr()->AsMemberExpression()->Compile(pg); } else { assert(expression_->IsCallExpression()); expression_->AsCallExpression()->Compile(pg); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-non-null-expression-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-non-null-expression-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4c814060532d3f1be03cddb45ce2b96f026c0f2a --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-non-null-expression-expected.txt @@ -0,0 +1 @@ +non-null-test diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-non-null-expression.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-non-null-expression.ts new file mode 100644 index 0000000000000000000000000000000000000000..39fbff0ebd91cd230ac56b18e29f2df51ce511b5 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-non-null-expression.ts @@ -0,0 +1,31 @@ +function parse(page) { + return page; +} + +class Page { + process(context) { + return parse(context?.page!); + } +} + +function getPropertyAccess(obj) { + return obj!.property; +} + +function getElementAccess(arr, index) { + return arr![index]; +} + +function getCall(func, arg) { + func!(arg); +} + +function getCondition(value) { + return value ? value! : "defaultValue"; +} + +function getAsExpr(value) { + return value! as number; +} + +print("non-null-test"); diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 0b9428c5cebba35f6c520d095617fd3a553475b7..b32168bdac5b51b4e18eecbcfeccb2e4f21bd7ce 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -1282,7 +1282,8 @@ class TypeExtractorRunner(Runner): if directory.startswith("testcases_with_assert") or directory.startswith("testcases_with_running"): if (self.ld_library_path == "" or self.ark_aot_compiler == ""): break - test = TypeExtractorWithAOTTest(f, flags, directory.startswith("testcases_with_running"), directory.endswith("projects")) + test = TypeExtractorWithAOTTest(f, flags, directory.startswith("testcases_with_running"), + directory.endswith("projects")) self.tests.append(test) else: test = TypeExtractorTest(f, flags, is_dts_test) diff --git a/es2panda/typescript/extractor/typeSystem.h b/es2panda/typescript/extractor/typeSystem.h index 3c26630935e991b3efb6bf11fba9f8a288f87435..72f369b44c031b0c18bb05739f44a421ff99c7ed 100644 --- a/es2panda/typescript/extractor/typeSystem.h +++ b/es2panda/typescript/extractor/typeSystem.h @@ -572,7 +572,7 @@ private: if (param->IsAssignmentPattern()) { param = param->AsAssignmentPattern()->Left(); } - + // Identifier / SpreadElement / RestElement / ArrayExpression / ObjectExpression auto identifier = extractor_->GetIdentifierFromExpression(param); if (identifier != nullptr) {