From 5791befea0c2436221b6e9c4e0440789fdee3d44 Mon Sep 17 00:00:00 2001 From: dongchao Date: Wed, 30 Jul 2025 17:28:37 +0800 Subject: [PATCH] Fix declgen bugs Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICPV5N Signed-off-by: dongchao Change-Id: I7dc6648ba468adbb4d565a4d8f7b5180e9e828de --- ets2panda/declgen_ets2ts/declgenEts2Ts.cpp | 27 ++++++++++++------- .../build_system/src/build/base_mode.ts | 2 +- .../build_system/src/build/declgen_worker.ts | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index 40b69aa39d..e685df218f 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -334,11 +334,7 @@ void TSDeclGen::AddSuperType(const ir::Expression *super) if (super->TsType() == nullptr) { return; } - const auto superType = checker::ETSChecker::ETSType(super->TsType()); - if (superType == checker::TypeFlag::ETS_OBJECT) { - auto objectType = super->TsType()->AsETSObjectType(); - AddObjectDependencies(objectType->Name()); - } + AddSuperType(super->TsType()); } void TSDeclGen::AddSuperType(const checker::Type *tsType) @@ -347,6 +343,11 @@ void TSDeclGen::AddSuperType(const checker::Type *tsType) if (superType == checker::TypeFlag::ETS_OBJECT) { auto objectType = tsType->AsETSObjectType(); AddObjectDependencies(objectType->Name()); + } else if (superType == checker::TypeFlag::ETS_UNION) { + auto unionType = tsType->AsETSUnionType(); + std::vector filteredTypes = FilterUnionTypes(unionType->ConstituentTypes()); + GenSeparated( + filteredTypes, [this](checker::Type *type) { AddSuperType(type); }, ""); } } @@ -414,7 +415,10 @@ void TSDeclGen::GenImportDeclarations() void TSDeclGen::GenImportRecordDeclarations(const std::string &source) { - OutDts("import type { Record } from \"", source, "\";\n"); + const std::string recordKey = "Record"; + if (indirectDependencyObjects_.find(recordKey) != indirectDependencyObjects_.end()) { + OutDts("import type { Record } from \"", source, "\";\n"); + } } template @@ -573,6 +577,8 @@ bool TSDeclGen::HandleObjectType(const checker::Type *checkerType) OutDts("number"); } else if (typeStr == "BigInt") { OutDts("bigint"); + } else if (typeStr == "ESValue") { + OutDts("ESObject"); } else { GenObjectType(checkerType->AsETSObjectType()); } @@ -2005,7 +2011,7 @@ void TSDeclGen::GenPartName(std::string &partName) partName = "string"; } else if (numberTypes_.count(partName) != 0U) { partName = "number"; - } else if (partName == "ESObject") { + } else if (partName == "ESValue") { partName = "ESObject"; } else if (partName == "BigInt") { partName = "bigint"; @@ -2241,6 +2247,9 @@ bool TSDeclGen::ShouldSkipMethodDeclaration(const ir::MethodDefinition *methodDe void TSDeclGen::EmitMethodGlueCode(const std::string &methodName, const ir::Identifier *methodIdentifier) { + if (!state_.inGlobalClass && (!state_.inNamespace || state_.isClassInNamespace || state_.isInterfaceInNamespace)) { + return; + } if (!ShouldEmitDeclarationSymbol(methodIdentifier)) { return; } @@ -2474,9 +2483,7 @@ void TSDeclGen::GenPropAccessor(const ir::ClassProperty *classProp, const std::s OutDts(accessorKind, propName, accessorKind == "set " ? "(value: " : "(): "); auto typeAnnotation = classProp->TypeAnnotation(); auto tsType = classProp->TsType(); - if (tsType != nullptr && tsType->IsETSTypeParameter()) { - OutDts("ESObject"); - } else if (typeAnnotation != nullptr) { + if (typeAnnotation != nullptr) { ProcessTypeAnnotationType(typeAnnotation, tsType); } else { GenType(tsType); diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index 86e78db7b9..88ffef40cd 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -181,7 +181,7 @@ export abstract class BaseMode { ) const declEtsOutputDir = path.dirname(declEtsOutputPath); const staticRecordRelativePath = changeFileExtension( - path.relative(declEtsOutputDir, staticRecordPath).replaceAll(/\\/g, '\/'), + path.relative(declEtsOutputDir, staticRecordPath).replace(/\\/g, '\/'), "", DECL_TS_SUFFIX ); diff --git a/ets2panda/driver/build_system/src/build/declgen_worker.ts b/ets2panda/driver/build_system/src/build/declgen_worker.ts index f2b402035d..6ed77c0556 100644 --- a/ets2panda/driver/build_system/src/build/declgen_worker.ts +++ b/ets2panda/driver/build_system/src/build/declgen_worker.ts @@ -72,7 +72,7 @@ process.on('message', async (message: { const staticRecordPath = path.join(moduleInfo.declgenV1OutPath!, STATIC_RECORD_FILE); const declEtsOutputDir = path.dirname(declEtsOutputPath); const staticRecordRelativePath = changeFileExtension( - path.relative(declEtsOutputDir, staticRecordPath).replaceAll(/\\/g, '/'), + path.relative(declEtsOutputDir, staticRecordPath).replace(/\\/g, '/'), '', DECL_TS_SUFFIX ); -- Gitee