diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 535a1adc4054046cf7763dad920e3ad694939845..a8c5d64119f02f277793c694162dcd3010481be1 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -18,6 +18,7 @@ #include "checker/ETSchecker.h" #include "checker/types/globalTypesHolder.h" +#include "checker/types/gradualType.h" #include "checker/checkerContext.h" #include "checker/ETSAnalyzerHelpers.h" #include "checker/types/ets/etsEnumType.h" @@ -1706,6 +1707,26 @@ std::pair FindSpecifierForModuleObject(ir::ETSImportDecl return std::make_pair(false, util::StringView()); } +static void BuildExportedFunctionSignature(ETSChecker *checker, varbinder::Variable *var) +{ + auto method = var->AsLocalVariable()->Declaration()->Node()->AsMethodDefinition(); + ES2PANDA_ASSERT(method->Parent()->IsClassDefinition() && + method->Parent()->AsClassDefinition()->Ident()->Name().Is(compiler::Signatures::ETS_GLOBAL)); + auto classDef = method->Parent()->AsClassDefinition(); + if (classDef->TsType() == nullptr) { + checker->BuildBasicClassProperties(classDef); + } + + auto containingClass = classDef->TsType()->IsGradualType() + ? classDef->TsType()->AsGradualType()->GetBaseType()->AsETSObjectType() + : classDef->TsType()->AsETSObjectType(); + SavedCheckerContext scc(checker, checker->Context().Status(), containingClass); + auto funcType = checker->BuildMethodSignature(method); + funcType->SetVariable(var); + var->SetTsType(funcType); + method->SetTsType(funcType); +} + template void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleObjType, ir::ETSImportDeclaration *importDecl, @@ -1721,6 +1742,10 @@ void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleO if ((var->AsLocalVariable()->Declaration()->Node()->IsExported() || var->AsLocalVariable()->Declaration()->Node()->HasExportAlias()) && found) { + if (var->AsLocalVariable()->Declaration()->Node()->IsMethodDefinition()) { + BuildExportedFunctionSignature(this, var); + } + if (!aliasedName.Empty()) { moduleObjType->AddReExportAlias(var->Declaration()->Name(), aliasedName); } diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index 578de8289a33d633ada9a85afce0f426b3942fcf..4294c512eeb8e469a66935cf1f0e9423ad7404ec 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -47,7 +47,8 @@ import { createFileIfNotExists, ensurePathExists, getFileHash, - isMac + isMac, + isMixCompileProject } from '../utils'; import { PluginDriver, @@ -151,7 +152,11 @@ export abstract class BaseMode { this.isBuildConfigModified = buildConfig.isBuildConfigModified as boolean | undefined; this.hasCleanWorker = false; this.byteCodeHar = buildConfig.byteCodeHar as boolean; - this.es2pandaMode = buildConfig?.es2pandaMode ?? ES2PANDA_MODE.RUN_PARALLEL; + this.es2pandaMode = buildConfig?.es2pandaMode ?? ( + isMixCompileProject(buildConfig) + ? ES2PANDA_MODE.RUN_PARALLEL + : ES2PANDA_MODE.RUN + ); this.skipDeclCheck = buildConfig?.skipDeclCheck as boolean ?? true; } diff --git a/ets2panda/driver/build_system/src/utils.ts b/ets2panda/driver/build_system/src/utils.ts index e3a7a2bc37bded3628572266173df97059b5cb17..d80cf572d630498c6b427627a25e1b4bbd9373f4 100644 --- a/ets2panda/driver/build_system/src/utils.ts +++ b/ets2panda/driver/build_system/src/utils.ts @@ -21,6 +21,7 @@ import * as path from 'path'; import { ARKTS_MODULE_NAME, DECL_ETS_SUFFIX, + LANGUAGE_VERSION, NATIVE_MODULE, sdkConfigPrefix } from './pre_define'; @@ -30,7 +31,7 @@ import { LogDataFactory } from './logger'; import { ErrorCode } from './error_code'; -import { ModuleInfo, OHOS_MODULE_TYPE } from './types'; +import { BuildConfig, ModuleInfo, OHOS_MODULE_TYPE } from './types'; const WINDOWS: string = 'Windows_NT'; const LINUX: string = 'Linux'; @@ -201,3 +202,15 @@ export function createFileIfNotExists(filePath: string, content: string): boolea return false; } } + +export function isMixCompileProject(buildConfig: BuildConfig): boolean { + for (const moduleInfo of buildConfig.dependentModuleList) { + if ( + moduleInfo.language === LANGUAGE_VERSION.ARKTS_1_1 || + moduleInfo.language === LANGUAGE_VERSION.ARKTS_HYBRID + ) { + return true; + } + } + return false; +} \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import1.ets b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import1.ets new file mode 100644 index 0000000000000000000000000000000000000000..00da04ded574c1c7722cc3dc9b8b0c06915f9c40 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import1.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +import * as ns2 from "./namespace_import2" + +export function A() { + return ns2.A() +} + +export let a = 1 \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import2.ets b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import2.ets new file mode 100644 index 0000000000000000000000000000000000000000..07c0f8d1240e845f3ff06f5f43f5e48d3835d009 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_import2.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import * as ns1 from "./namespace_import1" + +export function A() { + return ns1.a; +} \ No newline at end of file