diff --git a/ets2panda/bindings/native/src/bridges.cpp b/ets2panda/bindings/native/src/bridges.cpp index e34e2dbb39086eaa6a4c61981b0c4a72263ba461..5e4c941d47091c03f6a38b6ade0c928f001e4502 100644 --- a/ets2panda/bindings/native/src/bridges.cpp +++ b/ets2panda/bindings/native/src/bridges.cpp @@ -45,14 +45,16 @@ KNativePointer impl_CreateContextFromStringWithHistory(KNativePointer configPtr, TS_INTEROP_3(CreateContextFromStringWithHistory, KNativePointer, KNativePointer, KStringPtr, KStringPtr) KInt impl_GenerateTsDeclarationsFromContext(KNativePointer contextPtr, KStringPtr &outputDeclEts, KStringPtr &outputEts, - KBoolean exportAll, KBoolean isolated, KStringPtr &recordFile) + KBoolean exportAll, KBoolean isolated, KStringPtr &recordFile, + KBoolean genAnnotations) { auto context = reinterpret_cast(contextPtr); return static_cast(GetPublicImpl()->GenerateTsDeclarationsFromContext( - context, outputDeclEts.Data(), outputEts.Data(), exportAll != 0, isolated != 0, recordFile.Data())); + context, outputDeclEts.Data(), outputEts.Data(), exportAll != 0, isolated != 0, recordFile.Data(), + genAnnotations != 0)); } -TS_INTEROP_6(GenerateTsDeclarationsFromContext, KInt, KNativePointer, KStringPtr, KStringPtr, KBoolean, KBoolean, - KStringPtr) +TS_INTEROP_7(GenerateTsDeclarationsFromContext, KInt, KNativePointer, KStringPtr, KStringPtr, KBoolean, KBoolean, + KStringPtr, KBoolean) KNativePointer impl_CreateContextFromFile(KNativePointer configPtr, KStringPtr &filenamePtr) { diff --git a/ets2panda/bindings/src/common/Es2pandaNativeModule.ts b/ets2panda/bindings/src/common/Es2pandaNativeModule.ts index b1f2d4da0db209e805cb9202cd75753077b930a2..269b7917d9608d54ac1bfc66186a658b2ba48e7d 100644 --- a/ets2panda/bindings/src/common/Es2pandaNativeModule.ts +++ b/ets2panda/bindings/src/common/Es2pandaNativeModule.ts @@ -83,7 +83,8 @@ export class Es2pandaNativeModule { outputEts: String, exportAll: KBoolean, isolated: KBoolean, - recordFile: String + recordFile: String, + genAnnotations: KBoolean ): KPtr { throw new Error('Not implemented'); } diff --git a/ets2panda/bindings/src/common/driver_helper.ts b/ets2panda/bindings/src/common/driver_helper.ts index 0f3b97b9435a633f6f3031ae098467dde97d543e..73d9d97fb39b18211ae0cb81620204c130d077ed 100644 --- a/ets2panda/bindings/src/common/driver_helper.ts +++ b/ets2panda/bindings/src/common/driver_helper.ts @@ -82,17 +82,20 @@ export class DriverHelper { etsOutPath: string, exportAll: boolean, isolated: boolean, - recordFile: string + recordFile: string, + genAnnotations: boolean ): void { let exportAll_: KBoolean = exportAll ? 1 : 0; let isolated_: KBoolean = isolated ? 1 : 0; + let genAnnotations_: KBoolean = genAnnotations ? 1 : 0; global.es2panda._GenerateTsDeclarationsFromContext( this._cfg.peer, declOutPath, etsOutPath, exportAll_, isolated_, - recordFile + recordFile, + genAnnotations_ ); } } diff --git a/ets2panda/bindings/src/lsp/lsp_helper.ts b/ets2panda/bindings/src/lsp/lsp_helper.ts index 44d91ac0e13d05755d85531bb4b6a506089a6226..99a4f26f2eeed2accaef9cc41d392cd914deeeac 100644 --- a/ets2panda/bindings/src/lsp/lsp_helper.ts +++ b/ets2panda/bindings/src/lsp/lsp_helper.ts @@ -229,7 +229,7 @@ export class Lsp { this.declFileMap[declEtsOutputPath] = filePath; ensurePathExists(declEtsOutputPath); ensurePathExists(etsOutputPath); - global.es2pandaPublic._GenerateTsDeclarationsFromContext(ctx, declEtsOutputPath, etsOutputPath, 1, 0, ''); + global.es2pandaPublic._GenerateTsDeclarationsFromContext(ctx, declEtsOutputPath, etsOutputPath, 1, 0, '', 1); } finally { this.destroyContext(cfg, ctx); } diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index 30b22ef0bee4629ad088cc018c71c143269f93e2..6318d06191a29757655e7e35b725174c3be01227 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -1123,7 +1123,8 @@ std::string TSDeclGen::RemoveModuleExtensionName(const std::string &filepath) template void TSDeclGen::GenAnnotations(const ir::AnnotationAllowed *node) { - if (node == nullptr || (!node->HasAnnotations() && node->Annotations().size() == 0U)) { + if (!declgenOptions_.genAnnotations || node == nullptr || + (!node->HasAnnotations() && node->Annotations().size() == 0U)) { return; } GenSeparated( diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.h b/ets2panda/declgen_ets2ts/declgenEts2Ts.h index 7e79a37f53dd68670a761269820aa93329fb4e8d..3ec916d23b6c702f72a6a776202227233e6d76cb 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.h +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.h @@ -35,6 +35,7 @@ struct DeclgenOptions { std::string outputDeclEts; std::string outputEts; std::string recordFile; + bool genAnnotations = true; }; // Consume program after checker stage and generate out_path typescript file with declarations diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index eeb15985ea85f5a39b11127d44e3c6be469d4b31..231eaa73492433aa195173e9d409202725f39fc8 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -125,6 +125,7 @@ export abstract class BaseMode { public byteCodeHar: boolean; public es2pandaMode: number; public skipDeclCheck: boolean; + public genDeclAnnotations: boolean; constructor(buildConfig: BuildConfig) { this.buildConfig = buildConfig; @@ -166,6 +167,7 @@ export abstract class BaseMode { : ES2PANDA_MODE.RUN ); this.skipDeclCheck = buildConfig?.skipDeclCheck as boolean ?? true; + this.genDeclAnnotations = buildConfig?.genDeclAnnotations as boolean ?? true; } public declgen(fileInfo: CompileFileInfo): void { @@ -227,7 +229,8 @@ export abstract class BaseMode { etsOutputPath, false, false, - staticRecordRelativePath + staticRecordRelativePath, + this.genDeclAnnotations ); // Generate 1.0 declaration files & 1.0 glue code this.logger.printInfo('declaration files generated'); } catch (error) { diff --git a/ets2panda/driver/build_system/src/build/declgen_worker.ts b/ets2panda/driver/build_system/src/build/declgen_worker.ts index fcb5ae0adca06c95140e87a8c0e3e75e55158674..acdaae46873659d0626aaed917cca030c1ab8ab8 100644 --- a/ets2panda/driver/build_system/src/build/declgen_worker.ts +++ b/ets2panda/driver/build_system/src/build/declgen_worker.ts @@ -98,6 +98,7 @@ process.on('message', async (message: { arktsGlobal.compilerContext = arkts.Context.createFromStringWithHistory(source); pluginDriver.getPluginContext().setArkTSProgram(arktsGlobal.compilerContext.program); const skipDeclCheck = buildConfig?.skipDeclCheck ?? true; + const genDeclAnnotations = buildConfig?.genDeclAnnotations ?? true; arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, arktsGlobal.compilerContext.peer, skipDeclCheck); let ast = arkts.EtsScript.fromContext(); @@ -114,7 +115,8 @@ process.on('message', async (message: { etsOutputPath, false, false, - staticRecordRelativePath + staticRecordRelativePath, + genDeclAnnotations ); logger.printInfo(`[declgen] ${fileInfo.filePath} processed successfully`); diff --git a/ets2panda/driver/build_system/src/types.ts b/ets2panda/driver/build_system/src/types.ts index fe66126e8354e446a373f24c4ba497bc96c91d4a..73d44ab46babdc6333e1cc25fdeb60a58dbc73f6 100644 --- a/ets2panda/driver/build_system/src/types.ts +++ b/ets2panda/driver/build_system/src/types.ts @@ -173,6 +173,7 @@ export interface DeclgenConfig { declgenBridgeCodePath?: string; skipDeclCheck?: boolean; continueOnError?: boolean; + genDeclAnnotations?: boolean; } export interface LoggerConfig { diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 671ec8b85d45556f059f64b31d7a025b0dc5d282..ea052d5e3db5af155a51433bd6f289da2e13ba95 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -1270,7 +1270,8 @@ extern "C" es2panda_AstNode **AllDeclarationsByNameFromProgram([[maybe_unused]] extern "C" __attribute__((unused)) int GenerateTsDeclarationsFromContext(es2panda_Context *ctx, const char *outputDeclEts, const char *outputEts, bool exportAll, - bool isolated, const char *recordFile) + bool isolated, const char *recordFile, + bool genAnnotations) { auto *ctxImpl = reinterpret_cast(ctx); auto *checker = reinterpret_cast(ctxImpl->GetChecker()); @@ -1281,6 +1282,7 @@ extern "C" __attribute__((unused)) int GenerateTsDeclarationsFromContext(es2pand declgenOptions.outputEts = outputEts ? outputEts : ""; declgenOptions.isolated = isolated; declgenOptions.recordFile = recordFile ? recordFile : ""; + declgenOptions.genAnnotations = genAnnotations; return ark::es2panda::declgen_ets2ts::GenerateTsDeclarations(checker, ctxImpl->parserProgram, declgenOptions) ? 0 : 1; diff --git a/ets2panda/public/es2panda_lib.h b/ets2panda/public/es2panda_lib.h index a1562a4fd690c3c9a576037d2ff968a103a2f1f3..992e068bbe718b903d84968d04b6ce26e5312592 100644 --- a/ets2panda/public/es2panda_lib.h +++ b/ets2panda/public/es2panda_lib.h @@ -274,7 +274,7 @@ struct CAPI_EXPORT es2panda_Impl { int (*GenerateTsDeclarationsFromContext)(es2panda_Context *context, const char *outputDeclEts, const char *outputEts, bool exportAll, bool isolated, - const char *recordFile); + const char *recordFile, bool genAnnotations); void (*InsertETSImportDeclarationAndParse)(es2panda_Context *context, es2panda_Program *program, es2panda_AstNode *importDeclaration); int (*GenerateStaticDeclarationsFromContext)(es2panda_Context *context, const char *outputPath); diff --git a/ets2panda/public/es2panda_lib.idl.erb b/ets2panda/public/es2panda_lib.idl.erb index 56f82661069d7e324abdcbecb7775f6e8c8ed467..b91f57b1c66fa7cefb7f6f30b1442166fa34ecbf 100644 --- a/ets2panda/public/es2panda_lib.idl.erb +++ b/ets2panda/public/es2panda_lib.idl.erb @@ -235,6 +235,9 @@ interface es2panda_Impl { ir.AstNode FirstDeclarationByNameFromProgram(es2panda_Context ctx, es2panda_Program program, String name); sequence AllDeclarationsByNameFromNode(es2panda_Context ctx, ir.AstNode node, String name); sequence AllDeclarationsByNameFromProgram(es2panda_Context ctx, es2panda_Program program, String name); + i32 GenerateTsDeclarationsFromContext(es2panda_Context ctx, String outputDeclEts, String outputEts, + boolean exportAll, boolean isolated, String recordFile, + boolean genAnnotations); void InsertETSImportDeclarationAndParse(es2panda_Context context, es2panda_Program program, ETSImportDeclaration node); i32 GenerateStaticDeclarationsFromContext(es2panda_Context context, String outputPath); diff --git a/ets2panda/scripts/arkui.properties b/ets2panda/scripts/arkui.properties index 7f0cf795d6fc08a4c06153255f150ddd2741e69f..d5acadafe7fe15d713a9e0d264378c72bd17edae 100644 --- a/ets2panda/scripts/arkui.properties +++ b/ets2panda/scripts/arkui.properties @@ -1,3 +1,3 @@ ARKUI_DEV_REPO=https://gitee.com/rri_opensource/koala_projects.git -ARKUI_DEV_BRANCH=panda_rev_11 +ARKUI_DEV_BRANCH=panda_rev_11-interop_0702 ARKUI_DEST=koala-sig diff --git a/ets2panda/test/unit/declgen/CMakeLists.txt b/ets2panda/test/unit/declgen/CMakeLists.txt index 601c09c31e173c088e0dcef05729c0af4599286e..0bf413a536913f8c92654a1d79b44a2c0ba50c76 100644 --- a/ets2panda/test/unit/declgen/CMakeLists.txt +++ b/ets2panda/test/unit/declgen/CMakeLists.txt @@ -31,6 +31,7 @@ set(ETS2TS_ISOLATED_TESTS "./ets2ts_isolated/test_ets2ts_isolated_interface.ets" "./ets2ts_isolated/test_ets2ts_isolated_function_with_optional_parameter.ets" "./ets2ts_isolated/test_ets2ts_infer_function_return_type_with_import_symbol.ets" + "./ets2ts_isolated/test_ets2ts_isolated_annotation.ets" ) foreach(TEST_DATA IN ITEMS ${DECLGEN_PLUGIN_TESTS}) diff --git a/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation-expected.txt b/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1725174a5e8cbdcf81b506a4d90e7f052c01eaf --- /dev/null +++ b/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation-expected.txt @@ -0,0 +1 @@ +export declare function foo(): void; diff --git a/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation.ets b/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation.ets new file mode 100644 index 0000000000000000000000000000000000000000..071cbf9efbb3ffd0e42d17a6b673170acfbde0c7 --- /dev/null +++ b/ets2panda/test/unit/declgen/ets2ts_isolated/test_ets2ts_isolated_annotation.ets @@ -0,0 +1,17 @@ +/** + * 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. + */ + +@Builer +export function foo(): void {} \ No newline at end of file diff --git a/ets2panda/test/unit/declgen/test_ets2ts_isolated_declgen.cpp b/ets2panda/test/unit/declgen/test_ets2ts_isolated_declgen.cpp index a2049a3800f5ca30420c1480774859e57712ea74..319a02bd46f866fa690f308260b740848c20580b 100644 --- a/ets2panda/test/unit/declgen/test_ets2ts_isolated_declgen.cpp +++ b/ets2panda/test/unit/declgen/test_ets2ts_isolated_declgen.cpp @@ -49,7 +49,7 @@ int main(int argc, char **argv) impl->ProceedToState(context, ES2PANDA_STATE_CHECKED); CheckForErrors("CHECKED", context); std::string declName = GetDeclPrefix(argv[argc - 1]) + ".d.ets"; - int result = impl->GenerateTsDeclarationsFromContext(context, declName.c_str(), "dump.ets", false, true, ""); + int result = impl->GenerateTsDeclarationsFromContext(context, declName.c_str(), "dump.ets", false, true, "", false); if (result != 0) { std::cerr << "FAILED TO GENERATE DECLARATIONS" << std::endl; return result;