From 6c387cb86fd81c7560ea0b49ab3fac2423626329 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Tue, 20 May 2025 21:45:36 +0300 Subject: [PATCH 1/3] Update koala_mirror 47068d924 Signed-off-by: Anton Tarasov --- .../koala_mirror/incremental/BUILD.gn | 57 + .../incremental/build-common/package.json | 2 +- .../incremental/common/oh-package.json5 | 50 + .../incremental/common/package.json | 6 +- .../incremental/compat/oh-package.json5 | 29 + .../incremental/compat/package.json | 4 +- .../compat/src/arkts/observable.ts | 98 +- .../compat/src/typescript/double.ts | 2 +- .../compat/src/typescript/observable.ts | 121 +- .../incremental/gn/command/npm.py | 104 ++ .../koala_mirror/incremental/package.json | 8 +- .../incremental/runtime/annotations/index.ts | 14 - .../runtime/docs/basic-concepts.md | 193 --- .../runtime/docs/call.graph.drawio.svg | 144 -- .../runtime/docs/explicit-state.md | 642 ------- .../incremental/runtime/oh-package.json5 | 36 + .../incremental/runtime/package.json | 18 +- .../runtime/src/animation/AnimatedState.ts | 48 +- .../runtime/src/animation/TimeAnimation.ts | 12 +- .../incremental/runtime/src/animation/memo.ts | 11 +- .../incremental/runtime/src/index.ts | 2 + .../incremental/runtime/src/internals.ts | 5 + .../incremental/runtime/src/memo/bind.ts | 1 + .../runtime/src/memo/changeListener.ts | 5 +- .../runtime/src/memo/contextLocal.ts | 1 + .../incremental/runtime/src/memo/entry.ts | 1 + .../incremental/runtime/src/memo/node.ts | 5 +- .../incremental/runtime/src/memo/remember.ts | 4 +- .../incremental/runtime/src/memo/repeat.ts | 9 +- .../incremental/runtime/src/memo/testing.ts | 13 +- .../runtime/src/states/Dependency.ts | 37 +- .../incremental/runtime/src/states/State.ts | 31 +- .../runtime/src/tree/IncrementalNode.ts | 8 +- .../incremental/runtime/test-arkts/tests.ts | 3 +- .../runtime/ui2abcconfig-recheck.json | 29 + .../test-utils/scripts/register.js | 2 +- .../incremental/tools/multi-pass/package.json | 29 + .../incremental/tools/multi-pass/rules.json | 4 + .../incremental/tools/multi-pass/src/main.ts | 76 + .../tools/multi-pass/tsconfig.json | 19 + .../tools/panda/arkts/std-lib/global.d.ts | 15 - .../incremental/tools/panda/package.json | 1 + .../tools/panda/patch/es2panda_lib.idl.patch | 27 + .../koala_mirror/interop/BUILD.gn | 51 + .../koala_mirror/interop/gn/command/npm.py | 104 ++ .../koala_mirror/interop/meson.build | 13 + .../koala_mirror/interop/meson_options.txt | 13 + .../koala_mirror/interop/oh-package.json5 | 58 + .../koala_mirror/interop/package.json | 5 +- .../interop/scripts/configure.mjs | 502 ------ .../koala_mirror/interop/scripts/utils.mjs | 248 --- .../interop/src/arkts/InteropNativeModule.ts | 6 +- .../interop/src/arkts/SerializerBase.ts | 38 +- .../interop/src/arkts/loadLibraries.ts | 7 +- .../interop/src/cangjie/cjpm.toml | 4 +- .../interop/src/cpp/callback-resource.cc | 2 +- .../interop/src/cpp/cangjie/convertors-cj.cc | 4 +- .../interop/src/cpp/common-interop.cc | 20 + .../interop/src/cpp/interop-types.h | 4 +- .../koala_mirror/interop/src/cpp/tracer.h | 4 +- .../koala_mirror/interop/src/cpp/vmloader.cc | 69 +- .../src/interop/InteropNativeModule.ts | 6 +- .../interop/src/interop/buffer.ts | 4 +- .../interop/src/interop/loadLibraries.ts | 4 +- .../arkts_frontend/koala_mirror/package.json | 14 +- .../koala_mirror/ui2abc/docs/UI2ABC_WORKS.md | 70 - .../PrimeNumbers.ets => fast-arktsc/index.js} | 7 +- .../ui2abc/fast-arktsc/package.json | 6 +- .../ui2abc/fast-arktsc/src/main.ts | 5 +- .../ui2abc/fast-arktsc/src/resolve-config.ts | 54 +- .../koala_mirror/ui2abc/gn/command/gen_sdk.py | 8 + .../ui2abc/gn/patch/es2panda_lib.idl.patch | 11 + .../koala_mirror/ui2abc/gn/sdk_config.json | 84 +- .../ui2abc/libarkts/arktsconfig.json | 26 +- .../ui2abc/libarkts/generator/options.json5 | 15 - .../ui2abc/libarkts/gn/command/copy.py | 2 +- .../ui2abc/libarkts/gn/command/npm.py | 4 +- .../ui2abc/libarkts/native/meson.build | 13 + .../ui2abc/libarkts/native/meson_options.txt | 13 + .../ui2abc/libarkts/native/src/bridges.cc | 16 +- .../ui2abc/libarkts/native/src/common.cc | 62 +- .../ui2abc/libarkts/native/src/common.h | 48 + .../libarkts/native/src/generated/bridges.cc | 389 +++-- .../koala_mirror/ui2abc/libarkts/package.json | 25 +- .../ui2abc/libarkts/playground/meson.build | 31 - .../libarkts/playground/meson_options.txt | 4 - .../libarkts/playground/src/playground.cc | 160 -- .../ui2abc/libarkts/plugins/input/direct.ets | 15 + .../ui2abc/libarkts/plugins/input/export.ets | 15 + .../ui2abc/libarkts/plugins/input/f.ets | 15 + .../ui2abc/libarkts/plugins/input/library.ets | 23 +- .../ui2abc/libarkts/plugins/input/main.ets | 53 +- .../plugins/input/no-import-no-struct.ets | 15 + .../libarkts/plugins/input/one_recursive.ts | 8 + .../libarkts/plugins/input/two_recursive.ts | 8 + .../libarkts/plugins/input/variable.ets | 15 + .../ui2abc/libarkts/plugins/src/no-visitor.ts | 4 +- .../libarkts/plugins/src/printer-plugin.ts | 4 +- .../ui2abc/libarkts/src-host/es2panda.ts | 599 ++++--- .../libarkts/src/InteropNativeModule.ts | 4 +- .../src/arkts-api/CheckedBackFilter.ts | 53 + .../src/arkts-api/SetBaseOverloads.ts} | 69 +- .../src/arkts-api/factory/nodeFactory.ts | 8 +- .../ui2abc/libarkts/src/arkts-api/index.ts | 3 + .../node-utilities/CallExpression.ts | 4 +- .../node-utilities/ClassDefinition.ts | 2 +- .../arkts-api/node-utilities/ClassProperty.ts | 31 +- .../node-utilities/ETSFunctionType.ts | 4 +- .../node-utilities/ETSImportDeclaration.ts | 5 +- .../node-utilities/ETSParameterExpression.ts | 4 +- .../node-utilities/ETSStructDeclaration.ts | 2 +- .../src/arkts-api/node-utilities/ETSTuple.ts | 2 +- .../node-utilities/MemberExpression.ts | 2 +- .../node-utilities/MethodDefinition.ts | 4 +- .../arkts-api/node-utilities/NumberLiteral.ts | 8 +- .../node-utilities/ObjectExpression.ts | 2 +- .../node-utilities/TSInterfaceDeclaration.ts | 40 +- .../node-utilities/TSTypeAliasDeclaration.ts | 12 +- .../node-utilities/TSTypeParameter.ts | 2 +- .../node-utilities/TSTypeReferencePart.ts | 2 +- .../node-utilities/VariableDeclaration.ts | 2 +- .../node-utilities/VariableDeclarator.ts | 2 +- .../libarkts/src/arkts-api/peers/AstNode.ts | 6 +- .../libarkts/src/arkts-api/peers/Context.ts | 3 +- .../libarkts/src/arkts-api/peers/Program.ts | 6 +- .../ui2abc/libarkts/src/arkts-api/plugins.ts | 48 + .../libarkts/src/arkts-api/static/global.ts | 5 +- .../libarkts/src/arkts-api/static/profiler.ts | 2 +- .../src/arkts-api/utilities/private.ts | 8 +- .../src/arkts-api/utilities/public.ts | 24 +- .../ui2abc/libarkts/src/arkts-api/visitor.ts | 152 +- .../libarkts/src/generated/Es2pandaEnums.ts | 223 +-- .../src/generated/Es2pandaNativeModule.ts | 41 +- .../ui2abc/libarkts/src/generated/factory.ts | 10 +- .../ui2abc/libarkts/src/generated/index.ts | 2 + .../src/generated/peers/ArrayExpression.ts | 2 +- .../generated/peers/AssignmentExpression.ts | 2 +- .../src/generated/peers/BlockExpression.ts | 2 +- .../src/generated/peers/DiagnosticInfo.ts} | 30 +- .../src/generated/peers/ETSClassLiteral.ts | 2 +- .../src/generated/peers/ETSFunctionType.ts | 2 +- .../generated/peers/ETSImportDeclaration.ts | 2 +- .../src/generated/peers/ETSKeyofType.ts | 2 +- .../libarkts/src/generated/peers/ETSModule.ts | 2 +- .../peers/ETSNewArrayInstanceExpression.ts | 2 +- .../peers/ETSNewClassInstanceExpression.ts | 2 +- .../ETSNewMultiDimArrayInstanceExpression.ts | 2 +- .../src/generated/peers/ETSNullType.ts | 2 +- .../generated/peers/ETSPackageDeclaration.ts | 2 +- .../generated/peers/ETSParameterExpression.ts | 2 +- .../src/generated/peers/ETSPrimitiveType.ts | 2 +- .../generated/peers/ETSStringLiteralType.ts | 2 +- .../generated/peers/ETSStructDeclaration.ts | 2 +- .../libarkts/src/generated/peers/ETSTuple.ts | 2 +- .../src/generated/peers/ETSTypeReference.ts | 2 +- .../generated/peers/ETSTypeReferencePart.ts | 2 +- .../src/generated/peers/ETSUndefinedType.ts | 2 +- .../src/generated/peers/ETSUnionType.ts | 2 +- .../src/generated/peers/ETSWildcardType.ts | 2 +- .../src/generated/peers/EmptyStatement.ts | 10 +- .../generated/peers/ExportNamedDeclaration.ts | 5 + .../src/generated/peers/ExportSpecifier.ts | 17 + .../src/generated/peers/NumberLiteral.ts | 3 - .../src/generated/peers/ObjectExpression.ts | 2 +- .../src/generated/peers/OpaqueTypeNode.ts | 2 +- .../src/generated/peers/ScriptFunction.ts | 8 + .../src/generated/peers/SpreadElement.ts | 2 +- .../libarkts/src/generated/peers/SrcDumper.ts | 7 +- .../src/generated/peers/SuggestionInfo.ts} | 34 +- .../src/generated/peers/SuperExpression.ts | 2 +- .../generated/peers/SwitchCaseStatement.ts | 2 +- .../src/generated/peers/SwitchStatement.ts | 2 +- .../src/generated/peers/TSAnyKeyword.ts | 2 +- .../src/generated/peers/TSArrayType.ts | 2 +- .../src/generated/peers/TSAsExpression.ts | 2 +- .../src/generated/peers/TSBigintKeyword.ts | 2 +- .../src/generated/peers/TSBooleanKeyword.ts | 2 +- .../src/generated/peers/TSClassImplements.ts | 2 +- .../src/generated/peers/TSConditionalType.ts | 2 +- .../src/generated/peers/TSConstructorType.ts | 2 +- .../src/generated/peers/TSEnumDeclaration.ts | 2 +- .../src/generated/peers/TSEnumMember.ts | 2 +- .../peers/TSExternalModuleReference.ts | 2 +- .../src/generated/peers/TSFunctionType.ts | 2 +- .../peers/TSImportEqualsDeclaration.ts | 2 +- .../src/generated/peers/TSImportType.ts | 2 +- .../src/generated/peers/TSIndexSignature.ts | 2 +- .../generated/peers/TSIndexedAccessType.ts | 2 +- .../src/generated/peers/TSInferType.ts | 2 +- .../src/generated/peers/TSInterfaceBody.ts | 2 +- .../generated/peers/TSInterfaceDeclaration.ts | 2 +- .../generated/peers/TSInterfaceHeritage.ts | 2 +- .../src/generated/peers/TSIntersectionType.ts | 2 +- .../src/generated/peers/TSLiteralType.ts | 2 +- .../src/generated/peers/TSMappedType.ts | 2 +- .../src/generated/peers/TSMethodSignature.ts | 2 +- .../src/generated/peers/TSModuleBlock.ts | 2 +- .../generated/peers/TSModuleDeclaration.ts | 2 +- .../src/generated/peers/TSNamedTupleMember.ts | 2 +- .../src/generated/peers/TSNeverKeyword.ts | 2 +- .../generated/peers/TSNonNullExpression.ts | 2 +- .../src/generated/peers/TSNullKeyword.ts | 2 +- .../src/generated/peers/TSNumberKeyword.ts | 2 +- .../src/generated/peers/TSObjectKeyword.ts | 2 +- .../generated/peers/TSParameterProperty.ts | 2 +- .../generated/peers/TSParenthesizedType.ts | 2 +- .../generated/peers/TSPropertySignature.ts | 2 +- .../src/generated/peers/TSQualifiedName.ts | 2 +- .../generated/peers/TSSignatureDeclaration.ts | 2 +- .../src/generated/peers/TSStringKeyword.ts | 2 +- .../src/generated/peers/TSThisType.ts | 2 +- .../src/generated/peers/TSTupleType.ts | 2 +- .../generated/peers/TSTypeAliasDeclaration.ts | 2 +- .../src/generated/peers/TSTypeAssertion.ts | 2 +- .../src/generated/peers/TSTypeLiteral.ts | 2 +- .../src/generated/peers/TSTypeOperator.ts | 2 +- .../src/generated/peers/TSTypeParameter.ts | 2 +- .../peers/TSTypeParameterDeclaration.ts | 2 +- .../peers/TSTypeParameterInstantiation.ts | 2 +- .../src/generated/peers/TSTypePredicate.ts | 2 +- .../src/generated/peers/TSTypeQuery.ts | 2 +- .../src/generated/peers/TSTypeReference.ts | 2 +- .../src/generated/peers/TSUndefinedKeyword.ts | 2 +- .../src/generated/peers/TSUnionType.ts | 2 +- .../src/generated/peers/TSUnknownKeyword.ts | 2 +- .../src/generated/peers/TSVoidKeyword.ts | 2 +- .../peers/TaggedTemplateExpression.ts | 2 +- .../src/generated/peers/TemplateElement.ts | 2 +- .../src/generated/peers/TemplateLiteral.ts | 2 +- .../src/generated/peers/ThisExpression.ts | 2 +- .../src/generated/peers/ThrowStatement.ts | 2 +- .../src/generated/peers/TryStatement.ts | 2 +- .../src/generated/peers/TypeofExpression.ts | 2 +- .../src/generated/peers/UnaryExpression.ts | 2 +- .../src/generated/peers/UpdateExpression.ts | 2 +- .../generated/peers/VariableDeclaration.ts | 2 +- .../src/generated/peers/VariableDeclarator.ts | 2 +- .../src/generated/peers/WhileStatement.ts | 2 +- .../src/generated/peers/YieldExpression.ts | 2 +- .../koala_mirror/ui2abc/libarkts/src/index.ts | 5 +- .../src/ts-api/factory/nodeFactory.ts | 2 +- .../libarkts/src/ts-api/factory/nodeTests.ts | 2 +- .../ui2abc/libarkts/src/ts-api/types.ts | 2 +- .../koala_mirror/ui2abc/libarkts/src/utils.ts | 24 +- .../arkts-api/filter-source/TreeNode.test.ts | 29 - .../filter-source/golden/TreeNode.ts | 100 -- .../arkts-api/filter-source/input/TreeNode.ts | 106 -- .../test/arkts-api/functions/create.test.ts | 2 +- .../arkts-api/general/annotations.test.ts | 2 +- .../test/arkts-api/general/recheck.test.ts | 341 +--- .../arkts-api/import-export/import.test.ts | 104 +- .../test/arkts-api/recheck/arktsconfig.json | 7 + .../arkts-api/recheck/constructor/index.ts | 37 + .../arkts-api/recheck/constructor/main.ts | 4 + .../recheck/imports/add-new-file/index.ts | 25 + .../recheck/imports/add-new-file/library.ts | 6 + .../recheck/imports/add-new-file/main.ts | 1 + .../imports/add-same-file/dump-src/main.ts | 9 + .../recheck/imports/add-same-file/index.ts | 25 + .../recheck/imports/add-same-file/library.ts | 6 + .../recheck/imports/add-same-file/main.ts | 2 + .../add-use-same-file/dump-src/main.ts | 10 + .../imports/add-use-same-file/index.ts | 39 + .../imports/add-use-same-file/library.ts | 6 + .../recheck/imports/add-use-same-file/main.ts | 2 + .../imports/recursive/dump-src/main.ts | 9 + .../recheck/imports/recursive/index.ts | 37 + .../recheck/imports/recursive/main.ts | 2 + .../imports/recursive/one_recursive.ts | 8 + .../imports/recursive/two_recursive.ts | 8 + .../overloads/getter-setter/dump-src/main.ts | 12 + .../recheck/overloads/getter-setter/index.ts | 32 + .../recheck/overloads/getter-setter/main.ts | 4 + .../test/arkts-api/recheck/recheck.test.ts | 216 +++ .../simple/add-class-method/dump-src/main.ts | 14 + .../recheck/simple/add-class-method/index.ts | 44 + .../recheck/simple/add-class-method/main.ts | 2 + .../simple/add-variable/dump-src/main.ts | 14 + .../recheck/simple/add-variable/index.ts | 75 + .../recheck/simple/add-variable/main.ts | 4 + .../test/arkts-api/recheck/simple/index.ts | 27 + .../simple/rename-class/dump-src/main.ts | 12 + .../recheck/simple/rename-class/index.ts | 19 + .../recheck/simple/rename-class/main.ts | 4 + .../static/constructor/dump-src/main.ts | 14 + .../recheck/static/constructor/main.ts | 4 + .../recheck/static/function/dump-src/main.ts | 7 + .../arkts-api/recheck/static/function/main.ts | 1 + .../static/import-type/dump-src/main.ts | 7 + .../recheck/static/import-type/library.ts | 12 + .../recheck/static/import-type/main.ts | 1 + .../arkts-api/recheck/static/property/main.ts | 7 + .../static/public-setter/dump-src/main.ts | 24 + .../recheck/static/public-setter/library.ts | 16 + .../recheck/static/public-setter/main.ts | 12 + .../static/trailing-block/dump-src/main.ts | 18 + .../recheck/static/trailing-block/main.ts | 9 + .../static/typed-property/dump-src/main.ts | 28 + .../recheck/static/typed-property/main.ts | 7 + .../arkts-api/recheck/this/dump-src/main.ts | 15 + .../test/arkts-api/recheck/this/index.ts | 35 + .../test/arkts-api/recheck/this/main.ts | 5 + .../ui2abc/libarkts/test/test-util.ts | 12 + .../ts-api/classes/heritage/extends.test.ts | 2 +- .../ts-api/demo-playground/classes.test.ts | 55 - .../test/ts-api/demo-playground/main.sts | 75 - .../demo-playground/memo-rewrites.test.ts | 60 - .../ui2abc/memo-plugin/.gitignore | 1 + .../ui2abc/memo-plugin/demo/demo/demo.ets | 2 +- .../ui2abc/memo-plugin/demo/package.json | 2 +- .../ui2abc/memo-plugin/demo/ui2abcconfig.json | 10 +- .../ui2abc/memo-plugin/package.json | 23 +- .../runtime-api/animation/AnimatedState.ets | 37 - .../runtime-api/animation/Easing.ets | 45 - .../runtime-api/animation/EasingSupport.ets | 23 - .../runtime-api/animation/TimeAnimation.ets | 60 - .../runtime-api/animation/memo.ets | 28 - .../runtime-api/annotations.ets | 15 - .../recheck-bringup/runtime-api/common.ets | 5 - .../recheck-bringup/runtime-api/index.ets | 165 -- .../recheck-bringup/runtime-api/internals.ets | 25 - .../recheck-bringup/runtime-api/memo/bind.ets | 29 - .../runtime-api/memo/contextLocal.ets | 20 - .../runtime-api/memo/entry.ets | 27 - .../recheck-bringup/runtime-api/memo/node.ets | 29 - .../runtime-api/memo/remember.ets | 28 - .../runtime-api/memo/repeat.ets | 26 - .../runtime-api/memo/testing.ets | 33 - .../runtime-api/states/Disposable.ets | 22 - .../runtime-api/states/GlobalStateManager.ets | 26 - .../runtime-api/states/State.ets | 84 - .../runtime-api/tree/IncrementalNode.ets | 41 - .../runtime-api/tree/TreeNode.ets | 59 - .../runtime-api/tree/TreeUpdater.ets | 30 - .../recheck-bringup/ui2abcconfig.json | 10 +- .../ui2abc/memo-plugin/rollup.config.mjs | 23 +- .../ui2abc/memo-plugin/src/AnalysisVisitor.ts | 11 + .../memo-plugin/src/FunctionTransformer.ts | 14 +- .../ui2abc/memo-plugin/src/MemoFactory.ts | 113 +- .../ui2abc/memo-plugin/src/MemoTransformer.ts | 15 +- .../Journal.ets => src/ParserTransformer.ts} | 35 +- .../memo-plugin/src/ReturnTranformer.ts | 4 +- .../memo-plugin/src/SignatureTransformer.ts | 43 +- .../ui2abc/memo-plugin/src/api-utils.ts | 61 +- .../ui2abc/memo-plugin/src/utils.ts | 43 +- .../ui2abc/memo-plugin/test/.gitignore | 3 + .../test/arktsconfig-executable.json | 30 + .../memo-plugin/test/arktsconfig-golden.json | 30 + .../test/diagnostics/diagnostics.test.ts | 87 + .../NonmemoPropertyShorthandAssignment.ts} | 14 +- .../input/PropertyShorthandAssignment.ts} | 22 +- .../diagnostics/input/global_memo.input.ts | 19 + .../diagnostics/input/memo_entry.input.ts | 24 + .../input/memo_in_handler.input.ts | 26 + .../input/memo_in_inner_function.input.ts | 26 + .../diagnostics/input/no_memo_entry.input.ts | 23 + .../diagnostics/input/smoke.input.ts} | 7 +- .../ui2abc/memo-plugin/test/golden/test.ets | 460 +++++ .../ui2abc/memo-plugin/test/package.json | 11 + .../ui2abc/memo-plugin/test/rewrite.test.ts | 203 +++ .../ui2abc/memo-plugin/test/test.ets | 235 +++ .../ui2abc/memo-plugin/test/tsconfig.json | 14 + .../koala_mirror/ui2abc/package.json | 13 +- .../koala_mirror/ui2abc/tests-memo/.gitignore | 3 + .../ui2abc/tests-memo/.mocharc.json | 14 + .../ui2abc/tests-memo/annotate-tests.json | 12 + .../arktsconfig-compiler-plugin.json | 17 + .../tests-memo/arktsconfig-memo-plugin.json | 33 + .../ui2abc/tests-memo/package.json | 52 + .../koala_mirror/ui2abc/tests-memo/readme.md | 26 + .../tests-memo/test/arkts/arkts_test.test.ts | 195 +++ .../test/arkts_run.ts} | 16 +- .../tests-memo/test/common/basic.test.ts | 1498 +++++++++++++++++ .../test/common/main_test_module_to_import.ts | 28 + .../test/common/test_module_to_import.ts | 23 + .../ui2abc/tests-memo/test/testUtils.ts | 77 + .../ui2abc/tests-memo/test/ts/ts_test.test.ts | 167 ++ .../ui2abc/tests-memo/test/ts_run.ts | 18 + .../ui2abc/tests-memo/test/tsconfig.json | 33 + .../tests-memo/test/ui2abc/arkts.test.ts | 80 + .../test/ui2abc/ui2abc_test.test.ts | 210 +++ .../ui2abc/tests-memo/test/ui2abc/utils.ts | 40 + .../test/ui2abc_run.ts} | 16 +- .../tests-memo/tsconfig-compiler-plugin.json | 31 + .../ui2abc/ui-plugins/package.json | 6 +- .../ui-plugins/src/annotation-translator.ts | 20 - .../src/builder-lambda-transformer.ts | 2 +- .../ui2abc/ui-plugins/src/call-transformer.ts | 89 + .../ui-plugins/src/checked-stage-plugin.ts | 8 +- .../ui-plugins/src/common/arkts-utils.ts | 6 + .../ui-plugins/src/component-transformer.ts | 529 ++++-- .../ui-plugins/src/imports-transformer.ts} | 31 +- .../ui-plugins/src/parsed-stage-plugin.ts | 18 +- .../ui-plugins/src/property-transformers.ts | 597 +++++++ .../src/property-translators/utils.ts | 4 +- .../ui2abc/ui-plugins/src/struct-recorder.ts | 96 ++ .../ui-plugins/src/struct-transformer.ts | 326 ---- .../ui2abc/ui-plugins/src/utils.ts | 74 +- 398 files changed, 9350 insertions(+), 5462 deletions(-) create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/BUILD.gn create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/oh-package.json5 create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/oh-package.json5 create mode 100755 frameworks/bridge/arkts_frontend/koala_mirror/incremental/gn/command/npm.py delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/basic-concepts.md delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/call.graph.drawio.svg delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/explicit-state.md create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/oh-package.json5 create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/ui2abcconfig-recheck.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/package.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/rules.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/tsconfig.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/patch/es2panda_lib.idl.patch create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/interop/BUILD.gn create mode 100755 frameworks/bridge/arkts_frontend/koala_mirror/interop/gn/command/npm.py create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/interop/oh-package.json5 delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/configure.mjs delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/utils.mjs delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/docs/UI2ABC_WORKS.md rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/{memo-plugin/recheck-bringup/runtime-api/tree/PrimeNumbers.ets => fast-arktsc/index.js} (79%) mode change 100644 => 100755 create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/patch/es2panda_lib.idl.patch delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/meson.build delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/meson_options.txt delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/src/playground.cc create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/one_recursive.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/two_recursive.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/CheckedBackFilter.ts rename frameworks/bridge/arkts_frontend/koala_mirror/{interop/scripts/get_prebuilt.mjs => ui2abc/libarkts/src/arkts-api/SetBaseOverloads.ts} (32%) create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/plugins.ts rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/{memo-plugin/recheck-bringup/input/ets/memo-hello-world.ts => libarkts/src/generated/peers/DiagnosticInfo.ts} (60%) rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/{memo-plugin/recheck-bringup/runtime-api/states/Dependency.ets => libarkts/src/generated/peers/SuggestionInfo.ts} (56%) delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/TreeNode.test.ts delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/golden/TreeNode.ts delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/input/TreeNode.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/arktsconfig.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/library.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/library.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/library.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/one_recursive.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/two_recursive.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/recheck.test.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/library.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/property/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/library.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/dump-src/main.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/main.ts delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/classes.test.ts delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/main.sts delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/memo-rewrites.test.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/.gitignore delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/AnimatedState.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/Easing.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/EasingSupport.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/TimeAnimation.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/memo.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/annotations.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/common.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/index.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/internals.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/bind.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/contextLocal.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/entry.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/node.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/remember.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/repeat.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/testing.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Disposable.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/GlobalStateManager.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/State.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/IncrementalNode.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreeNode.ets delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreeUpdater.ets rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/{recheck-bringup/runtime-api/states/Journal.ets => src/ParserTransformer.ts} (41%) create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/.gitignore create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/arktsconfig-executable.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/arktsconfig-golden.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/diagnostics.test.ts rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/{recheck-bringup/runtime-api/memo/changeListener.ets => test/diagnostics/input/NonmemoPropertyShorthandAssignment.ts} (63%) rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/{recheck-bringup/runtime-api/tree/TreePath.ets => test/diagnostics/input/PropertyShorthandAssignment.ts} (60%) create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/global_memo.input.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_entry.input.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_in_handler.input.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_in_inner_function.input.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/no_memo_entry.input.ts rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/{recheck-bringup/runtime-api/tree/ReadonlyTreeNode.ets => test/diagnostics/input/smoke.input.ts} (76%) create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/golden/test.ets create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/package.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/rewrite.test.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/test.ets create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/tsconfig.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/.gitignore create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/.mocharc.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/annotate-tests.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/arktsconfig-compiler-plugin.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/arktsconfig-memo-plugin.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/package.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/readme.md create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/arkts/arkts_test.test.ts rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/{memo-plugin/recheck-bringup/runtime-api/animation/AnimationRange.ets => tests-memo/test/arkts_run.ts} (59%) create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/basic.test.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/main_test_module_to_import.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/test_module_to_import.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/testUtils.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ts/ts_test.test.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ts_run.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/tsconfig.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/arkts.test.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/ui2abc_test.test.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/utils.ts rename frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/{memo-plugin/recheck-bringup/runtime-api/animation/GlobalTimer.ets => tests-memo/test/ui2abc_run.ts} (59%) create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/tsconfig-compiler-plugin.json create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/call-transformer.ts rename frameworks/bridge/arkts_frontend/koala_mirror/{interop/scripts/get_napi.mjs => ui2abc/ui-plugins/src/imports-transformer.ts} (52%) create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/property-transformers.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/struct-recorder.ts delete mode 100644 frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/struct-transformer.ts diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/BUILD.gn b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/BUILD.gn new file mode 100644 index 00000000000..f6242c21a72 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/BUILD.gn @@ -0,0 +1,57 @@ +# 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("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/arkui/ace_engine/ace_config.gni") + +incremental_root = "" +koala_root = ".." + +node_version = "v16.20.2" +host_arch = "${host_os}-${host_cpu}" + +action("incremental.abc") { + script = "gn/command/npm.py" + outputs = [ + "$target_out_dir/incremental.abc" + ] + args = [ + "--root-path", rebase_path(".."), + "--project-path", rebase_path("."), + "--node-path", rebase_path("//prebuilts/build-tools/common/nodejs/node-${node_version}-${host_arch}/bin"), + "--arklink-path", rebase_path("${static_linker_build_path}"), + "--es2panda-path", rebase_path("${ets2abc_build_path}"), + "--stdlib-path", rebase_path("//arkcompiler/runtime_core/static_core/plugins/ets/stdlib"), + "--npm-args", "run", "build:incremental:gn" + ] + + deps = [ + "${ohos_ets_api_deps}", + "${ohos_ets_arkts_deps}", + "$koala_root/ui2abc:ui2abc" + ] + + external_deps = ets2abc_build_deps + external_deps += static_linker_build_deps + + external_deps += [ + "ets_frontend:libes2panda_public(${host_toolchain})", + ] +} + +group("incremental") { + deps = [ + "$incremental_root:incremental.abc" + ] +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/build-common/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/build-common/package.json index 57be05a8481..e7208b3bf47 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/build-common/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/build-common/package.json @@ -1,6 +1,6 @@ { "name": "@koalaui/build-common", - "version": "1.5.15+devel", + "version": "1.7.1+devel", "description": "", "files": [ "tsconfig.json" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/oh-package.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/oh-package.json5 new file mode 100644 index 00000000000..a217907f839 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/oh-package.json5 @@ -0,0 +1,50 @@ +{ + "name": "@koalaui/common", + "version": "1.4.1+devel", + "description": "", + "main": "build/lib/src/index.js", + "types": "./index.d.ts", + "files": [ + "build/lib/**/*.js", + "build/lib/**/*.d.ts", + "build/bridges/ohos/**/*.js", + "build/bridges/ohos/**/*.d.ts" + ], + "exports": { + ".": "./build/lib/src/index.js", + "./golden": "./test/golden.js", + "./bridges": { + "ark": "./build/bridges/ohos/index.js", + "default": null + } + }, + "typesVersions": { + "*": { + "bridges": ["build/bridges/ohos/index.d.ts"], + "*": ["build/lib/src/*", "build/lib/typescript/*"] + } + }, + "scripts": { + "compile": "tsc -b .", + "clean": "rimraf build dist", + "test": "mocha", + "test:coverage": "nyc mocha", + "compile:arkts": "bash ../tools/panda/arkts/arktsc --arktsconfig arktsconfig.json --ets-module" + }, + "keywords": [], + "dependencies": { + "@koalaui/compat": "1.4.1+devel" + }, + "devDependencies": { + "@ohos/hypium": "^1.0.5", + "@types/chai": "^4.3.1", + "@types/mocha": "^9.1.0", + "@typescript-eslint/eslint-plugin": "^5.20.0", + "@typescript-eslint/parser": "^5.20.0", + "chai": "^4.3.6", + "eslint": "^8.13.0", + "eslint-plugin-unused-imports": "^2.0.0", + "mocha": "^9.2.2", + "source-map-support": "^0.5.21" + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/package.json index 556786e78ae..f57619e7cef 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/package.json @@ -1,6 +1,6 @@ { "name": "@koalaui/common", - "version": "1.5.15+devel", + "version": "1.7.1+devel", "description": "", "main": "build/lib/src/index.js", "types": "./index.d.ts", @@ -39,11 +39,11 @@ "clean:common": "npm run clean", "build:common": "npm run build:common:inc", "build:common:inc": "fast-arktsc --config ./arktsconfig.json --compiler ../tools/panda/arkts/arktsc --link-name ./build/common.abc && ninja ${NINJA_OPTIONS} -f build/abc/build.ninja", - "build:common:inc:ui2abc": "fast-arktsc --config ./arktsconfig.json --compiler ../tools/panda/arkts/ui2abc --file-option --link-name ./build/common.abc && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/abc/build.ninja" + "build:common:inc:ui2abc": "fast-arktsc --config ./arktsconfig.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/common.abc && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/abc/build.ninja" }, "keywords": [], "dependencies": { - "@koalaui/compat": "1.5.15+devel" + "@koalaui/compat": "1.7.1+devel" }, "devDependencies": { "@ohos/hypium": "1.0.6", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/oh-package.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/oh-package.json5 new file mode 100644 index 00000000000..45b5a9768f2 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/oh-package.json5 @@ -0,0 +1,29 @@ +{ + "name": "@koalaui/compat", + "version": "1.4.0+devel", + "description": "", + "main": "build/typescript/index.js", + "types": "build/typescript/index.d.ts", + "files": [ + "build/typescript/**/*.js", + "build/typescript/**/*.d.ts" + ], + "exports": { + ".": "./build/typescript/index.js" + }, + "scripts": { + "compile": "tsc -b .", + "clean": "rimraf build dist", + "compile:arkts": "bash ../tools/panda/arkts/arktsc --arktsconfig arktsconfig.json --ets-module" + }, + "keywords": [], + "dependencies": { + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.20.0", + "@typescript-eslint/parser": "^5.20.0", + "eslint": "^8.13.0", + "eslint-plugin-unused-imports": "^2.0.0", + "source-map-support": "^0.5.21" + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/package.json index 2a43e0eedcd..d9e1cbc7152 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/package.json @@ -1,6 +1,6 @@ { "name": "@koalaui/compat", - "version": "1.5.15+devel", + "version": "1.7.1+devel", "description": "", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -28,7 +28,7 @@ "compile:all": "npm run compile && npm run compile:ohos", "build:compat": "npm run build:compat:inc", "build:compat:inc": "fast-arktsc --config ./arktsconfig.json --compiler ../tools/panda/arkts/arktsc --link-name ./build/compat.abc && ninja ${NINJA_OPTIONS} -f build/abc/build.ninja", - "build:compat:inc:ui2abc": "fast-arktsc --config ./arktsconfig.json --compiler ../tools/panda/arkts/ui2abc --file-option --link-name ./build/compat.abc && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/abc/build.ninja" + "build:compat:inc:ui2abc": "fast-arktsc --config ./arktsconfig.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/compat.abc && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/abc/build.ninja" }, "keywords": [], "dependencies": {}, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/arkts/observable.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/arkts/observable.ts index ff5810c1741..81f0d7a1bdb 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/arkts/observable.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/arkts/observable.ts @@ -205,9 +205,8 @@ export function observableProxy(value: Value, parent?: ObservableHandler, return ObservableArray(value, parent, observed) as Value } else if (value instanceof Map) { return ObservableMap(value, parent, observed) as Value - // TODO: relates to https://gitee.com/rri_opensource/koala_projects/issues/IC14KY - // } else if (value instanceof Set) { - // return ObservableSet(value, parent, observed) as Value + } else if (value instanceof Set) { + return ObservableSet(value, parent, observed) as Value } else if (value instanceof Date) { return ObservableDate(value, parent, observed) as Value } @@ -628,21 +627,20 @@ class ObservableMap extends Map { } } -/* - * TODO: relates to https://gitee.com/rri_opensource/koala_projects/issues/IC14KY - * class ObservableSet extends Set { - static $_invoke(data: Map, parent?: ObservableHandler, observed?: boolean): Map { + private readonly elements: Map + + static $_invoke(data: Set, parent?: ObservableHandler, observed?: boolean): Set { return new ObservableSet(data, parent, observed); } constructor(data: Set, parent?: ObservableHandler, observed?: boolean) { - super(data) + this.elements = new Map() const handler = new ObservableHandler(parent) - // for (let item of data.values()) { - // if (observed === undefined) observed = ObservableHandler.contains(handler) - // super.add(observableProxy(item, handler, observed)) - // } + for (let item of data.values()) { + if (observed === undefined) observed = ObservableHandler.contains(handler) + this.elements.set(item, observableProxy(item, handler, observed)) + } ObservableHandler.installOn(this, handler) } @@ -650,58 +648,102 @@ class ObservableSet extends Set { return ObservableHandler.find(this) } + override toString(): string { + return new Set(this.elements.keys()).toString() + } + override get size(): number { this.handler?.onAccess() - return super.size + return this.elements.size } override has(value: T): boolean { this.handler?.onAccess() - return super.has(key) + return this.elements.has(value) } override add(value: T): this { - this.handler?.onModify() - super.add(value) + const handler = this.handler + let observable = value + if (handler) { + if (!this.elements.has(value)) handler.onModify() + const prev = this.elements.get(value) + if (prev) handler.removeChild(prev) + observable = observableProxy(value) + } + this.elements.set(value, observable) return this } override delete(value: T): boolean { - this.handler?.onModify() - return super.delete(key) + const handler = this.handler + if (handler) { + handler.onModify() + const prev = this.elements.get(value) + if (prev) handler.removeChild(prev) + } + return this.elements.delete(value) } override clear() { - this.handler?.onModify() - super.clear() + const handler = this.handler + if (handler) { + handler.onModify() + for (let value of this.elements.values()) { + handler!.removeChild(value) + } + } + this.elements.clear() } override keys(): IterableIterator { - this.handler?.onAccess() - return super.keys() + return this.values() } override values(): IterableIterator { this.handler?.onAccess() - return super.values() + return this.elements.values() } override $_iterator(): IterableIterator { - this.handler?.onAccess() - return super.$_iterator() + return this.values() } override entries(): IterableIterator<[T, T]> { this.handler?.onAccess() - return super.entries() + return new MappingIterator(this.elements.values(), (item) => [item, item]) } override forEach(callbackfn: (value: T, key: T, set: Set) => void) { this.handler?.onAccess() - super.forEach(callbackfn) + const it = this.elements.values() + while (true) { + const item = it.next() + if (item.done) return + callbackfn(item.value as T, item.value as T, this) + } + } +} + +class MappingIterator implements IterableIterator { + private it: IterableIterator + private mapper: (value: T) => V + + constructor(it: IterableIterator, fn: (value: T) => V) { + this.it = it + this.mapper = fn + } + + override next(): IteratorResult { + const item = this.it.next() + if (item.done) return new IteratorResult() + return new IteratorResult(this.mapper(item.value as T)) + } + + override $_iterator(): IterableIterator { + return this } } -*/ class ObservableDate extends Date { static $_invoke(value: Date, parent?: ObservableHandler, observed?: boolean): Date { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/typescript/double.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/typescript/double.ts index a8289f87c79..64ed41d2ac6 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/typescript/double.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/typescript/double.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/typescript/observable.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/typescript/observable.ts index 24709748a69..44066c80943 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/typescript/observable.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/src/typescript/observable.ts @@ -240,7 +240,22 @@ export function observableProxy(value: Value, parent?: ObservableHandler, }) return proxyObject(value, handler) } - // TODO: support set/map + if (value instanceof Map) { + const handler = new ObservableHandler(parent) + const data = proxyMapValues(value, handler, observed) + setObservable(data) + deleteObservable(data) + clearObservable(data) + return proxyMapOrSet(data, handler) + } + if (value instanceof Set) { + const handler = new ObservableHandler(parent) + const data = proxySetValues(value, handler, observed) + addObservable(data) + deleteObservable(data) + clearObservable(data) + return proxyMapOrSet(data, handler) + } const handler = new ObservableHandler(parent, isObserved(value)) if (handler.observed || observed) proxyFields(value, true, handler) return proxyObject(value, handler) @@ -402,3 +417,107 @@ function unshiftObservable(array: any) { } } } + +function proxyMapValues(data: Map, parent: ObservableHandler, observed?: boolean): Map { + if (observed === undefined) observed = ObservableHandler.contains(parent) + const result = new Map() + for (const [key, value] of data.entries()) { + result.set(key, observableProxy(value, parent, observed)) + } + return result +} + +function proxySetValues(data: Set, parent: ObservableHandler, observed?: boolean): Set { + // TODO: check if necessary to replace items of the set with observed objects as + // for complex objects add() function won't find original object inside the set of proxies + /* + if (observed === undefined) observed = ObservableHandler.contains(parent) + const result = new Set() + for (const value of data.values()) { + result.add(observableProxy(value, parent, observed)) + } + return result + */ + return data +} + +function proxyMapOrSet(value: any, observable: ObservableHandler) { + ObservableHandler.installOn(value, observable) + return new Proxy(value, { + get(target, property, receiver) { + if (property == OBSERVABLE_TARGET) return target + if (property == 'size') { + ObservableHandler.find(target)?.onAccess() + return target.size + } + const value: any = Reflect.get(target, property, receiver) + ObservableHandler.find(target)?.onAccess() + return typeof value == "function" + ? value.bind(target) + : value + }, + }) +} + +function addObservable(data: any) { + if (data.addOriginal === undefined) { + data.addOriginal = data.add + data.add = function (this, value: any) { + const observable = ObservableHandler.find(this) + if (observable && !this.has(value)) { + observable.onModify() + // TODO: check if necessary to replace items of the set with observed objects as + // for complex objects add() function won't find original object inside the set of proxies + // value = observableProxy(value, observable) + } + return this.addOriginal(value) + } + } +} + +function setObservable(data: any) { + if (data.setOriginal === undefined) { + data.setOriginal = data.set + data.set = function (this, key: any, value: any) { + const observable = ObservableHandler.find(this) + if (observable) { + observable.onModify() + observable.removeChild(this.get(key)) + value = observableProxy(value, observable) + } + return this.setOriginal(key, value) + } + } +} + +function deleteObservable(data: any) { + if (data.deleteOriginal === undefined) { + data.deleteOriginal = data.delete + data.delete = function (this, key: any) { + const observable = ObservableHandler.find(this) + if (observable) { + observable.onModify() + if (this instanceof Map) { + observable.removeChild(this.get(key)) + } else if (this instanceof Set) { + observable.removeChild(key) + } + } + return this.deleteOriginal(key) + } + } +} + +function clearObservable(data: any) { + if (data.clearOriginal === undefined) { + data.clearOriginal = data.clear + data.clear = function (this) { + const observable = ObservableHandler.find(this) + if (observable) { + observable.onModify() + Array.from(this.values()).forEach(it => observable.removeChild(it)) + } + return this.clearOriginal() + } + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/gn/command/npm.py b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/gn/command/npm.py new file mode 100755 index 00000000000..4f8208650d4 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/gn/command/npm.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# 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 subprocess +import sys +import os +import shutil +import argparse + +NPM_REPO = "https://repo.huaweicloud.com/repository/npm/" + +parser = argparse.ArgumentParser(description="npm command parser") +parser.add_argument("--root-path", help="root directory of koala repo") +parser.add_argument("--project-path", help="project directory in koala repo") +parser.add_argument("--node-path", help="nodejs path") +parser.add_argument("--arklink-path", help="ark-link path") +parser.add_argument("--es2panda-path", help="es2panda path") +parser.add_argument("--stdlib-path", help="stdlib path") +parser.add_argument("--target-out-path", help="out directory of built target", default=None) +parser.add_argument("--built-file-path", help="result of building", default=None) +parser.add_argument("--npm-args", nargs='+', help="npm command args") + + +args = parser.parse_args() + +root_path = args.root_path +project_path = args.project_path +node_path = args.node_path +arklink_path = args.arklink_path +es2panda_path = args.es2panda_path +ets_stdlib_path = args.stdlib_path + +target_out_path = args.target_out_path +built_file_path = args.built_file_path +npm_args = args.npm_args + +env = os.environ.copy() +env_orig = env["PATH"] +env["PATH"] = f"{node_path}:{env['PATH']}" + +if (es2panda_path != ""): + env["ES2PANDA_PATH"] = es2panda_path +if (arklink_path != ""): + env["ARKLINK_PATH"] = arklink_path +if (ets_stdlib_path != ""): + env["ETS_STDLIB_PATH"] = ets_stdlib_path + +koala_log = os.path.join(project_path, "koala_build.log") + +def install(dir): + os.chdir(dir) + try: + ret = subprocess.run(["npm", "install", "--registry", NPM_REPO, "--verbose"], capture_output=True, env=env, text=True, check=True) + with open(koala_log, "a+") as f: + f.write("\n") + f.write("install log:\n" + ret.stdout) + f.close() + except subprocess.CalledProcessError as e: + with open(koala_log, "a+") as f: + f.write("\n") + f.write("error message: "+ e.stderr + "\n") + f.close() + +def npm_command(dir, command): + os.chdir(dir) + try: + ret = subprocess.run(["npm"] + command, capture_output=True, env=env, text=True, check=True) + with open(koala_log, "a+") as f: + f.write("\n") + f.write("install log:\n" + ret.stdout) + f.close() + except subprocess.CalledProcessError as e: + with open(koala_log, "a+") as f: + f.write("\n") + f.write("error message: "+ e.output + "\n") + f.close() + +def main(): + install(root_path) + npm_command(project_path, npm_args) + + if target_out_path and built_file_path: + if not os.path.exists(built_file_path): + print(f"Error: Built file not found at {built_file_path}") + sys.exit(1) + + out_dir = os.path.join(target_out_path, os.path.basename(built_file_path)) + shutil.copy(built_file_path, out_dir) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/package.json index f93622c755d..f654dcbdcd5 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/package.json @@ -5,7 +5,10 @@ "build-common", "compat", "common", - "runtime" + "harness", + "runtime", + "demo-playground", + "compiler-plugin" ], "devDependencies": { "ts-node": "^10.7.0", @@ -18,7 +21,8 @@ "prepare": "cd node_modules/typescript && ts-patch install", "all:clean": "npm run clean --ws --if-present -s", "all:clean:unmemoized": "npm run clean:unmemoized --ws --if-present -s", - "compile": "npm run compile -w ./compat && npm run compile -w ./common && npm run compile -w ./runtime" + "compile": "npm run compile -w ./compat && npm run compile -w ./common && npm run compile -w ./harness && npm run compile -w ./runtime && npm run compile -w ./demo-playground && npm run compile -w ./compiler-plugin", + "build:incremental:gn": "npm run build:incremental:inc:ui2abc --prefix runtime" }, "dependencies": { "@koalaui/fast-arktsc": "1.5.15", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/annotations/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/annotations/index.ts index 7e51be7e2c8..11ec0d27174 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/annotations/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/annotations/index.ts @@ -1,17 +1,3 @@ -/* - * 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. - */ @Retention({policy: "SOURCE"}) export @interface memo {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/basic-concepts.md b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/basic-concepts.md deleted file mode 100644 index a9fadf46c6b..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/basic-concepts.md +++ /dev/null @@ -1,193 +0,0 @@ -# Basic concepts of the incremental UI building - -Incremental runtime is part of the declarative UI framework -designed to optimize calculations and rebuilding trees depending on states. -This document explains the basic concepts underlying the chosen approach. - -## 1. Positional memoization - -### Call graphs - -A call graph is a control-flow diagram, -which represents calling relationships between subroutines in a computer program. -Each node represents a function (or a method) -and each directional edge indicates that one function calls another one. - -![A call graph example](call.graph.drawio.svg) -> Figure 1. A call graph example - -### Idempotent functions - -Idempotence is the property of certain operations in mathematics and computer science -whereby they can be applied multiple times -without changing the result beyond the initial application. - -If all functions in some call graph are idempotent, then such graph is also idempotent. -Therefore, it's enough to call it only once and use the cached result later. - -### @memo functions - -The @memo function is a kind of idempotent function -that should recalculate the cached result when the used state has changed. -If none of the used states has changed, the @memo function is considered idempotent -and its cached result is used instead of recalculation. - -The @memo function can only be called within some @memo context, -i.e. from other @memo functions. -An attempt to call the @memo function without the @memo context -will cause a compiler error (in some cases a runtime error). - -```typescript -const state = mutableState("some text") - -/** @memo */ -function printAll() { - console.log("state: " + state.value) // recomposed on state change -} -``` - -Consider the example of a call graph shown in Figure 1. -Suppose that each of its functions is a @memo function. -Then the first time we evaluate `main entry`, -we need to call each used function in the specified order. -This initial calculation is called *composition*. - -Now assume that `create second paragraph` uses some state that has just changed. -This means that the cached result of this @memo function needs to be recalculated. -Also, `create body` must be recalculated too, because it uses `create second paragraph`. -Similarly, `main entry` must also be recalculated. -This partial recalculation of the call graph is called *recomposition*. -Thus, the recomposition of the considering example will look like this: -- compute the value of `main entry` - - use the cached value of `create prefix` - - compute the value of `create body` - - use the cached value of `create first paragraph` - - compute the value of `create second paragraph` - - use the cached value of `create third paragraph` - - use the cached value of `create postfix` - -### Parameters - -A @memo function can have parameters, -which (as well as states) affect its idempotence. -If some @memo function during recomposition computes a different argument, -the called @memo function will be recomputed even if its states are not changed. - -```typescript -const state = mutableState(10) - -/** @memo */ -function printAll() { - print(Math.floor(state.value / 10)) // recomposed on state change -} - -/** @memo */ -function print(value: number) { - console.log("parameter: " + value) // recomposed on parameter change -} -``` - -Consider the example above. -Both methods will be called during composition. -The argument for `print` will be `1`. -If the state value is changed, `printAll` will be recomposed -and the argument for `print` will be recalculated. - -Suppose the state value becomes `15`. -Then the argument will be `1`, and the recomposition of `print` will not occur. -But if the state value becomes `20`, the argument will be `2`. -Changing the parameter value will cause the recomposition of `print`, -and this value will be logged. - -### Positioning - -A @memo function can be called from another one several times. -Therefore, it is needed to distinguish between different calls. -For this purpose, *positional memoization* is used. -For each @memo function call, the compiler computes -the corresponding callsite key based on its position in the code. - -```typescript -const state1 = mutableState("some text") -const state2 = mutableState("separate text") - -/** @memo */ -function printAll() { - print("state1", state1.value) // recomposed on first state change - print("state2", state2.value) // recomposed on second state change -} - -/** @memo */ -function print(name: string, value: string) { - console.log(name + ": " + value) // recomposed on parameter change -} -``` - -In the example above, `print` is called twice during composition. -If a single state is changed, only the corresponding `print` is recomposed. -If both states are changed, `print` is recomposed twice, -even if the values of both states are equal. - -### Conditional constructs - -The @memo function can call other functions, both @memo and regular ones. -In addition, conditional statements can be used without any restrictions. - -```typescript -const state = mutableState(true) - -/** @memo */ -function print() { - const value = state.value ? random("ON") : random("OFF") - console.log("random value is " + value) -} - -/** @memo */ -function random(text: string): string { - return text + ": " + Math.random() -} -``` - -Consider the example above. -`print` has two different calls of `random`, -but only one of them is called during composition/recomposition -because of positional memoization. -When the state changes, -one call *leaves the composition* and another one *enters the composition*. -When a @memo function leaves the composition, all cached results are forgotten. - -Note that `random` is called with constant arguments and it does not use any states. -This means that this @memo function will be called only once during composition. -Therefore, the library `Math.random` will also be called only once, -and the calculated value will be cached for future use. - -### Loop constructs - -Positioning may be insufficient to distinguish -multiple calls at the same position in case of loops. -The current implementation allows to use loop statements -to iterate stable content only. -The example below contains ten `print` calls, -each of which is called with a constant argument. - -```typescript -/** @memo */ -function printAll() { - for (let i = 0; i < 10; i++) print(i) -} - -/** @memo */ -function print(index: number) { - console.log("index: " + index) -} -``` - -To resolve the positioning issue in loops, -the runtime provides additional @memo functions -to distinguish between calls on different iterations of the loop. -`RepeatWithKey`, `RepeatByArray`, and `RepeatRange` -allow to control the callsite key generation for each iteration. - -## 2. State management - -## 3. Build UI tree incrementally diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/call.graph.drawio.svg b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/call.graph.drawio.svg deleted file mode 100644 index 6f034476460..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/call.graph.drawio.svg +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - -
-
-
- main entry -
-
-
-
- - main entry - -
-
- - - - -
-
-
- create prefix -
-
-
-
- - create prefix - -
-
- - - - -
-
-
- create body -
-
-
-
- - create body - -
-
- - - - -
-
-
- create postfix -
-
-
-
- - create postfix - -
-
- - - - -
-
-
- create first paragraph -
-
-
-
- - create first paragraph - -
-
- - - - -
-
-
- create second paragraph -
-
-
-
- - create second paragraph - -
-
- - - - -
-
-
- create third paragraph -
-
-
-
- - create third paragraph - -
-
- - - - - - - - - - - - -
- - - - - Text is not SVG - cannot display - - - -
\ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/explicit-state.md b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/explicit-state.md deleted file mode 100644 index 7e681e9ab4a..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/docs/explicit-state.md +++ /dev/null @@ -1,642 +0,0 @@ -# Primitives for Explicit State Objects and Positional Memoization - -## Explicit State Interfaces - -The explicit state management interface allows to manipulate states as regular ArkTS objects. -This kind of primitive has proven to be useful in the industry and in our own experimental work. -It is a convenient implementation primitive. And it is a convenient user expression primitive. - -### The benefits - -#### Typing benefit - -The state objects explicitly differentiate the type of the value and the type of the state. - -#### Storage freedom - -The state objects can be stored global variables, local variables, class properties. They can be passed as function arguments. They can be placed in arrays and other standard data structures. - -#### Behaviour freedom - -The state interfaces are quite generic. But the implementation can be different. The state value updates can be done explicitly by user code (this is MutableState, see below), state values can be updated by implementation library, state value can change according some internal time based law allowing animated behavior. - -### The basic API structure - -The API consists of several areas: - - * State objects: several interfaces describing state abstraction - * Helper constructor functions that allow instantiate different kinds of states. - * "Construct and attach" helper functions. They instantiate a state of some kind and attach them to the tree. - -### The Interface - -#### State - -The most basic state interface is quite simple. - -``` -/** - * Individual state, wrapping a value of type `Value`. - */ -export interface State { - /** - * If state was modified since last UI computations. - */ - readonly modified: boolean - /** - * Current value of the state. - * State value doesn't change during memo code execution. - */ - readonly value: Value -} -``` -#### MutableState - -The most commonly used interface is - -``` -/** - * Individual mutable state, wrapping a value of type `Value`. - */ -export interface MutableState extends Disposable, State { - /** - * Current value of the state as a mutable value. - * You should not change state value from a memo code. - * State value doesn't change during memo code execution. - * In the event handlers and other non-memo code - * a changed value is immediately visible. - */ - value: Value -} -``` -#### ComputableState - -``` - -/** - * Individual computable state that provides recomputable value of type `Value`. - */ -export interface ComputableState extends Disposable, State { - /** - * If value will be recomputed on access. - */ - readonly recomputeNeeded: boolean -} - -``` - -### Constructor functions - -#### mutableState - -There is a constructor function to simplify instantiation of MutableState objects: - -``` -/** - * Creates new mutable state in the global state manager. - * This state is valid until it is manually detached from the manager. - * It will be detached automatically if it is in the {@link remember}. - * Note that thoughtless state disposing can lead to memory leaks. - * @param value - initial value to initialize the created state - * @param equivalent - optional value comparator for a state - * @param tracker - optional tracker of values assigned to a state - * @returns new mutable state trackable by memo-functions - */ -export function mutableState(value: T, equivalent?: Equivalent, tracker?: ValueTracker): MutableState -``` - -### Attachment Interfaces - -#### remember() - -The state objects can be cached in the UI tree. The basic attachment primitive is `remember` - -``` - -/** - * It calculates the value of the given lambda and caches its result. - * In contrast to the `memo` function, the given lambda is calculated only once - * even if it uses values of states (including parameters of @memo-functions). - * - * @param compute - a function to compute cacheable result - * @returns the last calculated value - * @see memo - */ -export function remember(compute: () => Value): Value - -``` - -#### memo() - -``` - -/** - * It calculates the value of the given lambda and caches its result. - * In contrast to the `remember` function, the given lambda can be recalculated - * if it uses values of states (including parameters of @memo-functions). - * If the given lambda does not use any state, it will be calculated only once. - * - * @param compute - a function to compute cacheable result - * @returns the last calculated value - * @see remember - * @experimental - */ -export function memo(compute: () => Value): Value -``` - -### Construct and remember helper functions - -#### rememberMutableState() - -This is the most regular instantiate+remember helper function. - -``` - -/** - * Creates remembered state which can be updated from anywhere, - * and if changed - all depending memo functions recache automatically. - * Note that you can specify the value directly for primitive values, - * which do not require computations or memory allocation. - * It is highly recommended to provide a lambda for all others values. - * - * @param initial - initial value supplier used on the state creation - * @returns a state remembered for the current code position - * @memo:intrinsic - */ -export function rememberMutableState(initial: (() => Value) | Value): MutableState -``` - -#### rememberMutableAsyncState() - -``` -/** - * Remember mutable state which is computed in async way and is undefined if promise - * is not fulfilled. - * - * @param compute function returning promise to compute the state - * @param initial value stored to the state - * @param onError callback called if promise was rejected - * @memo - */ -export function rememberMutableAsyncState(compute: () => Promise, initial?: Value, onError?: (error: Error) => void): MutableState -``` -#### rememberComputableState() - -``` -/** - * Remember mutable state which is - * re-computed in async way if key has changed - * and undefined while promise is not fulfilled. - * - * @param key a value to trigger state recomputation - * @param compute function returning promise to compute the state - * @param initial value stored to the state - * @param onError callback called if promise was rejected - * @memo - */ -export function rememberComputableState( - key: Key, - /** @skip:memo */ - compute: (key: Key) => Promise, - initial?: Value, - onError?: (error: Error) => void -): MutableState -``` - -#### rememberDisposableValue() - -``` - -/** - * It calculates the value of the given lambda, caches its result, - * and notifies, that this method is removed from the composition. - * - * @param compute - a function to compute cacheable result - * @param cleanup - a function to cleanup computed result on dispose - * @returns the last calculated value - * @see remember - * @memo:intrinsic - */ -export function rememberDisposable(compute: () => Value, cleanup: (value: Value | undefined) => void): Value - -``` - -#### rememberComputableValue() - -``` -/** - * Remember a value which is - * re-computed in async way if key has changed - * and undefined while promise is not fulfilled. - * - * @param key a value to trigger state recomputation - * @param compute function returning promise to compute the state - * @param initial value stored to the state - * @param onError callback called if promise was rejected - * @memo - */ -export function rememberComputableValue( - key: Key, - /** @skip:memo */ - compute: (key: Key) => Promise, - initial?: Value, - onError?: (e: Error) => void -): Value | undefined - -``` - -### Context local - -Context local state is a kind of state that allows named state scopes on the tree. - - -#### contextLocalScope() - -Creates a state, gives it a name and attaches it to the tree - -``` -/** - * Creates a named state with the specified value in the context scope. - * The specified value will be propagated immediately during recomposition. - * Note that the state name must not be dynamically changed. - * - * @param name - a name of a context state - * @param value - a value of a named state to share within the given content - * @param content - a scope content in which a named state is available - * @memo:intrinsic - */ -export function contextLocalScope( - name: string, - value: Value, - @memo - content: () => void -) -``` - -#### contextLocal() - -Finds the closest attached state with the given name up in the tree - -``` -/** - * @param name - a name of a context state - * @returns the named context state or `undefined` if it does not exist - * @memo:intrinsic - */ -export function contextLocal(name: string): State | undefined -``` - -#### contextLocalValue() - -Finds the closest attached state with the given name up in the tree and reurns its value - -``` -/** - * @param name - a name of a context state - * @returns a value of a context state - * @throws Error if a named context state does not exist - * @memo:intrinsic - */ -export function contextLocalValue(name: string): Value -``` - -### Positional memoization primitive functions - -#### Memo entry - -Memo entry is a family of functions to allow entering memoizing call chain. - -``` -/** - * This is where regular code can enter the memo realm. - * This function allows to run a memo function in a non-memo context. - * @internal - * @memo:entry - */ -export function memoEntry( - context: StateContext, - id: CallsiteKey, - @memo entry: () => R, -): R -``` - -``` -/** - * This is where regular code can enter the memo realm. - * This function allows to run a memo function in a non-memo context. - * @internal - * @memo:entry - */ -export function memoEntry1( - context: StateContext, - id: CallsiteKey, - @memo entry: (arg: T) => R, - arg: T, -): R -``` - -``` -/** - * This is where regular code can enter the memo realm. - * This function allows to run a memo function in a non-memo context. - * @internal - * @memo:entry - */ -export function memoEntry2( - memo_context: StateContext, - memo_id: CallsiteKey, - @memo entry: (arg1: T1, arg2: T2) => R, - arg1: T1, - arg2: T2, -): R -``` - -#### Memo bind - -These are functions transforming memo lambda arguments to memo lambda of lower arity by binding some arguments to given values. - -``` -export function memoBind( - @memo item: (arg: T) => void, - value: T -): @memo () => void - -``` - -``` -export function memoBind2( - @memo item: (arg1: T1, arg2: T2) => void, - value1: T1, - value2: T2 -): @memo () => void -``` - -## Positional Memoization - -### Semantics - -Functions marked with @memo provide "positional memoization semantics". -A function call, instead of evaluating the function again, returns the -same (memoized) value as the previous call at the same call site (position). -Unless any of two things happens: - 1. A value of any argument is changed - 2. Any state object the function is subscribed (see below) to is changed. - -### Subscription - -A memo function or a memo lambda subscribes to a state variable by the fact of reading its value. - -### Annotations - -There are several annotations used by the incremental runtime plugin - - * @memo - * @memo:entry - - -### Syntax - -The annotations are accepted at the following syntactic positions: - - -#### Function declaration - -``` -@memo -function foo() {} -``` - -#### Method declaration - -``` -class X { - @memo - foo() {} -} -``` - -#### Parameters of functional type - -``` -function foo( - @memo arg1: () => void -) -``` - -#### Lambda function literal -``` - @memo () => {...} -``` - - -#### Property declaration -``` -class X { - @memo public p -} -``` - -#### Function type declaration -``` -function foo(): - @memo () => void -``` - -### Memo code entry pointes @memo:entry -The places where regular code is allowed to enter memo realm are denoted @memo:entry. -The functions marked with @memo:entry are not memo themselves, -but they must provide enough implementation defined lexical context -for the memo call to succeed in their bodies. - -For example - -``` -/** @memo:entry */ -function entry( - context: Context, - id: MemoId, - @memo ui: () => void -) { - ui() -} -``` -### Inference and defaults - -For the first implementation we don't expect any type inference support. -There is the following simple inference allowing the user to omit memo markings. - -#### Call sites don't need special marks - -No special marking at the call site is needed. -Any call to an entity marked with @memo -(functions, methods, properties of functional types, variables of functional types, parameters of functional types etc) -including the entities declared in other modules -is automatically rewritten by the compiler. - -#### Lambda literal arguments - -Lambda literals passed as arguments to parameters marked as memo are treated by memo by default. For example: - -``` -function foo( - @memo content: () => void -) { - ... -} - - -foo(() => { // This lambda literal is assumed to be memo! - ... -}) -``` - -### Constraints - -#### memo code and state variables - -A memo function can only read state variable values. -A memo code can not write to a state variable. - -An attempt to assign a state variable will cause a compiler diagnostics or a runtime error. - -A memo function can create a non-memo lambda which contains an assignment to a state variable. -Such lambda can be called outside of memo context and is allowed to change the state variable value. - - -#### memo should only be called from memo code - -Any memo function should be called from another memo function. -An attempt to call a memo function in non-memo code will result in compiler diagnostics or a runtime error. - -See @memo:entry description for the details on how the implementation can initiate memo call sequence. - -Calling a non-memo code is allowed. -Although it is a good practice to call only pure functions without side effects. -As the memo function body is typically omitted because of positional memoisation. - - -### Implementation - -#### Annotations - -The annotations are to be implemented as compiler annotations. -For example: - -``` -@memo function foo() { - // ... -} -``` - - -## A vision for memo functions support in ArkTS - -We have three levels of desires of memo support in the static ArkTS language - -### Level 1 - -We'd like to have java-like code annotations (syntactically similar to TS decorators). -Like @Memo. -To be able to annotate callable declarations (functions; methods; lambdas; variables, parameters and properties of function types). -For example - -``` -@memo -function foo() { - // ... -} -``` - -We need the same set of annotations: @memo, @memo:intrinsic, @memo:entry and @skip:memo. -May be spelled differently (like @MemoIntrinsic). - -The implementation lowering should basically reproduce our current rewrite in the TS memo plugin. - -This lowering only needs to rewrite AST and read type information provided by the typechecker. -It needs to be able to read @Memo annotations from the other modules. - - -### Level 2 - -At the moment the typescript compiler doesn't help the user with type check and type inference of @memo functional types. -The only inference piece in the current TS compiler we have is the following - -``` -function foo( - /** @memo */ - content: () => void -) { - ... -} - - -foo(() => { // This lambda literal is assumed to be memo! - ... -}) -``` - -Just several examples of what would be nice: - -``` -let x = @memo n => { ... } // x is inferred to be of type @memo (int) => void - -function foo() { // foo return type is deduced as memo - return @memo (m, n) => {} -} - -// The right hand side is automatically promoted to @memo. -let y: @memo (String) => String = (s: String) => s - -let z: (String) => String = y // A type violation a memo assigned to non-memo. - -``` - - -The general rule seems to be: when there is an explicit type specified require exact memo/or non memo. When the type is induced propagate memo/non-memo information. - -After the inference is done we want the @Memo to stick to any functional type and only allow assigning memo types to memo types and non-memo to non-memo. - -That would also allow to drop the need to annotate variables, parameters and class properties as @Memo. Instead we can just annotate their types. -That would in general leave only two syntactic position for the @Memo annotation: on a function/method declaration and on a functional type. - - -In addition to the previous level, supporting this approach requires annotation stick to types. -And annotations need to participate in the inference and typecheking. -The plugin needs to interact with the type checker (may be provide the rules to handle the annotation). - - -### Level 3 - -memo function by themselves don't deal with anything UI specific. -This is just another semantics of function calls. - -It can be used whereever there is a need to incrementally update trees. -Like it can be used to implement a build system. - -If at some point we feel that it is a general useful mechanism and it is stable enough -we could promote @Memo annotation to a memo keyword. - -That would essentially turn the plugin supported AST transformation into regular lowerings. - -The compiler will have to enforce the typing and scoping rules -at the source as well as at the linker level. - -Also the compiler will need to answer the general questions such as for example, -how memo affects intermediate compiled artifacts, i.e. libraries. - -The question of stable ABI (for compatibility between releases and implementations) will need to be answered. -What is the stable runtime representation of memo functions? -What are the mechanism of compatibility under language and runtime evolution? - -### VM support and optimizations - -#### Optimizations - -The current implementation of memo semantics heavily relies on lambdas. -An efficient mechanisms of lambda instantiation and calls should benefit the performance. - -Aggressive inlining in the compiler or VM should also benefit the performance. - -#### Support - -The VM could provide intrinsics for efficient operations on positional id: compute, combine, compare diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/oh-package.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/oh-package.json5 new file mode 100644 index 00000000000..5dc6bc9a7ee --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/oh-package.json5 @@ -0,0 +1,36 @@ +{ + "name": "@koalaui/runtime", + "version": "1.4.1+devel", + "description": "", + "main": "./build/lib/src/index.js", + "types": "./build/lib/src/index.d.ts", + "files": [ + "build/lib/**/*.js", + "build/lib/**/*.d.ts" + ], + "scripts": { + "compile": "tsc -b .", + "compile:unmemoize": "tsc -b tsconfig-unmemoize.json", + "compile:test": "tsc -b tsconfig-test.json", + "clean": "rimraf build", + "clean:unmemoized": "rimraf unmemoized", + "test": "mocha", + "test:coverage": "nyc mocha", + "compile:arkts": "bash ../tools/panda/arkts/arktsc --arktsconfig arktsconfig.json --ets-module", + "compile:arkts:unmemoizing": "npm run compile:unmemoize && bash ../tools/panda/arkts/arktsc --arktsconfig arktsconfig-run-unmemoized.json --ets-module" + }, + "keywords": [], + "dependencies": { + "@koalaui/common": "1.4.1+devel", + "@koalaui/compat": "1.4.1+devel" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.20.0", + "@typescript-eslint/parser": "^5.20.0", + "eslint": "^8.13.0", + "eslint-plugin-unused-imports": "^2.0.0", + "mocha": "^9.2.2", + "source-map-support": "^0.5.21" + } + } + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/package.json index dca9a02fee5..bd168df9d1b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/package.json @@ -1,6 +1,6 @@ { "name": "@koalaui/runtime", - "version": "1.5.15+devel", + "version": "1.7.1+devel", "description": "", "main": "./build/lib/src/index.js", "types": "./build/lib/src/index.d.ts", @@ -20,8 +20,7 @@ "arkts:test:run": "bash ../tools/panda/arkts/ark build/runtime-tests.abc --ark-boot-files ../compat/build/compat.abc:../common/build/common.abc:../harness/build/harness.abc --ark-entry-point @koalaui.runtime-tests.test-arkts.tests.ETSGLOBAL::main", "arkts:test": "npm run panda:sdk:install && npm run build:compat && npm run build:common && npm run build:harness && npm run build:runtime:with:tests && npm run arkts:test:run", "unmemoize": "mkdir -p build/unmemoized/abc && mkdir -p build/test/lib && ets-tsc -b tsconfig-unmemoize.json && mkdir -p build/test/lib", - "prepare:unmemoize:test": "mkdir -p ./test-arkts/exec/ && cp ../../ui2abc/memo-plugin/test/executable/*.ts ./test-arkts/exec/", - "unmemoize:with:tests": "npm run prepare:unmemoize:test && npm run compile:all --prefix ../harness && mkdir -p build/unmemoized/abc && mkdir -p build/test/lib && ets-tsc -b tsconfig-unmemoize-with-tests.json && mkdir -p build/test/lib", + "unmemoize:with:tests": "npm run compile:all --prefix ../harness && mkdir -p build/unmemoized/abc && mkdir -p build/test/lib && ets-tsc -b tsconfig-unmemoize-with-tests.json && mkdir -p build/test/lib", "compile:arkts": "npm run unmemoize && ../tools/panda/arkts/arktsc --arktsconfig arktsconfig-run-unmemoized.json", "build:compat": "npm run build:compat --prefix ../compat", "build:compiler-plugin": "npm run compile --prefix ../compiler-plugin", @@ -34,24 +33,27 @@ "build:harness:inc": "npm run build:harness:inc --prefix ../harness", "build:runtime": "npm run build:runtime:inc", "build:runtime:inc": "npm run unmemoize && fast-arktsc --config ./arktsconfig-run-unmemoized.json --compiler ../tools/panda/arkts/arktsc --link-name ./build/runtime.abc && ninja ${NINJA_OPTIONS} -f build/unmemoized/abc/build.ninja", - "build:runtime:inc:ui2abc:restart": "npm run unmemoize && fast-arktsc --config ./ui2abcconfig-only-restart.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --file-option --restart-stages && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/build.ninja", + "build:runtime:inc:ui2abc:restart": "npm run unmemoize && fast-arktsc --config ./ui2abcconfig-only-restart.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --restart-stages && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/build.ninja", "annotate": "npm run compile --prefix ../../ui2abc/annotate && node ../../ui2abc/annotate", - "build:runtime:inc:ui2abc": "npm run annotate && fast-arktsc --config ./ui2abcconfig.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --file-option --restart-stages && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/build.ninja", + "build:runtime:inc:ui2abc": "npm run annotate && fast-arktsc --config ./ui2abcconfig.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --restart-stages && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/build.ninja", + "build:runtime:inc:ui2abc:recheck": "npm run annotate && fast-arktsc --config ./ui2abcconfig-recheck.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc && PANDA_SDK_PATH=../tools/panda/node_modules/@panda/sdk ninja ${NINJA_OPTIONS} -f build/recheck/build.ninja", "build:runtime:with:tests": "npm run unmemoize:with:tests && fast-arktsc --config ./arktsconfig-test-unmemoized.json --compiler ../tools/panda/arkts/arktsc --link-name ./build/runtime-tests.abc && ninja ${NINJA_OPTIONS} -f build/unmemoized/abc/build.ninja", "build:incremental:components": "npm run build:compat && npm run build:common && npm run build:runtime", "build:incremental:components:inc": "npm run build:compat:inc && npm run build:common:inc && npm run build:runtime:inc", "build:incremental:components:inc:ui2abc": "npm run build:compat:inc:ui2abc && npm run build:common:inc:ui2abc && npm run build:runtime:inc:ui2abc", + "build:incremental:components:inc:ui2abc:recheck": "npm run build:compat:inc:ui2abc && npm run build:common:inc:ui2abc && npm run build:runtime:inc:ui2abc:recheck", "link:incremental": "../tools/panda/arkts/arklink --output build/incremental.abc -- ../compat/build/compat.abc ../common/build/common.abc build/runtime.abc", "build:incremental": "npm run build:incremental:components && npm run link:incremental", "build:incremental:inc": "npm run build:incremental:components:inc && npm run link:incremental", "build:incremental:inc:ui2abc": "npm run build:incremental:components:inc:ui2abc && npm run link:incremental", + "build:incremental:inc:ui2abc:recheck": "npm run build:incremental:components:inc:ui2abc:recheck && npm run link:incremental", "clean:incremental": "npm run clean && npm run clean -C ../compat && npm run clean -C ../common" }, "keywords": [], "dependencies": { - "@koalaui/common": "1.5.15+devel", - "@koalaui/compat": "1.5.15+devel", - "@koalaui/harness": "1.5.15+devel" + "@koalaui/common": "1.7.1+devel", + "@koalaui/compat": "1.7.1+devel", + "@koalaui/harness": "1.7.1+devel" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.20.0", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/AnimatedState.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/AnimatedState.ts index ab50ecedb3d..1308eb70f93 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/AnimatedState.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/AnimatedState.ts @@ -26,9 +26,12 @@ import { ComputableState, MutableState, State, StateContext } from "../states/St * which value is changed according to the given animation. */ export interface AnimatedState extends State { - animation: TimeAnimation + getAnimation(): TimeAnimation + setAnimation(value: TimeAnimation): void readonly running: boolean - paused: boolean + getPaused(): boolean + setPaused(value: boolean): void + } /** @@ -51,7 +54,8 @@ export function animatedState(animation: TimeAnimation, startNow: boolean * to change the current value to the target one. */ export interface MutableAnimatedState extends MutableState { - animation: TimeAnimation + getAnimation(): TimeAnimation + setAnimation(value: TimeAnimation): void readonly running: boolean } @@ -137,25 +141,25 @@ class AnimatedStateImpl implements Disposable, AnimatedState { return this.runningState.value } - get paused(): boolean { + getPaused(): boolean { return this.pausedState.value } - set paused(paused: boolean) { + setPaused(paused: boolean) { this.pausedState.value = paused } - get animation(): TimeAnimation { + getAnimation(): TimeAnimation { return this.myAnimation } - set animation(animation: TimeAnimation) { + setAnimation(animation: TimeAnimation): void { if (this.myAnimation === animation) return // nothing to change this.myAnimation = animation - if (!this.paused) animation.onStart(this.timeProvider()) + if (!this.getPaused()) animation.onStart(this.timeProvider()) } - constructor(myAnimation: TimeAnimation, startNow: boolean, timeProvider?: () => int64) { + constructor(myAnimation: TimeAnimation, startNow: boolean, timeProvider: (() => int64)|undefined) { const manager = GlobalStateManager.instance if (timeProvider) { this.timeProvider = timeProvider @@ -176,22 +180,22 @@ class AnimatedStateImpl implements Disposable, AnimatedState { const paused = this.pausedState.value if (this.pausedState.modified) { if (paused) { - this.animation.onPause(time) + this.getAnimation().onPause(time) } else { - this.animation.onStart(time) + this.getAnimation().onStart(time) } } // compute value from the time provided - let newValue = this.animation.getValue(time) + let newValue = this.getAnimation().getValue(time) this.action?.(newValue) return newValue } finally { // update running state if needed - this.runningState.value = this.animation.running + this.runningState.value = this.getAnimation().running } }) if (startNow) { - this.animation.onStart(this.timeProvider()) + this.getAnimation().onStart(this.timeProvider()) } } @@ -212,7 +216,7 @@ class MutableAnimatedStateImpl implements MutableAnimatedState { } constructor(initial: Value, animationProvider: ImplicitAnimationProvider) { - this.animatedState = new AnimatedStateImpl(constAnimation(initial), true) + this.animatedState = new AnimatedStateImpl(constAnimation(initial), true, undefined) this.animationProvider = animationProvider } @@ -229,19 +233,19 @@ class MutableAnimatedStateImpl implements MutableAnimatedState { } set value(value: Value) { - this.animatedState.animation = this.animationProvider(this.value, value) + this.animatedState.setAnimation(this.animationProvider(this.value, value)) } get running(): boolean { return this.animatedState.running } - get animation(): TimeAnimation { - return this.animatedState.animation + getAnimation(): TimeAnimation { + return this.animatedState.getAnimation() } - set animation(animation: TimeAnimation) { - this.animatedState.animation = animation + setAnimation(animation: TimeAnimation): void { + this.animatedState.setAnimation(animation) } } @@ -253,7 +257,7 @@ class StateAnimatorImpl implements StateAnimator { constructor(parameter: P, animationProvider: ParametrizedAnimationProvider) { this.parameterState = GlobalStateManager.instance.mutableState

(parameter) - this.animatedState = new AnimatedStateImpl(animationProvider(parameter, undefined), true) + this.animatedState = new AnimatedStateImpl(animationProvider(parameter, undefined), true, undefined) this.animationProvider = animationProvider } @@ -264,7 +268,7 @@ class StateAnimatorImpl implements StateAnimator { set parameter(parameter: P) { if (refEqual(this.parameterState.value, parameter)) return // nothing to change this.parameterState.value = parameter - this.animatedState.animation = this.animationProvider(parameter, this.animatedState.value) + this.animatedState.setAnimation(this.animationProvider(parameter, this.animatedState.value)) } get value(): V { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/TimeAnimation.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/TimeAnimation.ts index d3843d4de02..0cb7f89f8bd 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/TimeAnimation.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/TimeAnimation.ts @@ -250,7 +250,10 @@ class TimeAnimationImpl implements TimeAnimation { running: boolean = false - constructor(compute: (time: int64) => Value, initial: int64 = 0) { + constructor( + compute: (time: int64) => Value, + initial: int64 = 0 + ) { this.lastState = initial this.lastValue = compute(initial) this.compute = compute @@ -298,7 +301,12 @@ class PeriodicAnimationImpl implements TimeAnimation { running: boolean = false - constructor(delay: int32, period: uint32, compute: (count: int64) => Value, initial: int64 = 0) { + constructor( + delay: int32, + period: uint32, + compute: (count: int64) => Value, + initial: int64 = 0 + ) { this.lastState = initial this.lastValue = compute(initial) this.compute = compute diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/memo.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/memo.ts index 06792a01685..8b2c8bf6862 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/memo.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/animation/memo.ts @@ -20,6 +20,7 @@ import { AnimatedState, ImplicitAnimationProvider, MutableAnimatedState, Paramet import { AnimationRange, NumberAnimationRange } from "./AnimationRange" import { Easing, EasingCurve } from "./Easing" import { AnimationSpec, TimeAnimation, animation, constAnimation, periodicAnimation, transition } from "./TimeAnimation" +import { __memo_context_type, __memo_id_type } from "../internals" /** * Function allowing to sample particular function with given rate. @@ -44,7 +45,7 @@ export function sampledValue(sampleRate: uint32, generator: (tick: int64) => */ /** @memo */ export function rememberAnimatedState(animation: () => TimeAnimation, startNow: boolean = false): AnimatedState { - return remember(() => animatedState(animation(), startNow)) + return remember((): AnimatedState => animatedState(animation(), startNow)) } /** @@ -77,7 +78,7 @@ export function rememberNumberTransition(on: boolean, duration: uint32, easing: /** @memo */ export function rememberTransition(on: boolean, duration: uint32, easing: EasingCurve, compute: AnimationRange, initial: boolean = on): AnimatedState { const state = rememberAnimatedState((): TimeAnimation => transition(duration, easing, compute, initial ? 1 : 0), on) - RunEffect(!on, (paused: boolean): void => { state.paused = paused }) + RunEffect(!on, (paused: boolean): void => { state.setPaused(paused) }) return state } @@ -91,7 +92,7 @@ export function rememberTransition(on: boolean, duration: uint32, easing: */ /** @memo */ export function rememberMutableAnimatedState(initial: Value, animationProvider: ImplicitAnimationProvider): MutableAnimatedState { - return remember(() => mutableAnimatedState(initial, animationProvider)) + return remember((): MutableAnimatedState => mutableAnimatedState(initial, animationProvider)) } /** @@ -104,7 +105,7 @@ export function rememberMutableAnimatedState(initial: Value, animationPro */ /** @memo */ export function rememberMutableAnimatedStateNumber(initial: float64, animationSpec: Partial): MutableAnimatedState { - return remember(() => mutableAnimatedState(initial, (from: float64, to: float64) => from == to + return remember((): MutableAnimatedState => mutableAnimatedState(initial, (from: float64, to: float64) => from == to ? constAnimation(to) : animation(animationSpec, NumberAnimationRange(from, to)))) } @@ -120,5 +121,5 @@ export function rememberMutableAnimatedStateNumber(initial: float64, animationSp */ /** @memo */ export function rememberAnimator(parameter: P, animationProvider: ParametrizedAnimationProvider): StateAnimator { - return remember(() => stateAnimator(parameter, animationProvider)) + return remember((): StateAnimator => stateAnimator(parameter, animationProvider)) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/index.ts index bc630ffe8df..2414d94b2c5 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/index.ts @@ -146,12 +146,14 @@ export { StateContext, StateManager, ValueTracker, + InternalScope, } from "./states/State" export { __context, __id, __key, + __hash, __memo_context_type, __memo_id_type, __memo_transformed, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/internals.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/internals.ts index 65939dfdefb..fb128360ac7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/internals.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/internals.ts @@ -38,3 +38,8 @@ export function __id(): KoalaCallsiteKey { export function __key(): KoalaCallsiteKey { throw new Error("All __key() references should have been transformed by the compiler plugin.") } + +export function __hash(value: string): KoalaCallsiteKey { + throw new Error("The __hash() function is only for source transformation tests.") +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/bind.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/bind.ts index e41c183a4aa..a48fc18a69e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/bind.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/bind.ts @@ -17,6 +17,7 @@ import { KoalaCallsiteKey } from "@koalaui/common" import { __context, __id } from "../internals" import { StateContext } from "../states/State" import { memoEntry1 } from "./entry" +import { __memo_context_type, __memo_id_type } from "../internals" /** @internal */ export class MemoCallbackContext { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/changeListener.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/changeListener.ts index b4fd4b1d35e..9f16778a250 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/changeListener.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/changeListener.ts @@ -17,6 +17,7 @@ import { KoalaCallsiteKey } from "@koalaui/common" import { scheduleCallback } from "../states/GlobalStateManager" import { StateContext } from "../states/State" import { __context, __id } from "../internals" +import { __memo_context_type, __memo_id_type } from "../internals" /** * Executes the specified function if the given value has changed. @@ -25,7 +26,7 @@ import { __context, __id } from "../internals" * @param listener - a function to perform if the given value has changed */ /** @memo:intrinsic */ -export function OnChange(value: Value, listener: (value: Value) => void) { +export function OnChange(value: Value, listener: (value: Value) => void): void { watch(__context(), __id(), false, value, listener) } @@ -36,7 +37,7 @@ export function OnChange(value: Value, listener: (value: Value) => void) * @param effect - a function to perform if the given value has changed or initialized */ /** @memo:intrinsic */ -export function RunEffect(value: Value, effect: (value: Value) => void) { +export function RunEffect(value: Value, effect: (value: Value) => void): void { watch(__context(), __id(), true, value, effect) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/contextLocal.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/contextLocal.ts index 756ed0ae256..7df85075396 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/contextLocal.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/contextLocal.ts @@ -15,6 +15,7 @@ import { __context, __id } from "../internals" import { State } from "../states/State" +import { __memo_context_type, __memo_id_type } from "../internals" /** * @param name - a name of a context state diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/entry.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/entry.ts index 894dece8796..b9389316ce7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/entry.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/entry.ts @@ -17,6 +17,7 @@ import { KoalaCallsiteKey, KoalaCallsiteKeys, KoalaProfiler } from "@koalaui/com import { GlobalStateManager } from "../states/GlobalStateManager" import { ComputableState, StateContext, StateManager } from "../states/State" import { IncrementalNode } from "../tree/IncrementalNode" +import { __memo_context_type, __memo_id_type } from "../internals" /** * @param node - a root node for the composition diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/node.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/node.ts index 73d13de3f68..4e99031630e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/node.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/node.ts @@ -16,7 +16,8 @@ import { className, uint32 } from "@koalaui/common" import { __context, __id } from "../internals" import { IncrementalNode } from "../tree/IncrementalNode" -import { memoEntry } from "./entry" +import { memoEntry1 } from "./entry" +import { __memo_context_type, __memo_id_type } from "../internals" /** * @param create - the node constructor is invoked only once, @@ -41,7 +42,7 @@ export function NodeAttach( update(__context().node as Node) else // reset ID addition to 0 to simplify the reuse process later - memoEntry(__context(), 0, () => { update(__context().node as Node) }) + memoEntry1(__context(), 0, update, __context().node as Node) } finally { scope.recache() } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/remember.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/remember.ts index 9627e44516a..aae64e3a362 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/remember.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/remember.ts @@ -17,6 +17,7 @@ import { functionOverValue } from "@koalaui/common" import { __context, __id } from "../internals" import { scheduleCallback } from "../states/GlobalStateManager" import { ArrayState, ControlledScope, MutableState } from "../states/State" +import { __memo_context_type, __memo_id_type } from "../internals" /** * It calculates the value of the given lambda and caches its result. @@ -167,7 +168,8 @@ function applyPromiseToState(promise: Promise, state: MutableState /** @memo */ export function rememberMutableAsyncState(compute: () => Promise, initial?: Value, onError?: (error: Error) => void): MutableState { const result = rememberMutableState(initial) - once(() => { applyPromiseToState(compute(), result, onError) }) + const callback = () => { applyPromiseToState(compute(), result, onError) } + once(callback) return result } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/repeat.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/repeat.ts index 150595d369d..3dec747b54c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/repeat.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/repeat.ts @@ -16,6 +16,7 @@ import { KoalaCallsiteKey, int32 } from "@koalaui/common" import { __context, __id } from "../internals" import { memoEntry1, memoEntry2 } from "./entry" +import { __memo_context_type, __memo_id_type } from "../internals" /** * Sequentially repeats the {@link action}. @@ -34,7 +35,7 @@ export function Repeat( count: int32, /** @memo */ action: (index: int32) => void -) { +): void { for (let i = 0; i < count; i++) { memoEntry1(__context(), i, action, i) } @@ -59,7 +60,7 @@ export function RepeatWithKey( key: (index: int32) => KoalaCallsiteKey, /** @memo */ action: (index: int32) => void -) { +): void { for (let i = 0; i < count; i++) { memoEntry1(__context(), key(i), action, i) } @@ -81,7 +82,7 @@ export function RepeatByArray( key: (element: T, index: int32) => KoalaCallsiteKey, /** @memo */ action: (element: T, index: int32) => void -) { +): void { const length = array.length for (let i = 0; i < length; i++) { const e: T = array[i] @@ -106,7 +107,7 @@ export function RepeatRange( key: (element: T, index: int32) => KoalaCallsiteKey, /** @memo */ action: (element: T, index: int32) => void -) { +): void { for (let i: int32 = start; i < end; i++) { const e: T = element(i) memoEntry2(__context(), key(e, i), action, e, i) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/testing.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/testing.ts index 8feb9486691..674956e946f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/testing.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/memo/testing.ts @@ -13,13 +13,14 @@ * limitations under the License. */ -import { uint32 } from "@koalaui/common" +import { int32, KoalaCallsiteKey, uint32 } from "@koalaui/common" import { GlobalStateManager } from "../states/GlobalStateManager" import { ComputableState, State, StateManager } from "../states/State" import { IncrementalNode } from "../tree/IncrementalNode" import { Disposable } from "../states/Disposable" import { memoRoot } from "./entry" import { NodeAttach } from "./node" +import { __memo_context_type, __memo_id_type } from "../internals" /** @internal */ export class TestNode extends IncrementalNode { @@ -45,16 +46,20 @@ export class TestNode extends IncrementalNode { /** @memo */ content: (node: TestNode) => void ) { - NodeAttach(() => new TestNode(), content) + NodeAttach(():TestNode => new TestNode(), content) } } /* parent node that has a Reusable pool */ export class ReusableTestNode extends TestNode { + constructor() { + super() + } + reusePool = new Map>() - override reuse(reuseKey: string): Disposable | undefined { + override reuse(reuseKey: string, id: KoalaCallsiteKey): Disposable | undefined { if (this.reusePool!.has(reuseKey)) { const scopes = this.reusePool!.get(reuseKey)!; return scopes.pop(); @@ -62,7 +67,7 @@ export class ReusableTestNode extends TestNode { return undefined; } - override recycle(reuseKey: string, child: Disposable): boolean { + override recycle(reuseKey: string, child: Disposable, id: KoalaCallsiteKey): boolean { if (!this.reusePool!.has(reuseKey)) { this.reusePool!.set(reuseKey, new Array()); } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/states/Dependency.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/states/Dependency.ts index ac791e5cd49..d00499d55f2 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/states/Dependency.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/states/Dependency.ts @@ -27,14 +27,14 @@ export interface Dependency { /** This class allows to store and update all dependencies. */ export class Dependencies { private frame = 0 - private dependencies: Set | undefined = undefined + private dependencies: Array | undefined = undefined private latest: Dependency | undefined = undefined /** Returns `true` if there are no dependencies to invalidate. */ get empty(): boolean { const dependencies = this.dependencies return dependencies - ? (dependencies.size == 0) + ? (dependencies.length == 0) : (this.latest === undefined) } @@ -43,13 +43,14 @@ export class Dependencies { if (dependency === undefined || dependency == this.latest || dependency.obsolete) return let dependencies = this.dependencies if (dependencies) { - dependencies.add(dependency) + // Array includes repeated elements, they will be processed in updateDependencies + dependencies.push(dependency) } else { const latest = this.latest if (latest) { - dependencies = new Set() - dependencies.add(latest) - dependencies.add(dependency) + dependencies = new Array() + dependencies.push(latest) + dependencies.push(dependency) this.dependencies = dependencies } } @@ -62,23 +63,15 @@ export class Dependencies { this.frame = 0 const dependencies = this.dependencies if (dependencies) { - let disposed: Array | undefined = undefined - const it = dependencies.values() - while (true) { - const result = it.next() - if (result.done) break - const dependency = result.value as Dependency - if (!updateDependency(invalidate, dependency)) { - if (disposed) { - disposed.push(dependency) - } else { - disposed = Array.of(dependency) + let dependenciesSet = new Set(dependencies); + this.dependencies = []; + const newDependencies = this.dependencies; + if (newDependencies) { + dependenciesSet.forEach((dependency: Dependency) => { + if (updateDependency(invalidate, dependency)) { + newDependencies.push(dependency); } - } - } - if (disposed) { - let index = disposed.length - while (0 < index--) dependencies.delete(disposed[index]) + }); } } else { const latest = this.latest diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/states/State.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/states/State.ts index 60395b0706b..aab34f593c2 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/states/State.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/states/State.ts @@ -595,7 +595,7 @@ class StateManagerImpl implements StateManager { updatableNode(node: Node, update: (context: StateContext) => void, cleanup?: () => void): ComputableState { this.checkForStateComputing() - const scope = new ScopeImpl(KoalaCallsiteKeys.empty, 0, (): Node => { + const scope = ScopeImpl.create(KoalaCallsiteKeys.empty, 0, (): Node => { update(this) return node }, cleanup === undefined ? undefined : (value: Node | undefined): void => { @@ -613,7 +613,7 @@ class StateManagerImpl implements StateManager { computableState(compute: (context: StateContext) => Value, cleanup?: (context: StateContext, value: Value | undefined) => void): ComputableState { if (this.current?.once == false) throw new Error("computable state created in memo-context without remember") this.checkForStateCreating() - const scope = new ScopeImpl(KoalaCallsiteKeys.empty, 0, (): Value => compute(this), cleanup === undefined ? undefined : (value: Value | undefined): void => { + const scope = ScopeImpl.create(KoalaCallsiteKeys.empty, 0, (): Value => compute(this), cleanup === undefined ? undefined : (value: Value | undefined): void => { cleanup?.(this, value) }) scope.manager = this @@ -803,19 +803,24 @@ class ScopeImpl implements ManagedScope, InternalScope, Computable parentScope: ManagedScope | undefined = undefined next: ManagedScope | undefined = undefined - private _id: KoalaCallsiteKey + private _id: KoalaCallsiteKey = -1 private _once: boolean = false private _node: IncrementalNode | undefined = undefined private _nodeRef: IncrementalNode | undefined = undefined - private readonly _reuseKey?: string /** need to store on Scope because not obtainable in every @method recache */ + private _reuseKey?: string /** need to store on Scope because not obtainable in every @method recache */ nodeCount: uint32 = 0 - constructor(id: KoalaCallsiteKey, paramCount: int32, compute?: () => Value, cleanup?: (value: Value | undefined) => void, reuseKey?: string) { - this._id = id // special type to distinguish scopes - this.params = paramCount > 0 ? new Array(paramCount) : undefined - this.myCompute = compute - this.myCleanup = cleanup - this._reuseKey = reuseKey + // Constructor with (compute?: () => Value, cleanup?: (value: Value | undefined) => void) + // signature causes es2panda recheck crash, so I have introduced a create + private constructor() {} + static create(id: KoalaCallsiteKey, paramCount: int32, compute?: () => V, cleanup?: (value: V | undefined) => void, reuseKey?: string): ScopeImpl { + const instance = new ScopeImpl() + instance._id = id // special type to distinguish scopes + instance.params = paramCount > 0 ? new Array(paramCount) : undefined + instance.myCompute = compute + instance.myCleanup = cleanup + instance._reuseKey = reuseKey + return instance } hasDependencies(): boolean { @@ -891,8 +896,8 @@ class ScopeImpl implements ManagedScope, InternalScope, Computable } } if (once != true && this.once) throw new Error("prohibited to create scope(" + KoalaCallsiteKeys.asString(id) + ") within the remember scope(" + KoalaCallsiteKeys.asString(this.id) + ")") - let reused = reuseKey ? this.nodeRef?.reuse(reuseKey) : undefined - const scope = reused ? reused as ScopeImpl : new ScopeImpl(id, paramCount, compute, cleanup, reuseKey) + let reused = reuseKey ? this.nodeRef?.reuse(reuseKey, id) : undefined + const scope = reused ? reused as ScopeImpl : ScopeImpl.create(id, paramCount, compute, cleanup, reuseKey) scope.manager = manager if (reused) { scope.recomputeNeeded = true @@ -1051,7 +1056,7 @@ class ScopeImpl implements ManagedScope, InternalScope, Computable private recycleOrDispose(child: ManagedScope): void { // TEMP: explicit compares to avoid compiler bug - const recycled = child.reuseKey !== undefined && this._nodeRef?.recycle(child.reuseKey!!, child) == true + const recycled = child.reuseKey !== undefined && this._nodeRef?.recycle(child.reuseKey!!, child, child.id) == true if (recycled) { // if parent node is also disposed, the recycled scopes would dispose in the ReusablePool if (!child.node) throw Error("reusable scope doesn't have a node") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/tree/IncrementalNode.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/tree/IncrementalNode.ts index 646060d3197..198c7073b04 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/tree/IncrementalNode.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/src/tree/IncrementalNode.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { className, uint32 } from "@koalaui/common" +import { className, KoalaCallsiteKey, uint32 } from "@koalaui/common" import { Disposable } from "../states/Disposable" import { ReadonlyTreeNode } from "./ReadonlyTreeNode" @@ -66,9 +66,10 @@ export class IncrementalNode implements Disposable, ReadonlyTreeNode { /** * Reuse a scope from the pool. * @param reuseKey - The type of the scope to reuse. + * @param id - The id of the scope to reuse. * @returns A recycled scope, or undefined if none is available. */ - reuse(reuseKey: string): Disposable | undefined { + reuse(reuseKey: string, id: KoalaCallsiteKey): Disposable | undefined { return undefined } @@ -76,9 +77,10 @@ export class IncrementalNode implements Disposable, ReadonlyTreeNode { * Recycle a scope by adding it to the recycler pool for reuse. * @param scope - The scope to recycle. * @param reuseKey - The type of the scope (used as the key in the pool). + * @param id - The id of the scope to recycle. * @return true if child is successfully recycled */ - recycle(reuseKey: string, child: Disposable): boolean { + recycle(reuseKey: string, child: Disposable, id: KoalaCallsiteKey): boolean { return false } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/test-arkts/tests.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/test-arkts/tests.ts index 0c015540a29..95172ddaaf8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/test-arkts/tests.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/test-arkts/tests.ts @@ -26,8 +26,7 @@ import { __ARKTEST__ as state_basics } from "./states/state_basics.test" import { __ARKTEST__ as State } from "./states/State.test" import { __ARKTEST__ as TreeNode } from "./tree/TreeNode.test" import { __ARKTEST__ as TreePath } from "./tree/TreePath.test" -import { __ARKTEST__ as basic_test } from "./exec/basic.test" suite("runtime", () => { - Array.of(basic_test, Easing, MarkableQueue, bind, changeListener, contextLocal, remember, repeat, Journal, /* state_basics, */State, TreeNode, TreePath) + Array.of(Easing, MarkableQueue, bind, changeListener, contextLocal, remember, repeat, Journal, /* state_basics, */State, TreeNode, TreePath) }) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/ui2abcconfig-recheck.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/ui2abcconfig-recheck.json new file mode 100644 index 00000000000..546e563c9ad --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/ui2abcconfig-recheck.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "package": "@koalaui/runtime", + "outDir": "build/recheck", + "baseUrl": "./ets", + "paths": { + "@koalaui/common": ["../../common/src"], + "@koalaui/compat": ["../../compat/src/arkts"], + "@koalaui/runtime/annotations": ["../annotations"] + }, + "plugins": [ + { + "transform": "@koalaui/memo-plugin/ParserTransformer", + "stage": "parsed", + "contextImport": "../internals", + "name": "memo" + }, + { + "transform": "@koalaui/memo-plugin", + "stage": "checked", + "contextImport": "../internals", + "name": "memo", + "manuallyDisableInsertingImport": true + } + ] + }, + "include": ["ets/**/*.ts"], + "exclude": ["ets/index.ts", "ets/internals.ts"] +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/test-utils/scripts/register.js b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/test-utils/scripts/register.js index 6e7df5f8c20..1d2f986a833 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/test-utils/scripts/register.js +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/test-utils/scripts/register.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/package.json new file mode 100644 index 00000000000..b689a85c634 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/package.json @@ -0,0 +1,29 @@ +{ + "name": "@koalaui/multi-pass", + "version": "1.0.0", + "description": "", + "main": "lib/index.js", + "bin": "lib/index.js", + "files": [ + "lib/*.js", + "rules.json" + ], + "scripts": { + "clean": "rimraf out lib", + "run": "npm run compile && node . --input-dirs ../../../arkoala-arkts/user/build/unmemoized/ --rules rules.json --output-dir ./tmp", + "compile": "WEBPACK_NO_MINIMIZE=true webpack --config webpack.config.node.js" + }, + "keywords": [], + "dependencies": { + "@types/node": "^18.0.0", + "commander": "^10.0.0", + "typescript": "^4.9.5" + }, + "devDependencies": { + "copy-webpack-plugin": "^12.0.2", + "rimraf": "^6.0.1", + "ts-loader": "^9.5.1", + "webpack": "^5.95.0", + "webpack-cli": "^5.1.4" + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/rules.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/rules.json new file mode 100644 index 00000000000..a7ee6635265 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/rules.json @@ -0,0 +1,4 @@ +[ + ["construct(\\.*)", "CONSTRUCT($1)"], + ["onClick(\\.*)", "ON_CLICK($1)"] +] \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/src/main.ts new file mode 100644 index 00000000000..6420044e824 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/src/main.ts @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 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 { program } from "commander" +import * as fs from "fs" +import * as path from "path" +import { minimatch } from 'minimatch' + +let replacedLines = 0 + +const options = program + .option('--input-dirs ', 'Path to input file(s), comma separated') + .option('--output-dir ', 'Path to output') + .option('--rules ', 'Path JSON file with rules') + .option('--includes ', 'Which files to process, *.ts by default') + .parse() + .opts() + +main(options.inputDirs, options.rules, options.outputDir, options.includes?.split(",") ?? ["**/*.ts"]) + +function findMatching(base: string, include: string[], exclude: string[]): string[] { + return fs.readdirSync(base, { recursive: true, withFileTypes: true }) + .map(it => path.join(it.parentPath, it.name)) + .filter(it => include.some(value => minimatch(it, path.join(base, value), {matchBase: true}))) + .filter(it => !exclude.some(value => minimatch(it, path.join(base, value), {matchBase: true}))) +} + +function main(inputDirs: string, rules: string, outputDir: string, include: string[]) { + let config = JSON.parse(fs.readFileSync(rules, 'utf8')) as string[2][] + let baseDir = path.resolve(inputDirs) + let exclude: string[] = [] + const files = findMatching(baseDir, include, exclude) + if (files.length == 0) { + throw new Error(`No files matching include "${include.join(",")}" exclude "${exclude.join(",")}"`) + } + fs.mkdirSync(outputDir, { recursive: true }) + multiReplace(inputDirs, outputDir, config, files) +} + +function multiReplace(inputDir: string, outputDir: string, config: string[2][], files: string[]) { + console.log(`Replace per ${config.map(it => `${it[0]} => ${it[1]}`)} in ${files.join(", ")} out to ${outputDir}`) + let base = path.resolve(inputDir) + let regexps: [RegExp, string][] = config.map(it => [new RegExp(it[0]), it[1]]) + files.forEach(file => { + const wholeFile = fs.readFileSync(file, 'utf-8').split(/\r?\n/) + const result: string[] = [] + wholeFile.forEach(line => { + result.push(processPerRules(line, regexps)) + }) + let rel = path.relative(base, file) + let newDir = path.join(outputDir, path.dirname(rel)) + fs.mkdirSync(newDir, { recursive: true }) + fs.writeFileSync(path.join(newDir, path.basename(rel)), result.join("\n")) + }) + console.log(`Replaced ${replacedLines} lines`) +} + +function processPerRules(line: string, rules: [RegExp, string][]): string { + let procesedLine = line + rules.forEach(rule => { + procesedLine = procesedLine.replace(rule[0], rule[1]) + }) + if (procesedLine != line) replacedLines++ + return procesedLine +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/tsconfig.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/tsconfig.json new file mode 100644 index 00000000000..6653c5b1dc2 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/multi-pass/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "es2017", + "moduleResolution": "node", + "composite": true, + "incremental": true, + "declarationMap": true, + "sourceMap": true, + "declaration": true, + "noEmitOnError": true, + "strict": true, + "skipLibCheck": true, + "removeComments": false, + "outDir": "build", + }, + "include": [ + "src/*.ts" + ] +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/arkts/std-lib/global.d.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/arkts/std-lib/global.d.ts index ee76c1d3b06..15bfc962afb 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/arkts/std-lib/global.d.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/arkts/std-lib/global.d.ts @@ -1,18 +1,3 @@ -/* - * 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. - */ - declare type int32 = number declare type int8 = number declare type float32 = number diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/package.json index 3962624acdc..89753bba2ab 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/package.json @@ -8,6 +8,7 @@ "rimraf": "^6.0.1" }, "scripts": { + "panda:patch": "git apply patch/es2panda_lib.idl.patch", "panda:sdk:check-install": "npm ls @panda/sdk || npm run panda:sdk:install", "panda:sdk:install": "npm install --prefix . --no-save @panda/sdk@${PANDA_SDK_VERSION:-next}", "panda:sdk:clean": "rimraf ./node_modules", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/patch/es2panda_lib.idl.patch b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/patch/es2panda_lib.idl.patch new file mode 100644 index 00000000000..aedb3d7989a --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/patch/es2panda_lib.idl.patch @@ -0,0 +1,27 @@ +--- ./node_modules/@panda/sdk/ohos_arm64/include/tools/es2panda/generated/es2panda_lib/es2panda_lib.idl 2025-04-28 17:25:03.787222095 +0300 ++++ ./node_modules/@panda/sdk/ohos_arm64/include/tools/es2panda/generated/es2panda_lib/es2panda_lib.idl 2025-04-28 17:28:54.616765363 +0300 +@@ -1779,7 +1779,10 @@ + + namespace ir { + +-[Entity=Class, c_type=es2panda_AstNode] interface NumberLiteral: Literal { ++[Entity=Class, Es2pandaAstNodeType=52, c_type=es2panda_AstNode] interface NumberLiteral: Literal { ++ ++ /* [[nodiscard]] const util::StringView &Str() const noexcept */ ++ [get] String StrConst(es2panda_Context context); + ir.AstNode Create(es2panda_Context ctx, i32 value); + ir.AstNode Create1(es2panda_Context ctx, i64 value); + ir.AstNode Create2(es2panda_Context ctx, f64 value); +@@ -2487,12 +2490,6 @@ + void SetTypeParams(es2panda_Context context, ir.TSTypeParameterInstantiation typeParams); + }; + +-[Entity=Class, Es2pandaAstNodeType=52, c_type=es2panda_AstNode] interface NumberLiteral: Literal { +- +- /* [[nodiscard]] const util::StringView &Str() const noexcept */ +- [get] String StrConst(es2panda_Context context); +-}; +- + [Entity=Class, Es2pandaAstNodeType=124, c_type=es2panda_AstNode] interface TSFunctionType: TypeNode { + + /* explicit TSFunctionType(FunctionSignature &&signature, ArenaAllocator *const allocator) */ diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/BUILD.gn b/frameworks/bridge/arkts_frontend/koala_mirror/interop/BUILD.gn new file mode 100644 index 00000000000..72953e4eb81 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/BUILD.gn @@ -0,0 +1,51 @@ +# 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("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/arkui/ace_engine/ace_config.gni") + +interop_root = "" + +node_version = "v16.20.2" +host_arch = "${host_os}-${host_cpu}" + +action("interop.abc") { + script = "gn/command/npm.py" + outputs = [ + "$target_out_dir/interop.abc" + ] + args = [ + "--root-path", rebase_path(".."), + "--project-path", rebase_path("."), + "--node-path", rebase_path("//prebuilts/build-tools/common/nodejs/node-${node_version}-${host_arch}/bin"), + "--arklink-path", rebase_path("${static_linker_build_path}"), + "--es2panda-path", rebase_path("${ets2abc_build_path}"), + "--stdlib-path", rebase_path("//arkcompiler/runtime_core/static_core/plugins/ets/stdlib"), + "--npm-args", "run", "build:interop:gn" + ] + + deps = [ + "${ohos_ets_api_deps}", + "${ohos_ets_arkts_deps}", + ] + + external_deps = ets2abc_build_deps + external_deps += static_linker_build_deps +} + +group("interop") { + deps = [ + "$interop_root:interop.abc" + ] +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/gn/command/npm.py b/frameworks/bridge/arkts_frontend/koala_mirror/interop/gn/command/npm.py new file mode 100755 index 00000000000..0ec200567bb --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/gn/command/npm.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# 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 subprocess +import sys +import os +import shutil +import argparse + +NPM_REPO = "https://repo.huaweicloud.com/repository/npm/" + +parser = argparse.ArgumentParser(description="npm command parser") +parser.add_argument("--root-path", help="root directory of koala repo") +parser.add_argument("--project-path", help="project directory in koala repo") +parser.add_argument("--node-path", help="nodejs path") +parser.add_argument("--arklink-path", help="ark-link path") +parser.add_argument("--es2panda-path", help="es2panda path") +parser.add_argument("--stdlib-path", help="stdlib path") +parser.add_argument("--target-out-path", help="out directory of built target", default=None) +parser.add_argument("--built-file-path", help="result of building", default=None) +parser.add_argument("--npm-args", nargs='+', help="npm command args") + + +args = parser.parse_args() + +root_path = args.root_path +project_path = args.project_path +node_path = args.node_path +arklink_path = args.arklink_path +es2panda_path = args.es2panda_path +ets_stdlib_path = args.stdlib_path + +target_out_path = args.target_out_path +built_file_path = args.built_file_path +npm_args = args.npm_args + +env = os.environ.copy() +env_orig = env["PATH"] +env["PATH"] = f"{node_path}:{env['PATH']}" + +if (es2panda_path != ""): + env["ES2PANDA_PATH"] = es2panda_path +if (arklink_path != ""): + env["ARKLINK_PATH"] = arklink_path +if (ets_stdlib_path != ""): + env["ETS_STDLIB_PATH"] = ets_stdlib_path + +koala_log = os.path.join(project_path, "koala_build.log") + +def install(dir): + os.chdir(dir) + try: + ret = subprocess.run(["npm", "install", "--registry", NPM_REPO, "--verbose"], capture_output=True, env=env, text=True, check=True) + with open(koala_log, "a+") as f: + f.write("\n") + f.write("install log:\n" + ret.stdout) + f.close() + except subprocess.CalledProcessError as e: + with open(koala_log, "a+") as f: + f.write("\n") + f.write("error message: "+ e.stderr + "\n") + f.close() + +def npm_command(dir, command): + os.chdir(dir) + try: + ret = subprocess.run(["npm"] + command, capture_output=True, env=env, text=True, check=True) + with open(koala_log, "a+") as f: + f.write("\n") + f.write("install log:\n" + ret.stdout + node_path + es2panda_path + ets_stdlib_path) + f.close() + except subprocess.CalledProcessError as e: + with open(koala_log, "a+") as f: + f.write("\n") + f.write("error message: "+ e.output + "\n") + f.close() + +def main(): + install(root_path) + npm_command(project_path, npm_args) + + if target_out_path and built_file_path: + if not os.path.exists(built_file_path): + print(f"Error: Built file not found at {built_file_path}") + sys.exit(1) + + out_dir = os.path.join(target_out_path, os.path.basename(built_file_path)) + shutil.copy(built_file_path, out_dir) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/meson.build b/frameworks/bridge/arkts_frontend/koala_mirror/interop/meson.build index 9b0e15cc40a..b76f7344fe8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/meson.build +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/meson.build @@ -1,3 +1,16 @@ +# 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. + project('InteropNativeModule', 'c', 'cpp', version: '0.1', default_options: ['cpp_std=c++17', 'buildtype=release'] diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/meson_options.txt b/frameworks/bridge/arkts_frontend/koala_mirror/interop/meson_options.txt index 1e7adce0ba6..0496ac5b57a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/meson_options.txt +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/meson_options.txt @@ -1,3 +1,16 @@ +# 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. + option('vm_kind', type : 'string', value : '', description : 'VM type') option('jdk_dir', type : 'string', value : '', diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/oh-package.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/interop/oh-package.json5 new file mode 100644 index 00000000000..96d62e6ba57 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/oh-package.json5 @@ -0,0 +1,58 @@ +{ + "name": "@koalaui/interop", + "version": "1.4.1+devel", + "description": "", + "files": [ + "build/lib/src/**/*.js", + "build/lib/src/**/*.d.ts" + ], + "main": "./build/lib/src/interop/index.js", + "exports": { + ".": "./build/lib/src/interop/index.js", + "./*.js": "./build/lib/src/interop/*.js", + "./*": "./build/lib/src/interop/*.js" + }, + "imports": { + "#common/wrappers": { + "browser": "./build/lib/src/wasm/wrappers/index.js", + "node": "./build/lib/src/napi/wrappers/index.js" + }, + "#common/wrappers/*": { + "browser": "./build/lib/src/wasm/wrappers/*.js", + "node": "./build/lib/src/napi/wrappers/*.js" + } + }, + "types": "./index.d.ts", + "typesVersions": { + "*": { + "*": ["./build/lib/src/interop/*"] + } + }, + "scripts": { + "clean": "tsc -b . --clean && rimraf dist build types", + "ets-api": "node scripts/download-ets-api.mjs", + "compile": "tsc -b .", + "compile:ohos": "npm run ets-api && npm run compile", + "compile:all": "npm run compile:ohos", + "compile:arkts": "bash ../tools/panda/arkts/arktsc --arktsconfig arktsconfig.json", + "lint": "eslint src test components", + "test:wasm:coverage": "NODE_OPTIONS='--conditions browser --no-experimental-fetch' nyc mocha", + "test:wasm": "NODE_OPTIONS='--conditions browser --no-experimental-fetch' mocha", + "test:node:coverage": "nyc mocha", + "test:node": "mocha", + "test:coverage": "npm run test:node:coverage", + "test": "npm run test:node", + "watch": "tsc -b . --watch" + }, + "keywords": [], + "dependencies": { + "@koalaui/common": "1.4.1+devel" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.20.0", + "@typescript-eslint/parser": "^5.20.0", + "eslint": "^8.13.0", + "eslint-plugin-unused-imports": "^2.0.0", + "source-map-support": "^0.5.21" + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/interop/package.json index e868ba47ddf..6c3a88f4d27 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/package.json @@ -1,6 +1,6 @@ { "name": "@koalaui/interop", - "version": "1.5.15+devel", + "version": "1.7.1+devel", "description": "", "workspaces": [ "../incremental/build-common", @@ -43,6 +43,7 @@ "clean": "rimraf dist build types", "compile": "ets-tsc -b .", "build:interop": "npm run build:interop:inc", + "build:interop:gn": "npm run build:interop:inc", "build:interop:inc": "fast-arktsc --config ./arktsconfig.json --compiler ../incremental/tools/panda/arkts/arktsc --link-name ./build/interop.abc && ninja ${NINJA_OPTIONS} -f build/abc/build.ninja", "clean:interop": "npm run clean", "lint": "eslint src test components", @@ -94,7 +95,7 @@ "keywords": [], "dependencies": { "@types/node": "^18.0.0", - "@koalaui/common": "1.5.15+devel" + "@koalaui/common": "1.7.1+devel" }, "devDependencies": { "@ohos/hypium": "1.0.6", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/configure.mjs b/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/configure.mjs deleted file mode 100644 index 04a49aafd55..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/configure.mjs +++ /dev/null @@ -1,502 +0,0 @@ -// This is a simplified version of the original configure.mjs script, with only targers -// "hzvm-ohos-arm32" and "hzvm-ohos-arm64" -// "panda-ohos-arm32" and "panda-ohos-arm64" - -/* - * 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 fs from "fs"; -import { exit, platform } from "process"; -import chalk from "chalk"; -import path from "path"; -import minimist from "minimist" - -import { findMeson, CrossFile, requireEnv, relativeToSourceRoot } from "./utils.mjs" - -import { createRequire } from 'node:module'; -import { ohConf } from "../../tools/ohos-tools/ohconf.mjs" -import { OH_SDK_COMPONENT, ohSdkInfo } from "../../tools/ohos-tools/ohos-sdk/download-ohos-sdk.mjs" -import url from "url" -const require = createRequire(import.meta.url); - -const __dirname = path.dirname(url.fileURLToPath(import.meta.url)) - -const OHCONF = ohConf(path.join(__dirname, "../../tools/ohos-tools/ohos-sdk/.ohconf.json")) - -let cliOptions = minimist(process.argv.slice(2)) - -let targets = cliOptions._; -let help = cliOptions.h || cliOptions.help; -let verbose = cliOptions.v || cliOptions.verbose; -let reconfigure = cliOptions.reconfigure; -let wipe = cliOptions.wipe; -let clean = cliOptions.clean; -let dryRun = cliOptions.n || cliOptions["dry-run"]; -let root = cliOptions.root || path.join(__dirname, "..") - -let nodeDir = cliOptions["node-dir"] || process.env.NODE_DIR || ''; -let nodeBuildType = cliOptions["node-buildtype"] || process.env.NODE_BUILDTYPE || "release"; - -let pandaBuildType = process.env.PANDA_BUILDTYPE || "Release"; -let pandaRuntimeOptions = process.env.PANDA_RUNTIME_OPTIONS || "jit:aot"; - -if (targets.length === 0 || help) { - usage(); - exit(1); -} - -const meson = findMeson(); - -if (nodeDir && !path.isAbsolute(nodeDir)) { - console.log("NODE_DIR must be an absolute path") - exit(1); -} - -nodeDir && console.log(`NODE_DIR: ${chalk.green(nodeDir)}`); -console.log(`NODE_BUILDTYPE: ${chalk.green(nodeBuildType)}`); - -targets.forEach(target => configure(target)); - -function getNdkRoot() { - if (process.env["ANDROID_NDK_ROOT"]) return process.env["ANDROID_NDK_ROOT"] - let dir = path.join(requireEnv("ANDROID_SDK_ROOT"), 'ndk') - let ndks = fs.readdirSync(dir).sort() - if (ndks.length < 1) throw new Error("Unexpected NDK dir layout") - return path.join(dir, ndks[ndks.length - 1]) -} - -function getJdkRoot() { - if (process.env["JAVA_HOME"]) return process.env["JAVA_HOME"] - throw new Error("Cannot find JAVA_HOME") -} - -export function configure(target) { - let buildDirName = `build-${target}`; - - if (fs.existsSync(buildDirName)) { - if (clean) { - !dryRun && fs.rmSync(buildDirName, { recursive: true, force: true }); - reconfigure = wipe = false; - } else if (!reconfigure && !wipe) { - console.log(chalk.yellow(`target ${target} already configured`) + - "\n restart with --clean, --wipe or --reconfigure to configure again"); - return; - } - } else { - reconfigure = false; - wipe = false; - } - - // TODO add architecture - let destDir = target; - let binDir = target == "wasm" ? destDir : void 0; // Wasm output can be an executable only - let libDir = target == "wasm" ? void 0 : destDir; - let vmKind = target.split('-')[0] - - const vsenv = process.platform === "win32" && target === "node-host" - - const doConfigure = (isJvm, ...crossFiles) => { - verbose && console.log(`Configuring target ${chalk.bold(target)}\n`); - try { - meson.configure({ - builddir: "build-" + target, - prefix: path.resolve(".runtime-prebuilt"), - wipe, - reconfigure, - verbose, - binDir, - libDir, - crossFiles, - dryRun, - vsenv, - options: { - "vm_kind": vmKind || undefined, - "jdk_dir": isJvm ? getJdkRoot() : null, - "vmloader": target.includes('vmloader'), - } - }); - verbose && console.log(); - console.log(`Target ${chalk.bold(target)}: ${chalk.green("SUCCESS")}`); - } catch (err) { - console.log(err); - console.log(`Target ${chalk.bold(target)}: ${chalk.red("FAIL")}`); - } - } - - switch (target) { - case "hzvm-ohos-arm32": - case "hzvm-ohos-arm64": - case "hzvm-ohos-arm32-vmloader": - case "hzvm-ohos-arm64-vmloader": - case "panda-ohos-arm32": - case "panda-ohos-arm64": - doConfigure(false, createOhosCrossFile(target)); - break; - case "panda-linux-x64": - case "panda-linux-arm64": - doConfigure(false, createLinuxCrossFile(target)); - break; - case "panda-windows-x64": - doConfigure(false, createWindowsClangCrossFile("x64")) - break; - case "node-macos-x64": - case "node-macos-arm64": - case "panda-macos-x64": - case "panda-macos-arm64": - doConfigure(false, createMacosCrossFile(target)); - break; - default: - console.log(chalk.yellow("unsupported target '" + target + "'")); - } -} - -function createWasmCrossFile() { - let cf = CrossFile("wasm"); - let emcc = "emcc", empp = "em++", emar = "emar"; - if (platform == "win32") { - if (process.env.EMSDK) { - let emsdk = process.env.EMSDK; - console.log("EMSDK: " + chalk.green(emsdk)); - let prefix = path.join(emsdk, "upstream", "emscripten"); - emcc = path.join(prefix, emcc + ".bat"); - empp = path.join(prefix, empp + ".bat"); - emar = path.join(prefix, emar + ".bat"); - } else { - console.log("EMSDK: " + chalk.red("not found") + "\r\n" + - chalk.gray(" set environment variable EMSDK=")); - exit(1); - } - } - cf.section("binaries", { - c: emcc, - cpp: empp, - ar: emar, - }) - .section("host_machine", { - system: 'emscripten', - cpu_family: 'wasm32', - cpu: 'wasm32', - endian: 'little', - }) - .close(); - - return cf.path; -} - -function createWindowsClangCrossFile(arch) { - let cf = CrossFile("windows-clang-" + arch); - let cpu = arch === "x64" ? "x86_64" : "x86"; // TODO check - let xwinHome = path.join(__dirname, "../prebuilt/wincrt") - if (!fs.existsSync(xwinHome)) xwinHome = requireEnv("WINCRT_HOME") - console.log(`Using CRT from ${chalk.bold(xwinHome)}`) - - let link_args = [ - `-L${xwinHome}/crt/lib/${cpu}`, - `-L${xwinHome}/sdk/lib/um/${cpu}`, - `-L${xwinHome}/sdk/lib/ucrt/${cpu}`, - ] - - let include_dirs = [ - `/I${xwinHome}/crt/include`, - `/I${xwinHome}/sdk/include/ucrt`, - `/I${xwinHome}/sdk/include/um`, - `/I${xwinHome}/sdk/include/shared`, - ] - - let llvmBin = (() => { - let llvmHome = process.env.LLVM_HOME; - if (!llvmHome) { - if (process.platform === "win32") { - llvmHome = path.join(process.env.ProgramFiles, "LLVM") - } else { - llvmHome = "/usr/lib/llvm-14" // Ubuntu - } - if (fs.existsSync(llvmHome)) { - console.log(`Using LLVM from ${chalk.bold(llvmHome)}`) - } else { - console.log(`Using LLVM from ${chalk.bold("PATH")}`) - llvmHome = null - } - } - if (llvmHome) { - return bin => path.join(llvmHome, 'bin', bin) - } else { - return bin => bin // search in PATH - } - })() - - cf.section("binaries", { - // Ninja must have /I flags for feature detection, so adding them here - c: [llvmBin("clang-cl"), ...include_dirs], - cpp: [llvmBin("clang-cl"), ...include_dirs], - ar: llvmBin("llvm-lib"), - }) - .section("built-in options", { - c_args: ['-Wno-unused-local-typedef'], - cpp_args: ['-Wno-unused-local-typedef'], - - c_link_args: [...link_args], - cpp_link_args: [...link_args], - }) - .section("host_machine", { - system: "windows", - cpu_family: cpu, - cpu: cpu, - endian: "little", - }) - .close(); - - return cf.path; -} - -function createLinuxCrossFile(target) { - let cf = CrossFile(target, root); - - let suffix = "" - if (platform == 'win32') { - suffix = ".exe"; - } - - let cpu = 'unknown' - if (target == 'panda-linux-arm64' || target == 'panda-linux-arm64-vmloader') { - cpu = 'aarch64' - } else if (target == 'panda-linux-x64' || target == 'panda-linux-x64-vmloader') { - cpu = 'x64' - } else { - throw "Unknown target " + target; - } - - cf.section("binaries", { - c: 'clang' + suffix, - cpp: 'clang++' + suffix, - }) - .section("host_machine", { - system: 'linux', - cpu_family: cpu, - cpu: cpu, - endian: 'little', - }) - .close(); - - return cf.path; -} - -function createAndroidCrossFile(target) { - let cf = CrossFile(target); - let ndkRoot = getNdkRoot() - let compilersPath = "" - let suffix = "" - if (platform == 'win32') { - compilersPath = path.join(ndkRoot, "toolchains", "llvm", "prebuilt", "windows-x86_64", "bin"); - suffix = ".cmd"; - } else - compilersPath = path.join(ndkRoot, "toolchains", "llvm", "prebuilt", platform + "-x86_64", "bin"); - compilersPath = path.resolve(compilersPath); - - let cpu = 'unknown' - if (target == 'android-arm64') - cpu = 'aarch64' - else if (target == 'android-x64') - cpu = 'x86_64' - else - throw "Unknown target " + target; - - cf.section("binaries", { - c: path.join(compilersPath, cpu + "-linux-android28-clang" + suffix), - cpp: path.join(compilersPath, cpu + "-linux-android28-clang++" + suffix), - ar: path.join(compilersPath, "llvm-ar"), - }) - .section("host_machine", { - system: 'android', - cpu_family: cpu, - cpu: cpu, - endian: 'little', - }) - .close(); - - return cf.path; -} - -function createOhosCrossFile(target) { - let cf = CrossFile(target, root); - let sdkNativePath = "" - let compilersPath = "" - let suffix = "" - if (platform == 'win32') { - suffix = ".exe"; - } - if (platform == 'linux') { - compilersPath = path.resolve('../arkoala-arkts/tools/compiler/llvm-toolchain/bin') - } else { - sdkNativePath = ohSdkInfo(OHCONF.sdkPath(), OH_SDK_COMPONENT.native).path - compilersPath = path.join(sdkNativePath, "llvm", "bin") - } - - let cflags = [ - '--sysroot=' + path.resolve(`../arkoala-arkts/tools/compiler/sysroot-${ target.includes('arm64') ? 'arm64' : 'arm' }`) - ] - let cpu = 'unknown' - if (target == 'hzvm-ohos-arm64' || target == 'hzvm-ohos-arm64-vmloader' || target == 'panda-ohos-arm64') { - cpu = 'aarch64' - cflags = [ - ...cflags, - '--target=aarch64-linux-ohos' - ] - } else if (target == 'hzvm-ohos-arm32' || target == 'hzvm-ohos-arm32-vmloader' || target == 'panda-ohos-arm32') { - cpu = 'armv7-a' - cflags = [ - ...cflags, - '--target=armv7-a-linux-ohos' - ] - } else { - throw "Unknown target " + target; - } - - cf.section("binaries", { - c: path.join(compilersPath, "clang" + suffix), - c_ld: path.join(compilersPath, "ld.lld" + suffix), - cpp: path.join(compilersPath, "clang++" + suffix), - cpp_ld: path.join(compilersPath, "ld.lld" + suffix), - ar: path.join(compilersPath, "llvm-ar" + suffix), - }) - .section("built-in options", { - c_args: cflags, - c_link_args: cflags, - cpp_args: cflags, - cpp_link_args: cflags - }) - .section("host_machine", { - system: 'ohos', - cpu_family: cpu, - cpu: cpu, - endian: 'little', - }) - .close(); - - return cf.path; -} - -function createIosCrossFile(target) { - let cf = CrossFile(target); - - let cflags = [ - ] - let cpu = 'unknown' - if (target == 'jsc-ios-arm64') { - cpu = 'aarch64' - cflags = [ - ...cflags, - '-arch', 'arm64', - "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" - ] - } else if (target == 'jsc-ios-x64') { - cpu = 'x86_64' - cflags = [ - ...cflags, - '-arch', 'x86_64', - "-isysroot", '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk' - ] - } else { - throw "Unknown target " + target; - } - - cf.section("binaries", { - c: 'clang', - cpp: 'clang++', - objcpp: 'clang++', - ar: 'ar', - strip: 'strip' - }) - .section("built-in options", { - c_args: cflags, - c_link_args: cflags, - cpp_args: cflags, - cpp_link_args: cflags, - objcpp_args: cflags, - objcpp_link_args: cflags, - }) - .section("host_machine", { - system: 'ios', - cpu_family: cpu, - cpu: cpu, - endian: 'little', - }) - .close(); - - return cf.path; -} - -function createMacosCrossFile(target) { - let cf = CrossFile(target); - - let cflags = [ - ] - let cpu = 'unknown' - if (target == 'panda-macos-arm64' || target == 'node-macos-arm64') { - cpu = 'aarch64' - cflags = [ - ...cflags, - '-arch', 'arm64', - ] - } else if (target == 'panda-macos-x64' || target == 'node-macos-x64') { - cpu = 'x86_64' - cflags = [ - ...cflags, - '-arch', 'x86_64', - ] - } else { - throw "Unknown target " + target; - } - - cf.section("binaries", { - c: 'clang', - cpp: 'clang++', - objcpp: 'clang++', - ar: 'ar', - strip: 'strip', - }) - .section("built-in options", { - c_args: cflags, - c_link_args: cflags, - cpp_args: cflags, - cpp_link_args: cflags, - objcpp_args: cflags, - objcpp_link_args: cflags, - }) - .section("host_machine", { - system: 'darwin', - cpu_family: cpu, - cpu: cpu, - endian: 'little', - }) - .close(); - - return cf.path; -} - -function usage() { - console.log(`USAGE: node configure.mjs [OPTION]... TARGET [TARGET]... - -TARGET = wasm | node-android-x64 | node-android-arm64 | jni-host | node-host | hzvm-ohos-arm64 | hzvm-ohos-arm32 | jsc-ios-arm64 | jsc-ios-x64 | node-macos-x64 | node-macos-arm64 compilation target - -OPTIONS: - -h, --help show this help and exit - -v, --verbose show Meson output - -n, --dry-run do not emit files and do not perform meson configuring - --wipe wipe build directory and reconfigure - --reconfigure reconfigure build directory (use if options were changed) - --clean remove build directory before configuring -`) -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/utils.mjs b/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/utils.mjs deleted file mode 100644 index c2e50d669fb..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/utils.mjs +++ /dev/null @@ -1,248 +0,0 @@ -/* - * 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 fs from "fs" -import { exit } from "process" -import { spawnSync } from "child_process" -import chalk from "chalk" -import path from "path" -import url from "url" - -const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); - -class Version { - constructor(version) { - let [major, minor, patch] = version.split(/\./).map(x => +x); - this.major = major; - this.minor = minor; - this.patch = patch; - } - - toString() { - return `${this.major}.${this.minor}.${this.patch}`; - } -} - -export function toIniValue(value) { - if (typeof value == "string") { - value = value.replace("'", "\\'"); - return `'${value}'`; - } else if (Array.isArray(value)) { - let res = '' - for (let i in value) { - res += toIniValue(value[i]) + (i < value.length - 1 ? ', ' : '') - } - return '[' + res + ']'; - } else { - return value.toString(); - } -} - - -export function CrossFile(target, root = path.join(__dirname, '..')) { - let filename = target + '.ini'; - let filepath = path.join(root, filename); - - let lines = [] - return { - section(name, values) { - lines.push(`\n[${name}]\n`); - if (values) { - for (let prop in values) { - if (values.hasOwnProperty(prop)) { - this.property(prop, values[prop]); - } - } - } - return this; - }, - property(name, value) { - value = toIniValue(value); - lines.push(`${name} = ${value}\n`); - return this; - }, - close() { - fs.writeFileSync(filepath, lines.join('')); - }, - get path() { - return filepath; - } - } -} - -class Meson { - #version; - - constructor(version) { - this.#version = new Version(version); - } - - get version() { - return this.#version; - } - - configure(options) { - let builddir = options.builddir; - let crossFiles = options.crossFiles || []; - let defs = options.options || {}; - let dryRun = options.dryRun || false; - - let args = ["setup", builddir]; - if (options.prefix) { - args.push("--prefix", options.prefix); - } - if (options.binDir) { - args.push("--bindir", options.binDir); - } - if (options.libDir) { - args.push("--libdir", options.libDir); - } - for (const file of crossFiles) { - args.push("--cross-file", file); - } - for (const def in defs) { - let value = defs[def]; - if (defs.hasOwnProperty(def) && value != null) { - args.push(`-D${def}=${value}`); - } - } - if (options.wipe) { - args.push("--wipe"); - } - if (options.reconfigure) { - args.push("--reconfigure"); - } - if (options.vsenv) { - // Force MSVC instead of clang - args.push("--vsenv"); - } - if (options.vm_kind) { - args.push(`-Dvm_kind=${options.vm_kind}`); - } - console.log(`> meson ${args.join(' ')}`); - if (!dryRun) { - let stdio = options.verbose ? ['inherit', 'inherit', 'inherit'] : void 0; - let env = process.env - let meson = spawnSync("meson", args, { encoding: "utf8", stdio, env }); - if (meson.status != 0) { - throw new Error("failed to configure"); - } - } - } -} - -export function findMeson() { - try { - let version = spawnSync("meson", ["-v"], { encoding: "utf8" }).output.join('').trim(); - console.log("Meson: " + chalk.green(version)); - return new Meson(version); - } catch (err) { - console.log("Meson: " + chalk.red("NOT FOUND")); - exit(1); - } -} - -export function findNinja() { - try { - let version = spawnSync("ninja", ["--version"], { encoding: "utf8" }).output.join('').trim(); - console.log("Ninja: " + chalk.green(version)); - return { version: new Version(version) }; - } catch (err) { - console.log("Ninja: " + chalk.red("NOT FOUND")); - exit(1); - } -} - -export function findPython() { - try { - let version = spawnSync("python3", ["--version"], { encoding: "utf8" }).output.join('').trim(); - version = version.replace(/^Python\s*/i, ""); - console.log("Python: " + chalk.green(version)); - return { version: new Version(version) }; - } catch (err) { - console.log("Python: " + chalk.red("NOT FOUND")); - exit(1); - } -} - -export function requireEnv(name, description) { - let value = process.env[name]; - if (value) { - console.log(`${name}: ${chalk.green(value)}`); - return value; - } else { - console.log(name + ": " + chalk.red("not found") + "\r\n" + - chalk.gray(` set environment variable ${name}=<${description}>`)); - exit(1); - } -} - -export function relativeToSourceRoot(abspath) { - let sourceRoot = path.resolve(__dirname, ".."); - return path.relative(sourceRoot, abspath); -} - -export function sourceRoot() { - return path.resolve(__dirname, ".."); -} - -class CMake { - #version; - - constructor(version) { - this.#version = new Version(version); - } - - get version() { - return this.#version; - } - - configure(options) { - let builddir = options.builddir; - let srcdir = options.srcdir - let defs = options.defs; - let dryRun = options.dryRun || false; - - let args = ['-GNinja', `-S${srcdir}`, `-B${builddir}`]; - for (const def in defs) { - let value = defs[def]; - if (defs.hasOwnProperty(def) && value != null) { - args.push(`-D${def}=${value}`); - } - } - console.log(`> cmake ${args.join(' ')}`); - if (!dryRun) { - let stdio = options.verbose ? ['inherit', 'inherit', 'inherit'] : void 0; - let cmake = spawnSync("cmake", args, { - encoding: "utf8", - stdio - }); - if (cmake.status != 0) { - throw new Error("failed to configure"); - } - } - } -} - -export function findCmake() { - try { - let version = spawnSync("cmake", ["--version"], { encoding: "utf8" }).output.join('').trim(); - console.log("CMake: " + chalk.green(version)); - return new CMake(version); - } catch (err) { - console.log("CMake: " + chalk.red("NOT FOUND")); - exit(1); - } -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/InteropNativeModule.ts b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/InteropNativeModule.ts index 4e8b046772b..002decba73d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/InteropNativeModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/InteropNativeModule.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,7 +11,7 @@ * 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 { int32, int64 } from "@koalaui/common"; import { KPointer, KUint8ArrayPtr, KInt, KSerializerBuffer } from "./InteropTypes"; @@ -55,7 +55,7 @@ export class InteropNativeModule { native static _LoadVirtualMachine(arg0: int32, arg1: string, arg2: string): int32 native static _RunApplication(arg0: int32, arg1: int32): boolean native static _StartApplication(appUrl: string, appParams: string): KPointer - native static _EmitEvent(eventType: int32, target: int32, arg0: int32, arg1: int32): void + native static _EmitEvent(eventType: int32, target: int32, arg0: int32, arg1: int32): string native static _CallForeignVM(context:KPointer, callback: int32, data: KSerializerBuffer, dataLength: int32): int32 native static _SetForeignVMContext(context: KPointer): void native static _RestartWith(page: string): void diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/SerializerBase.ts b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/SerializerBase.ts index dd6e76211c8..4ce785f63b4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/SerializerBase.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/SerializerBase.ts @@ -51,18 +51,32 @@ export class Tags { static OBJECT = 107 } -export function runtimeType(value: Object|String|number|undefined|null): int32 { - let type = typeof value - if (type == "number") return RuntimeType.NUMBER - if (type == "string") return RuntimeType.STRING - if (type == "undefined") return RuntimeType.UNDEFINED - if (type == "object") return RuntimeType.OBJECT - if (type == "boolean") return RuntimeType.BOOLEAN - if (type == "bigint") return RuntimeType.BIGINT - if (type == "function") return RuntimeType.FUNCTION - if (type == "symbol") return RuntimeType.SYMBOL +export function runtimeType(value: T): int32 { + if (value === undefined) + return RuntimeType.UNDEFINED; - throw new Error(`bug: ${value} is ${type}`) + if (value === null) + return RuntimeType.OBJECT; + + if (value instanceof String) + return RuntimeType.STRING + + if (value instanceof Numeric) + return RuntimeType.NUMBER + + if (value instanceof Boolean) + return RuntimeType.BOOLEAN + + if (value instanceof BigInt) + return RuntimeType.BIGINT + + if (value instanceof Function) + return RuntimeType.FUNCTION + + if (value instanceof Object) + return RuntimeType.OBJECT + + throw new Error(`bug: ${value} is ${typeof value}`) } export function registerCallback(value: object): int32 { @@ -98,7 +112,7 @@ export abstract class CustomSerializer { class DateSerializer extends CustomSerializer { constructor() { - super(Array.of("Date" as string)) + super(new Array("Date" as string)) } serialize(serializer: SerializerBase, value: object, kind: string): void { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/loadLibraries.ts b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/loadLibraries.ts index 33238bc6081..feda358f44b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/loadLibraries.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/arkts/loadLibraries.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,18 +11,21 @@ * 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. - */ +*/ const nativeModuleLibraries: Map = new Map() export function loadNativeLibrary(library: string) { + console.log(`[loadLibraries] Loading ${library} [${library}]`) loadLibrary(library) } export function registerNativeModuleLibraryName(nativeModule: string, libraryName: string) { + console.log(`[loadLibraries] Registered ${libraryName} as ${nativeModule}`) nativeModuleLibraries.set(nativeModule, libraryName) } export function loadNativeModuleLibrary(nativeModule: string) { + console.log(`[loadLibraries] Loading ${nativeModule} [${nativeModuleLibraries.get(nativeModule) ?? nativeModule}]`) loadLibrary(nativeModuleLibraries.get(nativeModule) ?? nativeModule) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cangjie/cjpm.toml b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cangjie/cjpm.toml index e909dcd4044..94a97320227 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cangjie/cjpm.toml +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cangjie/cjpm.toml @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,7 +11,7 @@ * 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. - */ +*/ [dependencies] [package] diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/callback-resource.cc b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/callback-resource.cc index 32ed23e5a01..8ae2f7206aa 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/callback-resource.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/callback-resource.cc @@ -11,7 +11,7 @@ * 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. - */ +*/ #undef KOALA_INTEROP_MODULE #define KOALA_INTEROP_MODULE InteropNativeModule diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/cangjie/convertors-cj.cc b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/cangjie/convertors-cj.cc index 724c5bbb040..ebb0dac2fe6 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/cangjie/convertors-cj.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/cangjie/convertors-cj.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,4 +11,4 @@ * 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. - */ \ No newline at end of file +*/ \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/common-interop.cc b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/common-interop.cc index 4686a831433..e740bc8973e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/common-interop.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/common-interop.cc @@ -251,6 +251,7 @@ typedef KNativePointer (*StartApplication_t)(const char* appUrl, const char* app typedef KBoolean (*RunApplication_t)(const KInt arg0, const KInt arg1); typedef const char* (*EmitEvent_t)(const KInt type, const KInt target, const KInt arg0, const KInt arg1); typedef void (*RestartWith_t)(const char* page); +typedef const char* (*LoadView_t)(const char* className, const char* params); void* getImpl(const char* path, const char* name) { static void* lib = nullptr; @@ -317,6 +318,16 @@ void impl_RestartWith(const KStringPtr& page) { } KOALA_INTEROP_V1(RestartWith, KStringPtr) +#ifdef KOALA_ANI +KStringPtr impl_LoadView(const KStringPtr& className, const KStringPtr& params) { + static LoadView_t impl = nullptr; + if (!impl) impl = reinterpret_cast(getImpl(nullptr, "LoadView")); + const char* result = impl(className.c_str(), params.c_str()); + return KStringPtr(result, strlen(result), true); +} +KOALA_INTEROP_2(LoadView, KStringPtr, KStringPtr, KStringPtr) +#endif // KOALA_ANI + KNativePointer impl_Malloc(KLong length) { const auto ptr = static_cast(malloc(length)); if (ptr == nullptr) { @@ -640,6 +651,15 @@ KStringPtr impl_Utf8ToString(KVMContext vmContext, KByte* data, KInt offset, KIn KOALA_INTEROP_CTX_3(Utf8ToString, KStringPtr, KByte*, KInt, KInt) #endif +#if defined(KOALA_NAPI) || defined(KOALA_ANI) +KStringPtr impl_RawUtf8ToString(KVMContext vmContext, KNativePointer data) { + auto string = (const char*)data; + KStringPtr result(string, strlen(string), false); + return result; +} +KOALA_INTEROP_CTX_1(RawUtf8ToString, KStringPtr, KNativePointer) +#endif + #if defined(KOALA_NAPI) || defined(KOALA_JNI) || defined(KOALA_CJ) || defined(KOALA_ETS_NAPI) || defined(KOALA_ANI) KStringPtr impl_StdStringToString(KVMContext vmContext, KNativePointer stringPtr) { std::string* string = reinterpret_cast(stringPtr); diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/interop-types.h b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/interop-types.h index 7efb52ea642..2cf6f188f5b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/interop-types.h +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/interop-types.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,7 +11,7 @@ * 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. - */ +*/ #ifndef _INTEROP_TYPES_H_ #define _INTEROP_TYPES_H_ diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/tracer.h b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/tracer.h index ac7089c86f7..e3ac0397f37 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/tracer.h +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/tracer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,7 +11,7 @@ * 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. - */ +*/ #ifndef _KOALA_TRACER_ #define _KOALA_TRACER_ diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/vmloader.cc b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/vmloader.cc index 6b04eefaa49..a5306f8fb25 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/vmloader.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/vmloader.cc @@ -151,6 +151,7 @@ struct VMEntry { void* enter; void* emitEvent; void* restartWith; + void* loadView; ForeignVMContext foreignVMContext; }; @@ -483,6 +484,8 @@ struct AppInfo { const char* emitEventMethodSig; const char* restartWithMethodName; const char* restartWithMethodSig; + const char* loadViewMethodName; + const char* loadViewMethodSig; }; #ifdef KOALA_JNI @@ -496,6 +499,8 @@ const AppInfo javaAppInfo = { "(IIJ)Z", "emitEvent", "(IIII)Ljava/lang/String;", + "UNUSED", + "()V" }; #endif @@ -510,6 +515,8 @@ const AppInfo pandaAppInfo = { "IIJ:Z", "emitEvent", "IIII:Lstd/core/String;", + "UNUSED", + "I:I" }; const AppInfo harnessAppInfo = { "@koalaui/ets-harness/src/EtsHarnessApplication/EtsHarnessApplication", @@ -538,6 +545,8 @@ const AppInfo harnessAniAppInfo = { "IIII:Lstd/core/String;", "restartWith", "Lstd/core/String;:V", + "UNUSED", + "I:I" }; const AppInfo aniAppInfo = { "L@ohos/arkui/Application/Application;", @@ -549,6 +558,10 @@ const AppInfo aniAppInfo = { "IIJ:Z", "emitEvent", "IIII:Lstd/core/String;", + "UNUSED", + "I:I", + "loadView", + "Lstd/core/String;Lstd/core/String;:Lstd/core/String;", }; #endif @@ -627,11 +640,7 @@ extern "C" DLL_EXPORT KNativePointer StartApplication(const char* appUrl, const } return nullptr; } -#if defined (KOALA_OHOS_ARM64) - auto useNativeLog = true; -#else auto useNativeLog = false; -#endif auto app = etsEnv->NewGlobalRef(etsEnv->CallStaticObjectMethod( appClass, create, etsEnv->NewStringUTF(appUrl), etsEnv->NewStringUTF(appParams), @@ -706,11 +715,7 @@ extern "C" DLL_EXPORT KNativePointer StartApplication(const char* appUrl, const return nullptr; } -#if defined (KOALA_OHOS_ARM64) - ani_boolean useNativeLog = ANI_TRUE; -#else ani_boolean useNativeLog = ANI_FALSE; -#endif ani_string appUrlString {}; status = env->String_NewUTF8(appUrl, strlen(appUrl), &appUrlString); if (status != ANI_OK) { @@ -762,12 +767,20 @@ extern "C" DLL_EXPORT KNativePointer StartApplication(const char* appUrl, const return nullptr; } g_vmEntry.emitEvent = reinterpret_cast(emitEvent); + ani_method loadView {}; + status = env->Class_FindMethod(appClass, appInfo->loadViewMethodName, appInfo->loadViewMethodSig, &loadView); + if (status != ANI_OK) { + LOGE("Cannot find `%" LOG_PUBLIC "s` method %" LOG_PUBLIC "s", appInfo->loadViewMethodName, appInfo->loadViewMethodSig); + ResetErrorIfExists(env); + return nullptr; + } + g_vmEntry.loadView = reinterpret_cast(loadView); if (isTestEnv) { ani_method restartWith {}; status = env->Class_FindMethod(appClass, appInfo->restartWithMethodName, appInfo->restartWithMethodSig, &restartWith); if (status != ANI_OK) { - LOGE("Cannot find `restartWith` method %" LOG_PUBLIC "s", appInfo->restartWithMethodSig); + LOGE("Cannot find `restartWith` method sig=%" LOG_PUBLIC "s", appInfo->restartWithMethodSig); ResetErrorIfExists(env); return nullptr; } @@ -1004,6 +1017,44 @@ extern "C" DLL_EXPORT void RestartWith(const char* page) { #endif } +extern "C" DLL_EXPORT const char* LoadView(const char* className, const char* params) { +#if defined(KOALA_ANI) + if (g_vmEntry.vmKind == PANDA_ANI_VM_KIND) { + ani_env *env = reinterpret_cast(g_vmEntry.env); + if (!g_vmEntry.loadView) { + return strdup("Cannot find loadView() method"); + } + ani_string classNameString {}; + auto status = env->String_NewUTF8(className, strlen(className), &classNameString); + if (status != ANI_OK) { + return strdup("Cannot make ANI string"); + } + ani_string paramsString {}; + status = env->String_NewUTF8(params, strlen(params), ¶msString); + if (status != ANI_OK) { + ResetErrorIfExists(env); + return strdup("Cannot make ANI string"); + } + ani_string resultString = nullptr; + status = env->Object_CallMethod_Ref(reinterpret_cast(g_vmEntry.app), + reinterpret_cast(g_vmEntry.loadView), + (ani_ref*)&resultString, + classNameString, paramsString); + if (status != ANI_OK) { + ResetErrorIfExists(env); + return strdup("Calling laodView() method gave an error"); + } + ani_size resultStringLength = 0; + status = env->String_GetUTF8Size(resultString, &resultStringLength); + char* resultChars = (char*)malloc(resultStringLength); + status = env->String_GetUTF8(resultString, resultChars, resultStringLength, &resultStringLength); + return resultChars; + + } +#endif + return strdup("Unsupported"); +} + namespace fs = std::filesystem; bool ends_with(std::string str, std::string suffix) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/InteropNativeModule.ts b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/InteropNativeModule.ts index 7aa61e70bc8..db159072211 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/InteropNativeModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/InteropNativeModule.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,7 +11,7 @@ * 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 { int32, int64 } from "@koalaui/common"; import { KPointer, KSerializerBuffer, KStringPtr, KUint8ArrayPtr } from "./InteropTypes"; @@ -51,7 +51,7 @@ export class InteropNativeModule { public static _LoadVirtualMachine(arg0: int32, arg1: string, arg2: string): int32 { throw "method not loaded" } public static _RunApplication(arg0: int32, arg1: int32): number { throw "method not loaded" } public static _StartApplication(appUrl: string, appParams: string): KPointer { throw "method not loaded" } - public static _EmitEvent(eventType: int32, target: int32, arg0: int32, arg1: int32): void { throw "method not loaded" } + public static _EmitEvent(eventType: int32, target: int32, arg0: int32, arg1: int32): string { throw "method not loaded" } public static _CallForeignVM(foreignContext: KPointer, kind: int32, args: KSerializerBuffer, argsSize: int32): int32 { throw "method not loaded" } public static _SetForeignVMContext(context: KPointer): void { throw "method not loaded" } public static _ReadByte(data: KPointer, index: int32, length: bigint): int32 { throw "method not loaded" } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/buffer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/buffer.ts index bfd04c207e0..02688d78674 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/buffer.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/buffer.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,7 +11,7 @@ * 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 { int32 } from "@koalaui/common" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/loadLibraries.ts b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/loadLibraries.ts index 84a5068d32e..2e345d944be 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/loadLibraries.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/interop/loadLibraries.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -11,7 +11,7 @@ * 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. - */ +*/ const nativeModuleLibraries: Map = new Map() diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/package.json index 9cb29ae28b8..9405b91009b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/package.json @@ -1,8 +1,8 @@ { - "name": "root", - "private": true, - "//": "DO NOT ADD dependencies or devDependencies clauses to this level! Keep subfolders autonomous.", - "scripts": { - "prepare": "cd incremental && npm i && cd .. && cd interop && npm i && cd .. && cd ui2abc && npm i" - } -} + "name": "root", + "private": true, + "//": "DO NOT ADD dependencies or devDependencies clauses to this level! Keep subfolders autonomous.", + "scripts": { + "prepare": "cd arkoala-arkts && npm i && cd .. && cd incremental && npm i && cd .. && cd interop && npm i && cd .. && cd ui2abc && npm i && cd .." + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/docs/UI2ABC_WORKS.md b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/docs/UI2ABC_WORKS.md deleted file mode 100644 index dec6f5cba01..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/docs/UI2ABC_WORKS.md +++ /dev/null @@ -1,70 +0,0 @@ -At least the following implementation steps are needed - -## General plugin API infrastructure - -### Large bodies of code - -We need to ensure we can pass through at least: - * incremental/runtime (v) - * arkoala-arkts/arkui/src/* -- the handwritten part of arkoala (v) - * arkoala-arkts/arkui-common/src/* -- the handwritten part of arkoala ( ) - * arkoala-arkts/arkui/src/generated/* -- the generated component classes (v) - * arkoala-arkts/arkui/src/sts/* -- the generated facades ( ) - -### Perfomance and memory approaches - - * keep node overproduction under control - * declaration cache (PR) - * update logics - * have fast-arktsc working with all three plugins (v) - * Compile against the d.ts surface of arkoala - -### The three plugin stack is capable of running in multi-file, multi-import scenario - - * In parallel work with the compiler people to ensure the proper scheme with "recheck" is moving (in progress: "rebind" + "recheck" works in small amount of cases, inserting imports in bound/checked stage plugin is non trivial) - * work on ui2abc and fast-arktsc tools to hide implementation details from users (v) - * The plugin configuration is per-module (v) - -## Memo plugin works - - * Ensure we can compile incremental runtime (as a large body of memo code) with and after memo rewrite (v) - * Ensure we can compile arkoala (in progress) - * Ensure the incremental runtime harness can run tests for ui2abc (v) - * Ensure we can run test on incremental runtime compiled by ui2abc ( ) - * Have the diagnostics issued where needed. ( ) - * First to console ( ) - * Then, after compiler issue is implemented thtrough the C API ( ) - * Functional completeness ( ) - -## UI plugin works - - * Ensure the ets-harness is capable of running tests for ui2abc ( ) - * Transfer ets-plugin functionality to ui-plugin, covering by executable tests in parallel in ets-harness ( ) - * directed by user - -## IDLize works - -### arkgen - - * Gnereare proper ETS facades with proper interfaces in proper packages ( ) - * Have the generator emit d.ts surfaces of arkoala layers - * Adapt enums, non-component interfaces, etc to be properly named and not expose users unneeded implementation details ( ) - * This is an iterative work in small steps ensuring runnability on every step. - -### arktsgen - - * keep maintaining the plugin author needs (v) - * keep following the @panda/sdk release cycle (v) - * work with DevOps to ensure the regular builds are really going (v) - -## User code and intergration work - - * Transition from the small demo working on prototype arkui.ts to correctly work through arkoala implementations ( ) - * Bring the user app to the desired shape - * This is an iterative work in small steps ensuring runnability on every step. (x) - * trivial can startup on the host - * trivial can run on a device/previewer - * trvial is running fine - * shopping can startup - * shopping is running fine - diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/PrimeNumbers.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/index.js old mode 100644 new mode 100755 similarity index 79% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/PrimeNumbers.ets rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/index.js index d5994c577d6..2fe2b948b55 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/PrimeNumbers.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/index.js @@ -1,5 +1,7 @@ +#!/usr/bin/env node + /* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -13,5 +15,4 @@ * limitations under the License. */ -import { uint32 } from "../common" -export declare const PrimeNumbers: ReadonlyArray \ No newline at end of file +module.exports = require("./lib") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/package.json index c875a6006f3..838f4ee8ee7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/package.json @@ -1,9 +1,9 @@ { "name": "@koalaui/fast-arktsc", - "version": "1.5.15+devel", + "version": "1.7.1+devel", "description": "", - "main": "lib/index.js", - "bin": "lib/index.js", + "main": "./index.js", + "bin": "./index.js", "scripts": { "clean": "rimraf out lib", "compile": "WEBPACK_NO_MINIMIZE=true webpack --config webpack.config.node.js" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/src/main.ts index b829db498e6..b4267d85d63 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/src/main.ts @@ -1,5 +1,3 @@ -#!/usr/bin/env node - /* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,7 +31,6 @@ export const options = program .option('--compiler ', 'Path to compiler') .option('--link-name ', 'Path to final linked file', "all") - .option('--file-option', 'When provided pass the source as --file rather than a free option') .option('--restart-stages', 'Compilation with plugins and compiler restarting') .option('--output-dir ', 'Path to output dir (only used by AOT compilation)') @@ -80,7 +77,7 @@ function produceNinjafile( let compilerPrefix = [...Array(stages).keys()].map((i) => ` rule arkts_compiler_stage${i} - command = ${tools_prefix}${compiler} --ets-module --arktsconfig ${path.resolve(config)} ${options.fileOption ? "--file" : ""} $in --output $out ${options.restartStages ? `--restart-stages` : ``} ${stages > 1 ? `--stage ${i}` : ``} + command = ${tools_prefix}${compiler} --ets-module --arktsconfig ${path.resolve(config)} --output $out ${options.restartStages ? `--restart-stages` : ``} ${stages > 1 ? `--stage ${i}` : ``} $in description = "Compiling ARKTS ${stages > 1 ? `(stage ${i})` : ``} $in" `).join('') diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/src/resolve-config.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/src/resolve-config.ts index 9a2620e0e48..a66c6fee414 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/src/resolve-config.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/fast-arktsc/src/resolve-config.ts @@ -155,19 +155,63 @@ export function resolveConfig(configPath: string, restartStages: boolean): [stri } for (const [k, v] of resolvedPaths) { - if ((k.startsWith('@') || k.startsWith('#')) && !v.endsWith('*') && !fs.existsSync(path.join(v, "index.ts")) && !fs.existsSync(path.join(v, "index.ets"))) { + let ext = path.extname(v) + let isResolvedToFile = ext === ".ts" || ext === ".ets" + if (isResolvedToFile) { + try { + isResolvedToFile = fs.statSync(v).isFile() + } catch (_e) { + isResolvedToFile = false + } + } + if (!isResolvedToFile && (k.startsWith('@') || k.startsWith('#')) && !v.endsWith('*') && !fs.existsSync(path.join(v, "index.ts")) && !fs.existsSync(path.join(v, "index.ets"))) { error(`File ${v}/index.[ts|ets] does not exists`) } } const newBaseUrl = i == 0 ? relativeOrDot(outDir, baseUrl) : `./${pluginNames[i - 1]}` - const pathsInConfig = Array.from(resolvedPaths).map(([k, v]) => { + const pathsInConfig = Array.from(resolvedPaths).flatMap(([k, v]) => { if (!path.relative(baseUrl, v).startsWith('..')) { const res = relativeOrDot(path.resolve(baseUrl), v) - return [k, [k.endsWith('*') && !res.endsWith('*') ? `${res}/*` : res]] + return [[k, [k.endsWith('*') && !res.endsWith('*') ? `${res}/*` : res]]] + } + const from = path.resolve(outDir ?? `.`, newBaseUrl) + const res = relativeOrDot(from, v) + if (k.endsWith('*') && res.endsWith('*')) { + const replaceTrailStar = (str: string, replaceStr: string = '') => { + if (str.length == 0 || str.charAt(str.length - 1) !== '*') + return str + return str.slice(0, -1) + replaceStr + } + const rmLeadSlash = (str: string) => { + if (str.startsWith("/")) + str = str.length > 1 ? str.substring(1) : "" + return str + } + const pattern = path.resolve(from, replaceTrailStar(res)) + const parent = path.parse(pattern).dir + + const ret: [string, string[]][] = [] + const traverseDir = (dir: string, filter: (file: string) => boolean, apply: (file: string) => void) => { + const dirents = fs.readdirSync(dir, { withFileTypes: true }) + for (const entry of dirents) { + const fullPath = path.join(dir, entry.name) + if (entry.isDirectory()) + traverseDir(fullPath, filter, apply) + else if (filter(fullPath)) + apply(fullPath) + } + } + traverseDir(parent, file => file.endsWith(".d.ets") && file.startsWith(pattern), file => { + let resolvedStar = rmLeadSlash(file.substring(pattern.length)) + let resolvedK = replaceTrailStar(k, resolvedStar) + resolvedK = resolvedK.substring(0, resolvedK.length - ".d.ets".length) + const resolvedV = replaceTrailStar(res, resolvedStar) + ret.push([resolvedK, [resolvedV]]) + }) + return ret } - const res = relativeOrDot(path.resolve(outDir ?? `.`, newBaseUrl), v) - return [k, [k.endsWith('*') && !res.endsWith('*') ? `${res}/*` : res]] + return [[k, [k.endsWith('*') && !res.endsWith('*') ? `${res}/*` : res]]] }) const arktsconfig = { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/command/gen_sdk.py b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/command/gen_sdk.py index eb54c8a120d..0575ab9ea79 100755 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/command/gen_sdk.py +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/command/gen_sdk.py @@ -16,6 +16,7 @@ import os import shutil import json import argparse +import subprocess def load_config(config_file): """Load the configuration file.""" @@ -62,6 +63,10 @@ def copy_files(config, src_base, dist_base, out_root): except Exception as e: print(f"Failed to copy directory: {source} -> {destination}, error: {e}") +def apply_patch(dist_base): + """Apply patch.""" + subprocess.run(["patch", "-d", dist_base, "-p", "0", "-i", f"{os.path.dirname(__file__)}/../patch/es2panda_lib.idl.patch"]) + def main(): # Parse command-line arguments parser = argparse.ArgumentParser(description="Copy files or directories.") @@ -77,5 +82,8 @@ def main(): # Copy files or directories copy_files(config, args.src, args.dist, args.out_root) + # Apply patch to the files copied + apply_patch(args.dist) + if __name__ == '__main__': main() \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/patch/es2panda_lib.idl.patch b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/patch/es2panda_lib.idl.patch new file mode 100644 index 00000000000..bb6d371437b --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/patch/es2panda_lib.idl.patch @@ -0,0 +1,11 @@ +--- "ohos_arm64/include/tools/es2panda/generated/es2panda_lib/es2panda_lib.idl" 2025-05-21 18:55:45.554925586 +0300 ++++ ohos_arm64/include/tools/es2panda/generated/es2panda_lib/es2panda_lib.idl 2025-05-21 19:19:16.496423554 +0300 +@@ -1821,7 +1821,7 @@ + + namespace ir { + +-[Entity=Class, c_type=es2panda_AstNode] interface NumberLiteral: Literal { ++[Entity=Class, Es2pandaAstNodeType=52, c_type=es2panda_AstNode] interface NumberLiteral: Literal { + ir.AstNode Create(es2panda_Context ctx, i32 value); + ir.AstNode Create1(es2panda_Context ctx, i64 value); + ir.AstNode Create2(es2panda_Context ctx, f64 value); diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/sdk_config.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/sdk_config.json index 5decb48a2fc..82c4d3aa1d5 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/sdk_config.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/gn/sdk_config.json @@ -1,44 +1,44 @@ { - "file_mappings": [ - { - "source": "$out_root/clang_x64/arkcompiler/ets_frontend/es2panda", - "destination": "linux_host_tools/bin/es2panda" - }, - { - "source": "$out_root/clang_x64/arkcompiler/ets_frontend/libes2panda_public.so", - "destination": "linux_host_tools/lib/libes2panda-public.so" - }, - { - "source": "$out_root/clang_x64/arkcompiler/runtime_core/ark_link", - "destination": "linux_host_tools/bin/ark_link" - }, - { - "source": "$out_root/clang_x64/arkcompiler/runtime_core/libarktsbase.so", - "destination": "linux_host_tools/lib/libarktsbase.so" - }, - { - "source": "arkcompiler/runtime_core/static_core/plugins/ets/stdlib/escompat", - "destination": "ets/stdlib/escompat" - }, - { - "source": "arkcompiler/runtime_core/static_core/plugins/ets/stdlib/std", - "destination": "ets/stdlib/std" - }, - { - "source": "arkcompiler/ets_frontend/ets2panda/public/es2panda_lib.h", - "destination": "linux_host_tools/include/tools/es2panda/public/es2panda_lib.h" - }, - { - "source": "$out_root/clang_x64/gen/arkcompiler/ets_frontend/ets2panda/generated/es2panda_lib", - "destination": "linux_host_tools/include/tools/es2panda/generated/es2panda_lib" - }, - { - "source": "$out_root/clang_x64/gen/arkcompiler/ets_frontend/ets2panda/generated/es2panda_lib", - "destination": "ohos_arm64/include/tools/es2panda/generated/es2panda_lib" - }, - { - "source": "$out_root/clang_x64/gen/arkcompiler/runtime_core/static_core/plugins/ets/etsstdlib.abc", - "destination": "ets/etsstdlib.abc" - } - ] + "file_mappings": [ + { + "source": "$out_root/clang_x64/arkcompiler/ets_frontend/es2panda", + "destination": "linux_host_tools/bin/es2panda" + }, + { + "source": "$out_root/clang_x64/arkcompiler/ets_frontend/libes2panda_public.so", + "destination": "linux_host_tools/lib/libes2panda-public.so" + }, + { + "source": "$out_root/clang_x64/arkcompiler/runtime_core/ark_link", + "destination": "linux_host_tools/bin/ark_link" + }, + { + "source": "$out_root/clang_x64/arkcompiler/runtime_core/libarktsbase.so", + "destination": "linux_host_tools/lib/libarktsbase.so" + }, + { + "source": "arkcompiler/runtime_core/static_core/plugins/ets/stdlib/escompat", + "destination": "ets/stdlib/escompat" + }, + { + "source": "arkcompiler/runtime_core/static_core/plugins/ets/stdlib/std", + "destination": "ets/stdlib/std" + }, + { + "source": "arkcompiler/ets_frontend/ets2panda/public/es2panda_lib.h", + "destination": "linux_host_tools/include/tools/es2panda/public/es2panda_lib.h" + }, + { + "source": "$out_root/clang_x64/gen/arkcompiler/ets_frontend/ets2panda/generated/es2panda_lib", + "destination": "linux_host_tools/include/tools/es2panda/generated/es2panda_lib" + }, + { + "source": "$out_root/clang_x64/gen/arkcompiler/ets_frontend/ets2panda/generated/es2panda_lib", + "destination": "ohos_arm64/include/tools/es2panda/generated/es2panda_lib" + }, + { + "source": "$out_root/clang_x64/gen/arkcompiler/runtime_core/static_core/plugins/ets/etsstdlib.abc", + "destination": "ets/etsstdlib.abc" + } + ] } \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/arktsconfig.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/arktsconfig.json index d1b9486cd97..3a00d970d1b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/arktsconfig.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/arktsconfig.json @@ -3,15 +3,6 @@ "package0": "@koalaui/example", "outDir": "./build/abc", "baseUrl": ".", - "paths": { - "@ohos.arkui": ["../../arkoala-arkts/arkui/src/ets-stubs"], - "@koalaui/compat": [ "../../incremental/compat/src/arkts" ], - "#platform": [ "../../incremental/compat/src/arkts" ], - "@koalaui/common": [ "../../incremental/common/src" ], - "@koalaui/interop": [ "../../interop/src/arkts" ], - "@koalaui/runtime": [ "../../incremental/runtime/ets" ], - "@koalaui/runtime/annotations": [ "../../incremental/runtime/annotations" ] - }, "plugins": [ { "transform": "./lib/plugins/printer-plugin.js", @@ -19,25 +10,16 @@ "name": "printer" }, { - "transform": "@koalaui/ui-plugins/parsed-stage-plugin", - "stage": "parsed", - "name": "ui" - }, - { - "transform": "@koalaui/ui-plugins/checked-stage-plugin", + "transform": "./lib/plugins/printer-plugin.js", "stage": "checked", - "name": "ui" + "name": "printer" }, { - "transform": "@koalaui/memo-plugin", + "transform": "./lib/plugins/printer-plugin.js", "stage": "checked", - "name": "memo" + "name": "printer2" } ] }, - "dependencies": { - "@koalaui/runtime": [ "../../incremental/runtime/ui2abcconfig.json" ], - "@ohos.arkui": ["../../arkoala-arkts/arkui/ui2abcconfig-pure-ets.json"] - }, "include": ["./plugins/input/main.ets", "./plugins/input/library.ets"] } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/generator/options.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/generator/options.json5 index 4e642e4d221..86a22e00a80 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/generator/options.json5 +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/generator/options.json5 @@ -1,18 +1,3 @@ -/* - * 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. - */ - { "irHack": [ "AnnotationUsage", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/gn/command/copy.py b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/gn/command/copy.py index 2d349e34197..4e6c8d3fa4b 100755 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/gn/command/copy.py +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/gn/command/copy.py @@ -45,7 +45,7 @@ def run_cmd(cmd, execution_path=None): def copy_output(options): - copy_files(os.path.join(options.from_path, 'clang_x64/libes2panda.node'), + copy_files(os.path.join(options.from_path, 'clang_x64/libes2panda_lib.node'), os.path.join(options.to_path, 'out/native/es2panda.node'), True) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/gn/command/npm.py b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/gn/command/npm.py index 47125f97a01..1429bcd835d 100755 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/gn/command/npm.py +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/gn/command/npm.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +# -*- coding: utf-8 -*- # 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. @@ -60,7 +60,7 @@ def install(dir): except subprocess.CalledProcessError as e: with open(koala_log, "a+") as f: f.write("\n") - f.write("error message: "+ e.output + "\n") + f.write("error message: "+ e.stderr + "\n") f.close() def npm_command(dir, command): diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/meson.build b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/meson.build index 6da74630c9a..5d1725f35a4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/meson.build +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/meson.build @@ -1,3 +1,16 @@ +# 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. + project( 'es2panda_interop', 'cpp', diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/meson_options.txt b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/meson_options.txt index 994cd4ce260..4c232cd2da6 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/meson_options.txt +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/meson_options.txt @@ -1,3 +1,16 @@ +# 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. + option( 'node_modules_dir', type : 'string', diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/bridges.cc b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/bridges.cc index 375d31b2e83..dbde6bbbe9b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/bridges.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/bridges.cc @@ -39,7 +39,7 @@ KNativePointer impl_AnnotationAllowedAnnotations(KNativePointer contextPtr, KNat auto node = reinterpret_cast(nodePtr); std::size_t params_len = 0; auto annotations = GetImpl()->AnnotationAllowedAnnotations(context, node, ¶ms_len); - return new std::vector(annotations, annotations + params_len); + return StageArena::cloneVector(annotations, params_len); } KOALA_INTEROP_3(AnnotationAllowedAnnotations, KNativePointer, KNativePointer, KNativePointer, KNativePointer) @@ -49,7 +49,7 @@ KNativePointer impl_AnnotationAllowedAnnotationsConst(KNativePointer contextPtr, auto node = reinterpret_cast(nodePtr); std::size_t params_len = 0; auto annotations = GetImpl()->AnnotationAllowedAnnotationsConst(context, node, ¶ms_len); - return new std::vector(annotations, annotations + params_len); + return StageArena::cloneVector(annotations, params_len); } KOALA_INTEROP_3(AnnotationAllowedAnnotationsConst, KNativePointer, KNativePointer, KNativePointer, KNativePointer) @@ -151,7 +151,7 @@ KOALA_INTEROP_1(ContextProgram, KNativePointer, KNativePointer) KNativePointer impl_ProgramAst(KNativePointer contextPtr, KNativePointer programPtr) { - auto context = reinterpret_cast(programPtr); + auto context = reinterpret_cast(contextPtr); auto program = reinterpret_cast(programPtr); return GetImpl()->ProgramAst(context, program); } @@ -190,7 +190,7 @@ KNativePointer impl_ContextErrorMessage(KNativePointer contextPtr) { auto context = reinterpret_cast(contextPtr); - return new string(GetImpl()->ContextErrorMessage(context)); + return StageArena::strdup(GetImpl()->ContextErrorMessage(context)); } KOALA_INTEROP_1(ContextErrorMessage, KNativePointer, KNativePointer) @@ -228,15 +228,15 @@ static KNativePointer impl_ProgramExternalSources(KNativePointer contextPtr, KNa auto&& instance = reinterpret_cast(instancePtr); std::size_t source_len = 0; auto external_sources = GetImpl()->ProgramExternalSources(context, instance, &source_len); - return new std::vector(external_sources, external_sources + source_len); + return StageArena::cloneVector(external_sources, source_len); } KOALA_INTEROP_2(ProgramExternalSources, KNativePointer, KNativePointer, KNativePointer); static KNativePointer impl_ExternalSourceName(KNativePointer instance) { auto&& _instance_ = reinterpret_cast(instance); - auto&& _result_ = GetImpl()->ExternalSourceName(_instance_); - return new std::string(_result_); + auto&& result = GetImpl()->ExternalSourceName(_instance_); + return StageArena::strdup(result); } KOALA_INTEROP_1(ExternalSourceName, KNativePointer, KNativePointer); @@ -245,7 +245,7 @@ static KNativePointer impl_ExternalSourcePrograms(KNativePointer instance) auto&& _instance_ = reinterpret_cast(instance); std::size_t program_len = 0; auto programs = GetImpl()->ExternalSourcePrograms(_instance_, &program_len); - return new std::vector(programs, programs + program_len); + return StageArena::cloneVector(programs, program_len); } KOALA_INTEROP_1(ExternalSourcePrograms, KNativePointer, KNativePointer); diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.cc b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.cc index c648e8a4a07..1d87e90fe3f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.cc @@ -14,11 +14,56 @@ */ #include +#include using std::string, std::cout, std::endl, std::vector; static es2panda_Impl *impl = nullptr; +static thread_local StageArena currentArena; + +StageArena* StageArena::instance() { + return ¤tArena; +} + +void StageArena::add(void* pointer) { + if (pointer) + allocated.push_back(pointer); +} + +void StageArena::cleanup() { + if (totalSize > 0 && false) + printf("cleanup %d objects %d bytes\n", (int)allocated.size(), (int)totalSize); + for (auto it : allocated) { + free(it); + } + totalSize = 0; + allocated.clear(); +} + +StageArena::StageArena() { + totalSize = 0; +} + +StageArena::~StageArena() { + cleanup(); +} + +char* StageArena::strdup(const char* string) { + auto* arena = StageArena::instance(); + auto size = strlen(string) + 1; + char* memory = (char*)arena->alloc(size); + memcpy(memory, string, size); + return memory; +} + +void* StageArena::alloc(size_t size) { + void* result = malloc(size); + totalSize += size; + add(result); + return result; +} + #ifdef KOALA_WINDOWS #include #define PLUGIN_DIR "windows_host_tools" @@ -58,12 +103,12 @@ es2panda_Impl *GetImpl() { } auto library = FindLibrary(); if (!library) { - printf("No library (es2panda_lib.cc)"); + printf("No library (es2panda_lib.cc)"); // TODO: dont use throw for ohos build abort(); } auto symbol = findSymbol(library, "es2panda_GetImpl"); if (!symbol) { - printf("No entry point"); + printf("no entry point"); abort(); } impl = reinterpret_cast(symbol)(ES2PANDA_LIB_VERSION); @@ -80,7 +125,7 @@ string getString(KStringPtr ptr) { } char* getStringCopy(KStringPtr& ptr) { - return strdup(ptr.c_str()); + return StageArena::strdup(ptr.c_str() ? ptr.c_str() : ""); } inline KUInt unpackUInt(const KByte* bytes) { @@ -93,7 +138,7 @@ inline KUInt unpackUInt(const KByte* bytes) { const KUInt BYTE_2_SHIFT = 16; const KUInt BYTE_3_SHIFT = 24; return ( - bytes[BYTE_0] + bytes[BYTE_0] | (bytes[BYTE_1] << BYTE_1_SHIFT) | (bytes[BYTE_2] << BYTE_2_SHIFT) | (bytes[BYTE_3] << BYTE_3_SHIFT) @@ -103,13 +148,13 @@ inline KUInt unpackUInt(const KByte* bytes) { KNativePointer impl_CreateConfig(KInt argc, KStringArray argvPtr) { const std::size_t headerLen = 4; - const char** argv = new const char*[argc]; + const char** argv = StageArena::allocArray(argc); std::size_t position = headerLen; std::size_t strLen; for (std::size_t i = 0; i < static_cast(argc); ++i) { strLen = unpackUInt(argvPtr + position); position += headerLen; - argv[i] = strdup(std::string(reinterpret_cast(argvPtr + position), strLen).c_str()); + argv[i] = StageArena::strdup(std::string(reinterpret_cast(argvPtr + position), strLen).c_str()); position += strLen; } return GetImpl()->CreateConfig(argc, argv); @@ -126,6 +171,7 @@ KOALA_INTEROP_1(DestroyConfig, KNativePointer, KNativePointer) KNativePointer impl_DestroyContext(KNativePointer contextPtr) { auto context = reinterpret_cast(contextPtr); GetImpl()->DestroyContext(context); + StageArena::instance()->cleanup(); return nullptr; } KOALA_INTEROP_1(DestroyContext, KNativePointer, KNativePointer) @@ -150,7 +196,7 @@ KNativePointer impl_UpdateCallExpression( auto nn = GetImpl()->CreateCallExpression( context, callee, arguments, argumentsLen, typeParams, optional, trailingComma - ); + ); GetImpl()->AstNodeSetOriginalNode(context, nn, node); return nn; } @@ -224,7 +270,7 @@ KNativePointer impl_AstNodeChildren( cachedChildren.clear(); GetImpl()->AstNodeIterateConst(context, node, visitChild); - return new std::vector(cachedChildren); + return StageArena::clone(cachedChildren); } KOALA_INTEROP_2(AstNodeChildren, KNativePointer, KNativePointer, KNativePointer) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.h b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.h index 60d111e0b7b..d08db0b23c2 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.h +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.h @@ -36,4 +36,52 @@ inline KUInt unpackUInt(const KByte* bytes); es2panda_ContextState intToState(KInt state); +class StageArena { + std::vector allocated; + size_t totalSize; + public: + StageArena(); + ~StageArena(); + static StageArena* instance(); + template + static T* alloc() { + auto* arena = StageArena::instance(); + void* memory = arena->alloc(sizeof(T)); + return new (memory) T(); + } + template + static T* alloc(T1 arg1) { + auto* arena = StageArena::instance(); + void* memory = arena->alloc(sizeof(T)); + return new (memory) T(std::forward(arg1)); + } + template + static T* alloc(T1 arg1, T2 arg2) { + auto* arena = StageArena::instance(); + void* memory = arena->alloc(sizeof(T)); + return new (memory) T(arg1, arg2); + } + template + static T* allocArray(size_t count) { + auto* arena = StageArena::instance(); + // align? + void* memory = arena->alloc(sizeof(T) * count); + return new (memory) T(); + } + template + static T* clone(const T& arg) { + auto* arena = StageArena::instance(); + void* memory = arena->alloc(sizeof(T)); + return new (memory) T(arg); + } + template + static std::vector* cloneVector(const T* arg, size_t count) { + return alloc, const T*, const T*>(arg, arg + count); + } + void* alloc(size_t size); + static char* strdup(const char* original); + void add(void* pointer); + void cleanup(); +}; + #endif // COMMON_H \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/generated/bridges.cc b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/generated/bridges.cc index d1bbdb6a5ca..4963a42b52d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/generated/bridges.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/generated/bridges.cc @@ -15,15 +15,6 @@ #include -KNativePointer impl_NumberLiteralStrConst(KNativePointer context, KNativePointer receiver) -{ - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - auto result = GetImpl()->NumberLiteralStrConst(_context, _receiver); - return new std::string(result); -} -KOALA_INTEROP_2(NumberLiteralStrConst, KNativePointer, KNativePointer, KNativePointer); - KNativePointer impl_CreateNumberLiteral(KNativePointer context, KInt value) { const auto _context = reinterpret_cast(context); @@ -284,7 +275,7 @@ KNativePointer impl_ClassPropertyAnnotations(KNativePointer context, KNativePoin const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassPropertyAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassPropertyAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -294,7 +285,7 @@ KNativePointer impl_ClassPropertyAnnotationsConst(KNativePointer context, KNativ const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassPropertyAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassPropertyAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -371,7 +362,7 @@ KNativePointer impl_ETSFunctionTypeParamsConst(KNativePointer context, KNativePo const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSFunctionTypeIrParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSFunctionTypeParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -646,7 +637,7 @@ KNativePointer impl_TSConstructorTypeParamsConst(KNativePointer context, KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSConstructorTypeParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSConstructorTypeParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -758,7 +749,7 @@ KNativePointer impl_TSEnumDeclarationMembersConst(KNativePointer context, KNativ const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSEnumDeclarationMembersConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSEnumDeclarationMembersConst, KNativePointer, KNativePointer, KNativePointer); @@ -767,7 +758,7 @@ KNativePointer impl_TSEnumDeclarationInternalNameConst(KNativePointer context, K const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->TSEnumDeclarationInternalNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(TSEnumDeclarationInternalNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -815,7 +806,7 @@ KNativePointer impl_TSEnumDeclarationDecoratorsConst(KNativePointer context, KNa const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSEnumDeclarationDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSEnumDeclarationDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -904,7 +895,7 @@ KNativePointer impl_ObjectExpressionPropertiesConst(KNativePointer context, KNat const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ObjectExpressionPropertiesConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ObjectExpressionPropertiesConst, KNativePointer, KNativePointer, KNativePointer); @@ -932,7 +923,7 @@ KNativePointer impl_ObjectExpressionDecoratorsConst(KNativePointer context, KNat const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ObjectExpressionDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ObjectExpressionDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -1260,7 +1251,7 @@ KNativePointer impl_CallExpressionArgumentsConst(KNativePointer context, KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->CallExpressionArgumentsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(CallExpressionArgumentsConst, KNativePointer, KNativePointer, KNativePointer); @@ -1270,7 +1261,7 @@ KNativePointer impl_CallExpressionArguments(KNativePointer context, KNativePoint const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->CallExpressionArguments(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(CallExpressionArguments, KNativePointer, KNativePointer, KNativePointer); @@ -1373,7 +1364,7 @@ KNativePointer impl_BigIntLiteralStrConst(KNativePointer context, KNativePointer const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->BigIntLiteralStrConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(BigIntLiteralStrConst, KNativePointer, KNativePointer, KNativePointer); @@ -1475,7 +1466,7 @@ KNativePointer impl_ClassElementDecoratorsConst(KNativePointer context, KNativeP const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassElementDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassElementDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -1698,7 +1689,7 @@ KNativePointer impl_FunctionDeclarationAnnotations(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->FunctionDeclarationAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(FunctionDeclarationAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -1708,7 +1699,7 @@ KNativePointer impl_FunctionDeclarationAnnotationsConst(KNativePointer context, const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->FunctionDeclarationAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(FunctionDeclarationAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -1936,7 +1927,7 @@ KNativePointer impl_TSFunctionTypeParamsConst(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSFunctionTypeParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSFunctionTypeParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -2011,7 +2002,7 @@ KNativePointer impl_TemplateElementRawConst(KNativePointer context, KNativePoint const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->TemplateElementRawConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(TemplateElementRawConst, KNativePointer, KNativePointer, KNativePointer); @@ -2020,7 +2011,7 @@ KNativePointer impl_TemplateElementCookedConst(KNativePointer context, KNativePo const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->TemplateElementCookedConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(TemplateElementCookedConst, KNativePointer, KNativePointer, KNativePointer); @@ -2096,7 +2087,7 @@ KNativePointer impl_TSInterfaceDeclarationInternalNameConst(KNativePointer conte const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->TSInterfaceDeclarationInternalNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(TSInterfaceDeclarationInternalNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -2152,7 +2143,7 @@ KNativePointer impl_TSInterfaceDeclarationExtends(KNativePointer context, KNativ const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSInterfaceDeclarationExtends(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSInterfaceDeclarationExtends, KNativePointer, KNativePointer, KNativePointer); @@ -2162,7 +2153,7 @@ KNativePointer impl_TSInterfaceDeclarationExtendsConst(KNativePointer context, K const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSInterfaceDeclarationExtendsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSInterfaceDeclarationExtendsConst, KNativePointer, KNativePointer, KNativePointer); @@ -2172,7 +2163,7 @@ KNativePointer impl_TSInterfaceDeclarationDecoratorsConst(KNativePointer context const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSInterfaceDeclarationDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSInterfaceDeclarationDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -2210,7 +2201,7 @@ KNativePointer impl_TSInterfaceDeclarationAnnotations(KNativePointer context, KN const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSInterfaceDeclarationAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSInterfaceDeclarationAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -2220,7 +2211,7 @@ KNativePointer impl_TSInterfaceDeclarationAnnotationsConst(KNativePointer contex const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSInterfaceDeclarationAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSInterfaceDeclarationAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -2264,7 +2255,7 @@ KNativePointer impl_VariableDeclarationDeclaratorsConst(KNativePointer context, const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->VariableDeclarationDeclaratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(VariableDeclarationDeclaratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -2283,7 +2274,7 @@ KNativePointer impl_VariableDeclarationDecoratorsConst(KNativePointer context, K const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->VariableDeclarationDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(VariableDeclarationDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -2303,7 +2294,7 @@ KNativePointer impl_VariableDeclarationAnnotations(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->VariableDeclarationAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(VariableDeclarationAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -2313,7 +2304,7 @@ KNativePointer impl_VariableDeclarationAnnotationsConst(KNativePointer context, const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->VariableDeclarationAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(VariableDeclarationAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -2646,7 +2637,7 @@ KNativePointer impl_ETSUnionTypeTypesConst(KNativePointer context, KNativePointe const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSUnionTypeIrTypesConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSUnionTypeTypesConst, KNativePointer, KNativePointer, KNativePointer); @@ -2933,7 +2924,7 @@ KNativePointer impl_TSTypeAliasDeclarationDecoratorsConst(KNativePointer context const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTypeAliasDeclarationDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTypeAliasDeclarationDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -2953,7 +2944,7 @@ KNativePointer impl_TSTypeAliasDeclarationAnnotations(KNativePointer context, KN const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTypeAliasDeclarationAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTypeAliasDeclarationAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -2963,7 +2954,7 @@ KNativePointer impl_TSTypeAliasDeclarationAnnotationsConst(KNativePointer contex const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTypeAliasDeclarationAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTypeAliasDeclarationAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -3184,7 +3175,7 @@ KNativePointer impl_ScriptFunctionParamsConst(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ScriptFunctionParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ScriptFunctionParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -3194,7 +3185,7 @@ KNativePointer impl_ScriptFunctionParams(KNativePointer context, KNativePointer const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ScriptFunctionParams(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ScriptFunctionParams, KNativePointer, KNativePointer, KNativePointer); @@ -3204,7 +3195,7 @@ KNativePointer impl_ScriptFunctionReturnStatementsConst(KNativePointer context, const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ScriptFunctionReturnStatementsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ScriptFunctionReturnStatementsConst, KNativePointer, KNativePointer, KNativePointer); @@ -3214,7 +3205,7 @@ KNativePointer impl_ScriptFunctionReturnStatements(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ScriptFunctionReturnStatements(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ScriptFunctionReturnStatements, KNativePointer, KNativePointer, KNativePointer); @@ -3603,13 +3594,32 @@ KUInt impl_ScriptFunctionFormalParamsLengthConst(KNativePointer context, KNative } KOALA_INTEROP_2(ScriptFunctionFormalParamsLengthConst, KUInt, KNativePointer, KNativePointer); +void impl_ScriptFunctionSetIsolatedDeclgenReturnType(KNativePointer context, KNativePointer receiver, KStringPtr& type) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + const auto _type = getStringCopy(type); + GetImpl()->ScriptFunctionSetIsolatedDeclgenReturnType(_context, _receiver, _type); + return ; +} +KOALA_INTEROP_V3(ScriptFunctionSetIsolatedDeclgenReturnType, KNativePointer, KNativePointer, KStringPtr); + +KNativePointer impl_ScriptFunctionGetIsolatedDeclgenReturnTypeConst(KNativePointer context, KNativePointer receiver) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + auto result = GetImpl()->ScriptFunctionGetIsolatedDeclgenReturnTypeConst(_context, _receiver); + return StageArena::strdup(result); +} +KOALA_INTEROP_2(ScriptFunctionGetIsolatedDeclgenReturnTypeConst, KNativePointer, KNativePointer, KNativePointer); + KNativePointer impl_ScriptFunctionAnnotations(KNativePointer context, KNativePointer receiver) { const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ScriptFunctionAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ScriptFunctionAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -3619,7 +3629,7 @@ KNativePointer impl_ScriptFunctionAnnotationsConst(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ScriptFunctionAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ScriptFunctionAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -3756,7 +3766,7 @@ KNativePointer impl_ClassDefinitionInternalNameConst(KNativePointer context, KNa const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ClassDefinitionInternalNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ClassDefinitionInternalNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -4014,7 +4024,7 @@ KNativePointer impl_ClassDefinitionBody(KNativePointer context, KNativePointer r const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassDefinitionBody(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassDefinitionBody, KNativePointer, KNativePointer, KNativePointer); @@ -4024,7 +4034,7 @@ KNativePointer impl_ClassDefinitionBodyConst(KNativePointer context, KNativePoin const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassDefinitionBodyConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassDefinitionBodyConst, KNativePointer, KNativePointer, KNativePointer); @@ -4053,7 +4063,7 @@ KNativePointer impl_ClassDefinitionImplements(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassDefinitionImplements(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassDefinitionImplements, KNativePointer, KNativePointer, KNativePointer); @@ -4063,7 +4073,7 @@ KNativePointer impl_ClassDefinitionImplementsConst(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassDefinitionImplementsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassDefinitionImplementsConst, KNativePointer, KNativePointer, KNativePointer); @@ -4136,7 +4146,7 @@ KNativePointer impl_ClassDefinitionLocalPrefixConst(KNativePointer context, KNat const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ClassDefinitionLocalPrefixConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ClassDefinitionLocalPrefixConst, KNativePointer, KNativePointer, KNativePointer); @@ -4240,7 +4250,7 @@ KNativePointer impl_ClassDefinitionAnnotations(KNativePointer context, KNativePo const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassDefinitionAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassDefinitionAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -4250,7 +4260,7 @@ KNativePointer impl_ClassDefinitionAnnotationsConst(KNativePointer context, KNat const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassDefinitionAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassDefinitionAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -4327,7 +4337,7 @@ KNativePointer impl_ArrayExpressionElementsConst(KNativePointer context, KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ArrayExpressionElementsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ArrayExpressionElementsConst, KNativePointer, KNativePointer, KNativePointer); @@ -4337,7 +4347,7 @@ KNativePointer impl_ArrayExpressionElements(KNativePointer context, KNativePoint const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ArrayExpressionElements(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ArrayExpressionElements, KNativePointer, KNativePointer, KNativePointer); @@ -4395,7 +4405,7 @@ KNativePointer impl_ArrayExpressionDecoratorsConst(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ArrayExpressionDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ArrayExpressionDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -4483,7 +4493,7 @@ KNativePointer impl_TSInterfaceBodyBody(KNativePointer context, KNativePointer r const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSInterfaceBodyBody(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSInterfaceBodyBody, KNativePointer, KNativePointer, KNativePointer); @@ -4493,7 +4503,7 @@ KNativePointer impl_TSInterfaceBodyBodyConst(KNativePointer context, KNativePoin const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSInterfaceBodyBodyConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSInterfaceBodyBodyConst, KNativePointer, KNativePointer, KNativePointer); @@ -4839,7 +4849,7 @@ KNativePointer impl_StringLiteralStrConst(KNativePointer context, KNativePointer const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->StringLiteralStrConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(StringLiteralStrConst, KNativePointer, KNativePointer, KNativePointer); @@ -5009,7 +5019,7 @@ KNativePointer impl_ETSTupleGetTupleTypeAnnotationsList(KNativePointer context, const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSTupleGetTupleTypeAnnotationsList(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSTupleGetTupleTypeAnnotationsList, KNativePointer, KNativePointer, KNativePointer); @@ -5019,7 +5029,7 @@ KNativePointer impl_ETSTupleGetTupleTypeAnnotationsListConst(KNativePointer cont const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSTupleGetTupleTypeAnnotationsListConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSTupleGetTupleTypeAnnotationsListConst, KNativePointer, KNativePointer, KNativePointer); @@ -5147,7 +5157,7 @@ KNativePointer impl_TryStatementCatchClausesConst(KNativePointer context, KNativ const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TryStatementCatchClausesConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TryStatementCatchClausesConst, KNativePointer, KNativePointer, KNativePointer); @@ -5369,7 +5379,7 @@ KNativePointer impl_AstNodeDecoratorsPtrConst(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->AstNodeDecoratorsPtrConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(AstNodeDecoratorsPtrConst, KNativePointer, KNativePointer, KNativePointer); @@ -5735,7 +5745,7 @@ KNativePointer impl_AstNodeDumpJSONConst(KNativePointer context, KNativePointer const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->AstNodeDumpJSONConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(AstNodeDumpJSONConst, KNativePointer, KNativePointer, KNativePointer); @@ -5744,7 +5754,7 @@ KNativePointer impl_AstNodeDumpEtsSrcConst(KNativePointer context, KNativePointe const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->AstNodeDumpEtsSrcConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(AstNodeDumpEtsSrcConst, KNativePointer, KNativePointer, KNativePointer); @@ -5753,10 +5763,19 @@ KNativePointer impl_AstNodeDumpDeclConst(KNativePointer context, KNativePointer const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->AstNodeDumpDeclConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(AstNodeDumpDeclConst, KNativePointer, KNativePointer, KNativePointer); +KNativePointer impl_AstNodeIsolatedDumpDeclConst(KNativePointer context, KNativePointer receiver) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + auto result = GetImpl()->AstNodeIsolatedDumpDeclConst(_context, _receiver); + return StageArena::strdup(result); +} +KOALA_INTEROP_2(AstNodeIsolatedDumpDeclConst, KNativePointer, KNativePointer, KNativePointer); + void impl_AstNodeDumpConst(KNativePointer context, KNativePointer receiver, KNativePointer dumper) { const auto _context = reinterpret_cast(context); @@ -6064,7 +6083,7 @@ KNativePointer impl_TSMethodSignatureParamsConst(KNativePointer context, KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSMethodSignatureParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSMethodSignatureParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -6683,7 +6702,7 @@ KNativePointer impl_ETSModuleAnnotations(KNativePointer context, KNativePointer const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSModuleAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSModuleAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -6693,7 +6712,7 @@ KNativePointer impl_ETSModuleAnnotationsConst(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSModuleAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSModuleAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -6809,7 +6828,7 @@ KNativePointer impl_TSSignatureDeclarationParamsConst(KNativePointer context, KN const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSSignatureDeclarationParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSSignatureDeclarationParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -6918,6 +6937,43 @@ KNativePointer impl_ExportSpecifierExportedConst(KNativePointer context, KNative } KOALA_INTEROP_2(ExportSpecifierExportedConst, KNativePointer, KNativePointer, KNativePointer); +void impl_ExportSpecifierSetDefault(KNativePointer context, KNativePointer receiver) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + GetImpl()->ExportSpecifierSetDefault(_context, _receiver); + return ; +} +KOALA_INTEROP_V2(ExportSpecifierSetDefault, KNativePointer, KNativePointer); + +KBoolean impl_ExportSpecifierIsDefaultConst(KNativePointer context, KNativePointer receiver) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + auto result = GetImpl()->ExportSpecifierIsDefaultConst(_context, _receiver); + return result; +} +KOALA_INTEROP_2(ExportSpecifierIsDefaultConst, KBoolean, KNativePointer, KNativePointer); + +void impl_ExportSpecifierSetConstantExpression(KNativePointer context, KNativePointer receiver, KNativePointer constantExpression) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + const auto _constantExpression = reinterpret_cast(constantExpression); + GetImpl()->ExportSpecifierSetConstantExpression(_context, _receiver, _constantExpression); + return ; +} +KOALA_INTEROP_V3(ExportSpecifierSetConstantExpression, KNativePointer, KNativePointer, KNativePointer); + +KNativePointer impl_ExportSpecifierGetConstantExpressionConst(KNativePointer context, KNativePointer receiver) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + auto result = GetImpl()->ExportSpecifierGetConstantExpressionConst(_context, _receiver); + return (void*)result; +} +KOALA_INTEROP_2(ExportSpecifierGetConstantExpressionConst, KNativePointer, KNativePointer, KNativePointer); + KNativePointer impl_CreateTSTupleType(KNativePointer context, KNativePointerArray elementTypes, KUInt elementTypesSequenceLength) { const auto _context = reinterpret_cast(context); @@ -6945,7 +7001,7 @@ KNativePointer impl_TSTupleTypeElementTypeConst(KNativePointer context, KNativeP const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTupleTypeElementTypeConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTupleTypeElementTypeConst, KNativePointer, KNativePointer, KNativePointer); @@ -7194,7 +7250,7 @@ KNativePointer impl_ImportDeclarationSpecifiersConst(KNativePointer context, KNa const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ImportDeclarationSpecifiersConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ImportDeclarationSpecifiersConst, KNativePointer, KNativePointer, KNativePointer); @@ -7204,7 +7260,7 @@ KNativePointer impl_ImportDeclarationSpecifiers(KNativePointer context, KNativeP const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ImportDeclarationSpecifiers(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ImportDeclarationSpecifiers, KNativePointer, KNativePointer, KNativePointer); @@ -7325,7 +7381,7 @@ KNativePointer impl_ETSImportDeclarationDeclPathConst(KNativePointer context, KN const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ETSImportDeclarationDeclPathConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ETSImportDeclarationDeclPathConst, KNativePointer, KNativePointer, KNativePointer); @@ -7334,7 +7390,7 @@ KNativePointer impl_ETSImportDeclarationOhmUrlConst(KNativePointer context, KNat const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ETSImportDeclarationOhmUrlConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ETSImportDeclarationOhmUrlConst, KNativePointer, KNativePointer, KNativePointer); @@ -7361,7 +7417,7 @@ KNativePointer impl_ETSImportDeclarationAssemblerName(KNativePointer context, KN const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ETSImportDeclarationAssemblerName(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ETSImportDeclarationAssemblerName, KNativePointer, KNativePointer, KNativePointer); @@ -7370,7 +7426,7 @@ KNativePointer impl_ETSImportDeclarationAssemblerNameConst(KNativePointer contex const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ETSImportDeclarationAssemblerNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ETSImportDeclarationAssemblerNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -7379,7 +7435,7 @@ KNativePointer impl_ETSImportDeclarationResolvedSourceConst(KNativePointer conte const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ETSImportDeclarationResolvedSourceConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ETSImportDeclarationResolvedSourceConst, KNativePointer, KNativePointer, KNativePointer); @@ -7429,7 +7485,7 @@ KNativePointer impl_TSModuleBlockStatementsConst(KNativePointer context, KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSModuleBlockStatementsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSModuleBlockStatementsConst, KNativePointer, KNativePointer, KNativePointer); @@ -7556,7 +7612,7 @@ KNativePointer impl_AnnotationDeclarationInternalNameConst(KNativePointer contex const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->AnnotationDeclarationInternalNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(AnnotationDeclarationInternalNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -7594,7 +7650,7 @@ KNativePointer impl_AnnotationDeclarationProperties(KNativePointer context, KNat const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->AnnotationDeclarationProperties(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(AnnotationDeclarationProperties, KNativePointer, KNativePointer, KNativePointer); @@ -7604,7 +7660,7 @@ KNativePointer impl_AnnotationDeclarationPropertiesConst(KNativePointer context, const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->AnnotationDeclarationPropertiesConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(AnnotationDeclarationPropertiesConst, KNativePointer, KNativePointer, KNativePointer); @@ -7688,7 +7744,7 @@ KNativePointer impl_AnnotationDeclarationAnnotations(KNativePointer context, KNa const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->AnnotationDeclarationAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(AnnotationDeclarationAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -7698,7 +7754,7 @@ KNativePointer impl_AnnotationDeclarationAnnotationsConst(KNativePointer context const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->AnnotationDeclarationAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(AnnotationDeclarationAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -7770,7 +7826,7 @@ KNativePointer impl_AnnotationUsageProperties(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->AnnotationUsageIrProperties(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(AnnotationUsageProperties, KNativePointer, KNativePointer, KNativePointer); @@ -7780,7 +7836,7 @@ KNativePointer impl_AnnotationUsagePropertiesConst(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->AnnotationUsageIrPropertiesConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(AnnotationUsagePropertiesConst, KNativePointer, KNativePointer, KNativePointer); @@ -7831,6 +7887,34 @@ KNativePointer impl_UpdateEmptyStatement(KNativePointer context, KNativePointer } KOALA_INTEROP_2(UpdateEmptyStatement, KNativePointer, KNativePointer, KNativePointer); +KNativePointer impl_CreateEmptyStatement1(KNativePointer context, KBoolean isBrokenStatement) +{ + const auto _context = reinterpret_cast(context); + const auto _isBrokenStatement = static_cast(isBrokenStatement); + auto result = GetImpl()->CreateEmptyStatement1(_context, _isBrokenStatement); + return result; +} +KOALA_INTEROP_2(CreateEmptyStatement1, KNativePointer, KNativePointer, KBoolean); + +KNativePointer impl_UpdateEmptyStatement1(KNativePointer context, KNativePointer original, KBoolean isBrokenStatement) +{ + const auto _context = reinterpret_cast(context); + const auto _original = reinterpret_cast(original); + const auto _isBrokenStatement = static_cast(isBrokenStatement); + auto result = GetImpl()->UpdateEmptyStatement1(_context, _original, _isBrokenStatement); + return result; +} +KOALA_INTEROP_3(UpdateEmptyStatement1, KNativePointer, KNativePointer, KNativePointer, KBoolean); + +KBoolean impl_EmptyStatementIsBrokenStatement(KNativePointer context, KNativePointer receiver) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + auto result = GetImpl()->EmptyStatementIsBrokenStatement(_context, _receiver); + return result; +} +KOALA_INTEROP_2(EmptyStatementIsBrokenStatement, KBoolean, KNativePointer, KNativePointer); + KNativePointer impl_CreateWhileStatement(KNativePointer context, KNativePointer test, KNativePointer body) { const auto _context = reinterpret_cast(context); @@ -7907,7 +7991,7 @@ KNativePointer impl_FunctionSignatureParamsConst(KNativePointer context, KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->FunctionSignatureParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(FunctionSignatureParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -7917,7 +8001,7 @@ KNativePointer impl_FunctionSignatureParams(KNativePointer context, KNativePoint const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->FunctionSignatureParams(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(FunctionSignatureParams, KNativePointer, KNativePointer, KNativePointer); @@ -8060,7 +8144,7 @@ KNativePointer impl_TSIntersectionTypeTypesConst(KNativePointer context, KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSIntersectionTypeTypesConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSIntersectionTypeTypesConst, KNativePointer, KNativePointer, KNativePointer); @@ -8150,7 +8234,7 @@ KNativePointer impl_BlockExpressionStatementsConst(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->BlockExpressionStatementsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(BlockExpressionStatementsConst, KNativePointer, KNativePointer, KNativePointer); @@ -8160,7 +8244,7 @@ KNativePointer impl_BlockExpressionStatements(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->BlockExpressionStatements(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(BlockExpressionStatements, KNativePointer, KNativePointer, KNativePointer); @@ -8212,7 +8296,7 @@ KNativePointer impl_TSTypeLiteralMembersConst(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTypeLiteralMembersConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTypeLiteralMembersConst, KNativePointer, KNativePointer, KNativePointer); @@ -8335,7 +8419,7 @@ KNativePointer impl_TSTypeParameterAnnotations(KNativePointer context, KNativePo const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTypeParameterAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTypeParameterAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -8345,7 +8429,7 @@ KNativePointer impl_TSTypeParameterAnnotationsConst(KNativePointer context, KNat const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTypeParameterAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTypeParameterAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -8431,7 +8515,7 @@ KNativePointer impl_SpreadElementDecoratorsConst(KNativePointer context, KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->SpreadElementDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(SpreadElementDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -8660,10 +8744,21 @@ KNativePointer impl_ExportNamedDeclarationSpecifiersConst(KNativePointer context const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ExportNamedDeclarationSpecifiersConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ExportNamedDeclarationSpecifiersConst, KNativePointer, KNativePointer, KNativePointer); +void impl_ExportNamedDeclarationReplaceSpecifiers(KNativePointer context, KNativePointer receiver, KNativePointerArray specifiers, KUInt specifiersSequenceLength) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + const auto _specifiers = reinterpret_cast(specifiers); + const auto _specifiersSequenceLength = static_cast(specifiersSequenceLength); + GetImpl()->ExportNamedDeclarationReplaceSpecifiers(_context, _receiver, _specifiers, _specifiersSequenceLength); + return ; +} +KOALA_INTEROP_V4(ExportNamedDeclarationReplaceSpecifiers, KNativePointer, KNativePointer, KNativePointerArray, KUInt); + KNativePointer impl_CreateETSParameterExpression(KNativePointer context, KNativePointer identOrSpread, KBoolean isOptional) { const auto _context = reinterpret_cast(context); @@ -8711,7 +8806,7 @@ KNativePointer impl_ETSParameterExpressionNameConst(KNativePointer context, KNat const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ETSParameterExpressionNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ETSParameterExpressionNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -8794,7 +8889,7 @@ KNativePointer impl_ETSParameterExpressionLexerSavedConst(KNativePointer context const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ETSParameterExpressionLexerSavedConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ETSParameterExpressionLexerSavedConst, KNativePointer, KNativePointer, KNativePointer); @@ -8889,7 +8984,7 @@ KNativePointer impl_ETSParameterExpressionAnnotations(KNativePointer context, KN const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSParameterExpressionAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSParameterExpressionAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -8899,7 +8994,7 @@ KNativePointer impl_ETSParameterExpressionAnnotationsConst(KNativePointer contex const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSParameterExpressionAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSParameterExpressionAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -8941,7 +9036,7 @@ KNativePointer impl_TSTypeParameterInstantiationParamsConst(KNativePointer conte const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTypeParameterInstantiationParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTypeParameterInstantiationParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -9047,7 +9142,7 @@ KNativePointer impl_SwitchCaseStatementConsequentConst(KNativePointer context, K const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->SwitchCaseStatementConsequentConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(SwitchCaseStatementConsequentConst, KNativePointer, KNativePointer, KNativePointer); @@ -9227,7 +9322,7 @@ KNativePointer impl_ClassStaticBlockNameConst(KNativePointer context, KNativePoi const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ClassStaticBlockNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ClassStaticBlockNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -9466,7 +9561,7 @@ KNativePointer impl_TemplateLiteralQuasisConst(KNativePointer context, KNativePo const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TemplateLiteralQuasisConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TemplateLiteralQuasisConst, KNativePointer, KNativePointer, KNativePointer); @@ -9476,7 +9571,7 @@ KNativePointer impl_TemplateLiteralExpressionsConst(KNativePointer context, KNat const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TemplateLiteralExpressionsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TemplateLiteralExpressionsConst, KNativePointer, KNativePointer, KNativePointer); @@ -9485,7 +9580,7 @@ KNativePointer impl_TemplateLiteralGetMultilineStringConst(KNativePointer contex const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->TemplateLiteralGetMultilineStringConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(TemplateLiteralGetMultilineStringConst, KNativePointer, KNativePointer, KNativePointer); @@ -9516,7 +9611,7 @@ KNativePointer impl_TSUnionTypeTypesConst(KNativePointer context, KNativePointer const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSUnionTypeTypesConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSUnionTypeTypesConst, KNativePointer, KNativePointer, KNativePointer); @@ -9599,7 +9694,7 @@ KNativePointer impl_IdentifierNameConst(KNativePointer context, KNativePointer r const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->IdentifierNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(IdentifierNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -9608,7 +9703,7 @@ KNativePointer impl_IdentifierName(KNativePointer context, KNativePointer receiv const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->IdentifierName(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(IdentifierName, KNativePointer, KNativePointer, KNativePointer); @@ -9628,7 +9723,7 @@ KNativePointer impl_IdentifierDecoratorsConst(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->IdentifierDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(IdentifierDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -9887,7 +9982,7 @@ KNativePointer impl_BlockStatementStatementsConst(KNativePointer context, KNativ const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->BlockStatementStatementsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(BlockStatementStatementsConst, KNativePointer, KNativePointer, KNativePointer); @@ -9897,7 +9992,7 @@ KNativePointer impl_BlockStatementStatements(KNativePointer context, KNativePoin const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->BlockStatementStatements(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(BlockStatementStatements, KNativePointer, KNativePointer, KNativePointer); @@ -10002,7 +10097,7 @@ KNativePointer impl_TSTypeParameterDeclarationParamsConst(KNativePointer context const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TSTypeParameterDeclarationParamsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TSTypeParameterDeclarationParamsConst, KNativePointer, KNativePointer, KNativePointer); @@ -10131,7 +10226,7 @@ KNativePointer impl_MethodDefinitionOverloadsConst(KNativePointer context, KNati const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->MethodDefinitionOverloadsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(MethodDefinitionOverloadsConst, KNativePointer, KNativePointer, KNativePointer); @@ -10425,7 +10520,7 @@ KNativePointer impl_ExpressionToStringConst(KNativePointer context, KNativePoint const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ExpressionToStringConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ExpressionToStringConst, KNativePointer, KNativePointer, KNativePointer); @@ -10475,15 +10570,16 @@ KNativePointer impl_CreateSrcDumper(KNativePointer context, KNativePointer node) } KOALA_INTEROP_2(CreateSrcDumper, KNativePointer, KNativePointer, KNativePointer); -KNativePointer impl_CreateSrcDumper1(KNativePointer context, KNativePointer node, KBoolean isDeclgen) +KNativePointer impl_CreateSrcDumper1(KNativePointer context, KNativePointer node, KBoolean isDeclgen, KBoolean isIsolatedDeclgen) { const auto _context = reinterpret_cast(context); const auto _node = reinterpret_cast(node); const auto _isDeclgen = static_cast(isDeclgen); - auto result = GetImpl()->CreateSrcDumper1(_context, _node, _isDeclgen); + const auto _isIsolatedDeclgen = static_cast(isIsolatedDeclgen); + auto result = GetImpl()->CreateSrcDumper1(_context, _node, _isDeclgen, _isIsolatedDeclgen); return result; } -KOALA_INTEROP_3(CreateSrcDumper1, KNativePointer, KNativePointer, KNativePointer, KBoolean); +KOALA_INTEROP_4(CreateSrcDumper1, KNativePointer, KNativePointer, KNativePointer, KBoolean, KBoolean); void impl_SrcDumperAdd(KNativePointer context, KNativePointer receiver, KStringPtr& str) { @@ -10540,7 +10636,7 @@ KNativePointer impl_SrcDumperStrConst(KNativePointer context, KNativePointer rec const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->SrcDumperStrConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(SrcDumperStrConst, KNativePointer, KNativePointer, KNativePointer); @@ -10581,6 +10677,15 @@ KBoolean impl_SrcDumperIsDeclgenConst(KNativePointer context, KNativePointer rec } KOALA_INTEROP_2(SrcDumperIsDeclgenConst, KBoolean, KNativePointer, KNativePointer); +KBoolean impl_SrcDumperIsIsolatedDeclgenConst(KNativePointer context, KNativePointer receiver) +{ + const auto _context = reinterpret_cast(context); + const auto _receiver = reinterpret_cast(receiver); + auto result = GetImpl()->SrcDumperIsIsolatedDeclgenConst(_context, _receiver); + return result; +} +KOALA_INTEROP_2(SrcDumperIsIsolatedDeclgenConst, KBoolean, KNativePointer, KNativePointer); + void impl_SrcDumperDumpNode(KNativePointer context, KNativePointer receiver, KStringPtr& key) { const auto _context = reinterpret_cast(context); @@ -10757,7 +10862,7 @@ KNativePointer impl_RegExpLiteralPatternConst(KNativePointer context, KNativePoi const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->RegExpLiteralPatternConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(RegExpLiteralPatternConst, KNativePointer, KNativePointer, KNativePointer); @@ -10891,7 +10996,7 @@ KNativePointer impl_ClassDeclarationDecoratorsConst(KNativePointer context, KNat const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ClassDeclarationDecoratorsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ClassDeclarationDecoratorsConst, KNativePointer, KNativePointer, KNativePointer); @@ -10996,7 +11101,7 @@ KNativePointer impl_TSQualifiedNameNameConst(KNativePointer context, KNativePoin const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->TSQualifiedNameNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(TSQualifiedNameNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -11221,7 +11326,7 @@ KNativePointer impl_ETSNewMultiDimArrayInstanceExpressionDimensions(KNativePoint const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSNewMultiDimArrayInstanceExpressionDimensions(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSNewMultiDimArrayInstanceExpressionDimensions, KNativePointer, KNativePointer, KNativePointer); @@ -11231,7 +11336,7 @@ KNativePointer impl_ETSNewMultiDimArrayInstanceExpressionDimensionsConst(KNative const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSNewMultiDimArrayInstanceExpressionDimensionsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSNewMultiDimArrayInstanceExpressionDimensionsConst, KNativePointer, KNativePointer, KNativePointer); @@ -11356,7 +11461,7 @@ KNativePointer impl_AstDumperModifierToString(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); const auto _flags = static_cast(flags); auto result = GetImpl()->AstDumperModifierToString(_context, _receiver, _flags); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_3(AstDumperModifierToString, KNativePointer, KNativePointer, KNativePointer, KInt); @@ -11366,7 +11471,7 @@ KNativePointer impl_AstDumperTypeOperatorToString(KNativePointer context, KNativ const auto _receiver = reinterpret_cast(receiver); const auto _operatorType = static_cast(operatorType); auto result = GetImpl()->AstDumperTypeOperatorToString(_context, _receiver, _operatorType); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_3(AstDumperTypeOperatorToString, KNativePointer, KNativePointer, KNativePointer, KInt); @@ -11375,7 +11480,7 @@ KNativePointer impl_AstDumperStrConst(KNativePointer context, KNativePointer rec const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->AstDumperStrConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(AstDumperStrConst, KNativePointer, KNativePointer, KNativePointer); @@ -11535,7 +11640,7 @@ KNativePointer impl_TSEnumMemberNameConst(KNativePointer context, KNativePointer const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->TSEnumMemberNameConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(TSEnumMemberNameConst, KNativePointer, KNativePointer, KNativePointer); @@ -11596,7 +11701,7 @@ KNativePointer impl_SwitchStatementCasesConst(KNativePointer context, KNativePoi const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->SwitchStatementCasesConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(SwitchStatementCasesConst, KNativePointer, KNativePointer, KNativePointer); @@ -11606,7 +11711,7 @@ KNativePointer impl_SwitchStatementCases(KNativePointer context, KNativePointer const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->SwitchStatementCases(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(SwitchStatementCases, KNativePointer, KNativePointer, KNativePointer); @@ -11779,7 +11884,7 @@ KNativePointer impl_SequenceExpressionSequenceConst(KNativePointer context, KNat const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->SequenceExpressionSequenceConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(SequenceExpressionSequenceConst, KNativePointer, KNativePointer, KNativePointer); @@ -11789,7 +11894,7 @@ KNativePointer impl_SequenceExpressionSequence(KNativePointer context, KNativePo const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->SequenceExpressionSequence(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(SequenceExpressionSequence, KNativePointer, KNativePointer, KNativePointer); @@ -11864,7 +11969,7 @@ KNativePointer impl_ArrowFunctionExpressionAnnotations(KNativePointer context, K const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ArrowFunctionExpressionAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ArrowFunctionExpressionAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -11874,7 +11979,7 @@ KNativePointer impl_ArrowFunctionExpressionAnnotationsConst(KNativePointer conte const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ArrowFunctionExpressionAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ArrowFunctionExpressionAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -11963,7 +12068,7 @@ KNativePointer impl_ETSNewClassInstanceExpressionGetArguments(KNativePointer con const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSNewClassInstanceExpressionGetArguments(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSNewClassInstanceExpressionGetArguments, KNativePointer, KNativePointer, KNativePointer); @@ -11973,7 +12078,7 @@ KNativePointer impl_ETSNewClassInstanceExpressionGetArgumentsConst(KNativePointe const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->ETSNewClassInstanceExpressionGetArgumentsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(ETSNewClassInstanceExpressionGetArgumentsConst, KNativePointer, KNativePointer, KNativePointer); @@ -12281,7 +12386,7 @@ KNativePointer impl_ETSReExportDeclarationGetProgramPathConst(KNativePointer con const auto _context = reinterpret_cast(context); const auto _receiver = reinterpret_cast(receiver); auto result = GetImpl()->ETSReExportDeclarationGetProgramPathConst(_context, _receiver); - return new std::string(result); + return StageArena::strdup(result); } KOALA_INTEROP_2(ETSReExportDeclarationGetProgramPathConst, KNativePointer, KNativePointer, KNativePointer); @@ -12319,7 +12424,7 @@ KNativePointer impl_TypeNodeAnnotations(KNativePointer context, KNativePointer r const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TypeNodeAnnotations(_context, _receiver, &length); - return new std::vector(result, result + length); + return StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TypeNodeAnnotations, KNativePointer, KNativePointer, KNativePointer); @@ -12329,7 +12434,7 @@ KNativePointer impl_TypeNodeAnnotationsConst(KNativePointer context, KNativePoin const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->TypeNodeAnnotationsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(TypeNodeAnnotationsConst, KNativePointer, KNativePointer, KNativePointer); @@ -12382,7 +12487,7 @@ KNativePointer impl_NewExpressionArgumentsConst(KNativePointer context, KNativeP const auto _receiver = reinterpret_cast(receiver); std::size_t length; auto result = GetImpl()->NewExpressionArgumentsConst(_context, _receiver, &length); - return (void*)new std::vector(result, result + length); + return (void*)StageArena::cloneVector(result, length); } KOALA_INTEROP_2(NewExpressionArgumentsConst, KNativePointer, KNativePointer, KNativePointer); diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/package.json index e0d1d8b9499..b89e58270f3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/package.json @@ -1,6 +1,6 @@ { "name": "@koalaui/libarkts", - "version": "1.5.15+devel", + "version": "1.7.1+devel", "bin": "./lib/es2panda", "types": "./build/index.d.ts", "exports": { @@ -13,16 +13,17 @@ "./plugins/build/src/**/*" ], "config": { - "gen_version": "2.1.5", + "gen_version": "2.1.7", "panda_sdk_path": "../../incremental/tools/panda/node_modules/@panda/sdk", - "ohos_panda_sdk_path": "../build/sdk" + "ohos_panda_sdk_path": "../build/sdk", + "panda_sdk_version": "1.5.0-dev.31052" }, "dependencies": { "@koalaui/ets-tsc": "4.9.5-r5", - "@koalaui/build-common": "1.5.15+devel", - "@koalaui/compat": "1.5.15+devel", - "@koalaui/common": "1.5.15+devel", - "@koalaui/interop": "1.5.15+devel", + "@koalaui/build-common": "1.7.1+devel", + "@koalaui/compat": "1.7.1+devel", + "@koalaui/common": "1.7.1+devel", + "@koalaui/interop": "1.7.1+devel", "node-addon-api": "8.0.0", "node-api-headers": "0.0.5", "commander": "10.0.1" @@ -46,19 +47,19 @@ "compile:js": "npm run compile:src && rollup -c rollup.lib.mjs && rollup -c rollup.es2panda.mjs", "compile:gn": "npm run compile:koala:interop && npm run compile:js", "compile:plugins": "npx rollup -c ./rollup.printer-plugin.mjs && npx rollup -c ./rollup.no-visitor-plugin.mjs ", - "restart": "npx fast-arktsc --config arktsconfig.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build/abc/main.abc --file-option --restart-stages && ninja -f build/abc/build.ninja", - "direct": "PANDA_SDK_PATH=../../incremental/tools/panda/node_modules/@panda/sdk node . --file ./plugins/input/direct.ets --output ./build/abc/direct.abc --dump-plugin-ast --arktsconfig ./arktsconfig-direct.json && file build/abc/direct.abc", - "memo": "PANDA_SDK_PATH=../../incremental/tools/panda/node_modules/@panda/sdk node . --file ./plugins/input/memo.ets --output ./build/abc/memo.abc --dump-plugin-ast --arktsconfig ./arktsconfig-memo.json --restart-stages", - "run": "npm run compile && npm run compile:plugins && npm run compile --prefix ../memo-plugin && npm run restart", + "restart": "node ../fast-arktsc --config arktsconfig.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build/abc/main.abc --restart-stages && ninja -f build/abc/build.ninja", + "direct": "node ../fast-arktsc --config arktsconfig.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build/abc/main.abc && ninja -f build/abc/build.ninja", + "run": "npm run compile && npm run compile:plugins && npm run direct", "run:memo": "npm run compile && npm run compile:plugins && npm run compile --prefix ../memo-plugin && npm run memo", "run:abc": "../../incremental/tools/panda/node_modules/@panda/sdk/linux_host_tools/bin/ark --load-runtimes=ets --boot-panda-files=../../incremental/tools/panda/node_modules/@panda/sdk/ets/etsstdlib.abc ./main.abc main.ETSGLOBAL::main", "mocha": "PANDA_SDK_PATH=../../incremental/tools/panda/node_modules/@panda/sdk TS_NODE_PROJECT=./test/tsconfig.json mocha -r tsconfig-paths/register --reporter-option maxDiffSize=0", "mocha:ohos": "PANDA_SDK_PATH=../build/sdk TS_NODE_PROJECT=./test/tsconfig.json mocha -r tsconfig-paths/register --reporter-option maxDiffSize=0", "test": "npm run compile:native && npm run mocha", + "test:golden": "npm run compile:native && TEST_GOLDEN=1 npm run mocha", "compile:playground": "cd playground && meson setup build && meson compile -C build", "run:playground": "npm run compile:playground && ./playground/build/playground.out", "panda:sdk:clean": "cd ../../incremental/tools/panda && rimraf node_modules", - "panda:sdk:install": "cd ../../incremental/tools/panda && npm run panda:sdk:install", + "panda:sdk:install": "cd ../../incremental/tools/panda && PANDA_SDK_VERSION=$npm_package_config_panda_sdk_version npm run panda:sdk:install && npm run panda:patch", "panda:sdk:reinstall": "npm run panda:sdk:clean && npm run panda:sdk:install", "regenerate:current": "npm run compile -C ../../../arktscgen && node ../../../arktscgen --panda-sdk-path $npm_package_config_panda_sdk_path --output-dir ../ --options-file ./generator/options.json5 --no-initialize --debug", "regenerate": "npx --yes @idlizer/arktscgen@$npm_package_config_gen_version --panda-sdk-path $npm_package_config_panda_sdk_path --output-dir ../ --options-file ./generator/options.json5 --no-initialize", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/meson.build b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/meson.build deleted file mode 100644 index e70cb0ad810..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/meson.build +++ /dev/null @@ -1,31 +0,0 @@ -project('playground', 'cpp', - version: '1.0', - default_options: [ - 'cpp_std=c++17', - 'buildtype=debug', - ], -) - -cflags = [ - '-DKOALA_USE_NODE_VM', - '-DKOALA_NAPI' -] - -if target_machine.system() == 'windows' - cflags += ['-DKOALA_WINDOWS'] -else - cflags += ['-DKOALA_LINUX'] -endif - -executable( - 'playground.out', - [ - './src/playground.cc', - ], - include_directories: [ - get_option('panda_sdk_dir') / 'ohos_arm64/include/tools/es2panda/public', - get_option('panda_sdk_dir') / 'ohos_arm64/include/tools/es2panda', - get_option('interop_src_dir'), - ], - cpp_args: cflags -) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/meson_options.txt b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/meson_options.txt deleted file mode 100644 index 438cc37a430..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/meson_options.txt +++ /dev/null @@ -1,4 +0,0 @@ -option('panda_sdk_dir', type : 'string', value : '../../../incremental/tools/panda/node_modules/@panda/sdk/', - description : 'path to panda sdk') -option('interop_src_dir', type : 'string', value : '../../../interop/src/cpp/', - description : 'path to interop_src') diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/src/playground.cc b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/src/playground.cc deleted file mode 100644 index 96c28c1a398..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/playground/src/playground.cc +++ /dev/null @@ -1,160 +0,0 @@ -/* - * 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. - */ - -#include - -#include "dynamic-loader.h" -#include "es2panda_lib.h" - -#ifdef __x86_64__ - #define PLUGIN_DIR "linux_host_tools" -#else - #define PLUGIN_DIR "linux_arm64_host_tools" -#endif - -const char* libpath = "../../incremental/tools/panda/node_modules/@panda/sdk/" PLUGIN_DIR "/lib/libes2panda-public.so"; - -static es2panda_Impl *impl = nullptr; - -es2panda_Impl *GetImpl() { - if (impl) { - return impl; - } - auto library = loadLibrary(libpath); - if (!library) { - throw std::runtime_error("No library"); - } - auto symbol = findSymbol(library, "es2panda_GetImpl"); - if (!symbol) { - throw std::runtime_error("No entry point"); - } - impl = reinterpret_cast(symbol)(ES2PANDA_LIB_VERSION); - return impl; -} - -static const char* source = -"export class XXX {}" -; -static es2panda_AstNode* newStatements[1]; - -int main() { - impl = GetImpl(); - const char* args[] = { - // command with which the program is invoked (ignored) - "", - "--arktsconfig", - // path to config - "./arktsconfig.json", - // path to source - "./plugins/input/main.ets", - "--stdlib", - "../../incremental/tools/panda/node_modules/@panda/sdk/ets/stdlib" - }; - - auto config = GetImpl()->CreateConfig(6, args); - auto context = GetImpl()->CreateContextFromString(config, source, args[3]); - - GetImpl()->ProceedToState(context, ES2PANDA_STATE_PARSED); - if(GetImpl()->ContextState(context) == ES2PANDA_STATE_ERROR) - { - std::cout << "PROCEED TO PARSE ERROR" << std::endl; - std::cout << GetImpl()->ContextErrorMessage(context) << std::endl; - } - else { - std::cout << "PROCEED TO PARSE SUCCESS" << std::endl; - } - - auto ast = GetImpl()->ProgramAst(context, GetImpl()->ContextProgram(context)); - - std::cout << GetImpl()->AstNodeDumpEtsSrcConst(context, ast) << std::endl; - - std::size_t count = 0; - auto statements = impl->BlockStatementStatements(context, ast, &count); - auto oldClass = statements[0]; - auto oldDef = GetImpl()->ClassDeclarationDefinition(context, oldClass); - - std::cout << "statement count: " << count << std::endl; - - auto *identifier = impl->CreateIdentifier1(context, (char *)"XXX"); - auto *newDef = impl->CreateClassDefinition1( - context, - // oldDef, - identifier, nullptr, 0, Es2pandaClassDefinitionModifiers::CLASS_DEFINITION_MODIFIERS_CLASS_DECL, - Es2pandaModifierFlags::MODIFIER_FLAGS_DECLARE - ); - auto *newClazz = impl->CreateClassDeclaration(context, newDef); - newStatements[0] = newClazz; - - impl->BlockStatementSetStatements(context, ast, newStatements, 1); - impl->AstNodeSetParent(context, newDef, newClazz); - impl->AstNodeSetParent(context, identifier, newDef); - - impl->BlockStatementSetStatements(context, ast, newStatements, 1); - - (void)impl->BlockStatementStatements(context, ast, &count); - std::cout << "new statement count: " << count << std::endl; - - std::cout << GetImpl()->AstNodeDumpEtsSrcConst(context, ast) << std::endl; - - GetImpl()->ProceedToState(context, ES2PANDA_STATE_BOUND); - if(GetImpl()->ContextState(context) == ES2PANDA_STATE_ERROR) - { - std::cout << "PROCEED TO BOUND ERROR" << std::endl; - std::cout << GetImpl()->ContextErrorMessage(context) << std::endl; - } - else { - std::cout << "PROCEED TO BOUND SUCCESS" << std::endl; - } - - GetImpl()->ProceedToState(context, ES2PANDA_STATE_CHECKED); - if(GetImpl()->ContextState(context) == ES2PANDA_STATE_ERROR) - { - std::cout << "PROCEED TO CHECKED ERROR" << std::endl; - std::cout << GetImpl()->ContextErrorMessage(context) << std::endl; - } - else { - std::cout << "PROCEED TO CHECKED SUCCESS" << std::endl; - } - - GetImpl()->ProceedToState(context, ES2PANDA_STATE_LOWERED); - if(GetImpl()->ContextState(context) == ES2PANDA_STATE_ERROR) - { - std::cout << "PROCEED TO LOWERED ERROR" << std::endl; - std::cout << GetImpl()->ContextErrorMessage(context) << std::endl; - } - else { - std::cout << "PROCEED TO LOWERED SUCCESS" << std::endl; - } - - GetImpl()->ProceedToState(context, ES2PANDA_STATE_ASM_GENERATED); - if(GetImpl()->ContextState(context) == ES2PANDA_STATE_ERROR) - { - std::cout << "PROCEED TO ASM ERROR" << std::endl; - std::cout << GetImpl()->ContextErrorMessage(context) << std::endl; - } - else { - std::cout << "PROCEED TO ASM SUCCESS" << std::endl; - } - - GetImpl()->ProceedToState(context, ES2PANDA_STATE_BIN_GENERATED); - if(GetImpl()->ContextState(context) == ES2PANDA_STATE_ERROR) - { - std::cout << "PROCEED TO BIN ERROR" << std::endl; - std::cout << GetImpl()->ContextErrorMessage(context) << std::endl; - } - else { - std::cout << "PROCEED TO BIN SUCCESS" << std::endl; - } -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/direct.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/direct.ets index e265532a9dd..b51286dbbd7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/direct.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/direct.ets @@ -1,3 +1,18 @@ +/* + * 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 { __memo_context_type, __memo_id_type } from "@koalaui/runtime" @Retention({policy: "SOURCE"}) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/export.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/export.ets index d5f7c542e43..77e954c9173 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/export.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/export.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + export function foo() { console.log("Hello, world!") } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/f.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/f.ets index 369304938e2..6904403bc5a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/f.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/f.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + export function f() { console.log("Hello, world!") } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/library.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/library.ets index d801589a651..6a90478cce3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/library.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/library.ets @@ -1 +1,22 @@ -export @interface Component {} \ No newline at end of file +/* + * 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. + */ + +export function testFunction(): string { + return "yes" +} +export function anotherFunction(): string { + return "no" +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/main.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/main.ets index f55101d9765..4846a65a957 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/main.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/main.ets @@ -1,32 +1,35 @@ -import { Component } from "./library" +/* + * 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. + */ -@interface BuilderLambda { - value: string +enum X { + A = 17 } -@Component -struct MyComponent { - @BuilderLambda("MyComponent.instantiateImpl") - static $_instantiate(factory: () => MyComponent): MyComponent { - const instance = factory() - return instance - } - - static instantiateImpl(builder: (instance: MyComponent)=>void, factory: () => MyComponent): void { - const instance = factory() - builder(instance) - } - - width(value: number): MyComponent { return this } - build() {} +namespace Y { + function foo() { + } } +function foo(value: int): void { + switch (X.fromValue(value)) { + case X.A: + console.log("A") + break + default: + console.log("default") -@Component -struct AnotherComponent { - - build() { - MyComponent() - .width(17.0) - } + } } + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/no-import-no-struct.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/no-import-no-struct.ets index e1231f9cbde..c1e39867ade 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/no-import-no-struct.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/no-import-no-struct.ets @@ -1,3 +1,18 @@ +/* + * 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. + */ + @interface Component{} @interface BuilderLambda { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/one_recursive.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/one_recursive.ts new file mode 100644 index 00000000000..fc837a57b0f --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/one_recursive.ts @@ -0,0 +1,8 @@ +import { Two } from "./two_recursive" + +export interface One { + two(): Two { + throw new Error("") + } +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/two_recursive.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/two_recursive.ts new file mode 100644 index 00000000000..a4d708b6428 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/two_recursive.ts @@ -0,0 +1,8 @@ +import { One } from "./one_recursive" + +export interface Two { + one(): One { + throw new Error("") + } +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/variable.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/variable.ets index b79405ec234..289ef6ec995 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/variable.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/variable.ets @@ -1 +1,16 @@ +/* + * 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. + */ + export const X: number = 1.2345; diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/src/no-visitor.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/src/no-visitor.ts index 9fa3f0800f9..ef4df7cd56e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/src/no-visitor.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/src/no-visitor.ts @@ -16,7 +16,7 @@ import * as arkts from "@koalaui/libarkts" export default function noVisitor() { - return (node: arkts.ETSModule) => { - return node + return (program: arkts.Program) => { + return program } } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/src/printer-plugin.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/src/printer-plugin.ts index b600813d199..b58fb2860b4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/src/printer-plugin.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/src/printer-plugin.ts @@ -24,7 +24,7 @@ export interface TransformerOptions { export default function printerTransformer( userPluginOptions?: TransformerOptions ) { - return (node: arkts.ETSModule) => { - return new PrintVisitor().visitor(node) + return (program: arkts.Program) => { + return new PrintVisitor().visitor(program.astNode) } } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src-host/es2panda.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src-host/es2panda.ts index bcd5c256ef8..390b3396fed 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src-host/es2panda.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src-host/es2panda.ts @@ -1,276 +1,323 @@ -/* - * Copyright (c) 2022-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 fs from "node:fs" -import * as path from "node:path" -import { arktsGlobal as global } from "@koalaui/libarkts" -import { Command } from "commander" -import { filterSource, isNumber, throwError, withWarning } from "@koalaui/libarkts" -import { Es2pandaContextState } from "@koalaui/libarkts" -import { AstNode, checkErrors, Config, Context, createETSModuleFromContext, proceedToState, rebindSubtree, recheckSubtree } from "@koalaui/libarkts" - -function parseCommandLineArgs() { - const commander = new Command() - .option('--file, ', 'Path to file to be compiled') - .option('--arktsconfig, ', 'Path to arkts configuration file') - .option('--ets-module', 'Do nothing, legacy compatibility') - .option('--output, ', 'The name of result file') - .option('--dump-plugin-ast', 'Dump ast before and after each plugin') - .option('--restart-stages', 'Restart the compiler to proceed to next stage') - .option('--stage ', 'Stage of multistage compilation (from 0 to number of plugins in arktsconfig + 1)') - .parse(process.argv) - .opts() - - const restOptions = commander.args - - const filePath = path.resolve(commander.file) - const configPath = path.resolve(commander.arktsconfig) - const outputPath = path.resolve(commander.output) - if (!fs.existsSync(filePath)) { - throw new Error(`File path doesn't exist: ${filePath}`) - } - if (!fs.existsSync(configPath)) { - throw new Error(`Arktsconfig path doesn't exist: ${configPath}`) - } - - const dumpAst = commander.dumpPluginAst ?? false - const restartStages = commander.restartStages ?? false - const stage = commander.stage ?? 0 - - return { filePath, configPath, outputPath, dumpAst, restartStages, stage } -} - -function insertPlugin(transform: (ast: AstNode) => void, state: Es2pandaContextState, dumpAst: boolean, restart: boolean, updateWith?: (node: AstNode) => void): AstNode { - proceedToState(state) - const script = createETSModuleFromContext() - if (script === undefined) { - throwError(`Failed to receive ast from es2panda`) - } - - if (dumpAst) { - console.log(`BEFORE ${stateName(state)}:`) - console.log(filterSource(script.dumpSrc())) - } - - const beforeTransform = Date.now() - - transform?.(script) - - const afterTransform = Date.now() - global.profiler.transformTime += afterTransform - beforeTransform - - if (dumpAst) { - console.log(`AFTER ${stateName(state)}:`) - console.log(filterSource(script.dumpSrc())) - } - - setAllParents(script) - - if (!restart) { - updateWith?.(script) - } - // note: sometimes errors are generated, but state not changed to Es2pandaContextState.ES2PANDA_STATE_ERROR (01.04.25) - return script -} - -function restartCompiler(configPath: string, filePath: string, stdlib: string, outputPath: string, verbose: boolean = true) { - if (verbose) { - console.log(`restarting with config ${configPath}, file ${filePath}`) - } - const srcText = filterSource(createETSModuleFromContext().dumpSrc()) - global.es2panda._DestroyContext(global.context) - global.es2panda._DestroyConfig(global.config) - - global.filePath = filePath - global.config = Config.create([ - '_', - '--arktsconfig', - configPath, - filePath, - '--extension', - 'ets', - '--stdlib', - stdlib, - '--output', - outputPath - ]).peer - global.compilerContext = Context.createFromString(srcText) -} - -const defaultPandaSdk = "../../../incremental/tools/panda/node_modules/@panda/sdk" -function invokeWithPlugins( - configPath: string, - packageName: string, - baseUrl: string, - outDir: string, - filePath: string, - outputPath: string, - pluginsByState: Map void)[]>, - dumpAst: boolean, - restart: boolean, - stage: number, - pluginNames: string[], -): void { - const source = fs.readFileSync(filePath).toString() - const sdk = process.env.PANDA_SDK_PATH ?? withWarning( - defaultPandaSdk, - `PANDA_SDK_PATH not set, assuming ${defaultPandaSdk}` - ) - const stdlib = `${sdk}/ets/stdlib` - - global.filePath = filePath - global.packageName = packageName - global.filePathFromPackageRoot = path.relative(path.join(path.dirname(configPath), baseUrl), filePath) - global.config = Config.create([ - '_', - '--arktsconfig', - configPath, - filePath, - '--extension', - 'ets', - '--stdlib', - stdlib, - '--output', - outputPath - ]).peer - fs.mkdirSync(path.dirname(outputPath), {recursive: true}) - global.compilerContext = Context.createFromString(source) - - console.log("PLUGINS: ", pluginsByState.size, pluginsByState) - - pluginNames.push(`_proceed_to_binary`) - let pluginsApplied = 0 - - const restartProcedure = () => { - if (restart) { - const before = Date.now() - const ext = path.extname(configPath) - const newConfigPath = `${configPath.substring(0, configPath.length - pluginNames[pluginsApplied].length - ext.length)}${pluginNames[pluginsApplied + 1]}${ext}` - const newFilePath = path.resolve(outDir, pluginNames[pluginsApplied], global.filePathFromPackageRoot) - if (pluginsApplied == stage) { - // uncomment if switch to dets generator - // restartCompiler(configPath, filePath, stdlib, outputPath, false) - generateDeclFromCurrentContext(newFilePath) - } - pluginsApplied++ - restartCompiler(newConfigPath, newFilePath, stdlib, outputPath) - configPath = newConfigPath - filePath = newFilePath - const after = Date.now() - global.profiler.restartTime += after - before - } - } - - pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_PARSED)?.forEach(plugin => { - insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_PARSED, dumpAst, restart) - restartProcedure() - }) - - pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_BOUND)?.forEach(plugin => { - insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_BOUND, dumpAst, restart, rebindSubtree) - restartProcedure() - }) - - pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_CHECKED)?.forEach(plugin => { - insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_CHECKED, dumpAst, restart, recheckSubtree) - restartProcedure() - }) - proceedToState(Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) -} - -const exportsFromInitialFile: string[] = [] - -function generateDeclFromCurrentContext(filePath: string): never { - proceedToState(Es2pandaContextState.ES2PANDA_STATE_PARSED) - console.log(`Emitting to ${filePath}`) - let out = [ - filterSource(global.compilerContext.program.astNode.dumpSrc()), - ...exportsFromInitialFile - ].join('\n') - fs.mkdirSync(path.dirname(filePath), { recursive: true }) - fs.writeFileSync(filePath, out) - process.exit(0) -} - -function setAllParents(ast: AstNode) { - global.es2panda._AstNodeUpdateAll(global.context, ast.peer) -} - -function loadPlugin(configDir: string, jsonPlugin: any) { - const pluginPath = jsonPlugin.transform ?? throwError(`arktsconfig plugins objects should specify transform`) - /** TODO: read and pass plugin options */ - const plugin = (pluginPath.startsWith(".") || pluginPath.startsWith("/")) ? - path.resolve(configDir, pluginPath) : pluginPath - const pluginFunction: (config?: any) => any = require(plugin)(jsonPlugin) - return pluginFunction -} - -function selectPlugins(configDir: string, plugins: any[], stage: string): ((arg: AstNode) => AstNode)[] | undefined { - const selected = plugins - .filter(it => (it.stage == stage)) - .map(it => loadPlugin(configDir, it)) - if (selected.length == 0) { - return undefined - } - return selected -} - -function stateName(value: Es2pandaContextState): string { - return Es2pandaContextState[value].substring("ES2PANDA_STATE_".length) -} - -function readAndSortPlugins(configDir: string, plugins: any[]) { - const pluginsByState = new Map void)[]>() - - Object.values(Es2pandaContextState) - .filter(isNumber) - .forEach(it => { - const selected = selectPlugins(configDir, plugins, stateName(it).toLowerCase()) - if (selected) pluginsByState.set( - it, - selected - ) - }) - - return pluginsByState -} - -export function main() { - const before = Date.now() - const { filePath, configPath, outputPath, dumpAst, restartStages, stage } = parseCommandLineArgs() - const arktsconfig = JSON.parse(fs.readFileSync(configPath).toString()) - const configDir = path.dirname(configPath) - const compilerOptions = arktsconfig.compilerOptions ?? throwError(`arktsconfig should specify compilerOptions`) - const packageName = compilerOptions.package ?? "" - const baseUrl = compilerOptions.baseUrl ?? "." - const outDir = path.resolve(path.dirname(configPath), compilerOptions.outDir ?? ".") - const plugins = compilerOptions.plugins ?? [] - const pluginNames = plugins.map((it: any) => `${it.name}-${it.stage}`) - - const pluginsByState = readAndSortPlugins(configDir, plugins) - - exportsFromInitialFile.push( - ...[...fs.readFileSync(filePath).toString().matchAll(/export {([\s\S]*?)} from .*(\n|$)/g)].map(it => it[0]), - ...[...fs.readFileSync(filePath).toString().matchAll(/export \* from .*(\n|$)/g)].map(it => it[0]) - ) - - invokeWithPlugins(configPath, packageName, baseUrl, outDir, filePath, outputPath, pluginsByState, dumpAst, restartStages, stage, pluginNames) - - const after = Date.now() - global.profiler.totalTime = after - before - global.profiler.report() -} - -main() +/* + * Copyright (c) 2022-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 fs from "node:fs" +import * as path from "node:path" +import { arktsGlobal as global } from "@koalaui/libarkts" +import { CheckedBackFilter } from "@koalaui/libarkts" +import { Command } from "commander" +import { filterSource, isNumber, throwError, withWarning } from "@koalaui/libarkts" +import { Es2pandaContextState } from "@koalaui/libarkts" +import { AstNode, CompilationOptions, Config, Context, createETSModuleFromContext, listPrograms, proceedToState, ProgramTransformer, rebindSubtree, recheckSubtree, setBaseOverloads } from "@koalaui/libarkts" + +function parseCommandLineArgs() { + const commander = new Command() + .argument('[file]', 'Path to file to be compiled') + .option('--file, ', 'Path to file to be compiled (deprecated)') + .option('--arktsconfig, ', 'Path to arkts configuration file') + .option('--ets-module', 'Do nothing, legacy compatibility') + .option('--output, ', 'The name of result file') + .option('--dump-plugin-ast', 'Dump ast before and after each plugin') + .option('--restart-stages', 'Restart the compiler to proceed to next stage') + .option('--stage ', 'Stage of multistage compilation (from 0 to number of plugins in arktsconfig + 1)') + .parse(process.argv) + + const cliOptions = commander.opts() + const cliArgs = commander.args + const filePathArg = cliOptions.file ?? cliArgs[0] + if (!filePathArg) { + reportErrorAndExit(`Either --file option or file argument is required`) + } + const filePath = path.resolve(filePathArg) + const configPath = path.resolve(cliOptions.arktsconfig) + const outputPath = path.resolve(cliOptions.output) + if (!fs.existsSync(filePath)) { + reportErrorAndExit(`File path doesn't exist: ${filePath}`) + } + if (!fs.existsSync(configPath)) { + reportErrorAndExit(`Arktsconfig path doesn't exist: ${configPath}`) + } + + const dumpAst = cliOptions.dumpPluginAst ?? false + const restartStages = cliOptions.restartStages ?? false + const stage = cliOptions.stage ?? 0 + + return { filePath, configPath, outputPath, dumpAst, restartStages, stage } +} + +function insertPlugin( + source: string, + transform: ProgramTransformer, + state: Es2pandaContextState, + dumpAst: boolean, restart: boolean, + updateWith?: (node: AstNode) => void): AstNode { + proceedToState(state) + const script = createETSModuleFromContext() + // Or this: const script = createETSModuleFromSource(source) + if (script === undefined) { + throw new Error(`Failed to receive AST from es2panda for ${source}`) + } + + if (dumpAst) { + console.log(`BEFORE ${stateName(state)}:`) + console.log(filterSource(script.dumpSrc())) + } + + const beforeTransform = Date.now() + + if (!restart) { + const programs = listPrograms(global.compilerContext.program) + programs.forEach((program, index) => { + if (index == 0) { + return + } + const ast = program.program.astNode + transform?.(program.program, { isMainProgram: false, name: program.name, stage: state }) + setBaseOverloads(ast) + setAllParents(ast) + }) + } + + transform?.(global.compilerContext.program, { isMainProgram: true, name: `${global.packageName}.${global.filePathFromPackageRoot}`, stage: state }) + + const afterTransform = Date.now() + global.profiler.transformTime += afterTransform - beforeTransform + + if (dumpAst) { + console.log(`AFTER ${stateName(state)}:`) + if (restart) { + console.log(filterSource(script.dumpSrc())) + } else { + console.log(script.dumpSrc()) + } + } + + setBaseOverloads(script) + setAllParents(script) + + if (!restart) { + console.log("UPDATE...") + updateWith?.(script) + console.log("DONE!") + } + return script +} + +function restartCompiler(source: string, configPath: string, filePath: string, stdlib: string, outputPath: string, verbose: boolean = true) { + if (verbose) { + console.log(`restarting with config ${configPath}, file ${filePath}`) + } + const module = createETSModuleFromContext() + if (module == undefined) throw new Error(`Cannot restart compiler for ${source}`) + const filterTransform = new CheckedBackFilter() + const srcText = filterSource( + filterTransform.visitor(module) + .dumpSrc() + ) + global.es2panda._DestroyContext(global.context) + global.es2panda._DestroyConfig(global.config) + + global.filePath = filePath + global.config = Config.create([ + '_', + '--arktsconfig', + configPath, + filePath, + '--extension', + 'ets', + '--stdlib', + stdlib, + '--output', + outputPath + ]).peer + global.compilerContext = Context.createFromString(srcText) +} + +const defaultPandaSdk = "../../../incremental/tools/panda/node_modules/@panda/sdk" +function invokeWithPlugins( + configPath: string, + packageName: string, + baseUrl: string, + outDir: string, + filePath: string, + outputPath: string, + pluginsByState: Map, + dumpAst: boolean, + restart: boolean, + stage: number, + pluginNames: string[], +): void { + const source = fs.readFileSync(filePath).toString() + const sdk = process.env.PANDA_SDK_PATH ?? withWarning( + defaultPandaSdk, + `PANDA_SDK_PATH not set, assuming ${defaultPandaSdk}` + ) + const stdlib = `${sdk}/ets/stdlib` + + global.filePath = filePath + global.packageName = packageName + global.filePathFromPackageRoot = path.relative(path.join(path.dirname(configPath), baseUrl), filePath) + global.config = Config.create([ + '_', + '--arktsconfig', + configPath, + filePath, + '--extension', + 'ets', + '--stdlib', + stdlib, + '--output', + outputPath + ]).peer + if (!global.configIsInitialized()) + throw new Error(`Wrong config: path=${configPath} file=${filePath} stdlib=${stdlib} output=${outputPath}`) + fs.mkdirSync(path.dirname(outputPath), {recursive: true}) + global.compilerContext = Context.createFromString(source) + + console.log("PLUGINS: ", pluginsByState.size, pluginsByState) + + pluginNames.push(`_proceed_to_binary`) + let pluginsApplied = 0 + + const restartProcedure = () => { + if (restart) { + const before = Date.now() + const ext = path.extname(configPath) + const newConfigPath = `${configPath.substring(0, configPath.length - pluginNames[pluginsApplied].length - ext.length)}${pluginNames[pluginsApplied + 1]}${ext}` + const newFilePath = path.resolve(outDir, pluginNames[pluginsApplied], global.filePathFromPackageRoot) + if (pluginsApplied == stage) { + // uncomment if switch to dets generator + // restartCompiler(configPath, filePath, stdlib, outputPath, false) + generateDeclFromCurrentContext(newFilePath) + } + pluginsApplied++ + restartCompiler(source, newConfigPath, newFilePath, stdlib, outputPath) + configPath = newConfigPath + filePath = newFilePath + const after = Date.now() + global.profiler.restartTime += after - before + } + } + + pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_PARSED)?.forEach(plugin => { + insertPlugin(source, plugin, Es2pandaContextState.ES2PANDA_STATE_PARSED, dumpAst, restart) + restartProcedure() + }) + + pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_BOUND)?.forEach(plugin => { + insertPlugin(source, plugin, Es2pandaContextState.ES2PANDA_STATE_BOUND, dumpAst, restart, rebindSubtree) + restartProcedure() + }) + + pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_CHECKED)?.forEach(plugin => { + insertPlugin(source, plugin, Es2pandaContextState.ES2PANDA_STATE_CHECKED, dumpAst, restart, recheckSubtree) + restartProcedure() + }) + proceedToState(Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) +} + +const exportsFromInitialFile: string[] = [] + +function generateDeclFromCurrentContext(filePath: string): never { + proceedToState(Es2pandaContextState.ES2PANDA_STATE_PARSED) + console.log(`Emitting to ${filePath}`) + const filterTransform = new CheckedBackFilter() + let out = [ + filterSource( + filterTransform.visitor(global.compilerContext.program.astNode) + .dumpSrc() + ), + ...exportsFromInitialFile + ].join('\n') + fs.mkdirSync(path.dirname(filePath), { recursive: true }) + fs.writeFileSync(filePath, out) + process.exit(0) +} + +function setAllParents(ast: AstNode) { + global.es2panda._AstNodeUpdateAll(global.context, ast.peer) +} + +function loadPlugin(configDir: string, jsonPlugin: any) { + const pluginPath = jsonPlugin.transform ?? throwError(`arktsconfig plugins objects should specify transform`) + /** TODO: read and pass plugin options */ + const plugin = (pluginPath.startsWith(".") || pluginPath.startsWith("/")) ? + path.resolve(configDir, pluginPath) : pluginPath + const pluginFunction: (config?: any) => any = require(plugin)(jsonPlugin) + return pluginFunction +} + +function selectPlugins(configDir: string, plugins: any[], stage: string): ProgramTransformer[] | undefined { + const selected = plugins + .filter(it => (it.stage == stage)) + .map(it => loadPlugin(configDir, it)) + if (selected.length == 0) { + return undefined + } + return selected +} + +function stateName(value: Es2pandaContextState): string { + return Es2pandaContextState[value].substring("ES2PANDA_STATE_".length) +} + +function readAndSortPlugins(configDir: string, plugins: any[]) { + const pluginsByState = new Map() + + Object.values(Es2pandaContextState) + .filter(isNumber) + .forEach(it => { + const selected = selectPlugins(configDir, plugins, stateName(it).toLowerCase()) + if (selected) pluginsByState.set( + it, + selected + ) + }) + + return pluginsByState +} + +export function main() { + const before = Date.now() + const { filePath, configPath, outputPath, dumpAst, restartStages, stage } = parseCommandLineArgs() + const arktsconfig = JSON.parse(fs.readFileSync(configPath).toString()) + const configDir = path.dirname(configPath) + const compilerOptions = arktsconfig.compilerOptions ?? throwError(`arktsconfig should specify compilerOptions`) + const packageName = compilerOptions.package ?? "" + const baseUrl = compilerOptions.baseUrl ?? "." + const outDir = path.resolve(path.dirname(configPath), compilerOptions.outDir ?? ".") + const plugins = compilerOptions.plugins ?? [] + const pluginNames = plugins.map((it: any) => `${it.name}-${it.stage}`) + + const pluginsByState = readAndSortPlugins(configDir, plugins) + + exportsFromInitialFile.push( + ...[...fs.readFileSync(filePath).toString().matchAll(/export {([\s\S]*?)} from .*(\n|$)/g)].map(it => it[0]), + ...[...fs.readFileSync(filePath).toString().matchAll(/export \* from .*(\n|$)/g)].map(it => it[0]) + ) + + invokeWithPlugins(configPath, packageName, baseUrl, outDir, filePath, outputPath, pluginsByState, dumpAst, restartStages, stage, pluginNames) + + const after = Date.now() + global.profiler.totalTime = after - before + global.profiler.report() +} + +function reportErrorAndExit(message: string): never { + console.error(message) + process.exit(1) +} + +main() diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/InteropNativeModule.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/InteropNativeModule.ts index ffdab5d8313..5b4d4804846 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/InteropNativeModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/InteropNativeModule.ts @@ -19,7 +19,6 @@ import { registerNativeModuleLibraryName, loadNativeModuleLibrary } from "@koalaui/interop" -import * as path from "path" import { findNativeModule } from "./Es2pandaNativeModule" export class InteropNativeModule { @@ -32,6 +31,9 @@ export class InteropNativeModule { _GetStringFinalizer(): KPtr { throw new Error("Not implemented") } + _RawUtf8ToString(ptr: KPtr): string { + throw new Error("Not implemented") + } _InvokeFinalizer(ptr: KPtr, finalizer: KPtr): void { throw new Error("Not implemented") } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/CheckedBackFilter.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/CheckedBackFilter.ts new file mode 100644 index 00000000000..22091694ae4 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/CheckedBackFilter.ts @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022-2023 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 { ClassDefinition, ClassElement, ClassProperty, Es2pandaModifierFlags, Expression, TSEnumDeclaration, TSEnumMember, asString, factory, isCallExpression, isClassDeclaration, isClassDefinition, isClassProperty, isETSNewClassInstanceExpression } from "./index"; +import { AbstractVisitor } from "./AbstractVisitor"; +import { AstNode } from "./peers/AstNode" + + +export class CheckedBackFilter extends AbstractVisitor { + transformInitializer(node: Expression|undefined): Expression|undefined { + if (node == undefined) return undefined + if (!isETSNewClassInstanceExpression(node)) return node + // new ZZZ(ordinal, value) !-> value + return node.arguments[1] + } + transformEnum(node: ClassDefinition): AstNode { + return TSEnumDeclaration.createTSEnumDeclaration( + node.ident, + node.body.map(it => { + const member: ClassElement = it as ClassElement + if (!isClassProperty(member)) return undefined + if (isClassProperty(member) && member.id?.name.startsWith("#")) return undefined + return factory.createTSEnumMember( + member.key, + this.transformInitializer(member.value), + false + ) + }).filter(it => it != undefined) as TSEnumMember[], + false, + false, + !!(node.modifierFlags & Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE) + ) + } + visitor(beforeChildren: AstNode): AstNode { + const node = this.visitEachChild(beforeChildren) + if (isClassDefinition(node) && node.isEnumTransformed) { + return this.transformEnum(node) + } + return node + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/get_prebuilt.mjs b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/SetBaseOverloads.ts similarity index 32% rename from frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/get_prebuilt.mjs rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/SetBaseOverloads.ts index d76ac6aec21..0164d8cab5a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/get_prebuilt.mjs +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/SetBaseOverloads.ts @@ -13,46 +13,39 @@ * limitations under the License. */ -import { GitLab } from "../../tools/storage/gitlab/gitlab.mjs"; -import minimist from "minimist"; -import path from "path" +import { factory } from "./factory/nodeFactory" +import { ETSModule, isMethodDefinition, MethodDefinition } from "../generated" +import { AbstractVisitor } from "./AbstractVisitor" +import { AstNode } from "./peers/AstNode" -const gitlab = new GitLab() - -let args = minimist(process.argv.slice(2)) - -const version = args.version -const buildType = args['build-type'] -const machine = args.machine -const target = args.target +export class SetBaseOverloads extends AbstractVisitor { + visitor(node: MethodDefinition, baseOverloadMethod?: MethodDefinition): MethodDefinition + visitor(node: AstNode, baseOverloadMethod?: MethodDefinition): AstNode + visitor(node: AstNode, baseOverloadMethod?: MethodDefinition): AstNode { + if (isMethodDefinition(node)) { + const result = factory.updateMethodDefinition( + node, + node.kind, + node.key, + node.value, + node.modifierFlags, + node.isComputed, + node.overloads.map((it) => this.visitor(it, node)), + ) + if (baseOverloadMethod) { + result.setBaseOverloadMethod(baseOverloadMethod) + } + return result + } + return this.visitEachChild(node) + } -const nodeVersion = version.split('-')[0] -const buildName = buildType + '-' + target + '-' + machine -const outDir = path.join('prebuilt', version, buildName) + static instance?: SetBaseOverloads +} -if (target === 'android') { - gitlab.downloadRawArchive( - 'node-bin', - nodeVersion, - `node-${target}-${buildType}-${machine}-${version}.zip`, - outDir - ) -} else { - gitlab.downloadRawArchive( - 'node-bin', - nodeVersion, - `node-v${nodeVersion}-headers.tar.gz`, - outDir, - `node-v${nodeVersion}/`, - ) - if (target === 'windows') { - gitlab.downloadRawFile( - 'node-bin', - nodeVersion, - `win-${machine}.node.lib`, - path.join(outDir, 'lib'), - 'node.lib' - ) +export function setBaseOverloads(node: ETSModule) { + if (!SetBaseOverloads.instance) { + SetBaseOverloads.instance = new SetBaseOverloads() } + SetBaseOverloads.instance.visitor(node) } - diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/factory/nodeFactory.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/factory/nodeFactory.ts index e302ced3555..9b806770fe1 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/factory/nodeFactory.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/factory/nodeFactory.ts @@ -38,10 +38,10 @@ import { createETSImportDeclaration, updateETSImportDeclaration } from "../node- import { updateVariableDeclarator } from "../node-utilities/VariableDeclarator" import { updateClassDefinition } from "../node-utilities/ClassDefinition" import { updateETSStructDeclaration } from "../node-utilities/ETSStructDeclaration" -import { updateClassProperty } from "../node-utilities/ClassProperty" +import { createClassProperty, updateClassProperty } from "../node-utilities/ClassProperty" import { createETSFunctionType, updateETSFunctionType } from "../node-utilities/ETSFunctionType" import { createMethodDefinition, updateMethodDefinition } from "../node-utilities/MethodDefinition" -import { updateTSInterfaceDeclaration } from "../node-utilities/TSInterfaceDeclaration" +import { createTSInterfaceDeclaration, updateTSInterfaceDeclaration } from "../node-utilities/TSInterfaceDeclaration" import { createArrowFunctionExpression, updateArrowFunctionExpression } from "../node-utilities/ArrowFunctionExpression" import { updateTryStatement } from "../node-utilities/TryStatement" import { createVariableDeclaration, updateVariableDeclaration } from "../node-utilities/VariableDeclaration" @@ -90,7 +90,7 @@ export const factory = { createClassDefinition: ClassDefinition.createClassDefinition, updateClassDefinition, - createClassProperty: ClassProperty.createClassProperty, + createClassProperty, updateClassProperty, createETSFunctionType, @@ -99,7 +99,7 @@ export const factory = { createMethodDefinition, updateMethodDefinition, - createInterfaceDeclaration: TSInterfaceDeclaration.createTSInterfaceDeclaration, + createInterfaceDeclaration: createTSInterfaceDeclaration, updateInterfaceDeclaration: updateTSInterfaceDeclaration, createArrowFunctionExpression, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/index.ts index 6ce9b80d4b9..26e11e2b2a1 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/index.ts @@ -21,6 +21,9 @@ export * from "./utilities/public" export * from "./factory/nodeFactory" export * from "./visitor" export * from "./AbstractVisitor" +export * from "./CheckedBackFilter" +export * from "./SetBaseOverloads" +export * from "./plugins" export * from "./peers/AstNode" export * from "./peers/Config" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/CallExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/CallExpression.ts index 714b703e927..d50e0c64069 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/CallExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/CallExpression.ts @@ -24,7 +24,7 @@ export function createCallExpression( optional_arg: boolean = false, trailingComma: boolean = false, trailingBlock: BlockStatement | undefined = undefined, -) { +): CallExpression { const res = CallExpression.createCallExpression( callee, _arguments, @@ -46,7 +46,7 @@ export function updateCallExpression( optional_arg: boolean = false, trailingComma: boolean = false, trailingBlock: BlockStatement | undefined = undefined, -) { +): CallExpression { if (isSameNativeObject(callee, original.callee) && isSameNativeObject(_arguments, original.arguments) && isSameNativeObject(typeParams, original.typeParams) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ClassDefinition.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ClassDefinition.ts index 071127e44f4..9f7cc78c255 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ClassDefinition.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ClassDefinition.ts @@ -40,7 +40,7 @@ export function updateClassDefinition( body: readonly AstNode[], modifiers: Es2pandaClassDefinitionModifiers, flags: Es2pandaModifierFlags -) { +): ClassDefinition { if (original.ctor !== undefined && !isMethodDefinition(original.ctor)) { throwError(`class definition constructor is not method definition: ${ctor?.dump()}`) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ClassProperty.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ClassProperty.ts index 5718f19de14..afa0454ed3e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ClassProperty.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ClassProperty.ts @@ -13,29 +13,52 @@ * limitations under the License. */ -import { ClassProperty, Expression, TypeNode } from "../../generated" +import { AnnotationUsage, ClassProperty, Expression, TypeNode } from "../../generated" import { Es2pandaModifierFlags } from "../../generated/Es2pandaEnums" import { isSameNativeObject } from "../peers/ArktsObject" import { updateNodeByNode } from "../utilities/private" +export function createClassProperty( + key: Expression | undefined, + value: Expression | undefined, + typeAnnotation: TypeNode | undefined, + modifiers: Es2pandaModifierFlags, + isComputed: boolean, + annotations?: readonly AnnotationUsage[], +): ClassProperty { + const res = ClassProperty.createClassProperty( + key, + value, + typeAnnotation, + modifiers, + isComputed, + ) + if (annotations) { + res.setAnnotations(annotations) + } + return res +} + export function updateClassProperty( original: ClassProperty, key: Expression | undefined, value: Expression | undefined, typeAnnotation: TypeNode | undefined, modifiers: Es2pandaModifierFlags, - isComputed: boolean -) { + isComputed: boolean, + annotations?: readonly AnnotationUsage[], +): ClassProperty { if (isSameNativeObject(key, original.key) && isSameNativeObject(value, original.value) && isSameNativeObject(typeAnnotation, original.typeAnnotation) && isSameNativeObject(modifiers, original.modifierFlags) && isSameNativeObject(isComputed, original.isComputed) + && isSameNativeObject(annotations, original.annotations) ) { return original } return updateNodeByNode( - ClassProperty.createClassProperty(key, value, typeAnnotation, modifiers, isComputed), + createClassProperty(key, value, typeAnnotation, modifiers, isComputed, annotations), original ) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSFunctionType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSFunctionType.ts index 7ca6883a222..5c21d633d3c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSFunctionType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSFunctionType.ts @@ -25,7 +25,7 @@ export function createETSFunctionType( hasReceiver: boolean, funcFlags: Es2pandaScriptFunctionFlags, annotations?: readonly AnnotationUsage[], -) { +): ETSFunctionType { const res = ETSFunctionType.createETSFunctionType( FunctionSignature.createFunctionSignature( typeParams, @@ -49,7 +49,7 @@ export function updateETSFunctionType( hasReceiver: boolean, funcFlags: Es2pandaScriptFunctionFlags, annotations?: readonly AnnotationUsage[], -) { +): ETSFunctionType { if (isSameNativeObject(typeParams, original.typeParams) && isSameNativeObject(params, original.params) && isSameNativeObject(returnTypeAnnotation, original.returnType) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSImportDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSImportDeclaration.ts index 4eabb1173e1..05a6d3bbcc4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSImportDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSImportDeclaration.ts @@ -28,6 +28,7 @@ export function createETSImportDeclaration( program: Program, flags: Es2pandaImportFlags ): ETSImportDeclaration { + // TODO: check that plugin is on parsed stage const res = unpackNonNullableNode( global.es2panda._ETSParserBuildImportDeclaration( global.context, @@ -39,7 +40,7 @@ export function createETSImportDeclaration( flags ) ) - global.es2panda._InsertETSImportDeclarationAndParse(global.context, global.compilerContext.program.peer, res.peer) + global.es2panda._InsertETSImportDeclarationAndParse(global.context, program.peer, res.peer) return new ETSImportDeclaration(res.peer) } @@ -48,7 +49,7 @@ export function updateETSImportDeclaration( source: StringLiteral | undefined, specifiers: readonly AstNode[], importKind: Es2pandaImportKinds -) { +): ETSImportDeclaration { if (isSameNativeObject(source, original.source) && isSameNativeObject(specifiers, original.specifiers) /* no getter for importKind */ diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSParameterExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSParameterExpression.ts index 8071ba195d5..355465311a3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSParameterExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSParameterExpression.ts @@ -23,7 +23,7 @@ export function createETSParameterExpression( initExpr?: Expression, typeAnnotation?: TypeNode, annotations?: readonly AnnotationUsage[] -) { +): ETSParameterExpression { const res = ETSParameterExpression.createETSParameterExpression(identOrSpread, isOptional) if (initExpr) { res.setInitializer(initExpr) @@ -44,7 +44,7 @@ export function updateETSParameterExpression( initExpr?: Expression, typeAnnotation?: TypeNode, annotations?: readonly AnnotationUsage[], -) { +): ETSParameterExpression { if ((isSameNativeObject(identOrSpread, original.ident) || isSameNativeObject(identOrSpread, original.restParameter)) && isSameNativeObject(isOptional, original.isOptional) && isSameNativeObject(initExpr, original.initializer) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSStructDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSStructDeclaration.ts index 5d286ee13c9..f4fbd959604 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSStructDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSStructDeclaration.ts @@ -20,7 +20,7 @@ import { updateNodeByNode } from "../utilities/private" export function updateETSStructDeclaration( original: ETSStructDeclaration, def?: ClassDefinition -) { +): ETSStructDeclaration { if (isSameNativeObject(def, original.definition)) { return original } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSTuple.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSTuple.ts index 10c683968d5..65bc8633adf 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSTuple.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ETSTuple.ts @@ -20,7 +20,7 @@ import { updateNodeByNode } from "../utilities/private" export function updateETSTuple( original: ETSTuple, typeList: readonly TypeNode[] -) { +): ETSTuple { if (isSameNativeObject(typeList, original.tupleTypeAnnotationsList)) { return original } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/MemberExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/MemberExpression.ts index 1972a79a13e..fdaa969d9b6 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/MemberExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/MemberExpression.ts @@ -25,7 +25,7 @@ export function updateMemberExpression( kind: Es2pandaMemberExpressionKind, computed: boolean, optional_arg: boolean -) { +): MemberExpression { if (isSameNativeObject(object_arg, original.object) && isSameNativeObject(property, original.property) && isSameNativeObject(kind, original.kind) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/MethodDefinition.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/MethodDefinition.ts index 3d8034cafa8..4f8553fedd3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/MethodDefinition.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/MethodDefinition.ts @@ -29,7 +29,7 @@ export function createMethodDefinition( modifiers: Es2pandaModifierFlags, isComputed: boolean, overloads?: readonly MethodDefinition[] -) { +): MethodDefinition { const res = MethodDefinition.createMethodDefinition( kind, key, @@ -51,7 +51,7 @@ export function updateMethodDefinition( modifiers: Es2pandaModifierFlags, isComputed: boolean, overloads?: readonly MethodDefinition[] -) { +): MethodDefinition { if (isSameNativeObject(kind, original.kind) && isSameNativeObject(key, original.key) && isSameNativeObject(value, original.value) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/NumberLiteral.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/NumberLiteral.ts index f1ca1116478..8691a280cce 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/NumberLiteral.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/NumberLiteral.ts @@ -15,12 +15,11 @@ import { global } from "../static/global" import { NumberLiteral } from "../../generated" -import { isSameNativeObject } from "../peers/ArktsObject" import { updateNodeByNode } from "../utilities/private" export function createNumberLiteral( value: number -) { +): NumberLiteral { return new NumberLiteral( global.es2panda._CreateNumberLiteral( global.context, @@ -32,10 +31,7 @@ export function createNumberLiteral( export function updateNumberLiteral( original: NumberLiteral, value: number -) { - if (isSameNativeObject(value.toString(), original.str)) { - return original - } +): NumberLiteral { return updateNodeByNode( createNumberLiteral(value), original diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ObjectExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ObjectExpression.ts index 8009b122aa2..175f0114c0a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ObjectExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/ObjectExpression.ts @@ -20,7 +20,7 @@ import { nodeType, updateNodeByNode } from "../utilities/private" export function updateObjectExpression( original: ObjectExpression, properties: readonly Expression[] -) { +): ObjectExpression { if (isSameNativeObject(properties, original.properties)){ return original } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts index 2ea6cf3395d..f3c6748b5de 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts @@ -14,21 +14,38 @@ */ import { - ETSFunctionType, - Expression, - FunctionSignature, - MethodDefinition, TSInterfaceDeclaration, TSInterfaceHeritage } from "../../generated" import { - Es2pandaMethodDefinitionKind, Es2pandaModifierFlags, - Es2pandaScriptFunctionFlags } from "../../generated/Es2pandaEnums" import { isSameNativeObject } from "../peers/ArktsObject" import { updateNodeByNode } from "../utilities/private" import { AstNode } from "../peers/AstNode" +export function createTSInterfaceDeclaration( + _extends: readonly TSInterfaceHeritage[], + id: AstNode | undefined, + typeParams: AstNode | undefined, + body: AstNode | undefined, + isStatic: boolean, + isExternal: boolean, + modifierFlags?: Es2pandaModifierFlags, +): TSInterfaceDeclaration { + const res = TSInterfaceDeclaration.createTSInterfaceDeclaration( + _extends, + id, + typeParams, + body, + isStatic, + isExternal + ) + if (modifierFlags) { + res.modifierFlags = modifierFlags + } + return res +} + export function updateTSInterfaceDeclaration( original: TSInterfaceDeclaration, _extends: readonly TSInterfaceHeritage[], @@ -36,25 +53,28 @@ export function updateTSInterfaceDeclaration( typeParams: AstNode | undefined, body: AstNode | undefined, isStatic: boolean, - isExternal: boolean -) { + isExternal: boolean, + modifierFlags?: Es2pandaModifierFlags, +): TSInterfaceDeclaration { if (isSameNativeObject(_extends, original.extends) && isSameNativeObject(id, original.id) && isSameNativeObject(typeParams, original.typeParams) && isSameNativeObject(body, original.body) && isSameNativeObject(isStatic, original.isStatic) && isSameNativeObject(isExternal, original.isFromExternal) + && isSameNativeObject(modifierFlags, original.modifierFlags) ) { return original } return updateNodeByNode( - TSInterfaceDeclaration.createTSInterfaceDeclaration( + createTSInterfaceDeclaration( _extends, id, typeParams, body, isStatic, - isExternal + isExternal, + modifierFlags, ), original ) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts index 4f5d2ce1361..aa35be25f5d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +import { Es2pandaModifierFlags } from ".." import { AnnotationUsage, Identifier, TSTypeAliasDeclaration, TSTypeParameterDeclaration, TypeNode } from "../../generated" import { isSameNativeObject } from "../peers/ArktsObject" import { updateNodeByNode } from "../utilities/private" @@ -21,7 +22,8 @@ export function createTSTypeAliasDeclaration( id?: Identifier, typeParams?: TSTypeParameterDeclaration, typeAnnotation?: TypeNode, - annotations?: readonly AnnotationUsage[] + annotations?: readonly AnnotationUsage[], + modifiers?: Es2pandaModifierFlags ): TSTypeAliasDeclaration { const res = TSTypeAliasDeclaration.createTSTypeAliasDeclaration( id, @@ -31,6 +33,9 @@ export function createTSTypeAliasDeclaration( if (annotations) { res.setAnnotations(annotations) } + if (modifiers) { + res.modifierFlags = modifiers + } return res } @@ -39,12 +44,14 @@ export function updateTSTypeAliasDeclaration( id?: Identifier, typeParams?: TSTypeParameterDeclaration, typeAnnotation?: TypeNode, - annotations?: readonly AnnotationUsage[] + annotations?: readonly AnnotationUsage[], + modifiers?: Es2pandaModifierFlags ): TSTypeAliasDeclaration { if (isSameNativeObject(id, original.id) && isSameNativeObject(typeParams, original.typeParams) && isSameNativeObject(typeAnnotation, original.typeAnnotation) && isSameNativeObject(annotations, original.annotations) + && isSameNativeObject(modifiers, original.modifierFlags) ) { return original } @@ -54,6 +61,7 @@ export function updateTSTypeAliasDeclaration( typeParams, typeAnnotation, annotations, + modifiers ), original, ) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeParameter.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeParameter.ts index 5ac0dde4b31..e60b4315346 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeParameter.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeParameter.ts @@ -24,7 +24,7 @@ export function updateTSTypeParameter( constraint: TypeNode | undefined, defaultType: TypeNode | undefined, flags: Es2pandaModifierFlags -) { +): TSTypeParameter { if (isSameNativeObject(name, original.name) && isSameNativeObject(constraint, original.constraint) && isSameNativeObject(defaultType, original.defaultType) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeReferencePart.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeReferencePart.ts index a9d96fd0381..b68d6ba3dc8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeReferencePart.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/TSTypeReferencePart.ts @@ -22,7 +22,7 @@ export function updateETSTypeReferencePart( name?: Expression, typeParams?: TSTypeParameterInstantiation, prev?: ETSTypeReferencePart -) { +): ETSTypeReferencePart { if (isSameNativeObject(name, original.name) && isSameNativeObject(typeParams, original.typeParams) && isSameNativeObject(prev, original.previous) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/VariableDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/VariableDeclaration.ts index a37ca4964f5..3a590db614a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/VariableDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/VariableDeclaration.ts @@ -40,7 +40,7 @@ export function updateVariableDeclaration( kind: Es2pandaVariableDeclarationKind, declarators: readonly VariableDeclarator[], annotations?: readonly AnnotationUsage[] -) { +): VariableDeclaration { if (isSameNativeObject(kind, original.kind) && isSameNativeObject(declarators, original.declarators) && isSameNativeObject(annotations, original.annotations) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/VariableDeclarator.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/VariableDeclarator.ts index c964396c26d..75c2ef64991 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/VariableDeclarator.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/node-utilities/VariableDeclarator.ts @@ -23,7 +23,7 @@ export function updateVariableDeclarator( flag: Es2pandaVariableDeclaratorFlag, ident?: Expression, init?: Expression -) { +): VariableDeclarator { if (isSameNativeObject(flag, original.flag) && isSameNativeObject(ident, original.id) && isSameNativeObject(init, original.init) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/AstNode.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/AstNode.ts index 1ec8da92e46..2861b14cba0 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/AstNode.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/AstNode.ts @@ -13,11 +13,11 @@ * limitations under the License. */ -import { isNullPtr, KInt, KNativePointer as KPtr, KNativePointer, nullptr } from "@koalaui/interop" +import { isNullPtr, KInt, KNativePointer, nullptr } from "@koalaui/interop" import { global } from "../static/global" -import { allFlags, nodeType, unpackNodeArray, unpackNonNullableNode, unpackString } from "../utilities/private" +import { allFlags, unpackNodeArray, unpackNonNullableNode, unpackString } from "../utilities/private" import { throwError } from "../../utils" -import { Es2pandaAstNodeType, Es2pandaModifierFlags } from "../../generated/Es2pandaEnums" +import { Es2pandaModifierFlags } from "../../generated/Es2pandaEnums" import { ArktsObject } from "./ArktsObject" export abstract class AstNode extends ArktsObject { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/Context.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/Context.ts index 78f1bfc28cb..bc5c9c23cc7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/Context.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/Context.ts @@ -16,7 +16,6 @@ import { ArktsObject } from "./ArktsObject" import { Program } from "./Program" import { global } from "../static/global" -import { throwError } from "../../utils" import { passString } from "../utilities/private" import { KNativePointer } from "@koalaui/interop" @@ -29,7 +28,7 @@ export class Context extends ArktsObject { source: string ): Context { if (!global.configIsInitialized()) { - throwError(`Config not initialized`) + throw new Error(`Config not initialized`) } return new Context( global.es2panda._CreateContextFromString( diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/Program.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/Program.ts index f38f2c4a0f6..5d9321b0173 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/Program.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/peers/Program.ts @@ -16,7 +16,7 @@ import { ArktsObject } from "./ArktsObject" import { global } from "../static/global" import { acceptNativeObjectArrayResult, unpackString } from "../utilities/private" -import { KNativePointer } from "@koalaui/interop" +import { KNativePointer, nullptr } from "@koalaui/interop" import { ETSModule } from "../../generated" export class Program extends ArktsObject { @@ -25,7 +25,9 @@ export class Program extends ArktsObject { } get astNode(): ETSModule { - return new ETSModule(global.es2panda._ProgramAst(global.context, this.peer)) + let program = global.es2panda._ProgramAst(global.context, this.peer) + if (program == nullptr) throw new Error(`astNode() cannt get AST`) + return new ETSModule(program) } get externalSources(): ExternalSource[] { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/plugins.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/plugins.ts new file mode 100644 index 00000000000..1c6f45cf412 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/plugins.ts @@ -0,0 +1,48 @@ +/* + * 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 { Es2pandaContextState } from "../generated/Es2pandaEnums" +import { ExternalSource, Program } from "./peers/Program" + +export interface CompilationOptions { + readonly isMainProgram: boolean, + readonly name: string, + readonly stage: Es2pandaContextState, +} + +export type ProgramTransformer = (program: Program, compilationOptions: CompilationOptions) => void + +export function defaultFilter(name: string) { + if (name.startsWith("std.")) return false + if (name.startsWith("escompat")) return false + return true +} + +export interface ProgramWithName { + program: Program, + name: string +} + +export function listPrograms(program: Program, filter: (name: string) => boolean = defaultFilter): ProgramWithName[] { + return [ + { program, name: "" }, + ...program.externalSources.flatMap((it: ExternalSource) => { + if (filter(it.getName())) { + return it.programs.map(program => ({ program, name: it.getName() } as ProgramWithName)) + } + return [] + }) + ] +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/static/global.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/static/global.ts index 34067cfafb3..63003254e2c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/static/global.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/static/global.ts @@ -14,12 +14,13 @@ */ import { throwError } from "../../utils" -import { KNativePointer } from "@koalaui/interop" +import { KNativePointer, nullptr } from "@koalaui/interop" import { initEs2panda, Es2pandaNativeModule, initGeneratedEs2panda } from "../../Es2pandaNativeModule" import { Es2pandaNativeModule as GeneratedEs2pandaNativeModule } from "../../generated/Es2pandaNativeModule" import { initInterop, InteropNativeModule } from "../../InteropNativeModule" import { Context } from "../peers/Context" import { Profiler } from "./profiler" +import { Program } from "../peers/Program" export class global { public static filePath: string = "./plugins/input/main.ets" @@ -34,7 +35,7 @@ export class global { return global._config ?? throwError('Global.config not initialized') } public static configIsInitialized(): boolean { - return global._config !== undefined + return global._config !== undefined && global._config !== nullptr } // TODO: rename to contextPeer diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/static/profiler.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/static/profiler.ts index 06964da88fe..6e96e24eab3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/static/profiler.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/static/profiler.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/utilities/private.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/utilities/private.ts index d6c67985176..2149e3de96a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/utilities/private.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/utilities/private.ts @@ -21,8 +21,7 @@ import { KNativePointer, nullptr, withString, - withStringArray, - withStringResult + withStringArray } from "@koalaui/interop" import { NativePtrDecoder } from "./nativePtrDecoder" import { Es2pandaAstNodeType, Es2pandaModifierFlags, Es2pandaScriptFunctionFlags } from "../../generated/Es2pandaEnums" @@ -117,9 +116,10 @@ export function unpackObject(type: { new (peer: KNativePo } export function unpackString(peer: KNativePointer): string { - return withStringResult(peer) ?? throwError(`failed to unpack (peer shouldn't be NULLPTR)`) + return global.interop._RawUtf8ToString(peer) } +// TODO: use direct string arguments instead. export function passString(str: string | undefined): string { if (str === undefined) { return "" @@ -127,6 +127,8 @@ export function passString(str: string | undefined): string { return withString(str, (it: string) => it) } + +// TODO: use direct string arguments instead. export function passStringArray(strings: readonly string[]): string[] { return withStringArray(strings, (it: string[]) => it) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/utilities/public.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/utilities/public.ts index d6290295ce8..46df8f56126 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/utilities/public.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/utilities/public.ts @@ -29,14 +29,19 @@ import { isFunctionDeclaration, isMemberExpression, isScriptFunction, - isIdentifier + isIdentifier, + isETSModule } from "../../generated" import { Config } from "../peers/Config" import { Context } from "../peers/Context" import { NodeCache } from "../node-cache" export function createETSModuleFromContext(): ETSModule { - return new ETSModule(global.es2panda._ProgramAst(global.context, global.es2panda._ContextProgram(global.context))) + let program = global.es2panda._ContextProgram(global.context) + if (program == nullptr) { + throw new Error(`Program is null for context ${global.context.toString(16)}`) + } + return new ETSModule(global.es2panda._ProgramAst(global.context, program)) } export function createETSModuleFromSource( @@ -48,7 +53,10 @@ export function createETSModuleFromSource( } global.compilerContext = Context.createFromString(source) proceedToState(state) - return new ETSModule(global.es2panda._ProgramAst(global.context, global.es2panda._ContextProgram(global.context))) + let program = global.es2panda._ContextProgram(global.compilerContext.peer) + if (program == nullptr) + throw new Error(`Program is null for ${source} 0x${global.compilerContext.peer.toString(16)}`) + return new ETSModule(global.es2panda._ProgramAst(global.context, program)) } export function updateETSModuleByStatements( @@ -157,12 +165,6 @@ export function classPropertySetOptional(node: ClassProperty, value: boolean): C return node; } -// TODO: Import statements should be inserted to the statements. -export function importDeclarationInsert(node: ETSImportDeclaration): void { - const program = global.compilerContext.program; // TODO: external source has different program. Currently not considered. - global.es2panda._InsertETSImportDeclarationAndParse(global.context, program.peer, node.peer) -} - export function hasModifierFlag(node: AstNode, flag: Es2pandaModifierFlags): boolean { if (!node) return false; @@ -188,6 +190,10 @@ export function nameIfIdentifier(node: AstNode): string { return isIdentifier(node) ? `'${node.name}'` : "" } +export function nameIfETSModule(node: AstNode): string { + return isETSModule(node) ? `'${node.ident?.name}'` : "" +} + export function asString(node: AstNode|undefined): string { return `${node?.constructor.name} ${node ? nameIfIdentifier(node) : undefined}` } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/visitor.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/visitor.ts index 8de8b144646..6d106ede3fe 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/visitor.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/arkts-api/visitor.ts @@ -21,6 +21,7 @@ import { isAssignmentExpression, isBlockExpression, isBlockStatement, + isBinaryExpression, isCallExpression, isChainExpression, isClassDeclaration, @@ -52,10 +53,25 @@ import { isETSUnionType, isETSFunctionType, isWhileStatement, + isForUpdateStatement, + isForInStatement, + isForOfStatement, + isDoWhileStatement, + isSwitchStatement, + isSwitchCaseStatement, + isETSImportDeclaration, + isProperty, + isETSNewClassInstanceExpression, + isTSNonNullExpression, + isUpdateExpression, + isETSTypeReference, + isETSTypeReferencePart, + isTSTypeParameterInstantiation, + isTSTypeParameterDeclaration } from "../generated" import { updateETSModuleByStatements } from "./utilities/public" import { global } from "./static/global" -import { Es2pandaScriptFunctionFlags } from "../generated/Es2pandaEnums" +import { Es2pandaImportKinds, Es2pandaScriptFunctionFlags } from "../generated/Es2pandaEnums" type Visitor = (node: AstNode, options?: object) => AstNode @@ -255,6 +271,20 @@ export function visitEachChild( node.isOptional ) } + if (isSwitchStatement(node)) { + return factory.updateSwitchStatement( + node, + nodeVisitor(node.discriminant, visitor), + nodesVisitor(node.cases, visitor) + ) + } + if (isSwitchCaseStatement(node)) { + return factory.updateSwitchCaseStatement( + node, + nodeVisitor(node.test, visitor), + nodesVisitor(node.consequent, visitor) + ) + } if (isTSInterfaceDeclaration(node)) { return factory.updateInterfaceDeclaration( node, @@ -263,7 +293,8 @@ export function visitEachChild( nodeVisitor(node.typeParams, visitor), nodeVisitor(node.body, visitor), node.isStatic, - node.isFromExternal + node.isFromExternal, + node.modifierFlags, ) } if (isTSInterfaceBody(node)) { @@ -340,6 +371,7 @@ export function visitEachChild( nodeVisitor(node.typeParams, visitor), nodeVisitor(node.typeAnnotation, visitor), nodesVisitor(node.annotations, visitor), + node.modifierFlags, ) } if (isTryStatement(node)) { @@ -398,7 +430,7 @@ export function visitEachChild( nodesVisitor(node.params, visitor), nodeVisitor(node.returnType, visitor), false, // TODO: how to get it? - Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, + node.flags, nodesVisitor(node.annotations, visitor), ) } @@ -409,9 +441,27 @@ export function visitEachChild( nodeVisitor(node.value, visitor), nodeVisitor(node.typeAnnotation, visitor), node.modifierFlags, + node.isComputed, + node.annotations, + ) + } + if (isProperty(node)) { + return factory.updateProperty( + node, + node.kind, + nodeVisitor(node.key, visitor), + nodeVisitor(node.value, visitor), + node.isMethod, node.isComputed ) } + if (isBinaryExpression(node)) { + return factory.updateBinaryExpression( + node, + nodeVisitor(node.left, visitor), + nodeVisitor(node.right, visitor), + node.operatorType) + } if (isIdentifier(node)) { return factory.updateIdentifier( node, @@ -419,6 +469,13 @@ export function visitEachChild( nodeVisitor(node.typeAnnotation, visitor) ) } + if (isETSNewClassInstanceExpression(node)) { + return factory.updateETSNewClassInstanceExpression( + node, + nodeVisitor(node.typeRef, visitor), + nodesVisitor(node.arguments, visitor) + ) + } if (isWhileStatement(node)) { return factory.updateWhileStatement( node, @@ -426,5 +483,94 @@ export function visitEachChild( nodeVisitor(node.body, visitor), ) } + if (isDoWhileStatement(node)) { + return factory.updateDoWhileStatement( + node, + nodeVisitor(node.body, visitor), + nodeVisitor(node.test, visitor), + ) + } + if (isForUpdateStatement(node)) { + return factory.updateForUpdateStatement( + node, + nodeVisitor(node.init, visitor), + nodeVisitor(node.test, visitor), + nodeVisitor(node.update, visitor), + nodeVisitor(node.body, visitor), + ) + } + if (isForInStatement(node)) { + return factory.updateForInStatement( + node, + nodeVisitor(node.left, visitor), + nodeVisitor(node.right, visitor), + nodeVisitor(node.body, visitor), + ) + } + if (isForOfStatement(node)) { + return factory.updateForOfStatement( + node, + nodeVisitor(node.left, visitor), + nodeVisitor(node.right, visitor), + nodeVisitor(node.body, visitor), + node.isAwait + ) + } + if (isETSImportDeclaration(node)) { + return factory.updateETSImportDeclaration( + node, + nodeVisitor(node.source, visitor), + nodesVisitor(node.specifiers, visitor), + Es2pandaImportKinds.IMPORT_KINDS_ALL + ) + } + if (isTSNonNullExpression(node)) { + return factory.updateTSNonNullExpression( + node, + nodeVisitor(node.expr, visitor) + ) + } + if (isUpdateExpression(node)) { + return factory.updateUpdateExpression( + node, + nodeVisitor(node.argument, visitor), + node.operatorType, + node.isPrefix + ) + } + if (isETSTypeReference(node)) { + return factory.updateETSTypeReference( + node, + nodeVisitor(node.part, visitor), + ) + } + if (isETSTypeReferencePart(node)) { + return factory.updateETSTypeReferencePart( + node, + nodeVisitor(node.name, visitor), + nodeVisitor(node.typeParams, visitor), + nodeVisitor(node.previous, visitor), + ) + } + if (isTSTypeParameterInstantiation(node)) { + return factory.updateTSTypeParameterInstantiation( + node, + nodesVisitor(node.params, visitor), + ) + } + if (isTSTypeParameterDeclaration(node)) { + return factory.updateTSTypeParameterDeclaration( + node, + nodesVisitor(node.params, visitor), + node.requiredParams, + ) + } + /** TODO: fix this case! + if (isClassStaticBlock(node)) { + return factory.updateClassStaticBlock( + + ) + nodeVisitor(node.function, visitor) + } */ return node } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/Es2pandaEnums.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/Es2pandaEnums.ts index b89e20d176a..02d37ae4adb 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/Es2pandaEnums.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/Es2pandaEnums.ts @@ -23,6 +23,11 @@ export enum Es2pandaContextState { ES2PANDA_STATE_BIN_GENERATED = 6, ES2PANDA_STATE_ERROR = 7 } +export enum Es2pandaPluginDiagnosticType { + ES2PANDA_PLUGIN_WARNING = 0, + ES2PANDA_PLUGIN_ERROR = 1, + ES2PANDA_PLUGIN_SUGGESTION = 2 +} export enum Es2pandaAstNodeType { AST_NODE_TYPE_ARROW_FUNCTION_EXPRESSION = 0, AST_NODE_TYPE_ANNOTATION_DECLARATION = 1, @@ -86,108 +91,109 @@ export enum Es2pandaAstNodeType { AST_NODE_TYPE_SCRIPT_FUNCTION = 59, AST_NODE_TYPE_SEQUENCE_EXPRESSION = 60, AST_NODE_TYPE_STRING_LITERAL = 61, - AST_NODE_TYPE_ETS_NULL_TYPE = 62, - AST_NODE_TYPE_ETS_UNDEFINED_TYPE = 63, - AST_NODE_TYPE_ETS_NEVER_TYPE = 64, - AST_NODE_TYPE_ETS_STRING_LITERAL_TYPE = 65, - AST_NODE_TYPE_ETS_FUNCTION_TYPE = 66, - AST_NODE_TYPE_ETS_WILDCARD_TYPE = 67, - AST_NODE_TYPE_ETS_PRIMITIVE_TYPE = 68, - AST_NODE_TYPE_ETS_PACKAGE_DECLARATION = 69, - AST_NODE_TYPE_ETS_CLASS_LITERAL = 70, - AST_NODE_TYPE_ETS_TYPE_REFERENCE = 71, - AST_NODE_TYPE_ETS_TYPE_REFERENCE_PART = 72, - AST_NODE_TYPE_ETS_UNION_TYPE = 73, - AST_NODE_TYPE_ETS_KEYOF_TYPE = 74, - AST_NODE_TYPE_ETS_NEW_ARRAY_INSTANCE_EXPRESSION = 75, - AST_NODE_TYPE_ETS_NEW_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION = 76, - AST_NODE_TYPE_ETS_NEW_CLASS_INSTANCE_EXPRESSION = 77, - AST_NODE_TYPE_ETS_IMPORT_DECLARATION = 78, - AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION = 79, - AST_NODE_TYPE_ETS_TUPLE = 80, - AST_NODE_TYPE_ETS_MODULE = 81, - AST_NODE_TYPE_SUPER_EXPRESSION = 82, - AST_NODE_TYPE_STRUCT_DECLARATION = 83, - AST_NODE_TYPE_SWITCH_CASE_STATEMENT = 84, - AST_NODE_TYPE_SWITCH_STATEMENT = 85, - AST_NODE_TYPE_TS_ENUM_DECLARATION = 86, - AST_NODE_TYPE_TS_ENUM_MEMBER = 87, - AST_NODE_TYPE_TS_EXTERNAL_MODULE_REFERENCE = 88, - AST_NODE_TYPE_TS_NUMBER_KEYWORD = 89, - AST_NODE_TYPE_TS_ANY_KEYWORD = 90, - AST_NODE_TYPE_TS_STRING_KEYWORD = 91, - AST_NODE_TYPE_TS_BOOLEAN_KEYWORD = 92, - AST_NODE_TYPE_TS_VOID_KEYWORD = 93, - AST_NODE_TYPE_TS_UNDEFINED_KEYWORD = 94, - AST_NODE_TYPE_TS_UNKNOWN_KEYWORD = 95, - AST_NODE_TYPE_TS_OBJECT_KEYWORD = 96, - AST_NODE_TYPE_TS_BIGINT_KEYWORD = 97, - AST_NODE_TYPE_TS_NEVER_KEYWORD = 98, - AST_NODE_TYPE_TS_NON_NULL_EXPRESSION = 99, - AST_NODE_TYPE_TS_NULL_KEYWORD = 100, - AST_NODE_TYPE_TS_ARRAY_TYPE = 101, - AST_NODE_TYPE_TS_UNION_TYPE = 102, - AST_NODE_TYPE_TS_TYPE_LITERAL = 103, - AST_NODE_TYPE_TS_PROPERTY_SIGNATURE = 104, - AST_NODE_TYPE_TS_METHOD_SIGNATURE = 105, - AST_NODE_TYPE_TS_SIGNATURE_DECLARATION = 106, - AST_NODE_TYPE_TS_PARENT_TYPE = 107, - AST_NODE_TYPE_TS_LITERAL_TYPE = 108, - AST_NODE_TYPE_TS_INFER_TYPE = 109, - AST_NODE_TYPE_TS_CONDITIONAL_TYPE = 110, - AST_NODE_TYPE_TS_IMPORT_TYPE = 111, - AST_NODE_TYPE_TS_INTERSECTION_TYPE = 112, - AST_NODE_TYPE_TS_MAPPED_TYPE = 113, - AST_NODE_TYPE_TS_MODULE_BLOCK = 114, - AST_NODE_TYPE_TS_THIS_TYPE = 115, - AST_NODE_TYPE_TS_TYPE_OPERATOR = 116, - AST_NODE_TYPE_TS_TYPE_PARAMETER = 117, - AST_NODE_TYPE_TS_TYPE_PARAMETER_DECLARATION = 118, - AST_NODE_TYPE_TS_TYPE_PARAMETER_INSTANTIATION = 119, - AST_NODE_TYPE_TS_TYPE_PREDICATE = 120, - AST_NODE_TYPE_TS_PARAMETER_PROPERTY = 121, - AST_NODE_TYPE_TS_MODULE_DECLARATION = 122, - AST_NODE_TYPE_TS_IMPORT_EQUALS_DECLARATION = 123, - AST_NODE_TYPE_TS_FUNCTION_TYPE = 124, - AST_NODE_TYPE_TS_CONSTRUCTOR_TYPE = 125, - AST_NODE_TYPE_TS_TYPE_ALIAS_DECLARATION = 126, - AST_NODE_TYPE_TS_TYPE_REFERENCE = 127, - AST_NODE_TYPE_TS_QUALIFIED_NAME = 128, - AST_NODE_TYPE_TS_INDEXED_ACCESS_TYPE = 129, - AST_NODE_TYPE_TS_INTERFACE_DECLARATION = 130, - AST_NODE_TYPE_TS_INTERFACE_BODY = 131, - AST_NODE_TYPE_TS_INTERFACE_HERITAGE = 132, - AST_NODE_TYPE_TS_TUPLE_TYPE = 133, - AST_NODE_TYPE_TS_NAMED_TUPLE_MEMBER = 134, - AST_NODE_TYPE_TS_INDEX_SIGNATURE = 135, - AST_NODE_TYPE_TS_TYPE_QUERY = 136, - AST_NODE_TYPE_TS_AS_EXPRESSION = 137, - AST_NODE_TYPE_TS_CLASS_IMPLEMENTS = 138, - AST_NODE_TYPE_TS_TYPE_ASSERTION = 139, - AST_NODE_TYPE_TAGGED_TEMPLATE_EXPRESSION = 140, - AST_NODE_TYPE_TEMPLATE_ELEMENT = 141, - AST_NODE_TYPE_TEMPLATE_LITERAL = 142, - AST_NODE_TYPE_THIS_EXPRESSION = 143, - AST_NODE_TYPE_TYPEOF_EXPRESSION = 144, - AST_NODE_TYPE_THROW_STATEMENT = 145, - AST_NODE_TYPE_TRY_STATEMENT = 146, - AST_NODE_TYPE_UNARY_EXPRESSION = 147, - AST_NODE_TYPE_UPDATE_EXPRESSION = 148, - AST_NODE_TYPE_VARIABLE_DECLARATION = 149, - AST_NODE_TYPE_VARIABLE_DECLARATOR = 150, - AST_NODE_TYPE_WHILE_STATEMENT = 151, - AST_NODE_TYPE_YIELD_EXPRESSION = 152, - AST_NODE_TYPE_OPAQUE_TYPE_NODE = 153, - AST_NODE_TYPE_BLOCK_EXPRESSION = 154, - AST_NODE_TYPE_BROKEN_TYPE_NODE = 155, - AST_NODE_TYPE_ARRAY_EXPRESSION = 156, - AST_NODE_TYPE_ARRAY_PATTERN = 157, - AST_NODE_TYPE_ASSIGNMENT_EXPRESSION = 158, - AST_NODE_TYPE_ASSIGNMENT_PATTERN = 159, - AST_NODE_TYPE_OBJECT_EXPRESSION = 160, - AST_NODE_TYPE_OBJECT_PATTERN = 161, - AST_NODE_TYPE_SPREAD_ELEMENT = 162, - AST_NODE_TYPE_REST_ELEMENT = 163 + AST_NODE_TYPE_ETS_NON_NULLISH_TYPE = 62, + AST_NODE_TYPE_ETS_NULL_TYPE = 63, + AST_NODE_TYPE_ETS_UNDEFINED_TYPE = 64, + AST_NODE_TYPE_ETS_NEVER_TYPE = 65, + AST_NODE_TYPE_ETS_STRING_LITERAL_TYPE = 66, + AST_NODE_TYPE_ETS_FUNCTION_TYPE = 67, + AST_NODE_TYPE_ETS_WILDCARD_TYPE = 68, + AST_NODE_TYPE_ETS_PRIMITIVE_TYPE = 69, + AST_NODE_TYPE_ETS_PACKAGE_DECLARATION = 70, + AST_NODE_TYPE_ETS_CLASS_LITERAL = 71, + AST_NODE_TYPE_ETS_TYPE_REFERENCE = 72, + AST_NODE_TYPE_ETS_TYPE_REFERENCE_PART = 73, + AST_NODE_TYPE_ETS_UNION_TYPE = 74, + AST_NODE_TYPE_ETS_KEYOF_TYPE = 75, + AST_NODE_TYPE_ETS_NEW_ARRAY_INSTANCE_EXPRESSION = 76, + AST_NODE_TYPE_ETS_NEW_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION = 77, + AST_NODE_TYPE_ETS_NEW_CLASS_INSTANCE_EXPRESSION = 78, + AST_NODE_TYPE_ETS_IMPORT_DECLARATION = 79, + AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION = 80, + AST_NODE_TYPE_ETS_TUPLE = 81, + AST_NODE_TYPE_ETS_MODULE = 82, + AST_NODE_TYPE_SUPER_EXPRESSION = 83, + AST_NODE_TYPE_STRUCT_DECLARATION = 84, + AST_NODE_TYPE_SWITCH_CASE_STATEMENT = 85, + AST_NODE_TYPE_SWITCH_STATEMENT = 86, + AST_NODE_TYPE_TS_ENUM_DECLARATION = 87, + AST_NODE_TYPE_TS_ENUM_MEMBER = 88, + AST_NODE_TYPE_TS_EXTERNAL_MODULE_REFERENCE = 89, + AST_NODE_TYPE_TS_NUMBER_KEYWORD = 90, + AST_NODE_TYPE_TS_ANY_KEYWORD = 91, + AST_NODE_TYPE_TS_STRING_KEYWORD = 92, + AST_NODE_TYPE_TS_BOOLEAN_KEYWORD = 93, + AST_NODE_TYPE_TS_VOID_KEYWORD = 94, + AST_NODE_TYPE_TS_UNDEFINED_KEYWORD = 95, + AST_NODE_TYPE_TS_UNKNOWN_KEYWORD = 96, + AST_NODE_TYPE_TS_OBJECT_KEYWORD = 97, + AST_NODE_TYPE_TS_BIGINT_KEYWORD = 98, + AST_NODE_TYPE_TS_NEVER_KEYWORD = 99, + AST_NODE_TYPE_TS_NON_NULL_EXPRESSION = 100, + AST_NODE_TYPE_TS_NULL_KEYWORD = 101, + AST_NODE_TYPE_TS_ARRAY_TYPE = 102, + AST_NODE_TYPE_TS_UNION_TYPE = 103, + AST_NODE_TYPE_TS_TYPE_LITERAL = 104, + AST_NODE_TYPE_TS_PROPERTY_SIGNATURE = 105, + AST_NODE_TYPE_TS_METHOD_SIGNATURE = 106, + AST_NODE_TYPE_TS_SIGNATURE_DECLARATION = 107, + AST_NODE_TYPE_TS_PARENT_TYPE = 108, + AST_NODE_TYPE_TS_LITERAL_TYPE = 109, + AST_NODE_TYPE_TS_INFER_TYPE = 110, + AST_NODE_TYPE_TS_CONDITIONAL_TYPE = 111, + AST_NODE_TYPE_TS_IMPORT_TYPE = 112, + AST_NODE_TYPE_TS_INTERSECTION_TYPE = 113, + AST_NODE_TYPE_TS_MAPPED_TYPE = 114, + AST_NODE_TYPE_TS_MODULE_BLOCK = 115, + AST_NODE_TYPE_TS_THIS_TYPE = 116, + AST_NODE_TYPE_TS_TYPE_OPERATOR = 117, + AST_NODE_TYPE_TS_TYPE_PARAMETER = 118, + AST_NODE_TYPE_TS_TYPE_PARAMETER_DECLARATION = 119, + AST_NODE_TYPE_TS_TYPE_PARAMETER_INSTANTIATION = 120, + AST_NODE_TYPE_TS_TYPE_PREDICATE = 121, + AST_NODE_TYPE_TS_PARAMETER_PROPERTY = 122, + AST_NODE_TYPE_TS_MODULE_DECLARATION = 123, + AST_NODE_TYPE_TS_IMPORT_EQUALS_DECLARATION = 124, + AST_NODE_TYPE_TS_FUNCTION_TYPE = 125, + AST_NODE_TYPE_TS_CONSTRUCTOR_TYPE = 126, + AST_NODE_TYPE_TS_TYPE_ALIAS_DECLARATION = 127, + AST_NODE_TYPE_TS_TYPE_REFERENCE = 128, + AST_NODE_TYPE_TS_QUALIFIED_NAME = 129, + AST_NODE_TYPE_TS_INDEXED_ACCESS_TYPE = 130, + AST_NODE_TYPE_TS_INTERFACE_DECLARATION = 131, + AST_NODE_TYPE_TS_INTERFACE_BODY = 132, + AST_NODE_TYPE_TS_INTERFACE_HERITAGE = 133, + AST_NODE_TYPE_TS_TUPLE_TYPE = 134, + AST_NODE_TYPE_TS_NAMED_TUPLE_MEMBER = 135, + AST_NODE_TYPE_TS_INDEX_SIGNATURE = 136, + AST_NODE_TYPE_TS_TYPE_QUERY = 137, + AST_NODE_TYPE_TS_AS_EXPRESSION = 138, + AST_NODE_TYPE_TS_CLASS_IMPLEMENTS = 139, + AST_NODE_TYPE_TS_TYPE_ASSERTION = 140, + AST_NODE_TYPE_TAGGED_TEMPLATE_EXPRESSION = 141, + AST_NODE_TYPE_TEMPLATE_ELEMENT = 142, + AST_NODE_TYPE_TEMPLATE_LITERAL = 143, + AST_NODE_TYPE_THIS_EXPRESSION = 144, + AST_NODE_TYPE_TYPEOF_EXPRESSION = 145, + AST_NODE_TYPE_THROW_STATEMENT = 146, + AST_NODE_TYPE_TRY_STATEMENT = 147, + AST_NODE_TYPE_UNARY_EXPRESSION = 148, + AST_NODE_TYPE_UPDATE_EXPRESSION = 149, + AST_NODE_TYPE_VARIABLE_DECLARATION = 150, + AST_NODE_TYPE_VARIABLE_DECLARATOR = 151, + AST_NODE_TYPE_WHILE_STATEMENT = 152, + AST_NODE_TYPE_YIELD_EXPRESSION = 153, + AST_NODE_TYPE_OPAQUE_TYPE_NODE = 154, + AST_NODE_TYPE_BLOCK_EXPRESSION = 155, + AST_NODE_TYPE_BROKEN_TYPE_NODE = 156, + AST_NODE_TYPE_ARRAY_EXPRESSION = 157, + AST_NODE_TYPE_ARRAY_PATTERN = 158, + AST_NODE_TYPE_ASSIGNMENT_EXPRESSION = 159, + AST_NODE_TYPE_ASSIGNMENT_PATTERN = 160, + AST_NODE_TYPE_OBJECT_EXPRESSION = 161, + AST_NODE_TYPE_OBJECT_PATTERN = 162, + AST_NODE_TYPE_SPREAD_ELEMENT = 163, + AST_NODE_TYPE_REST_ELEMENT = 164 } export enum Es2pandaScopeType { SCOPE_TYPE_PARAM = 0, @@ -1063,6 +1069,19 @@ export enum Es2pandaEntityType { ENTITY_TYPE_CLASS_DEFINITION = 2, ENTITY_TYPE_TS_INTERFACE_DECLARATION = 3 } +export enum Es2pandaProgramFlags { + PROGRAM_FLAGS_NONE = 0, + PROGRAM_FLAGS_AST_CHECKED = 1, + PROGRAM_FLAGS_AST_CHECK_PROCESSED = 2, + PROGRAM_FLAGS_AST_ENUM_LOWERED = 4, + PROGRAM_FLAGS_AST_BOXED_TYPE_LOWERED = 8, + PROGRAM_FLAGS_AST_CONST_STRING_TO_CHAR_LOWERED = 16, + PROGRAM_FLAGS_AST_CONSTANT_EXPRESSION_LOWERED = 32, + PROGRAM_FLAGS_AST_STRING_CONSTANT_LOWERED = 64, + PROGRAM_FLAGS_AST_IDENTIFIER_ANALYZED = 128, + PROGRAM_FLAGS_AST_HAS_SCOPES_INITIALIZED = 256, + PROGRAM_FLAGS_AST_HAS_OPTIONAL_PARAMETER_ANNOTATION = 512 +} export enum Es2pandaCompilationMode { COMPILATION_MODE_GEN_STD_LIB = 0, COMPILATION_MODE_PROJECT = 1, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/Es2pandaNativeModule.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/Es2pandaNativeModule.ts index 2921278fe14..02a1ea6492b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/Es2pandaNativeModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/Es2pandaNativeModule.ts @@ -28,9 +28,6 @@ import { export type KNativePointerArray = BigUint64Array export class Es2pandaNativeModule { - _NumberLiteralStrConst(context: KNativePointer, receiver: KNativePointer): KStringPtr { - throw new Error("This methods was not overloaded by native module initialization") - } _CreateNumberLiteral(context: KNativePointer, value: KInt): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } @@ -1141,6 +1138,12 @@ export class Es2pandaNativeModule { _ScriptFunctionFormalParamsLengthConst(context: KNativePointer, receiver: KNativePointer): KUInt { throw new Error("This methods was not overloaded by native module initialization") } + _ScriptFunctionSetIsolatedDeclgenReturnType(context: KNativePointer, receiver: KNativePointer, type: KStringPtr): void { + throw new Error("This methods was not overloaded by native module initialization") + } + _ScriptFunctionGetIsolatedDeclgenReturnTypeConst(context: KNativePointer, receiver: KNativePointer): KStringPtr { + throw new Error("This methods was not overloaded by native module initialization") + } _ScriptFunctionAnnotations(context: KNativePointer, receiver: KNativePointer): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } @@ -1810,6 +1813,9 @@ export class Es2pandaNativeModule { _AstNodeDumpDeclConst(context: KNativePointer, receiver: KNativePointer): KStringPtr { throw new Error("This methods was not overloaded by native module initialization") } + _AstNodeIsolatedDumpDeclConst(context: KNativePointer, receiver: KNativePointer): KStringPtr { + throw new Error("This methods was not overloaded by native module initialization") + } _AstNodeDumpConst(context: KNativePointer, receiver: KNativePointer, dumper: KNativePointer): void { throw new Error("This methods was not overloaded by native module initialization") } @@ -2173,6 +2179,18 @@ export class Es2pandaNativeModule { _ExportSpecifierExportedConst(context: KNativePointer, receiver: KNativePointer): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } + _ExportSpecifierSetDefault(context: KNativePointer, receiver: KNativePointer): void { + throw new Error("This methods was not overloaded by native module initialization") + } + _ExportSpecifierIsDefaultConst(context: KNativePointer, receiver: KNativePointer): KBoolean { + throw new Error("This methods was not overloaded by native module initialization") + } + _ExportSpecifierSetConstantExpression(context: KNativePointer, receiver: KNativePointer, constantExpression: KNativePointer): void { + throw new Error("This methods was not overloaded by native module initialization") + } + _ExportSpecifierGetConstantExpressionConst(context: KNativePointer, receiver: KNativePointer): KNativePointer { + throw new Error("This methods was not overloaded by native module initialization") + } _CreateTSTupleType(context: KNativePointer, elementTypes: BigUint64Array, elementTypesSequenceLength: KUInt): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } @@ -2452,6 +2470,15 @@ export class Es2pandaNativeModule { _UpdateEmptyStatement(context: KNativePointer, original: KNativePointer): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } + _CreateEmptyStatement1(context: KNativePointer, isBrokenStatement: KBoolean): KNativePointer { + throw new Error("This methods was not overloaded by native module initialization") + } + _UpdateEmptyStatement1(context: KNativePointer, original: KNativePointer, isBrokenStatement: KBoolean): KNativePointer { + throw new Error("This methods was not overloaded by native module initialization") + } + _EmptyStatementIsBrokenStatement(context: KNativePointer, receiver: KNativePointer): KBoolean { + throw new Error("This methods was not overloaded by native module initialization") + } _CreateWhileStatement(context: KNativePointer, test: KNativePointer, body: KNativePointer): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } @@ -2704,6 +2731,9 @@ export class Es2pandaNativeModule { _ExportNamedDeclarationSpecifiersConst(context: KNativePointer, receiver: KNativePointer): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } + _ExportNamedDeclarationReplaceSpecifiers(context: KNativePointer, receiver: KNativePointer, specifiers: BigUint64Array, specifiersSequenceLength: KUInt): void { + throw new Error("This methods was not overloaded by native module initialization") + } _CreateETSParameterExpression(context: KNativePointer, identOrSpread: KNativePointer, isOptional: KBoolean): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } @@ -3268,7 +3298,7 @@ export class Es2pandaNativeModule { _CreateSrcDumper(context: KNativePointer, node: KNativePointer): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } - _CreateSrcDumper1(context: KNativePointer, node: KNativePointer, isDeclgen: KBoolean): KNativePointer { + _CreateSrcDumper1(context: KNativePointer, node: KNativePointer, isDeclgen: KBoolean, isIsolatedDeclgen: KBoolean): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } _SrcDumperAdd(context: KNativePointer, receiver: KNativePointer, str: KStringPtr): void { @@ -3301,6 +3331,9 @@ export class Es2pandaNativeModule { _SrcDumperIsDeclgenConst(context: KNativePointer, receiver: KNativePointer): KBoolean { throw new Error("This methods was not overloaded by native module initialization") } + _SrcDumperIsIsolatedDeclgenConst(context: KNativePointer, receiver: KNativePointer): KBoolean { + throw new Error("This methods was not overloaded by native module initialization") + } _SrcDumperDumpNode(context: KNativePointer, receiver: KNativePointer, key: KStringPtr): void { throw new Error("This methods was not overloaded by native module initialization") } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/factory.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/factory.ts index 793066c97ac..8c165f17b05 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/factory.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/factory.ts @@ -708,12 +708,14 @@ export const factory = { return updateNodeByNode(AnnotationUsage.create1AnnotationUsage(expr, properties), original) } , - createEmptyStatement(): EmptyStatement { - return EmptyStatement.createEmptyStatement() + createEmptyStatement(isBrokenStatement: boolean): EmptyStatement { + return EmptyStatement.create1EmptyStatement(isBrokenStatement) } , - updateEmptyStatement(original: EmptyStatement): EmptyStatement { - return updateNodeByNode(EmptyStatement.createEmptyStatement(), original) + updateEmptyStatement(original: EmptyStatement, isBrokenStatement: boolean): EmptyStatement { + if (isSameNativeObject(isBrokenStatement, original.isBrokenStatement)) + return original + return updateNodeByNode(EmptyStatement.create1EmptyStatement(isBrokenStatement), original) } , createWhileStatement(test?: Expression, body?: Statement): WhileStatement { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/index.ts index dbe9554134f..730824c9662 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/index.ts @@ -36,6 +36,8 @@ export * from "./peers/VerificationContext" export * from "./peers/Path" export * from "./peers/DynamicImportData" export * from "./peers/OverloadInfo" +export * from "./peers/SuggestionInfo" +export * from "./peers/DiagnosticInfo" export * from "./peers/NumberLiteral" export * from "./peers/TypedAstNode" export * from "./peers/AnnotatedAstNode" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ArrayExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ArrayExpression.ts index 8bb8abad31d..0a883bdd7b2 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ArrayExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ArrayExpression.ts @@ -36,7 +36,7 @@ import { TypeNode } from "./TypeNode" import { ValidationInfo } from "./ValidationInfo" export class ArrayExpression extends AnnotatedExpression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 156) + assertValidPeer(pointer, 157) super(pointer) } static create1ArrayExpression(nodeType: Es2pandaAstNodeType, elements: readonly Expression[], trailingComma: boolean): ArrayExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/AssignmentExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/AssignmentExpression.ts index 5433f16e0b5..45158f38618 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/AssignmentExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/AssignmentExpression.ts @@ -34,7 +34,7 @@ import { Es2pandaTokenType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class AssignmentExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 158) + assertValidPeer(pointer, 159) super(pointer) } static create1AssignmentExpression(type: Es2pandaAstNodeType, left: Expression | undefined, right: Expression | undefined, assignmentOperator: Es2pandaTokenType): AssignmentExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/BlockExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/BlockExpression.ts index 045fb82a5ac..cc2601f55ee 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/BlockExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/BlockExpression.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { Statement } from "./Statement" export class BlockExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 154) + assertValidPeer(pointer, 155) super(pointer) } static createBlockExpression(statements: readonly Statement[]): BlockExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/input/ets/memo-hello-world.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/DiagnosticInfo.ts similarity index 60% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/input/ets/memo-hello-world.ts rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/DiagnosticInfo.ts index 2c34a5b7255..59af3821975 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/input/ets/memo-hello-world.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/DiagnosticInfo.ts @@ -13,17 +13,23 @@ * limitations under the License. */ -import { memo as memo, memo_intrinsic as memo_intrinsic, memo_entry as memo_entry, memo_stable as memo_stable, memo_skip as memo_skip } from "@koalaui/runtime/annotations"; +import { + global, + passNode, + passNodeArray, + unpackNonNullableNode, + unpackNode, + unpackNodeArray, + assertValidPeer, + AstNode, + KNativePointer, + nodeByType, + ArktsObject, + unpackString +} from "../../reexport-for-generated" -import { __memo_context_type as __memo_context_type, __memo_id_type as __memo_id_type } from "@koalaui/runtime"; - -@memo -function foo(): number { - console.log('hello') - return 4 -} - -@memo_entry -function main() { - foo() +export class DiagnosticInfo extends ArktsObject { + constructor(pointer: KNativePointer) { + super(pointer) + } } \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSClassLiteral.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSClassLiteral.ts index d3c2d422eb8..ec60cc7c8ba 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSClassLiteral.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSClassLiteral.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class ETSClassLiteral extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 70) + assertValidPeer(pointer, 71) super(pointer) } static createETSClassLiteral(expr?: TypeNode): ETSClassLiteral { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSFunctionType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSFunctionType.ts index 7d17651d445..8569da0cd86 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSFunctionType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSFunctionType.ts @@ -37,7 +37,7 @@ import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" import { TypeNode } from "./TypeNode" export class ETSFunctionType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 66) + assertValidPeer(pointer, 67) super(pointer) } static createETSFunctionType(signature: FunctionSignature | undefined, funcFlags: Es2pandaScriptFunctionFlags): ETSFunctionType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSImportDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSImportDeclaration.ts index 54a080415f8..9bb69528856 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSImportDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSImportDeclaration.ts @@ -36,7 +36,7 @@ import { ImportDeclaration } from "./ImportDeclaration" import { StringLiteral } from "./StringLiteral" export class ETSImportDeclaration extends ImportDeclaration { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 78) + assertValidPeer(pointer, 79) super(pointer) } static createETSImportDeclaration(importPath: StringLiteral | undefined, specifiers: readonly AstNode[], importKinds: Es2pandaImportKinds): ETSImportDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSKeyofType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSKeyofType.ts index d387864ef15..33014b621f5 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSKeyofType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSKeyofType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class ETSKeyofType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 74) + assertValidPeer(pointer, 75) super(pointer) } static createETSKeyofType(type?: TypeNode): ETSKeyofType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSModule.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSModule.ts index ebaf0600e33..96738e8438d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSModule.ts @@ -34,7 +34,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Identifier } from "./Identifier" export class ETSModule extends BlockStatement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 81) + assertValidPeer(pointer, 82) super(pointer) } get ident(): Identifier | undefined { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewArrayInstanceExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewArrayInstanceExpression.ts index f253841aa33..a4fae96721c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewArrayInstanceExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewArrayInstanceExpression.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class ETSNewArrayInstanceExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 75) + assertValidPeer(pointer, 76) super(pointer) } static createETSNewArrayInstanceExpression(typeReference?: TypeNode, dimension?: Expression): ETSNewArrayInstanceExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewClassInstanceExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewClassInstanceExpression.ts index 5bb759388ec..18c558ace5d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewClassInstanceExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewClassInstanceExpression.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class ETSNewClassInstanceExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 77) + assertValidPeer(pointer, 78) super(pointer) } static createETSNewClassInstanceExpression(typeReference: Expression | undefined, _arguments: readonly Expression[]): ETSNewClassInstanceExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts index 9a03ce6a840..042996e7457 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class ETSNewMultiDimArrayInstanceExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 76) + assertValidPeer(pointer, 77) super(pointer) } static createETSNewMultiDimArrayInstanceExpression(typeReference: TypeNode | undefined, dimensions: readonly Expression[]): ETSNewMultiDimArrayInstanceExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNullType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNullType.ts index ee9eef44319..996265dbb89 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNullType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSNullType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class ETSNullType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 62) + assertValidPeer(pointer, 63) super(pointer) } static createETSNullType(): ETSNullType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSPackageDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSPackageDeclaration.ts index 0451b4a65ba..b85b61118db 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSPackageDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSPackageDeclaration.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { Statement } from "./Statement" export class ETSPackageDeclaration extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 69) + assertValidPeer(pointer, 70) super(pointer) } static createETSPackageDeclaration(name?: Expression): ETSPackageDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSParameterExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSParameterExpression.ts index 6e218bd07d6..f47f7e062cb 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSParameterExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSParameterExpression.ts @@ -37,7 +37,7 @@ import { SpreadElement } from "./SpreadElement" import { TypeNode } from "./TypeNode" export class ETSParameterExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 79) + assertValidPeer(pointer, 80) super(pointer) } static createETSParameterExpression(identOrSpread: AnnotatedExpression | undefined, isOptional: boolean): ETSParameterExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSPrimitiveType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSPrimitiveType.ts index 1c44273eeaf..bb6b9f49e20 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSPrimitiveType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSPrimitiveType.ts @@ -33,7 +33,7 @@ import { Es2pandaPrimitiveType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class ETSPrimitiveType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 68) + assertValidPeer(pointer, 69) super(pointer) } static createETSPrimitiveType(type: Es2pandaPrimitiveType): ETSPrimitiveType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSStringLiteralType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSStringLiteralType.ts index 42834e5db75..db3ffa4d933 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSStringLiteralType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSStringLiteralType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class ETSStringLiteralType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 65) + assertValidPeer(pointer, 66) super(pointer) } static createETSStringLiteralType(value: string): ETSStringLiteralType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSStructDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSStructDeclaration.ts index 0482a8ae5ca..5b10199a535 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSStructDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSStructDeclaration.ts @@ -33,7 +33,7 @@ import { ClassDefinition } from "./ClassDefinition" import { Es2pandaAstNodeType } from "./../Es2pandaEnums" export class ETSStructDeclaration extends ClassDeclaration { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 83) + assertValidPeer(pointer, 84) super(pointer) } static createETSStructDeclaration(def?: ClassDefinition): ETSStructDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTuple.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTuple.ts index 882ff92868d..0f66cd07857 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTuple.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTuple.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class ETSTuple extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 80) + assertValidPeer(pointer, 81) super(pointer) } static createETSTuple(): ETSTuple { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTypeReference.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTypeReference.ts index a9f5bd96639..41b34ab1028 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTypeReference.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTypeReference.ts @@ -34,7 +34,7 @@ import { Identifier } from "./Identifier" import { TypeNode } from "./TypeNode" export class ETSTypeReference extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 71) + assertValidPeer(pointer, 72) super(pointer) } static createETSTypeReference(part?: ETSTypeReferencePart): ETSTypeReference { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTypeReferencePart.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTypeReferencePart.ts index 165e86db6ee..932121fb6e2 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTypeReferencePart.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSTypeReferencePart.ts @@ -35,7 +35,7 @@ import { TSTypeParameterInstantiation } from "./TSTypeParameterInstantiation" import { TypeNode } from "./TypeNode" export class ETSTypeReferencePart extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 72) + assertValidPeer(pointer, 73) super(pointer) } static createETSTypeReferencePart(name?: Expression, typeParams?: TSTypeParameterInstantiation, prev?: ETSTypeReferencePart): ETSTypeReferencePart { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSUndefinedType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSUndefinedType.ts index eb275b59f86..455fd69a982 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSUndefinedType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSUndefinedType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class ETSUndefinedType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 63) + assertValidPeer(pointer, 64) super(pointer) } static createETSUndefinedType(): ETSUndefinedType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSUnionType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSUnionType.ts index fd4588122c2..86524263882 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSUnionType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSUnionType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class ETSUnionType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 73) + assertValidPeer(pointer, 74) super(pointer) } static createETSUnionType(types: readonly TypeNode[]): ETSUnionType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSWildcardType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSWildcardType.ts index 8832863f44d..9dc0c287a05 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSWildcardType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ETSWildcardType.ts @@ -34,7 +34,7 @@ import { Es2pandaModifierFlags } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class ETSWildcardType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 67) + assertValidPeer(pointer, 68) super(pointer) } static createETSWildcardType(typeReference: ETSTypeReference | undefined, flags: Es2pandaModifierFlags): ETSWildcardType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/EmptyStatement.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/EmptyStatement.ts index 6031a3cbe59..8ce782c48db 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/EmptyStatement.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/EmptyStatement.ts @@ -35,12 +35,18 @@ export class EmptyStatement extends Statement { assertValidPeer(pointer, 25) super(pointer) } - static createEmptyStatement(): EmptyStatement { - return new EmptyStatement(global.generatedEs2panda._CreateEmptyStatement(global.context)) + static create1EmptyStatement(isBrokenStatement: boolean): EmptyStatement { + return new EmptyStatement(global.generatedEs2panda._CreateEmptyStatement1(global.context, isBrokenStatement)) } static updateEmptyStatement(original?: EmptyStatement): EmptyStatement { return new EmptyStatement(global.generatedEs2panda._UpdateEmptyStatement(global.context, passNode(original))) } + static update1EmptyStatement(original: EmptyStatement | undefined, isBrokenStatement: boolean): EmptyStatement { + return new EmptyStatement(global.generatedEs2panda._UpdateEmptyStatement1(global.context, passNode(original), isBrokenStatement)) + } + get isBrokenStatement(): boolean { + return global.generatedEs2panda._EmptyStatementIsBrokenStatement(global.context, this.peer) + } } export function isEmptyStatement(node: object | undefined): node is EmptyStatement { return node instanceof EmptyStatement diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ExportNamedDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ExportNamedDeclaration.ts index ae10e7c3555..68216a5861b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ExportNamedDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ExportNamedDeclaration.ts @@ -64,6 +64,11 @@ export class ExportNamedDeclaration extends Statement { get specifiers(): readonly ExportSpecifier[] { return unpackNodeArray(global.generatedEs2panda._ExportNamedDeclarationSpecifiersConst(global.context, this.peer)) } + /** @deprecated */ + replaceSpecifiers(specifiers: readonly ExportSpecifier[]): this { + global.generatedEs2panda._ExportNamedDeclarationReplaceSpecifiers(global.context, this.peer, passNodeArray(specifiers), specifiers.length) + return this + } } export function isExportNamedDeclaration(node: object | undefined): node is ExportNamedDeclaration { return node instanceof ExportNamedDeclaration diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ExportSpecifier.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ExportSpecifier.ts index f498a7c218a..cea670ea3c9 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ExportSpecifier.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ExportSpecifier.ts @@ -29,6 +29,7 @@ import { } from "../../reexport-for-generated" import { Es2pandaAstNodeType } from "./../Es2pandaEnums" +import { Expression } from "./Expression" import { Identifier } from "./Identifier" import { Statement } from "./Statement" export class ExportSpecifier extends Statement { @@ -48,6 +49,22 @@ export class ExportSpecifier extends Statement { get exported(): Identifier | undefined { return unpackNode(global.generatedEs2panda._ExportSpecifierExportedConst(global.context, this.peer)) } + /** @deprecated */ + setDefault(): this { + global.generatedEs2panda._ExportSpecifierSetDefault(global.context, this.peer) + return this + } + get isDefault(): boolean { + return global.generatedEs2panda._ExportSpecifierIsDefaultConst(global.context, this.peer) + } + /** @deprecated */ + setConstantExpression(constantExpression?: Expression): this { + global.generatedEs2panda._ExportSpecifierSetConstantExpression(global.context, this.peer, passNode(constantExpression)) + return this + } + get constantExpression(): Expression | undefined { + return unpackNode(global.generatedEs2panda._ExportSpecifierGetConstantExpressionConst(global.context, this.peer)) + } } export function isExportSpecifier(node: object | undefined): node is ExportSpecifier { return node instanceof ExportSpecifier diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/NumberLiteral.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/NumberLiteral.ts index ff1adcf3247..f89f322c59d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/NumberLiteral.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/NumberLiteral.ts @@ -38,9 +38,6 @@ export class NumberLiteral extends Literal { static createNumberLiteral(value: number): AstNode { return new NumberLiteral(global.generatedEs2panda._CreateNumberLiteral(global.context, value)) } - get str(): string { - return unpackString(global.generatedEs2panda._NumberLiteralStrConst(global.context, this.peer)) - } static updateNumberLiteral(original: AstNode | undefined, value: number): AstNode { return new NumberLiteral(global.generatedEs2panda._UpdateNumberLiteral(global.context, passNode(original), value)) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ObjectExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ObjectExpression.ts index 2566b4494dc..654633ab12d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ObjectExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ObjectExpression.ts @@ -36,7 +36,7 @@ import { TypeNode } from "./TypeNode" import { ValidationInfo } from "./ValidationInfo" export class ObjectExpression extends AnnotatedExpression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 160) + assertValidPeer(pointer, 161) super(pointer) } static createObjectExpression(nodeType: Es2pandaAstNodeType, properties: readonly Expression[], trailingComma: boolean): ObjectExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/OpaqueTypeNode.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/OpaqueTypeNode.ts index a3a2ec34c7e..5461a48bd23 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/OpaqueTypeNode.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/OpaqueTypeNode.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class OpaqueTypeNode extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 153) + assertValidPeer(pointer, 154) super(pointer) } static create1OpaqueTypeNode(): OpaqueTypeNode { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ScriptFunction.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ScriptFunction.ts index 3543561a549..f26ae1781fb 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ScriptFunction.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ScriptFunction.ts @@ -189,6 +189,14 @@ export class ScriptFunction extends AstNode { get formalParamsLength(): number { return global.generatedEs2panda._ScriptFunctionFormalParamsLengthConst(global.context, this.peer) } + /** @deprecated */ + setIsolatedDeclgenReturnType(type: string): this { + global.generatedEs2panda._ScriptFunctionSetIsolatedDeclgenReturnType(global.context, this.peer, type) + return this + } + get isolatedDeclgenReturnType(): string { + return unpackString(global.generatedEs2panda._ScriptFunctionGetIsolatedDeclgenReturnTypeConst(global.context, this.peer)) + } get annotations(): readonly AnnotationUsage[] { return unpackNodeArray(global.generatedEs2panda._ScriptFunctionAnnotations(global.context, this.peer)) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SpreadElement.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SpreadElement.ts index 3d253dd6010..0e557f5d22f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SpreadElement.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SpreadElement.ts @@ -36,7 +36,7 @@ import { TypeNode } from "./TypeNode" import { ValidationInfo } from "./ValidationInfo" export class SpreadElement extends AnnotatedExpression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 162) + assertValidPeer(pointer, 163) super(pointer) } static createSpreadElement(nodeType: Es2pandaAstNodeType, argument?: Expression): SpreadElement { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SrcDumper.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SrcDumper.ts index bf40a953b58..34e913dffcb 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SrcDumper.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SrcDumper.ts @@ -32,8 +32,8 @@ export class SrcDumper extends ArktsObject { constructor(pointer: KNativePointer) { super(pointer) } - static create1SrcDumper(node: AstNode | undefined, isDeclgen: boolean): SrcDumper { - return new SrcDumper(global.generatedEs2panda._CreateSrcDumper1(global.context, passNode(node), isDeclgen)) + static create1SrcDumper(node: AstNode | undefined, isDeclgen: boolean, isIsolatedDeclgen: boolean): SrcDumper { + return new SrcDumper(global.generatedEs2panda._CreateSrcDumper1(global.context, passNode(node), isDeclgen, isIsolatedDeclgen)) } /** @deprecated */ add(str: string): this { @@ -81,6 +81,9 @@ export class SrcDumper extends ArktsObject { get isDeclgen(): boolean { return global.generatedEs2panda._SrcDumperIsDeclgenConst(global.context, this.peer) } + get isIsolatedDeclgen(): boolean { + return global.generatedEs2panda._SrcDumperIsIsolatedDeclgenConst(global.context, this.peer) + } /** @deprecated */ dumpNode(key: string): this { global.generatedEs2panda._SrcDumperDumpNode(global.context, this.peer, key) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Dependency.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SuggestionInfo.ts similarity index 56% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Dependency.ets rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SuggestionInfo.ts index af0c9d5a159..855d52b1ba0 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Dependency.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SuggestionInfo.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -13,15 +13,23 @@ * limitations under the License. */ -export declare interface Dependency { - readonly obsolete: boolean - invalidate(): void -} -export declare class Dependencies { - frame: int - dependencies: Set | undefined - latest: Dependency | undefined - get empty(): boolean - register(dependency?: Dependency): void - updateDependencies(invalidate: boolean): void -} +import { + global, + passNode, + passNodeArray, + unpackNonNullableNode, + unpackNode, + unpackNodeArray, + assertValidPeer, + AstNode, + KNativePointer, + nodeByType, + ArktsObject, + unpackString +} from "../../reexport-for-generated" + +export class SuggestionInfo extends ArktsObject { + constructor(pointer: KNativePointer) { + super(pointer) + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SuperExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SuperExpression.ts index 055d0a83f67..a6af6b8d557 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SuperExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SuperExpression.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class SuperExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 82) + assertValidPeer(pointer, 83) super(pointer) } static createSuperExpression(): SuperExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SwitchCaseStatement.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SwitchCaseStatement.ts index 2c7342133ca..ff8ab9268ff 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SwitchCaseStatement.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SwitchCaseStatement.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { Statement } from "./Statement" export class SwitchCaseStatement extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 84) + assertValidPeer(pointer, 85) super(pointer) } static createSwitchCaseStatement(test: Expression | undefined, consequent: readonly Statement[]): SwitchCaseStatement { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SwitchStatement.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SwitchStatement.ts index 527c3ead868..362c156be2b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SwitchStatement.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/SwitchStatement.ts @@ -34,7 +34,7 @@ import { Statement } from "./Statement" import { SwitchCaseStatement } from "./SwitchCaseStatement" export class SwitchStatement extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 85) + assertValidPeer(pointer, 86) super(pointer) } static createSwitchStatement(discriminant: Expression | undefined, cases: readonly SwitchCaseStatement[]): SwitchStatement { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSAnyKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSAnyKeyword.ts index c6102fbc642..1b031c62f3c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSAnyKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSAnyKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSAnyKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 90) + assertValidPeer(pointer, 91) super(pointer) } static createTSAnyKeyword(): TSAnyKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSArrayType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSArrayType.ts index 3f21d6669f7..b3213f6ac66 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSArrayType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSArrayType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSArrayType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 101) + assertValidPeer(pointer, 102) super(pointer) } static createTSArrayType(elementType?: TypeNode): TSArrayType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSAsExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSAsExpression.ts index a58416b831b..b54c30370dc 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSAsExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSAsExpression.ts @@ -34,7 +34,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSAsExpression extends AnnotatedExpression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 137) + assertValidPeer(pointer, 138) super(pointer) } static createTSAsExpression(expression: Expression | undefined, typeAnnotation: TypeNode | undefined, isConst: boolean): TSAsExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSBigintKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSBigintKeyword.ts index f4197534ffe..97da3eed34b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSBigintKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSBigintKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSBigintKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 97) + assertValidPeer(pointer, 98) super(pointer) } static createTSBigintKeyword(): TSBigintKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSBooleanKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSBooleanKeyword.ts index f401a379be1..4dd24c7c6f2 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSBooleanKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSBooleanKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSBooleanKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 92) + assertValidPeer(pointer, 93) super(pointer) } static createTSBooleanKeyword(): TSBooleanKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSClassImplements.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSClassImplements.ts index 76ce7ccaaaf..7c667dda078 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSClassImplements.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSClassImplements.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TSTypeParameterInstantiation } from "./TSTypeParameterInstantiation" export class TSClassImplements extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 138) + assertValidPeer(pointer, 139) super(pointer) } static createTSClassImplements(expression?: Expression, typeParameters?: TSTypeParameterInstantiation): TSClassImplements { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSConditionalType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSConditionalType.ts index 7793a319567..7a93a6877e5 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSConditionalType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSConditionalType.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSConditionalType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 110) + assertValidPeer(pointer, 111) super(pointer) } static createTSConditionalType(checkType?: Expression, extendsType?: Expression, trueType?: Expression, falseType?: Expression): TSConditionalType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSConstructorType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSConstructorType.ts index 1321491c2e8..f908b708756 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSConstructorType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSConstructorType.ts @@ -35,7 +35,7 @@ import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" import { TypeNode } from "./TypeNode" export class TSConstructorType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 125) + assertValidPeer(pointer, 126) super(pointer) } static createTSConstructorType(signature: FunctionSignature | undefined, abstract: boolean): TSConstructorType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSEnumDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSEnumDeclaration.ts index a5044b08326..e049a4b39f7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSEnumDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSEnumDeclaration.ts @@ -35,7 +35,7 @@ import { Identifier } from "./Identifier" import { TypedStatement } from "./TypedStatement" export class TSEnumDeclaration extends TypedStatement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 86) + assertValidPeer(pointer, 87) super(pointer) } static createTSEnumDeclaration(key: Identifier | undefined, members: readonly AstNode[], isConst: boolean, isStatic: boolean, isDeclare: boolean): TSEnumDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSEnumMember.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSEnumMember.ts index 3facabee01f..8bdd01847c8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSEnumMember.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSEnumMember.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { Statement } from "./Statement" export class TSEnumMember extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 87) + assertValidPeer(pointer, 88) super(pointer) } static create1TSEnumMember(key: Expression | undefined, init: Expression | undefined, isGenerated: boolean): TSEnumMember { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSExternalModuleReference.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSExternalModuleReference.ts index 5c4efa4b8b0..ebf31a34c28 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSExternalModuleReference.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSExternalModuleReference.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class TSExternalModuleReference extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 88) + assertValidPeer(pointer, 89) super(pointer) } static createTSExternalModuleReference(expr?: Expression): TSExternalModuleReference { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSFunctionType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSFunctionType.ts index c4985850f1b..1494635497f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSFunctionType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSFunctionType.ts @@ -35,7 +35,7 @@ import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" import { TypeNode } from "./TypeNode" export class TSFunctionType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 124) + assertValidPeer(pointer, 125) super(pointer) } static createTSFunctionType(signature?: FunctionSignature): TSFunctionType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSImportEqualsDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSImportEqualsDeclaration.ts index 282f832fc2c..afd4331b61f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSImportEqualsDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSImportEqualsDeclaration.ts @@ -34,7 +34,7 @@ import { Identifier } from "./Identifier" import { Statement } from "./Statement" export class TSImportEqualsDeclaration extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 123) + assertValidPeer(pointer, 124) super(pointer) } static createTSImportEqualsDeclaration(id: Identifier | undefined, moduleReference: Expression | undefined, isExport: boolean): TSImportEqualsDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSImportType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSImportType.ts index 7f240cfd535..f30059963a7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSImportType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSImportType.ts @@ -34,7 +34,7 @@ import { TSTypeParameterInstantiation } from "./TSTypeParameterInstantiation" import { TypeNode } from "./TypeNode" export class TSImportType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 111) + assertValidPeer(pointer, 112) super(pointer) } static createTSImportType(param: Expression | undefined, typeParams: TSTypeParameterInstantiation | undefined, qualifier: Expression | undefined, isTypeof: boolean): TSImportType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIndexSignature.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIndexSignature.ts index b3b2040a61e..5fbfba49da6 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIndexSignature.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIndexSignature.ts @@ -35,7 +35,7 @@ import { TypeNode } from "./TypeNode" import { TypedAstNode } from "./TypedAstNode" export class TSIndexSignature extends TypedAstNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 135) + assertValidPeer(pointer, 136) super(pointer) } static createTSIndexSignature(param: Expression | undefined, typeAnnotation: TypeNode | undefined, readonly_arg: boolean): TSIndexSignature { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIndexedAccessType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIndexedAccessType.ts index 360c2e763b0..ded50eae68c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIndexedAccessType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIndexedAccessType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSIndexedAccessType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 129) + assertValidPeer(pointer, 130) super(pointer) } static createTSIndexedAccessType(objectType?: TypeNode, indexType?: TypeNode): TSIndexedAccessType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInferType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInferType.ts index 1642b52242b..453b533bc3d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInferType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInferType.ts @@ -33,7 +33,7 @@ import { TSTypeParameter } from "./TSTypeParameter" import { TypeNode } from "./TypeNode" export class TSInferType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 109) + assertValidPeer(pointer, 110) super(pointer) } static createTSInferType(typeParam?: TSTypeParameter): TSInferType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceBody.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceBody.ts index 74e5c680c8f..68c93c17305 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceBody.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceBody.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class TSInterfaceBody extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 131) + assertValidPeer(pointer, 132) super(pointer) } static createTSInterfaceBody(body: readonly AstNode[]): TSInterfaceBody { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceDeclaration.ts index bfa80ac52d8..54ce5b8b088 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceDeclaration.ts @@ -39,7 +39,7 @@ import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" import { TypedStatement } from "./TypedStatement" export class TSInterfaceDeclaration extends TypedStatement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 130) + assertValidPeer(pointer, 131) super(pointer) } static createTSInterfaceDeclaration(_extends: readonly TSInterfaceHeritage[], id: AstNode | undefined, typeParams: AstNode | undefined, body: AstNode | undefined, isStatic: boolean, isExternal: boolean): TSInterfaceDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceHeritage.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceHeritage.ts index 41ae5ee2ee6..fa102d5e935 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceHeritage.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSInterfaceHeritage.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSInterfaceHeritage extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 132) + assertValidPeer(pointer, 133) super(pointer) } static createTSInterfaceHeritage(expr?: TypeNode): TSInterfaceHeritage { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIntersectionType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIntersectionType.ts index 7e5b7c07663..9d652edfb06 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIntersectionType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSIntersectionType.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSIntersectionType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 112) + assertValidPeer(pointer, 113) super(pointer) } static createTSIntersectionType(types: readonly Expression[]): TSIntersectionType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSLiteralType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSLiteralType.ts index ca345e4e007..0bb80814c24 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSLiteralType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSLiteralType.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSLiteralType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 108) + assertValidPeer(pointer, 109) super(pointer) } static createTSLiteralType(literal?: Expression): TSLiteralType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSMappedType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSMappedType.ts index c8cd77decc8..a7e7970dbfe 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSMappedType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSMappedType.ts @@ -34,7 +34,7 @@ import { TSTypeParameter } from "./TSTypeParameter" import { TypeNode } from "./TypeNode" export class TSMappedType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 113) + assertValidPeer(pointer, 114) super(pointer) } static createTSMappedType(typeParameter: TSTypeParameter | undefined, typeAnnotation: TypeNode | undefined, readonly_arg: Es2pandaMappedOption, optional_arg: Es2pandaMappedOption): TSMappedType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSMethodSignature.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSMethodSignature.ts index 1188cd18e89..b6a82dbb09f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSMethodSignature.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSMethodSignature.ts @@ -35,7 +35,7 @@ import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" import { TypeNode } from "./TypeNode" export class TSMethodSignature extends AstNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 105) + assertValidPeer(pointer, 106) super(pointer) } static createTSMethodSignature(key: Expression | undefined, signature: FunctionSignature | undefined, computed: boolean, optional_arg: boolean): TSMethodSignature { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSModuleBlock.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSModuleBlock.ts index 1e1c58111f4..4216aada3dc 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSModuleBlock.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSModuleBlock.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Statement } from "./Statement" export class TSModuleBlock extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 114) + assertValidPeer(pointer, 115) super(pointer) } static createTSModuleBlock(statements: readonly Statement[]): TSModuleBlock { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSModuleDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSModuleDeclaration.ts index 58cc7ccd05d..a128a272a8e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSModuleDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSModuleDeclaration.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { Statement } from "./Statement" export class TSModuleDeclaration extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 122) + assertValidPeer(pointer, 123) super(pointer) } static createTSModuleDeclaration(name: Expression | undefined, body: Statement | undefined, declare: boolean, _global: boolean): TSModuleDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNamedTupleMember.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNamedTupleMember.ts index 29c3e25d945..f33f5e860ee 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNamedTupleMember.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNamedTupleMember.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSNamedTupleMember extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 134) + assertValidPeer(pointer, 135) super(pointer) } static createTSNamedTupleMember(label: Expression | undefined, elementType: TypeNode | undefined, optional_arg: boolean): TSNamedTupleMember { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNeverKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNeverKeyword.ts index 5ab05cb6527..cd03e812698 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNeverKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNeverKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSNeverKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 98) + assertValidPeer(pointer, 99) super(pointer) } static createTSNeverKeyword(): TSNeverKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNonNullExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNonNullExpression.ts index 38c775419d5..2a3e0ec8f1a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNonNullExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNonNullExpression.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class TSNonNullExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 99) + assertValidPeer(pointer, 100) super(pointer) } static createTSNonNullExpression(expr?: Expression): TSNonNullExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNullKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNullKeyword.ts index 974d5e3b07c..22936071249 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNullKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNullKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSNullKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 100) + assertValidPeer(pointer, 101) super(pointer) } static createTSNullKeyword(): TSNullKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNumberKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNumberKeyword.ts index 051bf39808b..a8453f5e8f7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNumberKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSNumberKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSNumberKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 89) + assertValidPeer(pointer, 90) super(pointer) } static createTSNumberKeyword(): TSNumberKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSObjectKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSObjectKeyword.ts index a2c378cbde0..219bbcfb14e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSObjectKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSObjectKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSObjectKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 96) + assertValidPeer(pointer, 97) super(pointer) } static createTSObjectKeyword(): TSObjectKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSParameterProperty.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSParameterProperty.ts index dcab958228e..8a9374db1ba 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSParameterProperty.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSParameterProperty.ts @@ -33,7 +33,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class TSParameterProperty extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 121) + assertValidPeer(pointer, 122) super(pointer) } static createTSParameterProperty(accessibility: Es2pandaAccessibilityOption, parameter: Expression | undefined, readonly_arg: boolean, isStatic: boolean, isExport: boolean): TSParameterProperty { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSParenthesizedType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSParenthesizedType.ts index 320d4ec1a9a..3ce36a61dc5 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSParenthesizedType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSParenthesizedType.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSParenthesizedType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 107) + assertValidPeer(pointer, 108) super(pointer) } static createTSParenthesizedType(type?: TypeNode): TSParenthesizedType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSPropertySignature.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSPropertySignature.ts index f33c6510d8d..14c9b65c2b4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSPropertySignature.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSPropertySignature.ts @@ -34,7 +34,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSPropertySignature extends AnnotatedAstNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 104) + assertValidPeer(pointer, 105) super(pointer) } static createTSPropertySignature(key: Expression | undefined, typeAnnotation: TypeNode | undefined, computed: boolean, optional_arg: boolean, readonly_arg: boolean): TSPropertySignature { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSQualifiedName.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSQualifiedName.ts index 027cdb9ad0f..9f83cf887f3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSQualifiedName.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSQualifiedName.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { Identifier } from "./Identifier" export class TSQualifiedName extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 128) + assertValidPeer(pointer, 129) super(pointer) } static createTSQualifiedName(left?: Expression, right?: Identifier): TSQualifiedName { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSSignatureDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSSignatureDeclaration.ts index db97f153809..01d9e270751 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSSignatureDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSSignatureDeclaration.ts @@ -37,7 +37,7 @@ import { TypeNode } from "./TypeNode" import { TypedAstNode } from "./TypedAstNode" export class TSSignatureDeclaration extends TypedAstNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 106) + assertValidPeer(pointer, 107) super(pointer) } static createTSSignatureDeclaration(kind: Es2pandaTSSignatureDeclarationKind, signature?: FunctionSignature): TSSignatureDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSStringKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSStringKeyword.ts index 4d7c5d2d7c5..5415d0f2b11 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSStringKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSStringKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSStringKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 91) + assertValidPeer(pointer, 92) super(pointer) } static createTSStringKeyword(): TSStringKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSThisType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSThisType.ts index 9d872f160bc..e3cb663d102 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSThisType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSThisType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSThisType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 115) + assertValidPeer(pointer, 116) super(pointer) } static createTSThisType(): TSThisType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTupleType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTupleType.ts index 0073d6aefed..4aff2c470c2 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTupleType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTupleType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSTupleType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 133) + assertValidPeer(pointer, 134) super(pointer) } static createTSTupleType(elementTypes: readonly TypeNode[]): TSTupleType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeAliasDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeAliasDeclaration.ts index bd715e14cbf..d084aafdd26 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeAliasDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeAliasDeclaration.ts @@ -37,7 +37,7 @@ import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" import { TypeNode } from "./TypeNode" export class TSTypeAliasDeclaration extends AnnotatedStatement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 126) + assertValidPeer(pointer, 127) super(pointer) } static createTSTypeAliasDeclaration(id?: Identifier, typeParams?: TSTypeParameterDeclaration, typeAnnotation?: TypeNode): TSTypeAliasDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeAssertion.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeAssertion.ts index 860ceb12bd9..e9c4fc06710 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeAssertion.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeAssertion.ts @@ -34,7 +34,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSTypeAssertion extends AnnotatedExpression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 139) + assertValidPeer(pointer, 140) super(pointer) } static createTSTypeAssertion(typeAnnotation?: TypeNode, expression?: Expression): TSTypeAssertion { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeLiteral.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeLiteral.ts index 3b0ad66de84..dea2f45bf35 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeLiteral.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeLiteral.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSTypeLiteral extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 103) + assertValidPeer(pointer, 104) super(pointer) } static createTSTypeLiteral(members: readonly AstNode[]): TSTypeLiteral { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeOperator.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeOperator.ts index 9c6ef04db44..324d626e043 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeOperator.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeOperator.ts @@ -33,7 +33,7 @@ import { Es2pandaTSOperatorType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSTypeOperator extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 116) + assertValidPeer(pointer, 117) super(pointer) } static createTSTypeOperator(type: TypeNode | undefined, operatorType: Es2pandaTSOperatorType): TSTypeOperator { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameter.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameter.ts index 9ae3f309fd8..700b1f7b31f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameter.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameter.ts @@ -36,7 +36,7 @@ import { Identifier } from "./Identifier" import { TypeNode } from "./TypeNode" export class TSTypeParameter extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 117) + assertValidPeer(pointer, 118) super(pointer) } static create1TSTypeParameter(name: Identifier | undefined, constraint: TypeNode | undefined, defaultType: TypeNode | undefined, flags: Es2pandaModifierFlags): TSTypeParameter { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameterDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameterDeclaration.ts index 303fd99e77e..49f32861dba 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameterDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameterDeclaration.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TSTypeParameter } from "./TSTypeParameter" export class TSTypeParameterDeclaration extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 118) + assertValidPeer(pointer, 119) super(pointer) } static createTSTypeParameterDeclaration(params: readonly TSTypeParameter[], requiredParams: number): TSTypeParameterDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameterInstantiation.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameterInstantiation.ts index 3367228d6c3..73278fcd5c3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameterInstantiation.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeParameterInstantiation.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSTypeParameterInstantiation extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 119) + assertValidPeer(pointer, 120) super(pointer) } static createTSTypeParameterInstantiation(params: readonly TypeNode[]): TSTypeParameterInstantiation { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypePredicate.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypePredicate.ts index 6ca2b888a98..9276a76d180 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypePredicate.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypePredicate.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSTypePredicate extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 120) + assertValidPeer(pointer, 121) super(pointer) } static createTSTypePredicate(parameterName: Expression | undefined, typeAnnotation: TypeNode | undefined, asserts: boolean): TSTypePredicate { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeQuery.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeQuery.ts index 7a4e3957596..848f29800f3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeQuery.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeQuery.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TypeNode } from "./TypeNode" export class TSTypeQuery extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 136) + assertValidPeer(pointer, 137) super(pointer) } static createTSTypeQuery(exprName?: Expression): TSTypeQuery { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeReference.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeReference.ts index f8ec939454a..8e70a3bf909 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeReference.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSTypeReference.ts @@ -35,7 +35,7 @@ import { TSTypeParameterInstantiation } from "./TSTypeParameterInstantiation" import { TypeNode } from "./TypeNode" export class TSTypeReference extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 127) + assertValidPeer(pointer, 128) super(pointer) } static createTSTypeReference(typeName?: Expression, typeParams?: TSTypeParameterInstantiation): TSTypeReference { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUndefinedKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUndefinedKeyword.ts index a7538f5a660..780452d01ac 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUndefinedKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUndefinedKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSUndefinedKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 94) + assertValidPeer(pointer, 95) super(pointer) } static createTSUndefinedKeyword(): TSUndefinedKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUnionType.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUnionType.ts index 19ed0624fdb..8c42c4cb234 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUnionType.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUnionType.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSUnionType extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 102) + assertValidPeer(pointer, 103) super(pointer) } static createTSUnionType(types: readonly TypeNode[]): TSUnionType { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUnknownKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUnknownKeyword.ts index 05439e0cebc..e644472988a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUnknownKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSUnknownKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSUnknownKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 95) + assertValidPeer(pointer, 96) super(pointer) } static createTSUnknownKeyword(): TSUnknownKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSVoidKeyword.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSVoidKeyword.ts index cef192f23c6..af3ca21c04a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSVoidKeyword.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TSVoidKeyword.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { TypeNode } from "./TypeNode" export class TSVoidKeyword extends TypeNode { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 93) + assertValidPeer(pointer, 94) super(pointer) } static createTSVoidKeyword(): TSVoidKeyword { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TaggedTemplateExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TaggedTemplateExpression.ts index e27c7a75f1e..af0d80624cd 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TaggedTemplateExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TaggedTemplateExpression.ts @@ -34,7 +34,7 @@ import { TSTypeParameterInstantiation } from "./TSTypeParameterInstantiation" import { TemplateLiteral } from "./TemplateLiteral" export class TaggedTemplateExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 140) + assertValidPeer(pointer, 141) super(pointer) } static createTaggedTemplateExpression(tag?: Expression, quasi?: TemplateLiteral, typeParams?: TSTypeParameterInstantiation): TaggedTemplateExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TemplateElement.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TemplateElement.ts index fc939e479c2..03dd9f22712 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TemplateElement.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TemplateElement.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class TemplateElement extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 141) + assertValidPeer(pointer, 142) super(pointer) } static create1TemplateElement(raw: string, cooked: string): TemplateElement { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TemplateLiteral.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TemplateLiteral.ts index 3ed0b07ba0c..f65b4a3c617 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TemplateLiteral.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TemplateLiteral.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { TemplateElement } from "./TemplateElement" export class TemplateLiteral extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 142) + assertValidPeer(pointer, 143) super(pointer) } static createTemplateLiteral(quasis: readonly TemplateElement[], expressions: readonly Expression[], multilineString: string): TemplateLiteral { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ThisExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ThisExpression.ts index 1c54681676d..f7b16129979 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ThisExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ThisExpression.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class ThisExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 143) + assertValidPeer(pointer, 144) super(pointer) } static createThisExpression(): ThisExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ThrowStatement.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ThrowStatement.ts index 1d5f2df9dd7..8589acac870 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ThrowStatement.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/ThrowStatement.ts @@ -33,7 +33,7 @@ import { Expression } from "./Expression" import { Statement } from "./Statement" export class ThrowStatement extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 145) + assertValidPeer(pointer, 146) super(pointer) } static createThrowStatement(argument?: Expression): ThrowStatement { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TryStatement.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TryStatement.ts index 709c3cd50a9..3dc09ac3a82 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TryStatement.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TryStatement.ts @@ -35,7 +35,7 @@ import { LabelPair } from "./LabelPair" import { Statement } from "./Statement" export class TryStatement extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 146) + assertValidPeer(pointer, 147) super(pointer) } static createTryStatement(block: BlockStatement | undefined, catchClauses: readonly CatchClause[], finalizer: BlockStatement | undefined, finalizerInsertionsLabelPair: readonly LabelPair[], finalizerInsertionsStatement: readonly Statement[]): TryStatement { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TypeofExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TypeofExpression.ts index 043703df351..5c1856a3f9d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TypeofExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/TypeofExpression.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class TypeofExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 144) + assertValidPeer(pointer, 145) super(pointer) } static createTypeofExpression(argument?: Expression): TypeofExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/UnaryExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/UnaryExpression.ts index 8092f469376..b28ef8da0bd 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/UnaryExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/UnaryExpression.ts @@ -33,7 +33,7 @@ import { Es2pandaTokenType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class UnaryExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 147) + assertValidPeer(pointer, 148) super(pointer) } static createUnaryExpression(argument: Expression | undefined, unaryOperator: Es2pandaTokenType): UnaryExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/UpdateExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/UpdateExpression.ts index 7ae3efd104a..f1b6b45c335 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/UpdateExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/UpdateExpression.ts @@ -33,7 +33,7 @@ import { Es2pandaTokenType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class UpdateExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 148) + assertValidPeer(pointer, 149) super(pointer) } static createUpdateExpression(argument: Expression | undefined, updateOperator: Es2pandaTokenType, isPrefix: boolean): UpdateExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/VariableDeclaration.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/VariableDeclaration.ts index a4fc03e4343..08fe6148f83 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/VariableDeclaration.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/VariableDeclaration.ts @@ -36,7 +36,7 @@ import { Statement } from "./Statement" import { VariableDeclarator } from "./VariableDeclarator" export class VariableDeclaration extends Statement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 149) + assertValidPeer(pointer, 150) super(pointer) } static createVariableDeclaration(kind: Es2pandaVariableDeclarationKind, declarators: readonly VariableDeclarator[]): VariableDeclaration { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/VariableDeclarator.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/VariableDeclarator.ts index 3513e86a881..a1e286ba12d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/VariableDeclarator.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/VariableDeclarator.ts @@ -34,7 +34,7 @@ import { Expression } from "./Expression" import { TypedStatement } from "./TypedStatement" export class VariableDeclarator extends TypedStatement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 150) + assertValidPeer(pointer, 151) super(pointer) } static create1VariableDeclarator(flag: Es2pandaVariableDeclaratorFlag, ident?: Expression, init?: Expression): VariableDeclarator { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/WhileStatement.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/WhileStatement.ts index fd37a849963..d889b655046 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/WhileStatement.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/WhileStatement.ts @@ -34,7 +34,7 @@ import { LoopStatement } from "./LoopStatement" import { Statement } from "./Statement" export class WhileStatement extends LoopStatement { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 151) + assertValidPeer(pointer, 152) super(pointer) } static createWhileStatement(test?: Expression, body?: Statement): WhileStatement { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/YieldExpression.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/YieldExpression.ts index 111a2739c2f..3865bf89457 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/YieldExpression.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/generated/peers/YieldExpression.ts @@ -32,7 +32,7 @@ import { Es2pandaAstNodeType } from "./../Es2pandaEnums" import { Expression } from "./Expression" export class YieldExpression extends Expression { constructor(pointer: KNativePointer) { - assertValidPeer(pointer, 152) + assertValidPeer(pointer, 153) super(pointer) } static createYieldExpression(argument: Expression | undefined, isDelegate: boolean): YieldExpression { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/index.ts index 840594be45d..697544a9e89 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/index.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -23,6 +23,9 @@ export * from "./arkts-api/utilities/public" export * from "./arkts-api/factory/nodeFactory" export * from "./arkts-api/visitor" export * from "./arkts-api/AbstractVisitor" +export * from "./arkts-api/CheckedBackFilter" +export * from "./arkts-api/SetBaseOverloads" +export * from "./arkts-api/plugins" export * from "./arkts-api/peers/AstNode" export * from "./arkts-api/peers/Config" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/factory/nodeFactory.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/factory/nodeFactory.ts index 7424783a2fe..bc371b76899 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/factory/nodeFactory.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/factory/nodeFactory.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/factory/nodeTests.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/factory/nodeTests.ts index 74114702a74..d108973f6f6 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/factory/nodeTests.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/factory/nodeTests.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/types.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/types.ts index cb263beaad5..ebab4206e19 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/types.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/ts-api/types.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/utils.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/utils.ts index 7d436606669..1bb766b9216 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/utils.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/src/utils.ts @@ -117,8 +117,8 @@ function replaceGensymWrappers(code: string): string { function addExports(code: string): string { - const exportAstNodes = ["let", "const", "class", "abstract class", "@Entry() @Component() final class", "@Component() final class", "interface", "@interface", "type", "enum", "final class", "function", - "declare interface", + const exportAstNodes = [" enum", "let", "const", "class", "abstract class", "@Entry() @Component() final class", "@Component() final class", "interface", "@interface", "type", "enum", "final class", "function", + "declare interface", "@memo_stable() declare interface", "@memo_stable() interface", "@Retention({policy:\"SOURCE\"}) @interface", "@memo() function", "@memo_entry() function", "@memo_intrinsic() function", ] exportAstNodes.forEach((astNodeText) => { @@ -131,6 +131,7 @@ function addExports(code: string): string { ["export @memo() function", "@memo() export function"], ["export @memo_entry() function", "@memo_entry() export function"], ["export @memo_intrinsic() function", "@memo_intrinsic() export function"], + ["export @memo_stable()", "@memo_stable() export"], ["export class OhosRouter", "export default class OhosRouter"] ] for (var [f, t] of fix) { @@ -261,16 +262,11 @@ function fixDuplicateSettersInInterfaces(code: string): string { sometimes interfaces contains duplicate setters, this functions fixes it */ - code = code.replaceAll(/\n(.*)interface(.*){\n([\s\S]*?)\n}\n/g, (match, modifiers, p1, p2: string) => { + code = code.replaceAll(/\n[ ]*(.*)interface(.*){\n([\s\S]*?)\n[ ]*}\n/g, (match, modifiers, p1, p2: string) => { const keep = p2.split('\n').filter((it) => !it.trimStart().startsWith(`set`)) const setters = [...new Set(p2.split('\n').filter((it) => it.trimStart().startsWith(`set`)))] return `\n${modifiers}interface${p1}{\n${keep.join('\n')}\n${setters.join('\n')}\n}\n` }) - code = code.replaceAll(/\n (.*)interface(.*){\n([\s\S]*?)\n }\n/g, (match, modifiers, p1, p2: string) => { - const keep = p2.split('\n').filter((it) => !it.trimStart().startsWith(`set`)) - const setters = [...new Set(p2.split('\n').filter((it) => it.trimStart().startsWith(`set`)))] - return `\n ${modifiers}interface${p1}{\n${keep.join('\n')}\n${setters.join('\n')}\n }\n` - }) return code } @@ -285,14 +281,12 @@ function fixNamespace(code: string) { we have only one such place, so fix manually */ - code = code.replaceAll(` export abstract class Profiler { - public static _$initializerBlockInit$_() {} - - public static _$init$_() {}`, ` export namespace Profiler {`) - + code = code.replaceAll(/export (declare )?abstract class (Profiler|GestureControl|text|common2D) {/g, `export $1 namespace $2 {`) + code = code.replaceAll(`public static _$init$_() {}`, ``) + code = code.replaceAll(`public static _$initializerBlockInit$_() {}`, ``) code = code.replaceAll(/public static ((?:un)?registerVsyncCallback)/g, "export function $1") - return code.replaceAll(/export abstract class GestureControl {((.*)\n){4}/g, "export namespace GestureControl {") + return code } function fixEnums(code: string) { @@ -364,11 +358,11 @@ export function filterSource(text: string): string { //console.error("====") // console.error(text.split('\n').map((it, index) => `${`${index + 1}`.padStart(4)} |${it}`).join('\n')) const dumperUnwrappers = [ + addExports, fixNamespace, fixEnums, fixDuplicateSettersInInterfaces, removeAbstractFromInterfaces, - addExports, replaceGensymWrappers, // nested replaceGensymWrappers, // nested replaceGensymWrappers, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/TreeNode.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/TreeNode.test.ts deleted file mode 100644 index 4f34bedeeda..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/TreeNode.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2024 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 util from "../../test-util" -import { filterSource } from "../../../src/utils" - -import * as fs from "node:fs" -import * as path from "node:path" -import { assert } from "chai" - -suite(util.basename(__filename), () => { - test.skip("TreeNode", function() { - const input = fs.readFileSync(path.join(__dirname, `./input/TreeNode.ts`), `utf8`) - const expected = fs.readFileSync(path.join(__dirname, `./golden/TreeNode.ts`), `utf8`) - assert.equal(filterSource(input), expected) - }) -}) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/golden/TreeNode.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/golden/TreeNode.ts deleted file mode 100644 index f01419d011d..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/golden/TreeNode.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2024 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 { Assert as Assert, suite as suite, test as test } from "../../../../../../incremental/harness/src"; - -import { float64 as float64, int32 as int32, uint32 as uint32 } from "@koalaui/common"; - -import { TreeNode as TreeNode } from "./TreeNode"; - - function main() {} - - export function _init2() { - suite("TreeNode", (() => {})); - } - - export function contentOf(node: TreeNode): string | undefined { - return ((node as StringNode)?.content); - } - - export function assertContent(node: TreeNode, content: string) { - Assert.equal(contentOf(node), content); - } - - export function assertRoot(node: TreeNode) { - Assert.isUndefined(node.parent); - Assert.equal(node.depth, 0); - Assert.equal(node.index, -1); - } - - export function assertLeaf(node: TreeNode) { - Assert.equal(node.childrenCount, 0); - } - - export function assertNoChildAt(parent: TreeNode, index: int32) { - Assert.isUndefined(parent.childAt(index)); - } - - export function assertChildAt(parent: TreeNode, index: int32): TreeNode { - let child = parent.childAt(index); - Assert.isDefined(child); - Assert.equal((child?.parent), parent); - Assert.equal((child?.index), index); - return child!; - } - - export function assertToString(root: TreeNode, expected: string) { - Assert.equal(root.toHierarchy(), expected); - } - - export function assertRemoveChildrenAt(root: TreeNode, index: int32, count: uint32, expected: int32) { - let childrenCount = root.childrenCount; - let children = root.removeChildrenAt(index, count); - Assert.equal(children.length, expected); - Assert.equal(root.childrenCount, ((childrenCount) - (expected))); - for (let i = 0;((i) < (expected));(i++)) { - assertRoot(children[i]); - } - } - - export function createRoot() { - return new StringNode("root", new StringNode("first"), new StringNode("second"), new StringNode("third")); - } - - export function createDigitsRoot() { - return new StringNode("digits", new StringNode("0"), new StringNode("1"), new StringNode("2"), new StringNode("3"), new StringNode("4"), new StringNode("5"), new StringNode("6"), new StringNode("7"), new StringNode("8"), new StringNode("9")); - } - - export function hellohellohello() { - console.log("hello"); - } - - export const __ARKTEST__ = "tree/TreeNode.test"; - - -export class StringNode extends TreeNode { - public readonly content: string; - - public constructor(content: string, ...children: StringNode[]) { - super(); - (this).content = content; - (this).appendChildren(...children); - } - - public toString(): string { - return (this).content; - } - -} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/input/TreeNode.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/input/TreeNode.ts deleted file mode 100644 index e95a0bbee7b..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/filter-source/input/TreeNode.ts +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2024 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 { Assert as Assert, suite as suite, test as test } from "../../../../../../incremental/harness/src"; - -import { float64 as float64, int32 as int32, uint32 as uint32 } from "@koalaui/common"; - -import { TreeNode as TreeNode } from "./TreeNode"; - -abstract class ETSGLOBAL { - public static main() {} - - public static _$init$_() { - suite("TreeNode", (() => {})); - } - - public static contentOf(node: TreeNode): string | undefined { - return ({let gensym%%_21 = (node as StringNode); - (((gensym%%_21) == (null)) ? undefined : gensym%%_21.content)}); - } - - public static assertContent(node: TreeNode, content: string) { - Assert.equal(contentOf(node), content); - } - - public static assertRoot(node: TreeNode) { - Assert.isUndefined(node.parent); - Assert.equal(node.depth, 0); - Assert.equal(node.index, -1); - } - - public static assertLeaf(node: TreeNode) { - Assert.equal(node.childrenCount, 0); - } - - public static assertNoChildAt(parent: TreeNode, index: int32) { - Assert.isUndefined(parent.childAt(index)); - } - - public static assertChildAt(parent: TreeNode, index: int32): TreeNode { - let child = parent.childAt(index); - Assert.isDefined(child); - Assert.equal(({let gensym%%_22 = child; - (((gensym%%_22) == (null)) ? undefined : gensym%%_22.parent)}), parent); - Assert.equal(({let gensym%%_23 = child; - (((gensym%%_23) == (null)) ? undefined : gensym%%_23.index)}), index); - return child!; - } - - public static assertToString(root: TreeNode, expected: string) { - Assert.equal(root.toHierarchy(), expected); - } - - public static assertRemoveChildrenAt(root: TreeNode, index: int32, count: uint32, expected: int32) { - let childrenCount = root.childrenCount; - let children = root.removeChildrenAt(index, count); - Assert.equal(children.length, expected); - Assert.equal(root.childrenCount, ((childrenCount) - (expected))); - for (let i = 0;((i) < (expected));(i++)) { - assertRoot(children[i]); - } - } - - public static createRoot() { - return new StringNode("root", new StringNode("first"), new StringNode("second"), new StringNode("third")); - } - - public static createDigitsRoot() { - return new StringNode("digits", new StringNode("0"), new StringNode("1"), new StringNode("2"), new StringNode("3"), new StringNode("4"), new StringNode("5"), new StringNode("6"), new StringNode("7"), new StringNode("8"), new StringNode("9")); - } - - public static hellohellohello() { - console.log("hello"); - } - - public static __ARKTEST__ = "tree/TreeNode.test"; - - -} - -class StringNode extends TreeNode { - public readonly content: string; - - public constructor(content: string, ...children: StringNode[]) { - super(); - (this).content = content; - (this).appendChildren(...children); - } - - public toString(): string { - return (this).content; - } - -} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/functions/create.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/functions/create.test.ts index 59df9895d0a..b6e85b60da7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/functions/create.test.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/functions/create.test.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/general/annotations.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/general/annotations.test.ts index 05c00320ecf..4c2f8593ef7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/general/annotations.test.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/general/annotations.test.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/general/recheck.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/general/recheck.test.ts index 0b266cb4748..7a05e8ea5c7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/general/recheck.test.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/general/recheck.test.ts @@ -25,131 +25,72 @@ function createConfig() { '--extension', 'ets', '--stdlib', - '../../incremental/tools/panda/node_modules/@panda/sdk/ets/stdlib', + '../build/sdk/ets/stdlib', '--output', './build/main.abc' ]).peer } -function updateTopLevelClass( - module: arkts.ETSModule, - className: string, - update: (node: arkts.ClassDefinition) => arkts.ClassDefinition -) { - return arkts.updateETSModuleByStatements( - module, - [ - ...module.statements.map((node) => { - if (!arkts.isClassDeclaration(node)) { - return node - } - if (!arkts.isClassDefinition(node.definition)) { - return node - } - if (node.definition.ident?.name == className) { - return arkts.factory.updateClassDeclaration( - node, - update(node.definition) - ) - } - return node - }) - ] - ) +class RenameTestFunction extends arkts.AbstractVisitor { + visitor(beforeChildren: arkts.AstNode) { + const node = this.visitEachChild(beforeChildren) + // Don't change name at checked stage, add another import + if (arkts.isImportDeclaration(node)) return node + if (arkts.isIdentifier(node) && node.name == "testFunction") { + return arkts.factory.createIdentifier("testFunctionChanged") + } + return node + } } -suite(util.basename(__filename), () => { - - test("static (function)", function() { - createConfig() - - const code = - ` - function foo() {} - ` - - arkts.arktsGlobal.compilerContext = arkts.Context.createFromString(code) - - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED) - arkts.recheckSubtree(arkts.createETSModuleFromContext()) +suite(util.basename(__filename), () => { - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) - }) - test.skip("static (property)", function() { + test("add import at parsed stage and proceed to checked", function() { createConfig() - - const code = - ` - interface I { - prop: boolean - } - - class C implements I { - prop = true - } - ` - - arkts.arktsGlobal.compilerContext = arkts.Context.createFromString(code) - - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED) - - arkts.recheckSubtree(arkts.createETSModuleFromContext()) - - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) - }) - test("rename class", function() { - createConfig() - const code = ` - class C { - f(): void { - } - } + console.log("test") ` arkts.arktsGlobal.compilerContext = arkts.Context.createFromString(code) - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED) + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED) const module = arkts.createETSModuleFromContext() - updateTopLevelClass(module, "C", (node: arkts.ClassDefinition) => { - return arkts.factory.updateClassDefinition( - node, - node.ident ? arkts.factory.updateIdentifier( - node.ident, - "D" - ) : undefined, - node.typeParams, - node.superTypeParams, - node.implements, - undefined, - node.super, - node.body, - node.modifiers, - node.modifierFlags - ) - }) + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral( + './library' + ), + [ + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier( + 'testFunction' + ), + arkts.factory.createIdentifier( + 'testFunction' + ) + ) + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + arkts.arktsGlobal.compilerContext.program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE + ) arkts.arktsGlobal.es2panda._AstNodeUpdateAll(arkts.arktsGlobal.context, module.peer) + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED) arkts.recheckSubtree(module) - util.assert( - module.dumpSrc() == ` -function main() {} - + util.assert.equal( + module.dumpSrc(), ` +import { testFunction as testFunction } from "./library"; +function main() {} -class D { - public f(): void {} - - public constructor() {} - -} +console.log("test"); `, `invalid result: ${module.dumpSrc()}`) @@ -157,13 +98,13 @@ class D { arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) }) - test("add class method", function() { + test.skip("change function name in main program and in dependency", function() { createConfig() - + const code = ` - class C { - } + import { testFunction } from "./library" + testFunction() ` arkts.arktsGlobal.compilerContext = arkts.Context.createFromString(code) @@ -172,182 +113,40 @@ class D { const module = arkts.createETSModuleFromContext() - updateTopLevelClass(module, "C", (node: arkts.ClassDefinition) => { - return arkts.factory.updateClassDefinition( - node, - node.ident, - node.typeParams, - node.superTypeParams, - node.implements, - undefined, - node.super, - [ - arkts.factory.createMethodDefinition( - arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, - arkts.factory.createIdentifier("g"), - arkts.factory.createFunctionExpression( - arkts.factory.createIdentifier("g"), - arkts.factory.createScriptFunction( - arkts.factory.createBlockStatement([ - arkts.factory.createReturnStatement( - arkts.factory.createNumberLiteral(5) - ) - ]), - undefined, - [], - arkts.factory.createETSPrimitiveType( - arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_DOUBLE, - ), - false, - arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, - arkts.factory.createIdentifier("g"), - undefined, - ) - ), - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, - false, - ), - ...node.body, - ], - node.modifiers, - node.modifierFlags - ) + arkts.arktsGlobal.compilerContext.program.externalSources.forEach(it => { + if (!it.getName().includes("library")) return + it.programs.forEach(program => { + new RenameTestFunction().visitor(program.astNode) + }) }) - arkts.arktsGlobal.es2panda._AstNodeUpdateAll(arkts.arktsGlobal.context, module.peer) - arkts.recheckSubtree(module) - - util.assert( - module.dumpSrc() == ` -function main() {} - - - -class C { - public g(): double { - return 5; - } - - public constructor() {} - -} - -`, - `invalid result: ${module.dumpSrc()}`) - - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) - }) - - test("add variable declaration", function() { - createConfig() - - const code = - ` - class C { - f(): void { - } - } - ` - - arkts.arktsGlobal.compilerContext = arkts.Context.createFromString(code) - - arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED) - - const module = arkts.createETSModuleFromContext() + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral( + './library' + ), + [ + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier( + 'testFunctionChanged' + ), + arkts.factory.createIdentifier( + 'testFunctionChanged' + ) + ) + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + arkts.arktsGlobal.compilerContext.program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE + ) - updateTopLevelClass(module, "C", (node: arkts.ClassDefinition) => { - return arkts.factory.updateClassDefinition( - node, - node.ident, - node.typeParams, - node.superTypeParams, - node.implements, - undefined, - node.super, - [ - ...node.body.map((node: arkts.AstNode) => { - if (!arkts.isMethodDefinition(node)) { - return node - } - if (node.id?.name != "f") { - return node - } - if (!arkts.isFunctionExpression(node.value)) { - return node - } - const func = node.value.function - if (!func || !arkts.isBlockStatement(func.body)) { - return node - } - return arkts.factory.updateMethodDefinition( - node, - node.kind, - node.key, - arkts.factory.updateFunctionExpression( - node.value, - node.id, - arkts.factory.updateScriptFunction( - func, - arkts.factory.updateBlockStatement( - func.body, - [ - arkts.factory.createVariableDeclaration( - arkts.Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST, - [ - arkts.factory.createVariableDeclarator( - arkts.Es2pandaVariableDeclaratorFlag.VARIABLE_DECLARATOR_FLAG_CONST, - arkts.factory.createIdentifier("x"), - arkts.factory.createBinaryExpression( - arkts.factory.createNumberLiteral(1), - arkts.factory.createNumberLiteral(4), - arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_PLUS, - ), - ), - ], - ), - ...func.body.statements, - ], - ), - func.typeParams, - func.params, - func.returnTypeAnnotation, - func.hasReceiver, - func.flags, - func.modifierFlags, - func.id, - func.annotations, - ), - ), - node.modifierFlags, - node.isComputed, - node.overloads, - ) - }) - ], - node.modifiers, - node.modifierFlags - ) - }) + new RenameTestFunction().visitor(module) arkts.arktsGlobal.es2panda._AstNodeUpdateAll(arkts.arktsGlobal.context, module.peer) arkts.recheckSubtree(module) - util.assert( - module.dumpSrc() == ` -function main() {} - - - -class C { - public f(): void { - const x = ((1) + (4)); - } - - public constructor() {} - -} - + util.assert.equal( + module.dumpSrc(), ` +testFunctionChanged() `, `invalid result: ${module.dumpSrc()}`) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/import-export/import.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/import-export/import.test.ts index 8c5d42e4467..8871498412c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/import-export/import.test.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/import-export/import.test.ts @@ -26,29 +26,24 @@ suite(util.basename(__filename), () => { let script = arkts.createETSModuleFromSource(sample_in) - script = arkts.updateETSModuleByStatements( - script, + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral( + './variable' + ), [ - arkts.factory.createETSImportDeclaration( - arkts.factory.createStringLiteral( - './variable' + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier( + 'X' ), - [ - arkts.factory.createImportSpecifier( - arkts.factory.createIdentifier( - 'X' - ), - arkts.factory.createIdentifier( - 'X' - ) - ) - ], - arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, - global.compilerContext.program, - arkts.Es2pandaImportFlags.IMPORT_FLAGS_DEFAULT_IMPORT + arkts.factory.createIdentifier( + 'X' + ) ) - ] - ) + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + global.compilerContext.program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_DEFAULT_IMPORT + ) util.ARKTS_TEST_ASSERTION( script, @@ -68,31 +63,30 @@ suite(util.basename(__filename), () => { let script = arkts.createETSModuleFromSource(sample_in) const importDeclaration = script.statements[0] as arkts.ETSImportDeclaration - script = arkts.updateETSModuleByStatements( - script, + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral( + './variable' + ), [ - arkts.factory.updateETSImportDeclaration( - importDeclaration, - importDeclaration.source, - [ - arkts.factory.createImportSpecifier( - arkts.factory.createIdentifier( - 'X' - ), - arkts.factory.createIdentifier( - 'X' - ) - ) - ], - arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier( + 'X' + ), + arkts.factory.createIdentifier( + 'X' + ) ) - ] + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + global.compilerContext.program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_DEFAULT_IMPORT ) util.ARKTS_TEST_ASSERTION( script, ` import { X } from "./variable" + import { Y } from "./variable" `, arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED ) @@ -111,32 +105,30 @@ suite(util.basename(__filename), () => { let script = arkts.createETSModuleFromSource(sample_in) const importDeclaration = script.statements[0] as arkts.ETSImportDeclaration - script = arkts.updateETSModuleByStatements( - script, + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral( + './variable' + ), [ - arkts.factory.updateETSImportDeclaration( - importDeclaration, - importDeclaration.source, - [ - arkts.factory.createImportSpecifier( - arkts.factory.createIdentifier( - 'X' - ), - arkts.factory.createIdentifier( - 'X' - ) - ) - ], - arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, - ), - script.statements[1] - ] + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier( + 'X' + ), + arkts.factory.createIdentifier( + 'X' + ) + ) + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + global.compilerContext.program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_DEFAULT_IMPORT ) util.ARKTS_TEST_ASSERTION( script, ` import { X } from "./variable" + import { Y } from "./variable" function main() { console.log(X) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/arktsconfig.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/arktsconfig.json new file mode 100644 index 00000000000..a0a1a878861 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/arktsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "outDir": "./build/abc", + "baseUrl": "." + }, + "include": ["./**/*.ts"] +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/index.ts new file mode 100644 index 00000000000..1b24ce7da8b --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/index.ts @@ -0,0 +1,37 @@ +import * as arkts from "../../../../src/arkts-api" + +class ConstructorWithOverload extends arkts.AbstractVisitor { + visitor(beforeChildren: arkts.ETSModule): arkts.ETSModule + visitor(beforeChildren: arkts.AstNode): arkts.AstNode { + const node = this.visitEachChild(beforeChildren) + if (arkts.isScriptFunction(node) && node.id?.name == "constructor") { + return arkts.factory.updateScriptFunction( + node, + arkts.factory.createBlockStatement( + [ + + arkts.factory.createIfStatement( + arkts.factory.createBooleanLiteral(true), + arkts.factory.createReturnStatement(), + undefined + ), + ...(arkts.isBlockStatement(node.body) ? node.body.statements : []), + ] + ), + node.typeParams, + node.params, + node.returnTypeAnnotation, + node.hasReceiver, + node.flags, + node.modifierFlags, + node.id, + node.annotations + ) + } + return node + } +} + +export function constructorWithOverload(program: arkts.Program) { + return (new ConstructorWithOverload()).visitor(program.astNode) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/main.ts new file mode 100644 index 00000000000..975d1d79b36 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/main.ts @@ -0,0 +1,4 @@ +class XXX { + constructor(x: ()=>void, y?: ()=>void) { + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/index.ts new file mode 100644 index 00000000000..2946c348503 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/index.ts @@ -0,0 +1,25 @@ +import * as arkts from "../../../../../src/arkts-api" + +export function addImportNewFile(program: arkts.Program, options: arkts.CompilationOptions) { + if (options.isMainProgram) { + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral( + './library' + ), + [ + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier( + 'testFunction' + ), + arkts.factory.createIdentifier( + 'testFunction' + ) + ) + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + arkts.arktsGlobal.compilerContext.program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE + ) + } + return program +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/library.ts new file mode 100644 index 00000000000..226253e9d76 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/library.ts @@ -0,0 +1,6 @@ +export function testFunction(): string { + return "yes" +} +export function anotherFunction(): string { + return "no" +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/main.ts new file mode 100644 index 00000000000..2a2392b9dc5 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/main.ts @@ -0,0 +1 @@ +console.log("test") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/dump-src/main.ts new file mode 100644 index 00000000000..51d2896e435 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/dump-src/main.ts @@ -0,0 +1,9 @@ + +import { testFunction as testFunction } from "./library"; + +import { anotherFunction as anotherFunction } from "./library"; + +function main() {} + +console.log("test"); + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/index.ts new file mode 100644 index 00000000000..5f77f7fb3b4 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/index.ts @@ -0,0 +1,25 @@ +import * as arkts from "../../../../../src/arkts-api" + +export function addImportSameFile(program: arkts.Program, options: arkts.CompilationOptions) { + if (options.isMainProgram) { + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral( + './library' + ), + [ + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier( + 'testFunction' + ), + arkts.factory.createIdentifier( + 'testFunction' + ) + ) + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + arkts.arktsGlobal.compilerContext.program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE + ) + } + return program +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/library.ts new file mode 100644 index 00000000000..226253e9d76 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/library.ts @@ -0,0 +1,6 @@ +export function testFunction(): string { + return "yes" +} +export function anotherFunction(): string { + return "no" +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/main.ts new file mode 100644 index 00000000000..efa3eceaeb9 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/main.ts @@ -0,0 +1,2 @@ +import { anotherFunction } from "./library" +console.log("test") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/dump-src/main.ts new file mode 100644 index 00000000000..d6401c45269 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/dump-src/main.ts @@ -0,0 +1,10 @@ + +import { testFunction as testFunction } from "./library"; + +import { anotherFunction as anotherFunction } from "./library"; + +function main() {} + +console.log("test"); + +testFunction() diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/index.ts new file mode 100644 index 00000000000..6da984d08a8 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/index.ts @@ -0,0 +1,39 @@ +import * as arkts from "../../../../../src/arkts-api" + +export function addUseImportSameFile(program: arkts.Program, options: arkts.CompilationOptions) { + if (options.isMainProgram) { + arkts.updateETSModuleByStatements( + program.astNode, + [ + ...program.astNode.statements, + arkts.factory.createCallExpression( + arkts.factory.createIdentifier("testFunction"), + [], + undefined, + false, + false, + undefined + ) + ] + ) + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral( + './library' + ), + [ + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier( + 'testFunction' + ), + arkts.factory.createIdentifier( + 'testFunction' + ) + ) + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + arkts.arktsGlobal.compilerContext.program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE + ) + } + return program +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/library.ts new file mode 100644 index 00000000000..226253e9d76 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/library.ts @@ -0,0 +1,6 @@ +export function testFunction(): string { + return "yes" +} +export function anotherFunction(): string { + return "no" +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/main.ts new file mode 100644 index 00000000000..efa3eceaeb9 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/main.ts @@ -0,0 +1,2 @@ +import { anotherFunction } from "./library" +console.log("test") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/dump-src/main.ts new file mode 100644 index 00000000000..093458f2ff8 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/dump-src/main.ts @@ -0,0 +1,9 @@ + +import { One as One } from "./one_recursive"; + +import { Two as Two } from "./two_recursive"; + +function main() {} + + + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/index.ts new file mode 100644 index 00000000000..5925d2dab2e --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/index.ts @@ -0,0 +1,37 @@ +import * as arkts from "../../../../../src/arkts-api" + +class InsertParameter extends arkts.AbstractVisitor { + visitor(beforeChildren: arkts.ETSModule): arkts.ETSModule + visitor(beforeChildren: arkts.AstNode): arkts.AstNode { + const node = this.visitEachChild(beforeChildren) + if (arkts.isScriptFunction(node) && + (node.id?.name == "one" || node.id?.name == "two") ) { + + return arkts.factory.updateScriptFunction( + node, + node.body, + node.typeParams, + [ + arkts.factory.createETSParameterExpression( + arkts.factory.createIdentifier("createdParam"), + false, + undefined, + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_BOOLEAN), + undefined + ) + ], + node.returnTypeAnnotation, + node.hasReceiver, + node.flags, + node.modifierFlags, + node.id, + node.annotations + ) + } + return node + } +} + +export function insertParameter(program: arkts.Program) { + return (new InsertParameter()).visitor(program.astNode) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/main.ts new file mode 100644 index 00000000000..29cffa6f9e5 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/main.ts @@ -0,0 +1,2 @@ +import { One } from "./one_recursive" +import { Two } from "./two_recursive" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/one_recursive.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/one_recursive.ts new file mode 100644 index 00000000000..fc837a57b0f --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/one_recursive.ts @@ -0,0 +1,8 @@ +import { Two } from "./two_recursive" + +export interface One { + two(): Two { + throw new Error("") + } +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/two_recursive.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/two_recursive.ts new file mode 100644 index 00000000000..a4d708b6428 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/two_recursive.ts @@ -0,0 +1,8 @@ +import { One } from "./one_recursive" + +export interface Two { + one(): One { + throw new Error("") + } +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/dump-src/main.ts new file mode 100644 index 00000000000..5650ef6e54d --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/dump-src/main.ts @@ -0,0 +1,12 @@ + +function main() {} + + + +interface I { + get f(): ((createdParam: boolean)=> void) + + set f(f: ((createdParam: boolean)=> void)) + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/index.ts new file mode 100644 index 00000000000..2fd1bf9faf6 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/index.ts @@ -0,0 +1,32 @@ +import * as arkts from "../../../../../src/arkts-api" + +class InsertParameterToType extends arkts.AbstractVisitor { + visitor(beforeChildren: arkts.ETSModule): arkts.ETSModule + visitor(beforeChildren: arkts.AstNode): arkts.AstNode { + const node = this.visitEachChild(beforeChildren) + if (arkts.isETSFunctionType(node)) { + return arkts.factory.createETSFunctionType( + node.typeParams, + [ + arkts.factory.createETSParameterExpression( + arkts.factory.createIdentifier("createdParam"), + false, + undefined, + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_BOOLEAN), + undefined + ), + ...node.params + ], + node.returnType, + node.isExtensionFunction, + node.flags, + node.annotations, + ) + } + return node + } +} + +export function insertParameterToType(program: arkts.Program) { + return (new InsertParameterToType()).visitor(program.astNode) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/main.ts new file mode 100644 index 00000000000..a75751fe367 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/main.ts @@ -0,0 +1,4 @@ +interface I { + set f(f: () => void) + get f(): () => void +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/recheck.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/recheck.test.ts new file mode 100644 index 00000000000..4cbf2af62b4 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/recheck.test.ts @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2024-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 fs from "node:fs" +import * as util from "../../test-util" +import * as arkts from "../../../src/arkts-api" +import { constructorWithOverload } from "./constructor" +import { updateTopLevelClass } from "./simple" +import { renameClass } from "./simple/rename-class" +import { addClassMethod } from "./simple/add-class-method" +import { addVariableDeclaration } from "./simple/add-variable" +import { addThisReference } from "./this" +import { insertParameterToType } from "./overloads/getter-setter" +import { insertParameter } from "./imports/recursive" +import { addImportSameFile } from "./imports/add-same-file" +import { addUseImportSameFile } from "./imports/add-use-same-file" +import { addImportNewFile } from "./imports/add-new-file" + +const DIR = './test/arkts-api/recheck/' + +function createConfig(file: string) { + fs.mkdirSync(`${DIR}/build/abc/${file}`, { recursive: true }) + arkts.arktsGlobal.filePath = `${DIR}/${file}/main.ts` + arkts.arktsGlobal.config = arkts.Config.create([ + '_', + '--arktsconfig', + `${DIR}/arktsconfig.json`, + `${DIR}/${file}/main.ts`, + '--extension', + 'ets', + '--stdlib', + '../build/sdk/ets/stdlib', + '--output', + `${DIR}/build/abc/${file}/main.abc` + ]).peer +} + +function createContext(file: string) { + const code = fs.readFileSync(`${DIR}/${file}/main.ts`, 'utf-8') + arkts.arktsGlobal.compilerContext = arkts.Context.createFromString(code) +} + +function proceedToChecked() { + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED) +} + +function applyTransform(transform?: arkts.ProgramTransformer, onlyModifyMain?: boolean) { + arkts.arktsGlobal.compilerContext.program.externalSources.forEach(it => { + if (it.getName().startsWith("std.")) return + if (it.getName().startsWith("escompat")) return + it.programs.forEach(program => { + const ast = program.astNode + if (!onlyModifyMain) { + transform?.(program, { isMainProgram: false, name: "", stage: arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED }) + } + arkts.setBaseOverloads(ast) + arkts.arktsGlobal.es2panda._AstNodeUpdateAll(arkts.arktsGlobal.context, ast.peer) + }) + }) + + const script = arkts.createETSModuleFromContext() + transform?.(arkts.arktsGlobal.compilerContext.program, { isMainProgram: true, name: "", stage: arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED }) + arkts.setBaseOverloads(script) + arkts.arktsGlobal.es2panda._AstNodeUpdateAll(arkts.arktsGlobal.context, script.peer) +} + +function recheck() { + arkts.recheckSubtree(arkts.createETSModuleFromContext()) +} + +function dumpSrc(file: string) { + const src = arkts.createETSModuleFromContext().dumpSrc() + fs.mkdirSync(`${DIR}/${file}/dump-src`, { recursive: true }) + fs.writeFileSync(`${DIR}/${file}/dump-src/main.ts`, src) +} + +function dumpJson(file: string) { + const json = arkts.createETSModuleFromContext().dumpJson() + fs.mkdirSync(`${DIR}/${file}/dump-json`, { recursive: true }) + fs.writeFileSync(`${DIR}/${file}/dump-json/main.json`, json) +} + +function assertSrc(file: string) { + const src = arkts.createETSModuleFromContext().dumpSrc() + const expected = fs.readFileSync(`${DIR}/${file}/dump-src/main.ts`, 'utf-8') + util.assert.equal(src, expected) +} + +function assertJson(file: string) { + const json = arkts.createETSModuleFromContext().dumpJson() + const expected = fs.readFileSync(`${DIR}/${file}/dump-json/main.json`, 'utf-8') + util.assert.equal(json, expected) +} + +function proceedToBin() { + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) +} + +function runTest( + file: string, + transform?: arkts.ProgramTransformer, + skipSrc?: boolean, + skipJson?: boolean, + onlyModifyMain?: boolean, +) { + createConfig(file) + createContext(file) + proceedToChecked() + applyTransform(transform, onlyModifyMain) + recheck() + if (process.env.TEST_GOLDEN == "1") { + if (!skipSrc) dumpSrc(file) + if (!skipJson) dumpJson(file) + } else { + if (!skipSrc) assertSrc(file) + if (!skipJson) assertJson(file) + } + proceedToBin() +} + +suite(util.basename(__filename), () => { + suite('static', () => { + test("function", () => { + runTest('static/function', undefined, false, true) + }) + + test("public setter", () => { + runTest('static/public-setter', undefined, false, true) + }) + + test("constructor with overload", () => { + runTest('static/constructor', undefined, false, true) + }) + + // es2panda issue 24821 + test.skip("property", () => { + runTest('static/property', undefined, false, true) + }) + + test("typed property", () => { + runTest('static/typed-property', undefined, false, true) + }) + + test("trailing block", () => { + runTest('static/trailing-block', undefined, false, true) + }) + + test("import type", () => { + runTest('static/import-type', undefined, false, true) + }) + }) + + suite('simple', () => { + test('rename class', () => { + runTest('simple/rename-class', (program: arkts.Program) => { + return updateTopLevelClass(program.astNode, renameClass) + }, false, true) + }) + + test('add class method', () => { + runTest('simple/add-class-method', (program: arkts.Program) => { + return updateTopLevelClass(program.astNode, addClassMethod) + }, false, true) + }) + + test('add variable declaration', () => { + runTest('simple/add-variable', (program: arkts.Program) => { + return updateTopLevelClass(program.astNode, addVariableDeclaration) + }, false, true) + }) + }) + + test.skip('constructor', () => { + runTest('constructor', constructorWithOverload, false, true) + }) + + test('add this reference', () => { + runTest('this', addThisReference, false, true) + }) + + suite('imports', () => { + test('add another import from the same file with dedicated API', () => { + runTest('imports/add-same-file', addImportSameFile, false, true) + }) + + test('add another import from the same file with dedicated API and use it', () => { + runTest('imports/add-use-same-file', addUseImportSameFile, false, true, true) + }) + + test.skip('add import from the new file with dedicated API', () => { + runTest('imports/add-new-file', addImportNewFile, false, true, true) + }) + + test('recursive', () => { + runTest('imports/recursive', insertParameter, false, true) + }) + }) + + suite('overloads', () => { + test('getter and setter both modified simultaneously', () => { + runTest('overloads/getter-setter', insertParameterToType, false, true) + }) + }) +}) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/dump-src/main.ts new file mode 100644 index 00000000000..d15caa7a435 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/dump-src/main.ts @@ -0,0 +1,14 @@ + +function main() {} + + + +class C { + public g(): double { + return 5; + } + + public constructor() {} + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/index.ts new file mode 100644 index 00000000000..d8ec3449ca1 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/index.ts @@ -0,0 +1,44 @@ +import * as arkts from "../../../../../src/arkts-api" + +export function addClassMethod(node: arkts.ClassDefinition) { + return arkts.factory.updateClassDefinition( + node, + node.ident, + node.typeParams, + node.superTypeParams, + node.implements, + undefined, + node.super, + [ + arkts.factory.createMethodDefinition( + arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, + arkts.factory.createIdentifier("g"), + arkts.factory.createFunctionExpression( + arkts.factory.createIdentifier("g"), + arkts.factory.createScriptFunction( + arkts.factory.createBlockStatement([ + arkts.factory.createReturnStatement( + arkts.factory.createNumberLiteral(5) + ) + ]), + undefined, + [], + arkts.factory.createETSPrimitiveType( + arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_DOUBLE, + ), + false, + arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + arkts.factory.createIdentifier("g"), + undefined, + ) + ), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false, + ), + ...node.body, + ], + node.modifiers, + node.modifierFlags + ) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/main.ts new file mode 100644 index 00000000000..8ad54365639 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/main.ts @@ -0,0 +1,2 @@ +class C { +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/dump-src/main.ts new file mode 100644 index 00000000000..b180ebf3466 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/dump-src/main.ts @@ -0,0 +1,14 @@ + +function main() {} + + + +class C { + public f(): void { + const x = ((1) + (4)); + } + + public constructor() {} + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/index.ts new file mode 100644 index 00000000000..dd15eabbc8b --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/index.ts @@ -0,0 +1,75 @@ +import * as arkts from "../../../../../src/arkts-api" + +export function addVariableDeclaration(node: arkts.ClassDefinition) { + return arkts.factory.updateClassDefinition( + node, + node.ident, + node.typeParams, + node.superTypeParams, + node.implements, + undefined, + node.super, + [ + ...node.body.map((node: arkts.AstNode) => { + if (!arkts.isMethodDefinition(node)) { + return node + } + if (node.id?.name != "f") { + return node + } + if (!arkts.isFunctionExpression(node.value)) { + return node + } + const func = node.value.function + if (!func || !arkts.isBlockStatement(func.body)) { + return node + } + return arkts.factory.updateMethodDefinition( + node, + node.kind, + node.key, + arkts.factory.updateFunctionExpression( + node.value, + node.id, + arkts.factory.updateScriptFunction( + func, + arkts.factory.updateBlockStatement( + func.body, + [ + arkts.factory.createVariableDeclaration( + arkts.Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST, + [ + arkts.factory.createVariableDeclarator( + arkts.Es2pandaVariableDeclaratorFlag.VARIABLE_DECLARATOR_FLAG_CONST, + arkts.factory.createIdentifier("x"), + arkts.factory.createBinaryExpression( + arkts.factory.createNumberLiteral(1), + arkts.factory.createNumberLiteral(4), + arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_PLUS, + ), + ), + ], + ), + ...func.body.statements, + ], + ), + func.typeParams, + func.params, + func.returnTypeAnnotation, + func.hasReceiver, + func.flags, + func.modifierFlags, + func.id, + func.annotations, + ), + ), + node.modifierFlags, + node.isComputed, + node.overloads, + ) + }) + ], + node.modifiers, + node.modifierFlags + ) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/main.ts new file mode 100644 index 00000000000..3a7a5ed929f --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/main.ts @@ -0,0 +1,4 @@ +class C { + f(): void { + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/index.ts new file mode 100644 index 00000000000..e384d03c391 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/index.ts @@ -0,0 +1,27 @@ +import * as arkts from "../../../../src/arkts-api" + +export function updateTopLevelClass( + module: arkts.ETSModule, + update: (node: arkts.ClassDefinition) => arkts.ClassDefinition +) { + return arkts.updateETSModuleByStatements( + module, + [ + ...module.statements.map((node) => { + if (!arkts.isClassDeclaration(node)) { + return node + } + if (!arkts.isClassDefinition(node.definition)) { + return node + } + if (node.definition.ident?.name == "C") { + return arkts.factory.updateClassDeclaration( + node, + update(node.definition) + ) + } + return node + }) + ] + ) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/dump-src/main.ts new file mode 100644 index 00000000000..19141932f61 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/dump-src/main.ts @@ -0,0 +1,12 @@ + +function main() {} + + + +class D { + public f(): void {} + + public constructor() {} + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/index.ts new file mode 100644 index 00000000000..687e98b604e --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/index.ts @@ -0,0 +1,19 @@ +import * as arkts from "../../../../../src/arkts-api" + +export function renameClass(node: arkts.ClassDefinition) { + return arkts.factory.updateClassDefinition( + node, + node.ident ? arkts.factory.updateIdentifier( + node.ident, + "D" + ) : undefined, + node.typeParams, + node.superTypeParams, + node.implements, + undefined, + node.super, + node.body, + node.modifiers, + node.modifierFlags + ) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/main.ts new file mode 100644 index 00000000000..3a7a5ed929f --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/main.ts @@ -0,0 +1,4 @@ +class C { + f(): void { + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/dump-src/main.ts new file mode 100644 index 00000000000..19bfce52f3e --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/dump-src/main.ts @@ -0,0 +1,14 @@ + +function main() {} + + + +class XXX { + constructor(x: (()=> void)) { + (this)(x, undefined); + } + + public constructor(x: (()=> void), y: (()=> void) | undefined) {} + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/main.ts new file mode 100644 index 00000000000..975d1d79b36 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/main.ts @@ -0,0 +1,4 @@ +class XXX { + constructor(x: ()=>void, y?: ()=>void) { + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/dump-src/main.ts new file mode 100644 index 00000000000..59bd2154e84 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/dump-src/main.ts @@ -0,0 +1,7 @@ + +function main() {} + + +function foo() {} + + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/main.ts new file mode 100644 index 00000000000..b0400ee9b26 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/main.ts @@ -0,0 +1 @@ +function foo() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/dump-src/main.ts new file mode 100644 index 00000000000..e4df10838ff --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/dump-src/main.ts @@ -0,0 +1,7 @@ + +import { ExportedType as ExportedType } from "./library"; + +function main() {} + + + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/library.ts new file mode 100644 index 00000000000..514f6b6de0c --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/library.ts @@ -0,0 +1,12 @@ +export class Scope { + static scope(): Scope { + throw new Error("") + } + cached(): T { + throw new Error("") + } +} + +export interface ExportedType { + scope( value: () => V ) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/main.ts new file mode 100644 index 00000000000..ed36fa34b94 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/main.ts @@ -0,0 +1 @@ +import { ExportedType } from "./library" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/property/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/property/main.ts new file mode 100644 index 00000000000..3ec35cab43f --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/property/main.ts @@ -0,0 +1,7 @@ +interface I { + prop: boolean +} + +class C implements I { + prop = true +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/dump-src/main.ts new file mode 100644 index 00000000000..81e34015fe5 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/dump-src/main.ts @@ -0,0 +1,24 @@ + +import { AnimatedState as AnimatedState, one as one } from "./library"; + +let x: AnimatedState | undefined; + +function main() {} + +if (x) { + x!.paused = true +} + +class AnimatedStateImpl implements AnimatedState { + set paused(paused: boolean) { + throw new Error(""); + } + + public get paused(): boolean { + throw new Error(""); + } + + public constructor() {} + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/library.ts new file mode 100644 index 00000000000..3f285d4cf5c --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/library.ts @@ -0,0 +1,16 @@ +export interface AnimatedState { + paused: boolean +} + +class AnimatedStateImpl implements AnimatedState { + get paused(): boolean { + throw new Error("") + } + set paused(paused: boolean) { + throw new Error("") + } +} + +export function one() { + +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/main.ts new file mode 100644 index 00000000000..ff6230f6270 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/main.ts @@ -0,0 +1,12 @@ +import { AnimatedState, one } from "./library" + +let x: AnimatedState|undefined +if (x) x!.paused = true +class AnimatedStateImpl implements AnimatedState { + get paused(): boolean { + throw new Error("") + } + set paused(paused: boolean) { + throw new Error("") + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/dump-src/main.ts new file mode 100644 index 00000000000..b5ea13d894e --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/dump-src/main.ts @@ -0,0 +1,18 @@ + +function main() {} + + + +class C { + public f(arg: (()=> void)): void {} + + public g(): void { + (this).f((() => { + const x = ((6) + (5)); + })); + } + + public constructor() {} + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/main.ts new file mode 100644 index 00000000000..c16a244ace6 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/main.ts @@ -0,0 +1,9 @@ +class C { + f(arg: () => void): void { } + + g(): void { + this.f() { + const x = 6 + 5 + } + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/dump-src/main.ts new file mode 100644 index 00000000000..47d87b20892 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/dump-src/main.ts @@ -0,0 +1,28 @@ + +function main() {} + + + +interface I { + set prop(prop: boolean) + + get prop(): boolean + +} + +class C implements I { + public constructor() {} + + private _$property$_prop: boolean = true; + + set prop(_$property$_prop: boolean) { + (this)._$property$_prop = _$property$_prop; + return; + } + + public get prop(): boolean { + return (this)._$property$_prop; + } + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/main.ts new file mode 100644 index 00000000000..175c1b31155 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/main.ts @@ -0,0 +1,7 @@ +interface I { + prop: boolean +} + +class C implements I { + prop: boolean = true +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/dump-src/main.ts new file mode 100644 index 00000000000..5d580cf9c08 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/dump-src/main.ts @@ -0,0 +1,15 @@ + +function main() {} + + + +class A { + public no_this() { + (this); + console.log("test"); + } + + public constructor() {} + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/index.ts new file mode 100644 index 00000000000..e6c3f77195b --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/index.ts @@ -0,0 +1,35 @@ +import * as arkts from "../../../../src/arkts-api" + +class AddThisReference extends arkts.AbstractVisitor { + visitor(beforeChildren: arkts.ETSModule): arkts.ETSModule + visitor(beforeChildren: arkts.AstNode): arkts.AstNode { + const node = this.visitEachChild(beforeChildren) + if (arkts.isScriptFunction(node) && node.id?.name == "no_this") { + return arkts.factory.updateScriptFunction( + node, + arkts.factory.createBlockStatement( + [ + + arkts.factory.createExpressionStatement( + arkts.factory.createThisExpression() + ), + ...(arkts.isBlockStatement(node.body) ? node.body.statements : []), + ] + ), + node.typeParams, + node.params, + node.returnTypeAnnotation, + node.hasReceiver, + node.flags, + node.modifierFlags, + node.id, + node.annotations + ) + } + return node + } +} + +export function addThisReference(program: arkts.Program) { + return (new AddThisReference()).visitor(program.astNode) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/main.ts new file mode 100644 index 00000000000..66ca6f5572d --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/main.ts @@ -0,0 +1,5 @@ +class A { + no_this() { + console.log("test") + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/test-util.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/test-util.ts index 35269334e73..cc2a393690b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/test-util.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/test-util.ts @@ -144,3 +144,15 @@ export function assertEqualsBinaryOutput(output: string, ctx: Mocha.Context): vo global.es2panda._DestroyContext(global.context) } } + +export function trimLines(value: string): string { + return value.split('\n').map(it => it.trim()).join('\n') +} + +export function equalTrimming(value1: string, value2: string, message: string) { + return assert.equal( + trimLines(value1), + trimLines(value2), + message + ) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/classes/heritage/extends.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/classes/heritage/extends.test.ts index 0d8a4e55414..34d5b0ca250 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/classes/heritage/extends.test.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/classes/heritage/extends.test.ts @@ -11,7 +11,7 @@ * 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 util from "../../../test-util" import * as ts from "../../../../src/ts-api" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/classes.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/classes.test.ts deleted file mode 100644 index f6bd1167c97..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/classes.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022-2023 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 util from "../../test-util" -// import * as ts from "../../../src/ts-api" -// import { MemoTransformer } from "../../../plugins/src/memo-transformer" -// -// suite(util.basename(__filename), () => { -// test.skip("stinger-node-class", function() { -// const sample_in = -// ` -// // import { uint32 } from "@koalaui/common" -// // import { CONTEXT_ROOT_SCOPE, IncrementalNode, NodeAttach, ReadonlyTreeNode, -// // contextLocalValue, memoRoot, mutableState, updateStateManager, -// // } from "@koalaui/runtime" -// -// // type uint32 = int -// -// abstract class IncrementalNode { -// constructor(kind: int) {} -// }; -// -// class StringerNode extends IncrementalNode { -// constructor(kind: int = 1) { -// super(kind) -// } -// data: string | undefined = undefined -// } -// ` -// -// const sourceFile = ts.factory.createSourceFile(sample_in, ts.ContextState.ES2PANDA_STATE_CHECKED) -// util.assert(ts.isSourceFile(sourceFile)) -// -// const result = (new MemoTransformer()).visitor(sourceFile) -// util.assert(ts.isSourceFile(result)) -// -// util.assertEqualsSource( -// result.node.dumpSrc(), -// ` -// ` -// ) -// }) -// }) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/main.sts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/main.sts deleted file mode 100644 index 464b0be3c00..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/main.sts +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2022-2024 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 { uint32 } from "@koalaui/common" -import { CONTEXT_ROOT_SCOPE, IncrementalNode, NodeAttach, ReadonlyTreeNode, - contextLocalValue, memoRoot, mutableState, updateStateManager, -} from "@koalaui/runtime" - -class StringerNode extends IncrementalNode { - constructor(kind: uint32 = 1) { - super(kind) - } - data: string | undefined = undefined -} - -/** @memo */ -function Stringer( - arg: string, - /** @memo */ - content?: () => void -): void { - NodeAttach(() => new StringerNode(), (node: StringerNode): void => { - node.data = arg - console.log("I am recomputing with arg: ", arg) - content?.() - }) -} - -const state = mutableState(17) - -/** @memo */ -function demo(node: StringerNode): void { - Stringer("First", () => { - console.log("Content of the first") - Stringer(`Second ${state.value}`, () => { - console.log("Content of the second") - Stringer("Third") - }) - Stringer("Fourth", () => { - console.log("Content of the 4th") - Stringer("5th") - }) - }) - - // This is to dump the complete managed incremental scope tree - const scope = contextLocalValue(CONTEXT_ROOT_SCOPE) - console.log(scope?.toHierarchy()) -} - -// memoRoot is the entry point here. -// It initializes the incremental runtime and computes the first frame. -// Have a look at its implementation. -const root = memoRoot(new StringerNode(0), demo) -console.log(root.value.toHierarchy()) // dump ui subtree - -updateStateManager() // Compute next frame. -console.log(root.value.toHierarchy()) - -state.value = 19 - -updateStateManager() // Compute the next frame. -console.log(root.value.toHierarchy()) -console.log("-----END-----") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/memo-rewrites.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/memo-rewrites.test.ts deleted file mode 100644 index 142c57c212d..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/ts-api/demo-playground/memo-rewrites.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022-2023 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 util from "../../test-util" -// import * as ts from "../../../src/ts-api" -// import { MemoTransformer } from "../../../plugins/src/memo-transformer" -// -// suite(util.getSuiteTitle(__filename), () => { -// test.skip("function-stinger", function() { -// const sample_in = -// ` -// /** @memo */ -// function _MEMO_Stringer( -// arg: string, -// /** @memo */ -// _MEMO_content: () => void -// ): void { -// _MEMO_content() -// } -// ` -// -// const sourceFile = ts.factory.createSourceFile(sample_in, ts.ContextState.ES2PANDA_STATE_CHECKED) -// util.assert(ts.isSourceFile(sourceFile)) -// -// const result = (new MemoTransformer()).visitor(sourceFile) -// util.assert(ts.isSourceFile(result)) -// -// util.assertEqualsSource( -// result.node.dumpSrc(), -// ` -// abstract class ETSGLOBAL { -// public static _$init$_() {} -// -// public static Stringer(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg: string, _MEMO_content: (()=> void)) { -// if (__memo_scope.unchanged) { -// return __memo_scope.cached; -// } -// content(__memo_context, ((__memo_id) + ("key_id_main.ts"))); -// content(__memo_context, __memo_id); -// return __memo_scope.recache(); -// } -// -// -// } -// ` -// ) -// }) -// }) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/.gitignore b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/.gitignore new file mode 100644 index 00000000000..950eb2eef88 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/.gitignore @@ -0,0 +1 @@ +.rollup.cache \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/demo/demo.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/demo/demo.ets index 3da27bb38d5..7bc85bcd040 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/demo/demo.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/demo/demo.ets @@ -19,7 +19,7 @@ function Stringer( @memo content?: () => void ): void { - NodeAttach(() => + NodeAttach(():StringerNode => new StringerNode(), (node: StringerNode): void => { node.data = arg console.log("I am recomputing with arg: ", arg) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/package.json index c5a1ae3486b..6be3b7cea66 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/package.json @@ -1,7 +1,7 @@ { "scripts": { "clean": "rimraf build", - "compile": "fast-arktsc --config ui2abcconfig.json --compiler ../../../incremental/tools/panda/arkts/ui2abc --link-name ./build/demo.abc --file-option --restart-stages && ninja ${NINJA_OPTIONS} -f build/abc/build.ninja", + "compile": "node ../../fast-arktsc --config ui2abcconfig.json --compiler ../../../incremental/tools/panda/arkts/ui2abc --link-name ./build/demo.abc && ninja ${NINJA_OPTIONS} -f build/abc/build.ninja", "run": "../../../incremental/tools/panda/arkts/ark ./build/demo.abc --ark-boot-files ../../../incremental/runtime/build/incremental.abc --ark-entry-point @demo.demo.ETSGLOBAL::main", "disasm": "$(find build -name '*.abc' -exec ../../../incremental/tools/panda/arkts/arkdisasm {} \\;)" }, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/ui2abcconfig.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/ui2abcconfig.json index b66f95b9509..40de7362f7a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/ui2abcconfig.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/ui2abcconfig.json @@ -12,9 +12,15 @@ }, "plugins": [ { - "transform": "..", - "stage": "checked", + "transform": "@koalaui/memo-plugin/ParserTransformer", + "stage": "parsed", "name": "memo" + }, + { + "transform": "../lib/MemoTransformer", + "stage": "checked", + "name": "memo", + "manuallyDisableInsertingImport": true } ] }, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/package.json index b67895abe40..751de35923f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/package.json @@ -1,12 +1,18 @@ { "name": "@koalaui/memo-plugin", - "main": "lib/MemoTransformer.js", + "exports": { + "./*": "./lib/*.js", + ".": "./lib/MemoTransformer.js" + }, + "files": [ + "./lib/**/*" + ], "scripts": { "clean": "rimraf build", "compile": "rollup -c", "runtime:clean": "npm run all:clean --prefix ../../incremental", - "runtime:prepare": "npm run build:incremental:inc:ui2abc --prefix ../../incremental/runtime", + "runtime:prepare": "npm run build:incremental:inc:ui2abc --prefix ../../incremental/runtime && npm run build:incremental:inc:ui2abc:recheck --prefix ../../incremental/runtime", "compile:libarkts": "npm run compile --prefix ../libarkts", "demo:clean": "npm run clean --prefix demo", "demo:run": "npm run compile:libarkts && npm run compile && npm run compile --prefix demo && npm run run --prefix demo", @@ -17,19 +23,10 @@ "compile:deps": "npm run compile:libarkts && npm run compile && npm run compile:deps:harness && npm run runtime:prepare", "compile:annotate": "npm run compile --prefix ../annotate", - "executable:annotate:test": "npm run compile:annotate && node ../annotate annotate-test-executable.json", - "executable:ui2abc:fast-arktsc": "fast-arktsc --config ./test/arktsconfig-executable.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build/test/test.abc --file-option --restart-stages", - "executable:ui2abc:ninja": "cd build && ninja", - "executable:ui2abc": "npm run executable:ui2abc:fast-arktsc && npm run executable:ui2abc:ninja", - "executable:abc": "bash ../../incremental/tools/panda/arkts/ark ./build/test/test.abc --ark-boot-files ./build/test/test.abc:../../incremental/runtime/build/incremental.abc:../../incremental/harness/build/harness.abc --ark-entry-point @test.ets.basic.test.ETSGLOBAL::main", - "executable": "npm run compile:deps && npm run executable:annotate:test && npm run executable:ui2abc && npm run executable:abc", - + "executable": "npm run test:arkts:memo-plugin --prefix ../tests-memo", "diagnostics": "mocha --config mocharc.diagnostics.json", "test:diagnostics": "npm run compile && npm run diagnostics", - "test:all": "npm run test && npm run executable && npm run diagnostics", - "recheck:ui2abc:fast-arktsc": "fast-arktsc --config ./recheck-bringup/ui2abcconfig.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build/recheck-bringup/memo-hello-world.abc --file-option", - "recheck:ui2abc:ninja": "cd build/recheck-bringup && ninja", - "recheck:ui2abc": "npm run recheck:ui2abc:fast-arktsc && npm run recheck:ui2abc:ninja" + "test:all": "npm run test && npm run diagnostics && npm run executable" }, "devDependencies": { "@koalaui/harness": "1.5.15+devel" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/AnimatedState.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/AnimatedState.ets deleted file mode 100644 index 470d228f345..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/AnimatedState.ets +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2022-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 { int64 } from "../common" -import { TimeAnimation } from "./TimeAnimation" -import { MutableState, State } from "../states/State" -export declare interface AnimatedState extends State { - animation: TimeAnimation - readonly running: boolean - paused: boolean -} -export declare function animatedState(animation: TimeAnimation, startNow: boolean = false, timeProvider?: () => int64): AnimatedState -export declare interface MutableAnimatedState extends MutableState { - animation: TimeAnimation - readonly running: boolean -} -export declare function mutableAnimatedState(initial: Value, animationProvider: ImplicitAnimationProvider): MutableAnimatedState -export type ImplicitAnimationProvider = (from: Value, to: Value) => TimeAnimation -export declare interface StateAnimator { - parameter: Parameter - readonly value: Value - onValueChange(action: (newValue: Value) => void): void -} -export declare function stateAnimator(parameter: P, animationProvider: ParametrizedAnimationProvider): StateAnimator -export type ParametrizedAnimationProvider = (parameter: P, value: V | undefined) => TimeAnimation diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/Easing.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/Easing.ets deleted file mode 100644 index bc0a01b2593..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/Easing.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2022-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 { float64, uint32 } from "../common" -export type EasingCurve = (value: float64) => float64 -export declare class Easing { - static readonly Linear: EasingCurve - static readonly LinearReversed: EasingCurve - static readonly EaseInSine: EasingCurve - static readonly EaseOutSine: EasingCurve - static readonly EaseInOutSine: EasingCurve - static readonly Ease: EasingCurve - static readonly EaseIn: EasingCurve - static readonly EaseOut: EasingCurve - static readonly EaseInOut: EasingCurve - static readonly ViscousFluid: EasingCurve - static readonly Bubble: EasingCurve - static inverted(easing: EasingCurve): EasingCurve - static reversed(easing: EasingCurve): EasingCurve - static restarted(easing: EasingCurve): EasingCurve - static repeated(easing: EasingCurve, count: uint32): EasingCurve - static joined(...easing: EasingCurve[]): EasingCurve - static thereAndBackAgain(easing: EasingCurve): EasingCurve - static cubicBezier(p1x: float64, p1y: float64, p2x: float64, p2y: float64): EasingCurve - static steps(stops: uint32, jump: EasingStepJump = EasingStepJump.None): EasingCurve - static viscousFluid(v0: float64 = 1, f: float64 = 3): EasingCurve -} -export enum EasingStepJump { - Start, - End, - None, - Both, -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/EasingSupport.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/EasingSupport.ets deleted file mode 100644 index 51e86c58af0..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/EasingSupport.ets +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022-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 { float64, uint32 } from "../common" -export declare class EasingSupport { - x: Float64Array - y: Float64Array - constructor(size: uint32, xSupplier: (value: float64) => float64, ySupplier: (value: float64) => float64) - convert(value: float64): float64 - static newCubicBezier(p1x: float64, p1y: float64, p2x: float64, p2y: float64, size: uint32 = 1024): EasingSupport -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/TimeAnimation.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/TimeAnimation.ets deleted file mode 100644 index 6a128318282..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/TimeAnimation.ets +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022-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 { float64, int32, int64, uint32 } from "../common" -import { AnimationRange } from "./AnimationRange" -import { EasingCurve } from "./Easing" -export declare const DEFAULT_ANIMATION_DURATION: uint32 -export declare interface TimeAnimation { - readonly running: boolean - getValue(time: int64): Value - onStart(time: int64): void - onPause(time: int64): void -} -export declare interface AnimationSpec { - readonly duration: uint32 - readonly delay: uint32 - readonly easing: EasingCurve - readonly onEdge: OnEdge - readonly onPause: OnPause - readonly iterations: int32 | undefined - readonly onStart: (() => void) | undefined - readonly onEnd: (() => void) | undefined - readonly onReset: (() => void) | undefined -} -export declare class OnEdge { - static Nothing: OnEdge - static Reverse: OnEdge - static Restart: OnEdge - constructor(name: string) -} -export declare class OnPause { - static Nothing: OnPause - static Reset: OnPause - static Fade: OnPause - constructor(name: string) -} -export declare function constAnimation(value: Value): TimeAnimation -export declare function timeAnimation(compute: (time: int64) => Value, initialTime: int64 = 0): TimeAnimation -export declare function smoothAnimation(period: uint32, from: float64 = 0.0, to: float64 = 1.0): TimeAnimation -export declare function blinkAnimation(period: uint32, initialValue: boolean = false): TimeAnimation -export declare function countAnimation(period: uint32, initialCount: int64 = 0): TimeAnimation -export declare function periodicAnimation(period: uint32, compute: (count: int64) => Value, initialCount: int64 = 0): TimeAnimation -export declare function periodicAnimationWithDelay(delay: uint32, period: uint32, compute: (count: int64) => Value, initialCount: int64 = 0): TimeAnimation -export declare function frameAnimation(frameTime: ReadonlyArray, compute: (index: int64) => Value): TimeAnimation -export declare function numberAnimation(spec: Partial, to: float64 = 1.0, from: float64 = 0.0): TimeAnimation -export declare function animation(spec: Partial, compute: AnimationRange, initialState: float64 = 0): TimeAnimation -export declare function transition(duration: uint32, easing: EasingCurve, compute: AnimationRange, initialState: int64 = 0): TimeAnimation -export declare function linearTransition(duration: uint32, compute: AnimationRange, initialState: int64 = 0): TimeAnimation \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/memo.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/memo.ets deleted file mode 100644 index 1ed38006d8d..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/memo.ets +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2022-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 { memo } from "../annotations" -import { float64, int64, uint32 } from "../common" -import { AnimatedState, ImplicitAnimationProvider, MutableAnimatedState, ParametrizedAnimationProvider, StateAnimator, animatedState, mutableAnimatedState, stateAnimator } from "./AnimatedState" -import { AnimationRange } from "./AnimationRange" -import { Easing, EasingCurve } from "./Easing" -import { AnimationSpec, TimeAnimation } from "./TimeAnimation" -@memo export declare function sampledValue(sampleRate: uint32, generator: (tick: int64) => V): V -@memo export declare function rememberAnimatedState(animation: () => TimeAnimation, startNow: boolean = false): AnimatedState -@memo export declare function rememberNumberTransition(on: boolean, duration: uint32, easing: EasingCurve = Easing.Linear, to: float64 = 1.0, from: float64 = 0.0): AnimatedState -@memo export declare function rememberTransition(on: boolean, duration: uint32, easing: EasingCurve, compute: AnimationRange, initial: boolean = on): AnimatedState -@memo export declare function rememberMutableAnimatedState(initial: Value, animationProvider: ImplicitAnimationProvider): MutableAnimatedState -@memo export declare function rememberMutableAnimatedStateNumber(initial: float64, animationSpec: Partial): MutableAnimatedState -@memo export declare function rememberAnimator(parameter: P, animationProvider: ParametrizedAnimationProvider): StateAnimator \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/annotations.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/annotations.ets deleted file mode 100644 index 11ec0d27174..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/annotations.ets +++ /dev/null @@ -1,15 +0,0 @@ - -@Retention({policy: "SOURCE"}) -export @interface memo {} - -@Retention({policy: "SOURCE"}) -export @interface memo_intrinsic {} - -@Retention({policy: "SOURCE"}) -export @interface memo_entry {} - -@Retention({policy: "SOURCE"}) -export @interface memo_stable {} - -@Retention({policy: "SOURCE"}) -export @interface memo_skip {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/common.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/common.ets deleted file mode 100644 index 5110a388237..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/common.ets +++ /dev/null @@ -1,5 +0,0 @@ -export type KoalaCallsiteKey = int -export type int32 = int -export type uint32 = int -export type int64 = long -export type float64 = double diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/index.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/index.ets deleted file mode 100644 index a057aae3487..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/index.ets +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2022-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. - */ - -export { - AnimatedState, - ImplicitAnimationProvider, - MutableAnimatedState, - ParametrizedAnimationProvider, - StateAnimator, - animatedState, - mutableAnimatedState, - stateAnimator, -} from "./animation/AnimatedState" -export { - AnimationRange, - ArrayAnimationRange, - NumberAnimationRange, -} from "./animation/AnimationRange" -export { - Easing, - EasingCurve, - EasingStepJump, -} from "./animation/Easing" -export { - createAnimationTimer, - getAnimationTimer, -} from "./animation/GlobalTimer" -export { - rememberAnimatedState, - rememberAnimator, - rememberMutableAnimatedState, - rememberMutableAnimatedStateNumber, - rememberNumberTransition, - rememberTransition, - sampledValue, -} from "./animation/memo" -export { - AnimationSpec, - OnEdge, - OnPause, - TimeAnimation, - animation, - blinkAnimation, - constAnimation, - countAnimation, - frameAnimation, - linearTransition, - numberAnimation, - periodicAnimation, - periodicAnimationWithDelay, - smoothAnimation, - timeAnimation, - transition, -} from "./animation/TimeAnimation" - -export { - memoBind, - memoBind2, - memoPartialBind2_1, - memoPartialBind3_2, - MemoCallbackContext, -} from "./memo/bind" -export { - OnChange, - RunEffect, -} from "./memo/changeListener" -export { - contextLocal, - contextLocalScope, - contextLocalValue, -} from "./memo/contextLocal" -export { - memoRoot, - memoEntry, - memoEntry1, - memoEntry2, -} from "./memo/entry" -export { - DataNode, - NodeAttach, - contextNode, -} from "./memo/node" -export { - memoize, - memoLifecycle, - once, - remember, - rememberArrayState, - rememberComputableState, - rememberComputableValue, - rememberControlledScope, - rememberDisposable, - rememberMutableAsyncState, - rememberMutableState, -} from "./memo/remember" -export { - Repeat, - RepeatByArray, - RepeatRange, - RepeatWithKey, -} from "./memo/repeat" -export { - TestNode, - testRoot, - testTick, - testUpdate, -} from "./memo/testing" - -export { - Disposable, - disposeContent, - disposeContentBackward, - disposeContentForward, -} from "./states/Disposable" -export { - GlobalStateManager, - arrayState, - callScheduledCallbacks, - mutableState, - scheduleCallback, - updateStateManager, -} from "./states/GlobalStateManager" -export { - ArrayState, - CONTEXT_ROOT_NODE, - CONTEXT_ROOT_SCOPE, - ComputableState, - ControlledScope, - Equivalent, - MutableState, - State, - StateContext, - StateManager, - ValueTracker, -} from "./states/State" -export { - __context, - __id, - __key, - __memo_context_type, - __memo_id_type, - __memo_transformed, - __memo_transformed_before, - __memo_transformed_after, -} from "./internals" - -export { IncrementalNode } from "./tree/IncrementalNode" -export { PrimeNumbers } from "./tree/PrimeNumbers" -export { ReadonlyTreeNode } from "./tree/ReadonlyTreeNode" -export { TreeNode } from "./tree/TreeNode" -export { TreePath } from "./tree/TreePath" - -export { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "./annotations" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/internals.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/internals.ets deleted file mode 100644 index b8f3ff6a2f5..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/internals.ets +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2022-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 { KoalaCallsiteKey } from "./common" -import { StateContext } from "./states/State" -export type __memo_context_type = StateContext -export type __memo_id_type = KoalaCallsiteKey -export type __memo_transformed_before = string -export type __memo_transformed_after = number -export type __memo_transformed = __memo_transformed_before -export declare function __context(): StateContext -export declare function __id(): KoalaCallsiteKey -export declare function __key(): KoalaCallsiteKey diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/bind.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/bind.ets deleted file mode 100644 index 65d660d389d..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/bind.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022-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 { memo } from "../annotations" -import { KoalaCallsiteKey } from "../common" -import { StateContext } from "../states/State" -export declare class MemoCallbackContext { - readonly context: StateContext - readonly id: KoalaCallsiteKey - constructor(context: StateContext, id: KoalaCallsiteKey) - @memo static Make(): MemoCallbackContext - call(@memo callback: (args: Int32Array) => number, args: Int32Array): number -} -export declare function memoBind(@memo item: (arg: T) => void, value: T): @memo () => void -export declare function memoBind2(@memo item: (arg1: T1, arg2: T2) => void, value1: T1, value2: T2): @memo () => void -export declare function memoPartialBind2_1(@memo item: (arg1: T1, arg2: T2) => void, value1: T1): @memo (arg2: T2) => void -export declare function memoPartialBind3_2(@memo item: (arg1: T1, arg2: T2, arg3: T3) => void, value1: T1): @memo (arg2: T2, arg3: T3) => void diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/contextLocal.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/contextLocal.ets deleted file mode 100644 index 5cfb10ee7d8..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/contextLocal.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022-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 { memo, memo_intrinsic } from "../annotations" -import { State } from "../states/State" -@memo_intrinsic export declare function contextLocal(name: string): State | undefined -@memo_intrinsic export declare function contextLocalValue(name: string): Value -@memo_intrinsic export declare function contextLocalScope(name: string, value: Value, @memo content: () => void): void diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/entry.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/entry.ets deleted file mode 100644 index 2b7d437692c..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/entry.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2022-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 { memo, memo_entry } from "../annotations" -import { KoalaCallsiteKey } from "../common" -import { ComputableState, StateContext } from "../states/State" -import { IncrementalNode } from "../tree/IncrementalNode" -export declare function memoRoot(node: Node, @memo update: (node: Node) => void): ComputableState -export declare function memoRoot(node: Node, update: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: Node) => void): ComputableState -@memo_entry export declare function memoEntry(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, @memo entry: () => R): R -@memo_entry export declare function memoEntry(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, entry: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey) => R): R -@memo_entry export declare function memoEntry1(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, @memo entry: (arg: T) => R, arg: T): R -@memo_entry export declare function memoEntry1(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, entry: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, arg: T) => R, arg: T): R -@memo_entry export declare function memoEntry2(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, @memo entry: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): R -@memo_entry export declare function memoEntry2(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, entry: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): R diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/node.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/node.ets deleted file mode 100644 index 4e425cc51f4..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/node.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022-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 { memo, memo_intrinsic } from "../annotations" -import { uint32, KoalaCallsiteKey } from "../common" -import { IncrementalNode } from "../tree/IncrementalNode" -import { StateContext } from "../states/State" -@memo_intrinsic export declare function NodeAttach(create: () => Node, @memo update: (node: Node) => void): void -@memo_intrinsic export declare function contextNode(kind: uint32 = 1, name?: string): T -export declare function NodeAttach(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, create: () => Node, update: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: Node) => void): void -export declare function contextNode(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, kind: uint32 = 1, name?: string): T -export declare class DataNode extends IncrementalNode { - data: Data | undefined - constructor(kind: uint32 = 1) - static attach(kind: uint32, data: Data, onDataChange?: () => void): void - static extract(kind: uint32, node: IncrementalNode): Data | undefined -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/remember.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/remember.ets deleted file mode 100644 index 3476df08bbb..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/remember.ets +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2022-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 { memo, memo_skip, memo_intrinsic } from "../annotations" -import { ArrayState, ControlledScope, MutableState } from "../states/State" -@memo_intrinsic export declare function memoize(compute: () => Value): Value -@memo_intrinsic export declare function memoLifecycle(onAttach: () => void, onDetach: () => void): void -@memo_intrinsic export declare function once(callback: () => void): void -@memo_intrinsic export declare function remember(compute: () => Value): Value -@memo_intrinsic export declare function rememberDisposable(compute: () => Value, cleanup: (value: Value | undefined) => void): Value -@memo_intrinsic export declare function rememberMutableState(initial: (() => Value) | Value): MutableState -@memo_intrinsic export declare function rememberArrayState(initial?: () => ReadonlyArray): ArrayState -@memo export declare function rememberMutableAsyncState(compute: () => Promise, initial?: Value, onError?: (error: Error) => void): MutableState -@memo export declare function rememberComputableState(key: Key, @memo_skip compute: (key: Key) => Promise, initial?: Value, onError?: (error: Error) => void): MutableState -@memo export declare function rememberComputableValue(key: Key, @memo_skip compute: (key: Key) => Promise, initial?: Value, onError?: (e: Error) => void): Value | undefined -@memo_intrinsic export declare function rememberControlledScope(invalidate: () => void): ControlledScope diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/repeat.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/repeat.ets deleted file mode 100644 index d12ad9abf36..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/repeat.ets +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2022-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 { memo } from "../annotations" -import { KoalaCallsiteKey, int32 } from "../common" -import { StateContext } from "../states/State" -@memo export declare function Repeat(count: int32, @memo action: (index: int32) => void): void -export declare function Repeat(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, count: int32, action: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, index: int32) => void): void -@memo export declare function RepeatWithKey(count: int32, key: (index: int32) => KoalaCallsiteKey, @memo action: (index: int32) => void): void -export declare function RepeatWithKey(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, count: int32, key: (index: int32) => KoalaCallsiteKey, action: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, index: int32) => void): void -@memo export declare function RepeatByArray(array: ReadonlyArray, key: (element: T, index: int32) => KoalaCallsiteKey, @memo action: (element: T, index: int32) => void): void -export declare function RepeatByArray(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, array: ReadonlyArray, key: (element: T, index: int32) => KoalaCallsiteKey, action: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, element: T, index: int32) => void): void -@memo export declare function RepeatRange(start: int32, end: int32, element: (index: int32) => T, key: (element: T, index: int32) => KoalaCallsiteKey, @memo action: (element: T, index: int32) => void): void -export declare function RepeatRange(__memo_context: StateContext, __memo_id: KoalaCallsiteKey, start: int32, end: int32, element: (index: int32) => T, key: (element: T, index: int32) => KoalaCallsiteKey, action: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, element: T, index: int32) => void): void diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/testing.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/testing.ets deleted file mode 100644 index 57d9b70b6f1..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/testing.ets +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022-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 { memo, memo_intrinsic } from "../annotations" -import { uint32, KoalaCallsiteKey } from "../common" -import { GlobalStateManager } from "../states/GlobalStateManager" -import { ComputableState, State, StateContext, StateManager } from "../states/State" -import { IncrementalNode } from "../tree/IncrementalNode" -export declare class TestNode extends IncrementalNode { - content: string - constructor(kind: uint32 = 1) - toString(): string - static create(@memo content: (node: TestNode) => void): ComputableState - static create(content: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: TestNode) => void): ComputableState - @memo_intrinsic static attach(content: (node: TestNode) => void): void - @memo_intrinsic static attach(content: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: TestNode) => void): void -} -export declare function testRoot(@memo content: (node: TestNode) => void): State -export declare function testRoot(content: (__memo_context: StateContext, __memo_id: KoalaCallsiteKey, node: TestNode) => void): State -export declare function testUpdate(withCallbacks: boolean = true, manager: StateManager = GlobalStateManager.instance): uint32 -export declare function testTick(root: State, withCallbacks: boolean = true): void diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Disposable.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Disposable.ets deleted file mode 100644 index 59d045a4736..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Disposable.ets +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2022-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. - */ - -export declare interface Disposable { - readonly disposed: boolean - dispose(): void -} -export declare function disposeContentForward(array: ReadonlyArray): void -export declare function disposeContentBackward(array: ReadonlyArray): void -export declare function disposeContent(it: IterableIterator): void diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/GlobalStateManager.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/GlobalStateManager.ets deleted file mode 100644 index 9fa16240793..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/GlobalStateManager.ets +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2022-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 { ArrayState, Equivalent, MutableState, StateManager, ValueTracker } from "./State" -export declare class GlobalStateManager { - static current: StateManager | undefined - static get instance(): StateManager - static reset(): void -} -export declare function updateStateManager(manager: StateManager = GlobalStateManager.instance): void -export declare function callScheduledCallbacks(manager: StateManager = GlobalStateManager.instance): void -export declare function scheduleCallback(callback?: () => void, manager: StateManager = GlobalStateManager.instance): void -export declare function mutableState(value: T, equivalent?: Equivalent, tracker?: ValueTracker): MutableState -export declare function arrayState(array?: ReadonlyArray, equivalent?: Equivalent): ArrayState diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/State.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/State.ets deleted file mode 100644 index 0277e11149a..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/State.ets +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2022-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 { int32, KoalaCallsiteKey, uint32 } from "../common" -import { Disposable } from "./Disposable" -import { IncrementalNode } from "../tree/IncrementalNode" -export declare const CONTEXT_ROOT_SCOPE: string -export declare const CONTEXT_ROOT_NODE: string -export type Equivalent = (oldV: Value, newV: Value) => boolean -export declare function createStateManager(): StateManager -export declare interface StateManager extends StateContext { - syncChanges(): void - isUpdateNeeded(): boolean - updateSnapshot(): uint32 - updatableNode(node: Node, update: (context: StateContext) => void, cleanup?: () => void): ComputableState - scheduleCallback(callback: () => void): void - callCallbacks(): void - frozen: boolean - reset(): void -} -export declare interface State { - readonly modified: boolean - readonly value: Value -} -export declare interface MutableState extends Disposable, State { - value: Value -} -export declare interface ArrayState extends State> { - length: number - at(index: number): Item - get(index: number): Item - set(index: number, item: Item): void - copyWithin(target: number, start: number, end?: number): Array - fill(value: Item, start?: number, end?: number): Array - pop(): Item | undefined - push(...items: Item[]): number - reverse(): Array - shift(): Item | undefined - sort(comparator?: (a: Item, b: Item) => number): Array - splice(start: number, deleteCount: number | undefined, ...items: Item[]): Array - unshift(...items: Item[]): number -} -export declare interface ComputableState extends Disposable, State { - readonly recomputeNeeded: boolean -} -export declare interface StateContext { - readonly node: IncrementalNode | undefined - attach(id: KoalaCallsiteKey, create: () => Node, update: () => void, cleanup?: () => void): void - compute(id: KoalaCallsiteKey, compute: () => Value, cleanup?: (value: Value | undefined) => void, once?: boolean): Value - computableState(compute: (context: StateContext) => Value, cleanup?: (context: StateContext, value: Value | undefined) => void): ComputableState - mutableState(initial: Value, global?: boolean, equivalent?: Equivalent, tracker?: ValueTracker): MutableState - arrayState(initial?: ReadonlyArray, global?: boolean, equivalent?: Equivalent): ArrayState - namedState(name: string, create: () => Value, global?: boolean, equivalent?: Equivalent, tracker?: ValueTracker): MutableState - stateBy(name: string, global?: boolean): MutableState | undefined - valueBy(name: string, global?: boolean): Value - scope(id: KoalaCallsiteKey, paramCount?: int32, create?: () => IncrementalNode, compute?: () => Value, cleanup?: (value: Value | undefined) => void, once?: boolean): InternalScope - controlledScope(id: KoalaCallsiteKey, invalidate: () => void): ControlledScope -} -export declare interface ValueTracker { - onCreate(value: Value): Value - onUpdate(value: Value): Value -} -export declare interface InternalScope { - readonly unchanged: boolean - readonly cached: Value - recache(newValue?: Value): Value - param(index: int32, value: V, equivalent?: Equivalent, name?: string, contextLocal?: boolean): State -} -export declare interface ControlledScope { - enter(): void - leave(): void -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/IncrementalNode.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/IncrementalNode.ets deleted file mode 100644 index 7e70a5c64f9..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/IncrementalNode.ets +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022-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 { uint32 } from "../common" -import { Disposable } from "../states/Disposable" -import { ReadonlyTreeNode } from "./ReadonlyTreeNode" -export declare class IncrementalNode implements Disposable, ReadonlyTreeNode { - _disposed: boolean - _child: IncrementalNode | undefined - _prev: IncrementalNode | undefined - _next: IncrementalNode | undefined - _parent: IncrementalNode | undefined - _incremental: IncrementalNode | undefined - protected onChildInserted: ((node: IncrementalNode) => void) | undefined - protected onChildRemoved: ((node: IncrementalNode) => void) | undefined - readonly kind: uint32 - constructor(kind: uint32 = 1) - isKind(kind: uint32): boolean - get disposed(): boolean - dispose(): void - get parent(): IncrementalNode | undefined - toString(): string - toHierarchy(): string - get firstChild(): IncrementalNode | undefined - get nextSibling(): IncrementalNode | undefined - get previousSibling(): IncrementalNode | undefined - incrementalUpdateSkip(count: uint32): void - incrementalUpdateDone(parent?: IncrementalNode): void -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreeNode.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreeNode.ets deleted file mode 100644 index 56a72359cb2..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreeNode.ets +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2022-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 { float64, int32, uint32 } from "../common" -import { Disposable } from "../states/Disposable" -import { ReadonlyTreeNode } from "./ReadonlyTreeNode" -export declare class TreeNode implements Disposable, ReadonlyTreeNode { - myIndex: int32 - myParent: TreeNode | undefined - myChildren: Array - myIndicesValid: boolean - myDisposed: boolean - readonly kind: uint32 - protected onChildInserted: ((node: TreeNode, index: int32) => void) | undefined - protected onChildRemoved: ((node: TreeNode, index: int32) => void) | undefined - constructor(kind: uint32 = 1) - get disposed(): boolean - dispose(): void - get parent(): TreeNode | undefined - get depth(): uint32 - get childrenCount(): uint32 - get children(): ReadonlyArray - get index(): int32 - isKind(kind: uint32): boolean - find(valueOf: (node: TreeNode, index: int32) => V | undefined): V | undefined - forEach(action: (node: TreeNode, index: float64) => void): void - every(predicate: (node: TreeNode, index: float64) => boolean): boolean - some(predicate: (node: TreeNode, index: float64) => boolean): boolean - childAt(index: int32): TreeNode | undefined - appendChild(node: TreeNode): boolean - insertChildAt(index: int32, node: TreeNode): boolean - appendChildren(...nodes: TreeNode[]): boolean - insertChildrenAt(index: int32, ...nodes: TreeNode[]): boolean - removeChildAt(index: int32): TreeNode | undefined - removeChildrenAt(index: int32, count?: uint32): Array - removeChild(node: TreeNode): boolean - removeFromParent(): void - removeNodes(index: int32, count: uint32): Array - insertNodeAt(index: int32, node: TreeNode): void - insertable(node: TreeNode): boolean - accessible(index: int32, count: uint32 = 1): boolean - toString(): string - toHierarchy(): string - collectNodes(): Array - collectParentsTo(array: Array): void - collectChildrenTo(array: Array, deep: boolean = false): void -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreeUpdater.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreeUpdater.ets deleted file mode 100644 index a54302e8165..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreeUpdater.ets +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022-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 { int32, uint32 } from "../common" -import { TreePath } from "./TreePath" -export declare class TreeUpdater { - current: TreePath - readonly reverse: boolean - constructor(root: Node, reverse: boolean = false) - get path(): TreePath - get node(): Node - down(node: Node): void - up(): void - clear(): void - insert(index: int32, node: Node): void - remove(index: int32, amount: uint32): void - move(indexFrom: int32, indexTo: int32, amount: uint32): void -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/ui2abcconfig.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/ui2abcconfig.json index 3dfc8a6d3f4..75f8059debf 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/ui2abcconfig.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/ui2abcconfig.json @@ -7,14 +7,20 @@ "@koalaui/common": ["../../../incremental/common/src"], "@koalaui/compat": ["../../../incremental/compat/src/arkts"], "@koalaui/harness": ["../../../incremental/harness/src/arkts"], - "@koalaui/runtime": ["./runtime-api"], - "@koalaui/runtime/annotations": ["./runtime-api"] + "@koalaui/runtime": ["../../../incremental/runtime/src"], + "@koalaui/runtime/annotations": ["../../../incremental/runtime/annotations"] }, "plugins": [ + { + "transform": "@koalaui/memo-plugin/ParserTransformer", + "stage": "parsed", + "name": "memo" + }, { "transform": "@koalaui/memo-plugin", "stage": "checked", "name": "memo" + "manuallyDisableInsertingImport": true } ] }, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/rollup.config.mjs b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/rollup.config.mjs index a232e4ff118..8a706b1a54d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/rollup.config.mjs +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/rollup.config.mjs @@ -18,11 +18,23 @@ import commonjs from '@rollup/plugin-commonjs' const ENABLE_SOURCE_MAPS = true; // Enable for debugging -/** @type {import("rollup").RollupOptions} */ -export default { - input: "./src/MemoTransformer.ts", +export default [ + buildPlugin({ + src: "./src/ParserTransformer.ts", + dst: "./lib/ParserTransformer.js", + }), + buildPlugin({ + src: "./src/MemoTransformer.ts", + dst: "./lib/MemoTransformer.js", + }) +] + +/** @return {import("rollup").RollupOptions} */ +function buildPlugin({ src, dst }) { + return { + input: src, output: { - file: "./lib/MemoTransformer.js", + file: dst, format: "commonjs", plugins: [ // terser() @@ -46,7 +58,8 @@ export default { nodeResolve({ extensions: [".js", ".mjs", ".cjs", ".ts", ".cts", ".mts"] }) - ], + ] + } } function APACHE_LICENSE_HEADER() { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/AnalysisVisitor.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/AnalysisVisitor.ts index 9eb1d75fa88..46110e99d76 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/AnalysisVisitor.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/AnalysisVisitor.ts @@ -21,6 +21,14 @@ class AnalysisVisitorOptions { applyMemo?: MemoFunctionKind } +function isSetter(node: arkts.ScriptFunction) { + return node.flags & arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_SETTER +} + +function isGetter(node: arkts.ScriptFunction) { + return node.flags & arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_GETTER +} + export class AnalysisVisitor extends arkts.AbstractVisitor { // TODO: migrate to wrappers instead of pointers constructor( @@ -35,6 +43,9 @@ export class AnalysisVisitor extends arkts.AbstractVisitor { visitor(node: arkts.Expression, options?: AnalysisVisitorOptions): arkts.Expression visitor(node: arkts.AstNode, options?: AnalysisVisitorOptions): arkts.AstNode { if (arkts.isScriptFunction(node)) { + if (isSetter(node) || isGetter(node)) { + return this.visitEachChild(node, { applyMemo: options?.applyMemo ? options?.applyMemo : getMemoFunctionKind(node) }) + } const kind = options?.applyMemo ? options?.applyMemo : getMemoFunctionKind(node) this.scriptFunctions.set(node.originalPeer, kind) return this.visitEachChild(node, { applyMemo: false }) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/FunctionTransformer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/FunctionTransformer.ts index 759fffbcd5e..ebfa4971117 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/FunctionTransformer.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/FunctionTransformer.ts @@ -23,6 +23,7 @@ import { hasMemoStableAnnotation, isTrackableParam, isVoidType, + moveToFront, shouldWrap, } from "./utils" import { ParameterTransformer, ParamInfo } from "./ParameterTransformer" @@ -35,6 +36,8 @@ import { getParams, isMemo, isMemoizable, + memoizableHasReceiver, + parametersBlockHasReceiver, } from "./api-utils" function needThisRewrite(hasReceiver: boolean, isStatic: boolean, stableThis: boolean) { @@ -92,7 +95,7 @@ function updateFunctionBody( hasReceiver: boolean, isStatic: boolean, stableThis: boolean, - hash: arkts.NumberLiteral | arkts.StringLiteral, + hash: arkts.Expression, addLogging: boolean, ): [ arkts.BlockStatement, @@ -100,7 +103,7 @@ function updateFunctionBody( arkts.VariableDeclaration | undefined, arkts.ReturnStatement | arkts.BlockStatement | undefined, ] { - const shouldCreateMemoThisParam = needThisRewrite(hasReceiver, isStatic, stableThis) + const shouldCreateMemoThisParam = needThisRewrite(hasReceiver, isStatic, stableThis) && !parametersBlockHasReceiver(parameters) const parameterIdentifiers = getMemoParameterIdentifiers(parameters) const gensymParamsCount = fixGensymParams(parameterIdentifiers, node) const parameterNames = [...(shouldCreateMemoThisParam ? [RuntimeNames.THIS.valueOf()] : []), ...parameterIdentifiers.map(it => it.ident.name)] @@ -275,10 +278,15 @@ export class FunctionTransformer extends arkts.AbstractVisitor { return this.fixObjectArg(it, params[index]) }) this.modified = true + + let newArgs = [...factory.createHiddenArguments(this.positionalIdTracker.id(getName(decl))), ...updatedArguments] + if (memoizableHasReceiver(decl)) { + newArgs = moveToFront(newArgs, 2) + } return arkts.factory.updateCallExpression( node, node.callee, - [...factory.createHiddenArguments(this.positionalIdTracker.id(getName(decl))), ...updatedArguments], + newArgs, node.typeParams, node.isOptional, node.hasTrailingComma, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/MemoFactory.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/MemoFactory.ts index 7bf0851689c..9feefa275fe 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/MemoFactory.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/MemoFactory.ts @@ -30,12 +30,20 @@ export class factory { arkts.factory.createIdentifier(RuntimeNames.ID_TYPE, undefined), ) } - static createContextTypesImportDeclaration(path?: string): arkts.ETSImportDeclaration { - return arkts.factory.createETSImportDeclaration( + static createHashImportSpecifier(): arkts.ImportSpecifier { + return arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier(RuntimeNames.HASH, undefined), + arkts.factory.createIdentifier(RuntimeNames.HASH, undefined), + ) + } + + static createContextTypesImportDeclaration(program: arkts.Program, debug: boolean, path?: string) { + const mandatory = [factory.createContextTypeImportSpecifier(), factory.createIdTypeImportSpecifier()] + arkts.factory.createETSImportDeclaration( arkts.factory.createStringLiteral(path ?? RuntimeNames.CONTEXT_TYPE_DEFAULT_IMPORT), - [factory.createContextTypeImportSpecifier(), factory.createIdTypeImportSpecifier()], + debug ? [...mandatory, factory.createHashImportSpecifier()] : mandatory, arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, - arkts.global.compilerContext.program, + program, arkts.Es2pandaImportFlags.IMPORT_FLAGS_DEFAULT_IMPORT ) } @@ -49,7 +57,8 @@ export class factory { arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(RuntimeNames.CONTEXT_TYPE, undefined), undefined, - undefined ) + undefined + ) ) ), false @@ -77,22 +86,28 @@ export class factory { static createContextArgument(): arkts.Expression { return arkts.factory.createIdentifier(RuntimeNames.CONTEXT, undefined) } - static createIdArgument(hash: arkts.NumberLiteral | arkts.StringLiteral): arkts.Expression { + static createIdArgument(hash: arkts.Expression): arkts.Expression { return arkts.factory.createBinaryExpression( arkts.factory.createIdentifier(RuntimeNames.ID, undefined), hash, arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_PLUS, ) } - static createHiddenArguments(hash: arkts.NumberLiteral | arkts.StringLiteral): arkts.Expression[] { + static createHiddenArguments(hash: arkts.Expression): arkts.Expression[] { return [factory.createContextArgument(), factory.createIdArgument(hash)] } // Memo parameters static createMemoParameterIdentifier(name: string): arkts.Identifier { + if (name === "=t") { + return arkts.factory.createIdentifier(`${RuntimeNames.PARAMETER}_this`, undefined) + } return arkts.factory.createIdentifier(`${RuntimeNames.PARAMETER}_${name}`, undefined) } static createMemoParameterDeclarator(id: number, name: string): arkts.VariableDeclarator { + const original = (name == "this" || name == "=t") ? + arkts.factory.createThisExpression() : + arkts.factory.createIdentifier(name, undefined) return arkts.factory.createVariableDeclarator( arkts.Es2pandaVariableDeclaratorFlag.VARIABLE_DECLARATOR_FLAG_CONST, factory.createMemoParameterIdentifier(name), @@ -106,7 +121,7 @@ export class factory { ), [ arkts.factory.createNumberLiteral(id), - arkts.factory.createIdentifier(name, undefined), + original, ], undefined, ) @@ -169,7 +184,7 @@ export class factory { } // Recache - static createScopeDeclaration(returnTypeAnnotation: arkts.TypeNode | undefined, hash: arkts.NumberLiteral | arkts.StringLiteral, cnt: number): arkts.VariableDeclaration { + static createScopeDeclaration(returnTypeAnnotation: arkts.TypeNode | undefined, hash: arkts.Expression, cnt: number): arkts.VariableDeclaration { return arkts.factory.createVariableDeclaration( arkts.Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST, [ @@ -208,38 +223,41 @@ export class factory { false ), arg ? [arg] : [], - undefined, + undefined ) } static createReturnThis(): arkts.BlockStatement { return arkts.factory.createBlockStatement([ - factory.createRecacheCall(), + arkts.factory.createExpressionStatement( + factory.createRecacheCall() + ), arkts.factory.createReturnStatement( arkts.factory.createThisExpression() ) ]) } + static createCached(): arkts.Expression { + return arkts.factory.createMemberExpression( + arkts.factory.createIdentifier(RuntimeNames.SCOPE, undefined), + arkts.factory.createIdentifier(RuntimeNames.INTERNAL_VALUE, undefined), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + false, + ) + } static createSyntheticReturnStatement(isVoidReturn: boolean, stableThis: boolean): arkts.ReturnStatement | arkts.BlockStatement { if (isVoidReturn) { return arkts.factory.createBlockStatement([ - arkts.factory.createMemberExpression( - arkts.factory.createIdentifier(RuntimeNames.SCOPE, undefined), - arkts.factory.createIdentifier(RuntimeNames.INTERNAL_VALUE, undefined), - arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_NONE, - false, - false, + arkts.factory.createExpressionStatement( + this.createCached() ), arkts.factory.createReturnStatement(undefined) ]) } if (stableThis) { return arkts.factory.createBlockStatement([ - arkts.factory.createMemberExpression( - arkts.factory.createIdentifier(RuntimeNames.SCOPE, undefined), - arkts.factory.createIdentifier(RuntimeNames.INTERNAL_VALUE, undefined), - arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_NONE, - false, - false, + arkts.factory.createExpressionStatement( + this.createCached() ), arkts.factory.createReturnStatement( arkts.factory.createThisExpression() @@ -247,13 +265,7 @@ export class factory { ]) } return arkts.factory.createReturnStatement( - arkts.factory.createMemberExpression( - arkts.factory.createIdentifier(RuntimeNames.SCOPE, undefined), - arkts.factory.createIdentifier(RuntimeNames.INTERNAL_VALUE, undefined), - arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_NONE, - false, - false, - ), + this.createCached(), ) } static createIfStatementWithSyntheticReturnStatement(syntheticReturnStatement: arkts.ReturnStatement | arkts.BlockStatement): arkts.IfStatement { @@ -292,6 +304,43 @@ export class factory { ) } + // All these deduce functions is a huge woraround for + // recheck incapable to infer proper return types on lambdas. + static deduceWrapperType(node: arkts.Expression): arkts.TypeNode|undefined { + if (arkts.isArrowFunctionExpression(node)) return factory.deduceArrowWrapperType(node) + if (arkts.isObjectExpression(node)) return factory.deduceObjectWrapperType(node) + if (arkts.isTSAsExpression(node)) return factory.deduceAsWrapperType(node) + return undefined + } + static deduceAsWrapperType(node: arkts.TSAsExpression): arkts.TypeNode|undefined { + return node.typeAnnotation + } + static deduceObjectWrapperType(node: arkts.Expression): arkts.TypeNode|undefined { + return undefined + } + static deduceArrowWrapperType(arrow: arkts.ArrowFunctionExpression): arkts.TypeNode|undefined { + const origType: arkts.TypeNode | undefined = arrow.function?.returnTypeAnnotation + if (origType == undefined) return undefined + const params = arrow.function?.params?.map(it => { + const param = it as arkts.ETSParameterExpression + return arkts.factory.createETSParameterExpression( + arkts.factory.createIdentifier(param.ident!.name), + param.isOptional, + undefined, + param.typeAnnotation, + undefined + ) + }) ?? [] + return arkts.factory.createETSFunctionType( + undefined, + params, + origType, + false, + arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_NONE, + undefined + ) + } + // Compute static createLambdaWrapper(node: arkts.Expression): arkts.ArrowFunctionExpression { return arkts.factory.createArrowFunctionExpression( @@ -301,7 +350,7 @@ export class factory { ]), undefined, [], - undefined, + factory.deduceWrapperType(node), false, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, @@ -310,7 +359,7 @@ export class factory { ) ) } - static createComputeExpression(hash: arkts.NumberLiteral | arkts.StringLiteral, node: arkts.Expression): arkts.CallExpression { + static createComputeExpression(hash: arkts.Expression, node: arkts.Expression): arkts.CallExpression { return arkts.factory.createCallExpression( arkts.factory.createMemberExpression( arkts.factory.createIdentifier(RuntimeNames.CONTEXT, undefined), diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/MemoTransformer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/MemoTransformer.ts index 7e6321a8a28..d995da83c70 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/MemoTransformer.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/MemoTransformer.ts @@ -36,10 +36,7 @@ export interface TransformerOptions { export default function memoTransformer( userPluginOptions?: TransformerOptions ) { - return (node: arkts.AstNode) => { - if (!arkts.isETSModule(node)) { - throw new Error(`expected ETSModule got ${node.constructor.name}`) - } + return (program: arkts.Program) => { const scriptFunctions = new Map() const ETSFunctionTypes = new Map() const analysisVisitor = new AnalysisVisitor(scriptFunctions, ETSFunctionTypes) @@ -50,6 +47,7 @@ export default function memoTransformer( const parameterTransformer = new ParameterTransformer(positionalIdTracker) const returnTransformer = new ReturnTransformer() + const node = program.astNode analysisVisitor.visitor(node) diagnosticVisitor.visitor(node) @@ -66,14 +64,7 @@ export default function memoTransformer( let result = functionTransformer.visitor(node) if (userPluginOptions?.manuallyDisableInsertingImport != true) { if ((functionTransformer.modified || signatureTransformer.modified)) { - result = arkts.updateETSModuleByStatements( - node, - [ - ...node.getChildren().filter(it => arkts.isETSImportDeclaration(it)), - factory.createContextTypesImportDeclaration(userPluginOptions?.contextImport), - ...node.getChildren().filter(it => !arkts.isETSImportDeclaration(it)), - ] - ) + factory.createContextTypesImportDeclaration(program, userPluginOptions?.stableForTests ?? false, userPluginOptions?.contextImport) } } if (userPluginOptions?.keepTransformed) { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Journal.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/ParserTransformer.ts similarity index 41% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Journal.ets rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/ParserTransformer.ts index 8ff179ffb68..731c04e1628 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/states/Journal.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/ParserTransformer.ts @@ -13,22 +13,23 @@ * limitations under the License. */ -import { AtomicRef } from "../common" -export interface Changes { - getChange(state: Object): AtomicRef | undefined - clear(): void -} -export declare class Journal implements Changes { - readonly current: AtomicRef - setMarker(): void - addChange(state: Object, value: Value): void - getChanges(): Changes | undefined - getChange(state: Object): AtomicRef | undefined - clear(): void - getCachedArray(state: Object, array: Array): Array +import * as arkts from "@koalaui/libarkts" +import { factory } from "./MemoFactory" + +export interface TransformerOptions { + contextImport?: string, + stableForTests?: boolean } -declare class Chunk { - readonly previous: AtomicRef - readonly map: Map - get(state: Object): AtomicRef | undefined + +export default function memoParserTransformer( + userPluginOptions?: TransformerOptions +) { + return (program: arkts.Program, options: arkts.CompilationOptions) => { + if (userPluginOptions?.contextImport) { + /* Some files should not be processed by plugin actually */ + if (options.name.startsWith('@koalaui/common') || options.name.startsWith('@koalaui/compat')) return + if (options.name.startsWith('@koalaui/runtime.internals') || options.name.startsWith('@koalaui/runtime/annotations')) return + } + factory.createContextTypesImportDeclaration(program, userPluginOptions?.stableForTests ?? false, userPluginOptions?.contextImport) + } } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/ReturnTranformer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/ReturnTranformer.ts index 1c0aa7f3410..69ba23b9101 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/ReturnTranformer.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/ReturnTranformer.ts @@ -47,7 +47,9 @@ export class ReturnTransformer extends arkts.AbstractVisitor { } if (node.argument == undefined) { return arkts.factory.createBlockStatement([ - factory.createRecacheCall(), + arkts.factory.createExpressionStatement( + factory.createRecacheCall() + ), node ]) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/SignatureTransformer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/SignatureTransformer.ts index e55f091f0fa..74a91109b9e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/SignatureTransformer.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/SignatureTransformer.ts @@ -15,7 +15,21 @@ import * as arkts from "@koalaui/libarkts" import { factory } from "./MemoFactory" -import { MemoFunctionKind } from "./utils" +import { + MemoFunctionKind, + moveToFront, +} from "./utils" +import { + parametrizedNodeHasReceiver, +} from "./api-utils" + +function extendParameters(params: readonly arkts.Expression[], hasReceiver: boolean) { + let newParams = [...factory.createHiddenParameters(), ...params] + if (hasReceiver) { + newParams = moveToFront(newParams, 2) + } + return newParams +} export class SignatureTransformer extends arkts.AbstractVisitor { public modified = false @@ -33,19 +47,16 @@ export class SignatureTransformer extends arkts.AbstractVisitor { if (arkts.isScriptFunction(node)) { const memo = this.scriptFunctions.get(node.originalPeer) const shouldTransform = memo == MemoFunctionKind.MEMO || memo == MemoFunctionKind.INTRINSIC - if (shouldTransform) { - this.modified = true + if (!shouldTransform) { + return node } + this.modified = true return arkts.factory.updateScriptFunction( node, node.body, node.typeParams, - [...(shouldTransform ? factory.createHiddenParameters() : []), ...node.params], - node.returnTypeAnnotation - ? node.returnTypeAnnotation - : shouldTransform - ? arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID) - : undefined, + extendParameters(node.params, parametrizedNodeHasReceiver(node)), + node.returnTypeAnnotation, node.hasReceiver, node.flags, node.modifierFlags, @@ -55,16 +66,18 @@ export class SignatureTransformer extends arkts.AbstractVisitor { } if (arkts.isETSFunctionType(node)) { const memo = this.ETSFunctionTypes.get(node.originalPeer) - if (memo) { - this.modified = true + const shouldTransform = memo == MemoFunctionKind.MEMO || memo == MemoFunctionKind.INTRINSIC + if (!shouldTransform) { + return node } + this.modified = true return arkts.factory.updateETSFunctionType( node, - undefined, - [...(memo ? factory.createHiddenParameters() : []), ...node.params], + node.typeParams, + extendParameters(node.params, parametrizedNodeHasReceiver(node)), node.returnType, - false, - arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, + node.isExtensionFunction, + node.flags, node.annotations, ) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/api-utils.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/api-utils.ts index 3a3558998e7..3482e4f8cb3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/api-utils.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/api-utils.ts @@ -169,22 +169,8 @@ export function correctObjectExpression(node: arkts.AstNode | undefined): boolea return arkts.isObjectExpression(node) || (arkts.isTSAsExpression(node) && correctObjectExpression(node.expr)) } -export function correctFunctionParamType(type: arkts.TypeNode): boolean { - if (arkts.isETSFunctionType(type)) { - return true - } - if (arkts.isETSUnionType(type)) { - const nonUndefined: arkts.TypeNode[] = type.types.filter((it) => { - return !arkts.isETSUndefinedType(it) - }) - if (nonUndefined.length != 1) { - return false - } - if (arkts.isETSFunctionType(nonUndefined[0])) { - return true - } - } - return false +export function correctFunctionParamType(arg: arkts.Expression): boolean { + return arkts.isArrowFunctionExpression(arg) } function assertIsNever(isNever: never): never { @@ -232,3 +218,46 @@ export function getParams(decl: Memoizable) { } assertIsNever(decl) } + +function isThisParam(node: arkts.Expression | undefined): boolean { + if (node === undefined || !arkts.isETSParameterExpression(node)) { + return false + } + return node.ident?.isReceiver ?? false +} + +export function parametersBlockHasReceiver(params: readonly arkts.Expression[]): boolean { + return params.length > 0 && arkts.isETSParameterExpression(params[0]) && isThisParam(params[0]) +} + +export function parametrizedNodeHasReceiver(node: arkts.ScriptFunction | arkts.ETSFunctionType | undefined): boolean { + if (node === undefined) { + return false + } + return parametersBlockHasReceiver(node.params) +} + +export function memoizableHasReceiver(node: Memoizable): boolean { + if (arkts.isMethodDefinition(node)) { + return parametrizedNodeHasReceiver(node.function) + } + if (arkts.isETSParameterExpression(node)) { + if (arkts.isETSFunctionType(node.typeAnnotation)) { + return isThisParam(node.typeAnnotation.params[0]) + } + return false + } + if (arkts.isIdentifier(node)) { + if (arkts.isVariableDeclarator(node.parent) && arkts.isArrowFunctionExpression(node.parent.init)) { + return isThisParam(node.parent.init.function!.params[0]) + } + return false + } + if (arkts.isClassProperty(node)) { + if (arkts.isArrowFunctionExpression(node.value)) { + return isThisParam(node.value.function!.params[0]) + } + return false + } + assertIsNever(node) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/utils.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/utils.ts index dd3abd50a4a..c88eb3d60ef 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/utils.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/src/utils.ts @@ -33,6 +33,7 @@ export enum RuntimeNames { CONTEXT_TYPE = "__memo_context_type", CONTEXT_TYPE_DEFAULT_IMPORT = "@koalaui/runtime", GENSYM = "gensym%%_", + HASH = "__hash", ID = "__memo_id", ID_TYPE = "__memo_id_type", INTERNAL_PARAMETER_STATE = "param", @@ -84,7 +85,7 @@ export class PositionalIdTracker { return `${PositionalIdTracker.callCount++}_${callName}_${fileName}` } - id(callName: string = ""): arkts.NumberLiteral | arkts.StringLiteral { + id(callName: string = ""): arkts.Expression { const fileName = this.stableForTests ? baseName(this.filename) : @@ -96,7 +97,14 @@ export class PositionalIdTracker { return this.stableForTests - ? arkts.factory.createStringLiteral(positionId) + ? arkts.factory.createCallExpression( + arkts.factory.createIdentifier(RuntimeNames.HASH), + [arkts.factory.createStringLiteral(positionId)], + undefined, + false, + false, + undefined + ) : arkts.factory.createNumberLiteral(parseInt(positionId, 16)) } } @@ -156,7 +164,7 @@ export function getMemoFunctionKind(node: MemoAnnotatable): MemoFunctionKind { } export function isWrappable(type: arkts.TypeNode | undefined, arg: arkts.Expression) { - return (type && correctFunctionParamType(type)) || correctObjectExpression(arg) + return (type && correctFunctionParamType(arg)) || correctObjectExpression(arg) } export function isTrackableParam(node: arkts.ETSParameterExpression, isLast: boolean) { @@ -191,22 +199,24 @@ export function isSyntheticReturnStatement(node: arkts.AstNode) { ) || ( arkts.isBlockStatement(node) && node.statements.length === 2 && - arkts.isMemberExpression(node.statements[0]) && - arkts.isIdentifier(node.statements[0].object) && - node.statements[0].object.name === RuntimeNames.SCOPE && - arkts.isIdentifier(node.statements[0].property) && - node.statements[0].property.name === RuntimeNames.INTERNAL_VALUE && + arkts.isExpressionStatement(node.statements[0]) && + arkts.isMemberExpression(node.statements[0].expression) && + arkts.isIdentifier(node.statements[0].expression.object) && + node.statements[0].expression.object.name === RuntimeNames.SCOPE && + arkts.isIdentifier(node.statements[0].expression.property) && + node.statements[0].expression.property.name === RuntimeNames.INTERNAL_VALUE && arkts.isReturnStatement(node.statements[1]) && node.statements[1].argument && arkts.isThisExpression(node.statements[1].argument) ) || ( arkts.isBlockStatement(node) && node.statements.length === 2 && - arkts.isMemberExpression(node.statements[0]) && - arkts.isIdentifier(node.statements[0].object) && - node.statements[0].object.name === RuntimeNames.SCOPE && - arkts.isIdentifier(node.statements[0].property) && - node.statements[0].property.name === RuntimeNames.INTERNAL_VALUE && + arkts.isExpressionStatement(node.statements[0]) && + arkts.isMemberExpression(node.statements[0].expression) && + arkts.isIdentifier(node.statements[0].expression.object) && + node.statements[0].expression.object.name === RuntimeNames.SCOPE && + arkts.isIdentifier(node.statements[0].expression.property) && + node.statements[0].expression.property.name === RuntimeNames.INTERNAL_VALUE && arkts.isReturnStatement(node.statements[1]) && node.statements[1].argument == undefined ) @@ -255,3 +265,10 @@ export function getDeclResolveGensym(node: arkts.AstNode): arkts.AstNode | undef } return decl } + +export function moveToFront(arr: T[], idx: number): T[] { + if (idx >= arr.length) { + throw new Error(`Invalid argument, size of array: ${arr.length}, idx: ${idx}`) + } + return [arr[idx], ...arr.slice(0, idx), ...arr.slice(idx + 1)] +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/.gitignore b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/.gitignore new file mode 100644 index 00000000000..4fcb201b72b --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/.gitignore @@ -0,0 +1,3 @@ +build/ +out/ +ets/ diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/arktsconfig-executable.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/arktsconfig-executable.json new file mode 100644 index 00000000000..0cb699f0c71 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/arktsconfig-executable.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "package": "@test", + "outDir": "../build", + "baseUrl": ".", + "paths": { + "@koalaui/common": ["../../../incremental/common/src"], + "@koalaui/compat": ["../../../incremental/compat/src/arkts"], + "@koalaui/harness": ["../../../incremental/harness/src/arkts"], + "@koalaui/runtime": ["../../../incremental/runtime/src"], + "@koalaui/runtime/annotations": ["../../../incremental/runtime/annotations"] + }, + "plugins": [ + { + "transform": "@koalaui/memo-plugin", + "stage": "checked", + "name": "memo" + } + ] + }, + "include": [ + "./ets/**/*.ts" + ], + "exclude": [ + "./ets/diagnostics-input/**" + ], + "dependencies": { + "@koalaui/runtime": ["../../../incremental/runtime/ui2abcconfig.json"] + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/arktsconfig-golden.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/arktsconfig-golden.json new file mode 100644 index 00000000000..fe70c91a4c6 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/arktsconfig-golden.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "package": "@test", + "outDir": "build/abc", + "baseUrl": ".", + "paths": { + "@koalaui/compat": [ "../../../incremental/compat/src/arkts" ], + "#platform": [ "../../../incremental/compat/src/arkts" ], + "@koalaui/common": [ "../../../incremental/common/src" ], + "@koalaui/runtime": [ "../../../incremental/runtime/ets" ], + "@koalaui/runtime/annotations": [ "../../../incremental/runtime/annotations" ] + }, + "plugins": [ + { + "transform": "../lib/ParserTransformer", + "stage": "parsed", + "stableForTests": true, + "name": "memo" + }, + { + "transform": "../lib/MemoTransformer", + "stage": "checked", + "keepTransformed": "../test/out", + "stableForTests": true, + "manuallyDisableInsertingImport": true + } + ] + }, + "include": ["./test.ets"] +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/diagnostics.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/diagnostics.test.ts new file mode 100644 index 00000000000..9a6177fcd81 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/diagnostics.test.ts @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022-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 { assert } from "chai" +import * as child from "child_process" +import * as path from "path" + +function runTsc(file: string) { + return child.spawnSync("../../incremental/tools/panda/arkts/ui2abc", [ + "--arktsconfig", path.join("test", "arktsconfig-golden.json"), + "--output", file, + path.join('test', 'diagnostics', 'input', file), + ]) +} + +function diagnostics(name: string, file: string, message: string) { + test(name, () => { + const result = runTsc(file) + const out = result.stdout.toString() + "\n" + result.stderr.toString() + if (!out.includes(message)) + console.error(out) + assert.include(out, message) + }).timeout(30000); +} + +function noDiagnostics(name: string, file: string, message: string) { + test(name, () => { + const result = runTsc(file) + const out = result.stdout.toString() + "\n" + result.stderr.toString() + if (out.includes(message)) + console.error(out) + assert.notInclude(out, message) + }).timeout(30000); +} + +suite("Smoke", () => { + diagnostics("smoke", + "smoke.input.ts", + "SyntaxError: Unexpected token 'syntax'." + ) +}) + +suite("Memo in non-memo context", () => { + diagnostics("global memo", + "global_memo.input.ts", + 'Attempt to call @memo-method foo from non-@memo-method _$init$_' + ) + diagnostics("memo in handler", + "memo_in_handler.input.ts", + 'Attempt to call @memo-method foo from anonymous non-@memo-method' + ) + diagnostics("memo in inner function", + "memo_in_inner_function.input.ts", + 'Attempt to call @memo-method foo from anonymous non-@memo-method' + ) + noDiagnostics("memo with @memo:entry", + "memo_entry.input.ts", + 'Attempt to call @memo-method foo from' + ) + diagnostics("memo in non-memo stack", + "no_memo_entry.input.ts", + 'Attempt to call @memo-method foo from non-@memo-method bar' + ) +}) + +// suite("Shorthand @memo property assignment", () => { +// diagnostics("shorthand assignment to @memo property", +// "PropertyShorthandAssignment.ts", +// "Can not shorthand assign to memo property: x" +// ) +// noDiagnostics("shorthand assignment to non-memo property", +// "NonmemoPropertyShorthandAssignment.ts", +// "Can not shorthand assign to memo property: x" +// ) +// }) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/changeListener.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/NonmemoPropertyShorthandAssignment.ts similarity index 63% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/changeListener.ets rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/NonmemoPropertyShorthandAssignment.ts index bcaa2a50c47..fcf64c35252 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/memo/changeListener.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/NonmemoPropertyShorthandAssignment.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -13,6 +13,12 @@ * limitations under the License. */ -import { memo_intrinsic } from "../annotations" -@memo_intrinsic export declare function OnChange(value: Value, listener: (value: Value) => void): void -@memo_intrinsic export declare function RunEffect(value: Value, effect: (value: Value) => void): void +import { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "@koalaui/runtime/annotations" + +class Test { + x: ()=>void = ()=>{} +} + +const x: ()=>void = ()=>{} + +const test:Test = { x } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreePath.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/PropertyShorthandAssignment.ts similarity index 60% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreePath.ets rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/PropertyShorthandAssignment.ts index 55be5f191c5..c01a2ba57f2 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/TreePath.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/PropertyShorthandAssignment.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -13,13 +13,15 @@ * limitations under the License. */ -import { uint32 } from "../common" -export declare class TreePath { - readonly node: Node - readonly parent: TreePath | undefined - constructor(node: Node, parent?: TreePath) - child(node: Node): TreePath - get root(): TreePath - get depth(): uint32 - toString(): string +import { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "@koalaui/runtime/annotations" + +class Test { + @memo x: ()=>void } +function foo(test:Test) {} +const x = ()=>{} + + +foo({ x }) +let test:Test = { x } +test = { x } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/global_memo.input.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/global_memo.input.ts new file mode 100644 index 00000000000..9c22baa7958 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/global_memo.input.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022-2023 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 { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "@koalaui/runtime/annotations" + +@memo function foo() { } +foo() diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_entry.input.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_entry.input.ts new file mode 100644 index 00000000000..064fbec944e --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_entry.input.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022-2023 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 { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "@koalaui/runtime/annotations" + +@memo +function foo() { } + +@memo:entry +function bar() { + foo() +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_in_handler.input.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_in_handler.input.ts new file mode 100644 index 00000000000..65b8f0213d5 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_in_handler.input.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022-2023 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 { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "@koalaui/runtime/annotations" + +@memo +function foo() { } + +@memo +function bar() { + const x = () => { + foo() + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_in_inner_function.input.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_in_inner_function.input.ts new file mode 100644 index 00000000000..d543f3ac472 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/memo_in_inner_function.input.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022-2023 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 { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "@koalaui/runtime/annotations" + +@memo +function foo() { } + +@memo +function bar() { + const qux = () => { + foo() + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/no_memo_entry.input.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/no_memo_entry.input.ts new file mode 100644 index 00000000000..76c782d51d4 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/no_memo_entry.input.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022-2023 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 { memo, memo_intrinsic, memo_entry, memo_stable, memo_skip } from "@koalaui/runtime/annotations" + +@memo +function foo() { } + +function bar() { + foo() +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/ReadonlyTreeNode.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/smoke.input.ts similarity index 76% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/ReadonlyTreeNode.ets rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/smoke.input.ts index 7c7d9f52f3b..797d4d30f2d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/tree/ReadonlyTreeNode.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/diagnostics/input/smoke.input.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -13,7 +13,4 @@ * limitations under the License. */ -export declare interface ReadonlyTreeNode { - readonly parent: ReadonlyTreeNode | undefined - toHierarchy(): string -} +bad syntax here \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/golden/test.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/golden/test.ets new file mode 100644 index 00000000000..264235366b0 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/golden/test.ets @@ -0,0 +1,460 @@ + +import { __memo_context_type as __memo_context_type, __memo_id_type as __memo_id_type, __hash as __hash } from "@koalaui/runtime"; + +import { memo as memo, memo_stable as memo_stable, memo_intrinsic as memo_intrinsic, memo_entry as memo_entry } from "@koalaui/runtime/annotations"; + +import { __context as __context, __id as __id } from "@koalaui/runtime"; + +function main() {} + + +@memo() function param_capturing(__memo_context: __memo_context_type, __memo_id: __memo_id_type, s: string) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_param_capturing_@test.test.ets"))), 1); + const __memo_parameter_s = __memo_scope.param(0, s); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + let x = (() => { + console.log(__memo_parameter_s.value); + }); + x(); + let y = ((s: string) => { + console.log(s); + }); + y("she"); + { + __memo_scope.recache(); + return; + } +} + +@memo() function memo_arg_call(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg1: number, arg2: ((x: number)=> number), @memo() arg3: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, x: number)=> number), arg4?: ((x: number)=> number), @memo() arg5?: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, x: number)=> number)) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_memo_arg_call_@test.test.ets"))), 5); + const __memo_parameter_arg1 = __memo_scope.param(0, arg1), __memo_parameter_arg2 = __memo_scope.param(1, arg2), __memo_parameter_arg3 = __memo_scope.param(2, arg3), __memo_parameter_arg4 = __memo_scope.param(3, arg4), __memo_parameter_arg5 = __memo_scope.param(4, arg5); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_parameter_arg2.value(__memo_parameter_arg1.value); + __memo_parameter_arg3.value(__memo_context, ((__memo_id) + (__hash("id_arg3_@test.test.ets"))), __memo_parameter_arg1.value); + ({let gensym%%_265 = __memo_parameter_arg4.value; + (((gensym%%_265) == (null)) ? undefined : gensym%%_265(__memo_parameter_arg1.value))}); + ({let gensym%%_266 = __memo_parameter_arg5.value; + (((gensym%%_266) == (null)) ? undefined : gensym%%_266(__memo_context, ((__memo_id) + (__hash("id_arg5_@test.test.ets"))), __memo_parameter_arg1.value))}); + { + __memo_scope.recache(); + return; + } +} + + +type MemoType = @memo() ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void); + +@memo() type AnotherMemoType = ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void); + +@memo() type OneMoreMemoType = @memo() ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void); + +class A { + public x: int; + + public y: int; + + public constructor() {} + +} + +class Test { + @memo() public void_method(__memo_context: __memo_context_type, __memo_id: __memo_id_type): void { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_void_method_@test.test.ets"))), 1); + const __memo_parameter_this = __memo_scope.param(0, (this)); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo() public a_method_with_implicit_return_type(__memo_context: __memo_context_type, __memo_id: __memo_id_type) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_a_method_with_implicit_return_type_@test.test.ets"))), 1); + const __memo_parameter_this = __memo_scope.param(0, (this)); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo() public void_method_with_arg(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg: string) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_void_method_with_arg_@test.test.ets"))), 2); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg = __memo_scope.param(1, arg); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo() public void_method_with_return(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg: string) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_void_method_with_return_@test.test.ets"))), 2); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg = __memo_scope.param(1, arg); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo() public string_method_with_return(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg: string): string { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_string_method_with_return_@test.test.ets"))), 2); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg = __memo_scope.param(1, arg); + if (__memo_scope.unchanged) { + return __memo_scope.cached; + } + return __memo_scope.recache(__memo_parameter_arg.value); + } + + @memo() public method_with_type_parameter(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg: T): T { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_method_with_type_parameter_@test.test.ets"))), 2); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg = __memo_scope.param(1, arg); + if (__memo_scope.unchanged) { + return __memo_scope.cached; + } + return __memo_scope.recache(__memo_parameter_arg.value); + } + + @memo() public static static_method_with_type_parameter(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg: T): void { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_static_method_with_type_parameter_@test.test.ets"))), 1); + const __memo_parameter_arg = __memo_scope.param(0, arg); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo() public internal_call(__memo_context: __memo_context_type, __memo_id: __memo_id_type) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_internal_call_@test.test.ets"))), 1); + const __memo_parameter_this = __memo_scope.param(0, (this)); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_parameter_this.value.void_method(__memo_context, ((__memo_id) + (__hash("id_void_method_@test.test.ets")))); + { + __memo_scope.recache(); + return; + } + } + + @memo() public lambda_arg(__memo_context: __memo_context_type, __memo_id: __memo_id_type, @memo() arg: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void)) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_lambda_arg_@test.test.ets"))), 2); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg = __memo_scope.param(1, arg); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo() public lambda_arg_with_arg(__memo_context: __memo_context_type, __memo_id: __memo_id_type, @memo() arg: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, value: string)=> string)) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_lambda_arg_with_arg_@test.test.ets"))), 2); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg = __memo_scope.param(1, arg); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo_intrinsic() public intrinsic_method(__memo_context: __memo_context_type, __memo_id: __memo_id_type): int { + return 0; + } + + @memo_intrinsic() public intrinsic_method_with_this(__memo_context: __memo_context_type, __memo_id: __memo_id_type): int { + (this).void_method(__memo_context, ((__memo_id) + (__hash("id_void_method_@test.test.ets")))); + return 0; + } + + @memo() public method_with_internals(__memo_context: __memo_context_type, __memo_id: __memo_id_type) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_method_with_internals_@test.test.ets"))), 1); + const __memo_parameter_this = __memo_scope.param(0, (this)); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_context; + __memo_id; + { + __memo_scope.recache(); + return; + } + } + + @memo() public obj_arg(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg: A) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_obj_arg_@test.test.ets"))), 2); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg = __memo_scope.param(1, arg); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo_entry() public memoEntry(__memo_context: __memo_context_type, __memo_id: __memo_id_type, @memo() entry: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> R)): R { + const getContext = (() => { + return __memo_context; + }); + const getId = (() => { + return __memo_id; + }); + { + const __memo_context = getContext(); + const __memo_id = getId(); + return entry(__memo_context, ((__memo_id) + (__hash("id_entry_@test.test.ets")))); + } + } + + @memo() public memo_content(__memo_context: __memo_context_type, __memo_id: __memo_id_type, @memo() content: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void)) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_memo_content_@test.test.ets"))), 1); + const __memo_parameter_this = __memo_scope.param(0, (this)); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + content(__memo_context, ((__memo_id) + (__hash("id_content_@test.test.ets")))); + { + __memo_scope.recache(); + return; + } + } + + public memo_lambda() { + @memo() ((__memo_context: __memo_context_type, __memo_id: __memo_id_type) => { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id__@test.test.ets"))), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + }); + } + + @memo() public memo_variables(__memo_context: __memo_context_type, __memo_id: __memo_id_type) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_memo_variables_@test.test.ets"))), 1); + const __memo_parameter_this = __memo_scope.param(0, (this)); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + @memo() const f = ((__memo_context: __memo_context_type, __memo_id: __memo_id_type): number => { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id__@test.test.ets"))), 0); + if (__memo_scope.unchanged) { + return __memo_scope.cached; + } + return __memo_scope.recache(123); + }), g = ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, x: number): number => { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id__@test.test.ets"))), 1); + const __memo_parameter_x = __memo_scope.param(0, x); + if (__memo_scope.unchanged) { + return __memo_scope.cached; + } + return __memo_scope.recache(((123) + (x))); + }); + const h = @memo() ((__memo_context: __memo_context_type, __memo_id: __memo_id_type): number => { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id__@test.test.ets"))), 0); + if (__memo_scope.unchanged) { + return __memo_scope.cached; + } + return __memo_scope.recache(1); + }); + f(__memo_context, ((__memo_id) + (__hash("id_f_@test.test.ets")))); + g(__memo_context, ((__memo_id) + (__hash("id_g_@test.test.ets"))), 1); + h(__memo_context, ((__memo_id) + (__hash("id_h_@test.test.ets")))); + { + __memo_scope.recache(); + return; + } + } + + @memo() public compute_test(__memo_context: __memo_context_type, __memo_id: __memo_id_type, @memo() arg1: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) | undefined, arg2: (()=> void) | undefined, content: (()=> void) | undefined): void { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_compute_test_@test.test.ets"))), 3); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg1 = __memo_scope.param(1, arg1), __memo_parameter_arg2 = __memo_scope.param(2, arg2); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + } + + @memo() public args_with_default_values(__memo_context: __memo_context_type, __memo_id: __memo_id_type, gensym%%_1?: int, gensym%%_2?: (()=> int), gensym%%_3?: int, arg4?: int): void { + let arg1: int = (((gensym%%_1) !== (undefined)) ? gensym%%_1 : (10 as int)); + let arg2: (()=> int) = (((gensym%%_2) !== (undefined)) ? gensym%%_2 : ((() => { + return 20; + }) as (()=> int))); + let arg3: int = (((gensym%%_3) !== (undefined)) ? gensym%%_3 : (arg1 as int)); + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_args_with_default_values_@test.test.ets"))), 5); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg1 = __memo_scope.param(1, arg1), __memo_parameter_arg2 = __memo_scope.param(2, arg2), __memo_parameter_arg3 = __memo_scope.param(3, arg3), __memo_parameter_arg4 = __memo_scope.param(4, arg4); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + console.log(__memo_parameter_arg1.value, __memo_parameter_arg2.value, __memo_parameter_arg3.value, __memo_parameter_arg4.value); + console.log(__memo_parameter_arg2.value()); + { + __memo_scope.recache(); + return; + } + } + + @memo() public optional_args(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg1?: int, arg2?: (()=> int)) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_optional_args_@test.test.ets"))), 3); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg1 = __memo_scope.param(1, arg1), __memo_parameter_arg2 = __memo_scope.param(2, arg2); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + console.log(__memo_parameter_arg1.value); + console.log(__memo_parameter_arg2.value); + console.log(({let gensym%%_264 = __memo_parameter_arg2.value; + (((gensym%%_264) == (null)) ? undefined : gensym%%_264())})); + { + __memo_scope.recache(); + return; + } + } + + @memo() public type_alias(__memo_context: __memo_context_type, __memo_id: __memo_id_type, arg: MemoType) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_type_alias_@test.test.ets"))), 2); + const __memo_parameter_this = __memo_scope.param(0, (this)), __memo_parameter_arg = __memo_scope.param(1, arg); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_parameter_arg.value(__memo_context, ((__memo_id) + (__hash("id_arg_@test.test.ets")))); + { + __memo_scope.recache(); + return; + } + } + + public constructor() {} + +} + +declare class AbstractTest { + public test_signature(@memo() arg1: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void), @memo() arg2: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) | undefined, @memo() arg3: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) | undefined | ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> int) | undefined, @memo() x: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, y: ((z: @memo() ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void))=> void))=> void)): @memo() ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) + + public constructor() {} + +} + +class Use { + @memo() public test(__memo_context: __memo_context_type, __memo_id: __memo_id_type) { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id_test_@test.test.ets"))), 1); + const __memo_parameter_this = __memo_scope.param(0, (this)); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + const test = new Test(); + test.void_method(__memo_context, ((__memo_id) + (__hash("id_void_method_@test.test.ets")))); + test.void_method_with_arg(__memo_context, ((__memo_id) + (__hash("id_void_method_with_arg_@test.test.ets"))), "an arg"); + test.void_method_with_return(__memo_context, ((__memo_id) + (__hash("id_void_method_with_return_@test.test.ets"))), "a value"); + Test.static_method_with_type_parameter(__memo_context, ((__memo_id) + (__hash("id_static_method_with_type_parameter_@test.test.ets"))), "I'm static"); + test.string_method_with_return(__memo_context, ((__memo_id) + (__hash("id_string_method_with_return_@test.test.ets"))), "a string"); + test.method_with_type_parameter(__memo_context, ((__memo_id) + (__hash("id_method_with_type_parameter_@test.test.ets"))), "I'm string"); + test.lambda_arg(__memo_context, ((__memo_id) + (__hash("id_lambda_arg_@test.test.ets"))), __memo_context.compute(((__memo_id) + (__hash("id_lambda_arg_@test.test.ets"))), ((): ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) => { + return ((__memo_context: __memo_context_type, __memo_id: __memo_id_type): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id__@test.test.ets"))), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + }); + }))); + test.lambda_arg_with_arg(__memo_context, ((__memo_id) + (__hash("id_lambda_arg_with_arg_@test.test.ets"))), __memo_context.compute(((__memo_id) + (__hash("id_lambda_arg_with_arg_@test.test.ets"))), ((): ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, value: string)=> string) => { + return ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, value: string): string => { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id__@test.test.ets"))), 1); + const __memo_parameter_value = __memo_scope.param(0, value); + if (__memo_scope.unchanged) { + return __memo_scope.cached; + } + return __memo_scope.recache(__memo_parameter_value.value); + }); + }))); + test.obj_arg(__memo_context, ((__memo_id) + (__hash("id_obj_arg_@test.test.ets"))), __memo_context.compute(((__memo_id) + (__hash("id_obj_arg_@test.test.ets"))), ((): A => { + return ({ + x: 1, + y: 2, + } as A); + }))); + test.compute_test(__memo_context, ((__memo_id) + (__hash("id_compute_test_@test.test.ets"))), __memo_context.compute(((__memo_id) + (__hash("id_compute_test_@test.test.ets"))), ((): ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) => { + return ((__memo_context: __memo_context_type, __memo_id: __memo_id_type): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (__hash("id__@test.test.ets"))), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + { + __memo_scope.recache(); + return; + } + }); + })), __memo_context.compute(((__memo_id) + (__hash("id_compute_test_@test.test.ets"))), ((): (()=> void) => { + return ((): void => {}); + })), ((): void => {})); + { + __memo_scope.recache(); + return; + } + } + + public constructor() {} + +} + +interface InterfaceWithSetter { + @memo() set f(f: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void)) + +} + +interface InterfaceWithGetter { + @memo() get f(): ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) + +} + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/package.json new file mode 100644 index 00000000000..6dde1fdf036 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/package.json @@ -0,0 +1,11 @@ +{ + "scripts": { + "run": "../../../incremental/tools/panda/arkts/ui2abc --arktsconfig ./arktsconfig-golden.json --output ./build/test.abc ./test.ets", + "clean": "rm -rf out", + "test": "npm run clean && (npm run run 2> /dev/null || true) && diff golden/test.ets out/test.ets", + "test:debug": "npm run clean && npm run run", + "TODO": "get rid of old rewrite tests", + "test:mocha": "npm run compile --prefix ../../../incremental/harness && mocha", + "test:mocha:golden": "npm run compile --prefix ../../../incremental/harness && TEST_GOLDEN=1 mocha" + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/rewrite.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/rewrite.test.ts new file mode 100644 index 00000000000..77af0c7696e --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/rewrite.test.ts @@ -0,0 +1,203 @@ + + +import * as fs from "node:fs" +import * as child_process from "node:child_process" +import * as path from "node:path" +import { Assert, suite, test } from "@koalaui/harness" + +function makeFilesEqual(filePath: string) { + const out = fs.readFileSync(`./out/${filePath}.ets`, 'utf-8') + fs.mkdirSync(path.dirname(`./golden/${filePath}`), { recursive: true }) + fs.writeFileSync(`./golden/${filePath}.ets`, out) +} + +function assertFilesEqual(filePath: string) { + const golden = fs.readFileSync(`./golden/${filePath}.ets`, 'utf-8') + const out = fs.readFileSync(`./out/${filePath}.ets`, 'utf-8') + Assert.equal(out, golden) +} + +function testBody(path: string) { + if (process.env.TEST_GOLDEN == "1") { + makeFilesEqual(path) + } else { + assertFilesEqual(path) + } +} + +suite("golden tests", () => { + + test.expectFailure("compile", () => { + child_process.execSync("rm -rf ../build/golden", { stdio: "inherit" }) + child_process.execSync("rm -rf out", { stdio: "inherit" }) + child_process.execSync("npx fast-arktsc --config ./input/arktsconfig.json --compiler ../../../incremental/tools/panda/arkts/ui2abc --link-name ../build/golden/all.abc && ninja -f ../build/golden/build.ninja -k 1000", { stdio: "inherit" }) + }) + + suite("basic", () => { + test("function", () => { + testBody("basic/function") + }) + + test("method", () => { + testBody("basic/method") + }) + + test("arrow", () => { + testBody("basic/arrow") + }) + }) + + suite("HQ", () => { + test.skip("memo class property implemented from interface", () => { + testBody("HQ/implemented-property") + }) + + test("memo class method with memo argument with void return type", () => { + testBody("HQ/void-compute") + }) + + test("memo class method with memo argument with argument with void return type", () => { + testBody("HQ/string-compute") + }) + + test("memo class method with memo argument with void return type and call the memo argument within the method", () => { + testBody("HQ/content-usage") + }) + + test("memo class method with memo argument with void return type (for `compute` function)", () => { + testBody("HQ/compute") + }) + + test("callable class with memo $_invoke", () => { + testBody("HQ/invoke") + }) + + test("callable class with non-memo $_invoke with memo argument", () => { + testBody("HQ/invoke-param") + }) + + test("callable class with $_instantiate with memo argument", () => { + testBody("HQ/instantiate") + }) + + test("declared abstract class with memo method with argument", () => { + testBody("HQ/abstract") + }) + + test("memo class method with internal call", () => { + testBody("HQ/internal-call") + }) + + test("memo class method with internal __context() and __id()", () => { + testBody("HQ/internals") + }) + + test("class method with internal memo lambda", () => { + testBody("HQ/arrow") + }) + + test("memo class method with internal variables assigned to memo lambda", () => { + testBody("HQ/arrow-assignment") + }) + + test("memo class method with internal function calls that has default value in parameter", () => { + testBody("HQ/param-calls") + }) + + test("memo class method with internal function calls that is optional parameter", () => { + testBody("HQ/param-calls-optional") + }) + + test("memo class method with internal argument call with reffered memo type", () => { + testBody("HQ/call-type") + }) + + test("memo class method with void return type", () => { + testBody("HQ/void-method") + }) + + test("memo class method with non-void return type", () => { + testBody("HQ/string-method") + }) + + test("memo class method with type parameter", () => { + testBody("HQ/type-param-method") + }) + + test("memo class method with @memo_intrinsic", () => { + testBody("HQ/intrinsic") + }) + + test("memo class method with @memo_intrinsic and internal call memo method", () => { + testBody("HQ/intrinsic-call") + }) + + test("memo class method with @memo_entry", () => { + testBody("HQ/entry") + }) + + test("memo class method with implicit return type", () => { + testBody("HQ/implicit-void-method") + }) + + test("memo class method with parameter with void return type", () => { + testBody("HQ/void-method-with-param") + }) + + test("memo class method with return in function body with void return type", () => { + testBody("HQ/void-method-with-return") + }) + + test("memo static class method with void return type", () => { + testBody("HQ/static-void-method") + }) + + test("memo class method with object parameter with void return type", () => { + testBody("HQ/object-param") + }) + + test("class constructor has parameter that is referred to a defined interface with memo property", () => { + testBody("HQ/property-constructor") + }) + + test("non memo class property", () => { + testBody("HQ/non-memo-property") + }) + + test("memo class property", () => { + testBody("HQ/memo-property") + }) + + test("optional memo class property", () => { + testBody("HQ/memo-property-optional") + }) + + test("union memo class property with default value", () => { + testBody("HQ/memo-property-union-type") + }) + + test("class property with memo type", () => { + testBody("HQ/memo-property-type") + }) + + test("non-memo interface property", () => { + testBody("HQ/non-memo-interface-property") + }) + + test("memo interface property", () => { + testBody("HQ/memo-interface-property") + }) + + test("optional memo interface property", () => { + testBody("HQ/memo-interface-property-optional") + }) + + test("memo interface property with union type", () => { + testBody("HQ/memo-interface-property-union-type") + }) + + test("interface property with memo type", () => { + testBody("HQ/memo-interface-property-type") + }) + }) +}) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/test.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/test.ets new file mode 100644 index 00000000000..c2563ba7048 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/test.ets @@ -0,0 +1,235 @@ +/* + * 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 { memo, memo_stable, memo_intrinsic, memo_entry } from "@koalaui/runtime/annotations" +import { __context, __id } from "@koalaui/runtime" + +type MemoType = @memo () => void +@memo type AnotherMemoType = () => void +@memo type OneMoreMemoType = @memo () => void + + +@memo function param_capturing(s: string) { + let x = () => { + console.log(s) + } + x() + let y = (s: string) => { + console.log(s) + } + y("she") +} + +@memo function memo_arg_call( + arg1: number, + arg2: (x: number) => number, + @memo arg3: (x: number) => number, + arg4?: (x: number) => number, + @memo arg5?: (x: number) => number, +) { + arg2(arg1) + arg3(arg1) + arg4?.(arg1) + arg5?.(arg1) +} + +// Disabled for now it breaks recheck + +// @memo function call_with_receiver(obj: A, @memo v: (this: A) => int): int { +// const x = obj.v() +// const y = v(obj) +// return x + y +// } + +// @memo function test_call_with_receiver() { +// const a = new A() +// const f = @memo (this: A): int => { +// return 11 +// } +// call_with_receiver(a, f) +// } + +class A { + x: int + y: int +} + +class Test { + + @memo void_method(): void { + } + + @memo a_method_with_implicit_return_type() { + } + + @memo void_method_with_arg(arg: string) { + } + + @memo void_method_with_return(arg: string) { + return + } + + @memo string_method_with_return(arg: string): string { + return arg + } + + @memo method_with_type_parameter(arg: T): T { + return arg + } + + @memo static static_method_with_type_parameter(arg: T): void { + return + } + + @memo internal_call() { + this.void_method() + } + + @memo lambda_arg(@memo arg: () => void) { + + } + + @memo lambda_arg_with_arg(@memo arg: (value: string) => string) { + + } + + @memo_intrinsic intrinsic_method(): int { + return 0 + } + + @memo_intrinsic intrinsic_method_with_this(): int { + this.void_method() + return 0 + } + + @memo method_with_internals() { + __context() + __id() + } + + @memo obj_arg(arg: A) { + + } + + @memo_entry memoEntry(__memo_context: __memo_context_type, __memo_id: __memo_id_type, @memo entry: () => R): R { + const getContext = () => { + return __context() + } + const getId = () => { + return __id() + } + { + const __memo_context = getContext() + const __memo_id = getId() + return entry() + } + } + + @memo memo_content(@memo content: () => void) { + content() + } + + memo_lambda() { + @memo () => { + + } + } + + @memo memo_variables() { + @memo const f = (): number => { + return 123 + }, g = (x: number): number => { + return 123 + x + } + + const h = @memo (): number => { + return 1 + } + + f() + g(1) + h() + } + + @memo compute_test( + @memo arg1: (() => void) | undefined, + arg2: (() => void) | undefined, + content: (() => void) | undefined + ): void { + + } + + @memo args_with_default_values( + arg1: int = 10, + arg2: () => int = () => { return 20 }, + arg3: int = arg1, + arg4?: int + ): void { + console.log(arg1, arg2, arg3, arg4) + console.log(arg2()) + } + + @memo optional_args( + arg1?: int, + arg2?: () => int + ) { + console.log(arg1) + console.log(arg2) + console.log(arg2?.()) + } + + @memo type_alias( + arg: MemoType + ) { + arg() + } +} + +declare class AbstractTest { + test_signature( + @memo arg1: () => void, + @memo arg2: (() => void) | undefined, + @memo arg3: ((() => void) | undefined) | ((() => int) | undefined), + @memo x: (y: (z: @memo () => void) => void) => void, + ): @memo () => void +} + +class Use { + @memo test() { + const test = new Test() + + test.void_method() + test.void_method_with_arg("an arg") + test.void_method_with_return("a value") + Test.static_method_with_type_parameter("I'm static") + + test.string_method_with_return("a string") + test.method_with_type_parameter("I'm string") + + test.lambda_arg((): void => {}) + test.lambda_arg_with_arg((value: string): string => value) + + test.obj_arg({ x: 1, y: 2 }) + test.compute_test((): void => {}, (): void => {}, (): void => {}) + } +} + +interface InterfaceWithSetter { + @memo set f(f: () => void) +} + +interface InterfaceWithGetter { + @memo get f(): () => void +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/tsconfig.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/tsconfig.json new file mode 100644 index 00000000000..5e2e279cb29 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "baseUrl": "./", + "outDir": "../build/test", + "module": "CommonJS", + "noEmit": true, + "removeComments": false, + "paths": { + "@koalaui/harness": ["../../../incremental/harness/src/typescript"] + } + }, + "include": [] +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/package.json index ef3fcdbcb79..42aa809c777 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/package.json @@ -4,15 +4,18 @@ "workspaces": [ "./annotate", "./libarkts", + "./fast-arktsc", "./memo-plugin", "./ui-plugins", + "./tests-memo", "../incremental/build-common", "../interop", - "../incremental/harness" + "../incremental/harness", + "../incremental/common", + "../incremental/compat" ], "devDependencies": { "@koalaui/ets-tsc": "4.9.5-r5", - "@koalaui/fast-arktsc": "1.5.15", "@types/chai": "^4.3.1", "@types/mocha": "^9.1.0", "bin-links": "^4.0.4", @@ -35,9 +38,9 @@ "commander": "^13.1.0" }, "scripts": { - "clean:all": "npm run clean --prefix libarkts && npm run clean:plugins --prefix libarkts && npm run clean --prefix memo-plugin && npm run runtime:clean --prefix memo-plugin && npm run clean --prefix memo-plugin/demo", - "build:all": "npm run compile --prefix libarkts && npm run compile:plugins --prefix libarkts && npm run compile --prefix memo-plugin && npm run runtime:prepare --prefix memo-plugin && npm run compile --prefix ui-plugins", - "test:all": "npm run build:arkui:pure-ets --prefix ../arkoala-arkts/arkui && npm run run --prefix libarkts && npm run test --prefix libarkts && npm run demo:run --prefix memo-plugin && npm run test:all --prefix memo-plugin", + "clean:all": "npm run clean --prefix libarkts && npm run clean:plugins --prefix libarkts && npm run clean --prefix memo-plugin && npm run runtime:clean --prefix memo-plugin && npm run clean --prefix memo-plugin/demo && npm run clean --prefix ../arkoala-arkts/arkui && npm run clean --prefix ../arkoala-arkts/trivial/user", + "build:all": "npm run compile --prefix fast-arktsc && npm run compile --prefix libarkts && npm run compile:plugins --prefix libarkts && npm run compile --prefix memo-plugin && npm run runtime:prepare --prefix memo-plugin && npm run compile --prefix ui-plugins", + "test:all": "npm run build:harness --prefix ../incremental/harness && npm run test --prefix libarkts && npm run demo:run --prefix memo-plugin && npm run test:all --prefix memo-plugin", "all": "npm run clean:all && npm run build:all && npm run test:all" } } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/.gitignore b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/.gitignore new file mode 100644 index 00000000000..dca115d7eff --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/.gitignore @@ -0,0 +1,3 @@ +test/ets +test/unmemoized +build \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/.mocharc.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/.mocharc.json new file mode 100644 index 00000000000..5825b072feb --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/.mocharc.json @@ -0,0 +1,14 @@ +{ + "ui": "tdd", + "spec": "./test/**/*.test.ts", + "exclude": [ + "./test/ets/**/*", + "./test/unmemoized/**/*", + "./test/ui2abc/**/*.ts", + "./test/arkts/**/*", + "./test/ui2abc_run.ts", + "./test/artks_run.ts" + ], + "extension": ["ts"], + "require": ["../../incremental/test-utils/scripts/register"] +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/annotate-tests.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/annotate-tests.json new file mode 100644 index 00000000000..be0f91028b1 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/annotate-tests.json @@ -0,0 +1,12 @@ +{ + "inputDir": "./test/", + "outputDir": "./test/ets", + "include": ["./test/**/*.ts"], + "exclude": [ + "./test/arkts/**/*.ts", + "./test/ts/**/*.ts", + "./test/unmemoized/**/*.ts", + "./test/ets/**/*.ts", + "./test/arkts_run.ts" + ] +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/arktsconfig-compiler-plugin.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/arktsconfig-compiler-plugin.json new file mode 100644 index 00000000000..222ad5d753c --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/arktsconfig-compiler-plugin.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "package": "@compiler-plugin-tests", + "outDir": "build/compiler-plugin/abc", + "baseUrl": ".", + "paths": { + "@koalaui/common": ["../../incremental/common/src"], + "@koalaui/compat": ["../../incremental/compat/src/arkts"], + "@koalaui/harness": ["../../incremental/harness/src/arkts"], + "@koalaui/runtime": ["../../incremental/runtime/build/unmemoized/src"] + } + }, + "include": [ + "test/unmemoized/test/**/*.ts", + "test/unmemoized/test/*.ts" + ] +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/arktsconfig-memo-plugin.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/arktsconfig-memo-plugin.json new file mode 100644 index 00000000000..4f213f71e5b --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/arktsconfig-memo-plugin.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "package": "@memo-plugin-tests", + "outDir": "./build/memo-plugin", + "baseUrl": ".", + "paths": { + "@koalaui/common": ["../../incremental/common/src"], + "@koalaui/compat": ["../../incremental/compat/src/arkts"], + "@koalaui/harness": ["../../incremental/harness/src/arkts"], + "@koalaui/runtime": ["../../incremental/runtime/ets"], + "@koalaui/runtime/annotations": ["../../incremental/runtime/annotations"] + }, + "plugins": [ + { + "transform": "../memo-plugin/lib/ParserTransformer", + "stage": "parsed", + "name": "memo" + }, + { + "transform": "../memo-plugin/lib/MemoTransformer", + "stage": "checked", + "name": "memo", + "manuallyDisableInsertingImport": true + } + ] + }, + "include": [ + "./test/ets/**/*.ts" + ], + "dependencies": { + "@koalaui/runtime": ["../../incremental/runtime/ui2abcconfig.json"] + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/package.json new file mode 100644 index 00000000000..6314b0f878e --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/package.json @@ -0,0 +1,52 @@ +{ + "name": "tests-memo", + "private": true, + "description": "", + "main": "build/src/index.js", + "files": [ + "src/**/*.ts" + ], + "scripts": { + "clean": "rimraf build dist test/ets test/unmemoized", + + "annotate:ui2abc:tests": "node ../annotate annotate-tests.json", + "compile:ui2abc:tests": "node ../fast-arktsc --config ./arktsconfig-memo-plugin.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build/memo-plugin/test.abc", + "build:ui2abc:tests": "cd build/memo-plugin && ninja", + "executable:abc": "bash ../../incremental/tools/panda/arkts/ark ./build/memo-plugin/test.abc --ark-boot-files ./build/memo-plugin/test.abc:../../incremental/runtime/build/incremental.abc:../../incremental/harness/build/harness.abc --ark-entry-point @memo-plugin-tests.test.ets.ui2abc_run.ETSGLOBAL::main", + "test:arkts:memo-plugin": "npm run build:harness --prefix ../../incremental/harness && npm run annotate:ui2abc:tests && npm run compile:ui2abc:tests && npm run build:ui2abc:tests && npm run executable:abc", + + "unmemoize:arkts:tests": "ets-tsc -b tsconfig-compiler-plugin.json", + "compile:arkts:tests": "node ../fast-arktsc --config ./arktsconfig-compiler-plugin.json --compiler ../../incremental/tools/panda/arkts/arktsc --link-name ./build/compiler-plugin/test.abc", + "build:arkts:tests": "ninja ${NINJA_OPTIONS} -f build/compiler-plugin/abc/build.ninja", + "run:arkts:tests": "bash ../../incremental/tools/panda/arkts/ark ./build/compiler-plugin/test.abc --ark-boot-files ./build/compiler-plugin/test.abc:../../incremental/runtime/build/incremental.abc:../../incremental/harness/build/harness.abc --ark-entry-point @compiler-plugin-tests.test.unmemoized.test.arkts_run.ETSGLOBAL::main", + "test:arkts:compiler-plugin": "npm run unmemoize:arkts:tests && npm run compile:arkts:tests && npm run build:arkts:tests && npm run run:arkts:tests", + + "install:panda": "npm run panda:sdk:install --prefix ../../incremental/tools/panda", + "compile:deps": "npm run install:panda && cd ../../incremental && npm run compile && cd runtime && npm run build:incremental:components && cd ../harness && npm run compile:all && npm run build:harness && cd ../compiler-plugin && npm run compile && cd ../../ui2abc && npm run build:all && npm run build:incremental:inc:ui2abc --prefix ../incremental/runtime && cd tests-memo", + + "test:ts": "mocha" + }, + "dependencies": { + "@koalaui/common": "1.5.15+devel", + "@koalaui/compat": "1.5.15+devel", + "@koalaui/harness": "file:../../incremental/harness", + "@koalaui/build-common": "1.5.15+devel", + "@koalaui/runtime": "file:../../incremental/runtime", + + "@koalaui/annotate": "file:../annotate", + "@koalaui/ets-tsc": "4.9.5-r5", + "@koalaui/compiler-plugin": "file:../../incremental/compiler-plugin", + "@koalaui/fast-arktsc": "1.5.15" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.20.0", + "@typescript-eslint/parser": "^5.20.0", + "eslint": "^8.13.0", + "eslint-plugin-unused-imports": "^2.0.0", + "mocha": "^9.2.2", + "@types/mocha": "^9.1.0", + "source-map-support": "^0.5.21", + "chai": "^4.3.6", + "@types/chai": "^4.3.1" + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/readme.md b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/readme.md new file mode 100644 index 00000000000..1f71f3171bc --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/readme.md @@ -0,0 +1,26 @@ +```bash +# 1. prepare dependencies +cd ../.. +npm run prepare +npm run compile +npm run panda:sdk:install --prefix incremental/tools/panda +npm run build:incremental:components --prefix incremental/runtime +npm run compile:all --prefix incremental/harness +npm run build:harness --prefix incremental/harness +npm run compile --prefix incremental/compiler-plugin + +npm run compile --prefix ui2abc/libarkts # npm run clean --prefix ui2abc/libarkts +npm run compile --prefix ui2abc/annotate +npm run compile --prefix ui2abc/memo-plugin +npm run build:incremental:inc:ui2abc --prefix incremental/runtime + +# 1.1 OR you could use this command +npm run compile:deps --prefix ui2abc/tests-memo + +# 2. run tests +cd ui2abc/tests-memo +npm i +npm run test:ts # 1. +npm run test:arkts:compiler-plugin # 2. +npm run test:arkts:memo-plugin # 3. +``` \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/arkts/arkts_test.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/arkts/arkts_test.test.ts new file mode 100644 index 00000000000..0c7bb0cff3a --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/arkts/arkts_test.test.ts @@ -0,0 +1,195 @@ +/* + * 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 { Assert, suite, test } from "@koalaui/harness" +import { asArray, int32 } from "@koalaui/common" +import { TestNode, testRoot, testTick, mutableState, GlobalStateManager, StateContext } from "@koalaui/runtime" +import { __id, __key, __context } from "@koalaui/runtime" + +import defaultSharedMemoFunction from "../common/main_test_module_to_import" +import { SharedLog } from "../common/test_module_to_import" + + +function assertResultArray(actual: Array, ...expected: T[]) { + Assert.deepEqual(actual, asArray(expected)) +} + +class GlobalStateHolder { + static globalState = GlobalStateManager.instance.mutableState(0, true) +} + +interface B { + /** @memo */ + propFunctionB: () => void + /** @memo */ + testPropB(): void + + localLog: Array +} + +class A implements B { + localLog: Array + constructor(localLog: Array) { + this.localLog = localLog + } + + /** @memo */ + testPropB(): void { + GlobalStateHolder.globalState.value + this.localLog.push("propFunctionB call") + this.propFunctionB() + } + + /** @memo */ + propFunctionB = + /** @memo */ + () => { + this.localLog.push("propFunctionB") + } + + /** @memo */ + private privatePropFunction = + /** @memo */ + () => { + this.localLog.push("initial privatePropFunction") + } + + /** @memo */ + set customPropFunction( + /** @memo */ + value: + () => void + ) { + this.privatePropFunction = value + } + + /** @memo */ + get customPropFunction(): + () => void { + return this.privatePropFunction + } + + /** @memo */ + testCustomPropFunction() { + GlobalStateHolder.globalState.value + this.localLog.push("customPropFunction call") + this.privatePropFunction() + } +} + +class TestImportedMemo { + /** @memo */ + static testDefaultImportedFunction(): void { + GlobalStateHolder.globalState.value + SharedLog.log.push('testDefaultImportedFunction call') + defaultSharedMemoFunction() + } +} + +suite("[ARKTS+COMPILER PLUGIN] Basic memo semantic", () => { + test("Property of functional type in interface", () => { + // NOTE: should work with memo-plugin in the future + + const instance: B = new A(new Array()) + const root = testRoot( + /** @memo */ + () => { instance.testPropB() } + ) + assertResultArray(instance.localLog, + "propFunctionB call", + "propFunctionB" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.localLog, + "propFunctionB call", + "propFunctionB", + "propFunctionB call", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.localLog, + "propFunctionB call", + "propFunctionB", + "propFunctionB call", + "propFunctionB call", + ) + }) + + test("Getter/setter of functional type", () => { + // NOTE: should work with memo-plugin in the future + + const instance: A = new A(new Array()) + instance.customPropFunction = + /** @memo */ + () => { instance.localLog.push('lala') } + const root = testRoot( + /** @memo */ + () => { instance.testCustomPropFunction() } + ) + assertResultArray(instance.localLog, + "customPropFunction call", + "lala" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.localLog, + "customPropFunction call", + "lala", + "customPropFunction call" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.localLog, + "customPropFunction call", + "lala", + "customPropFunction call", + "customPropFunction call" + ) + }) +}) + +suite("[ARKTS+COMPILER PLUGIN] Memo functions with all kinds of import and export statements", () => { + test("Default import", () => { + // NOTE: should work with memo-plugin in the future + + SharedLog.log.length = 0 + const root = testRoot( + /** @memo */ + () => { TestImportedMemo.testDefaultImportedFunction() } + ) + assertResultArray(SharedLog.log, + "testDefaultImportedFunction call", + "defaultSharedMemoFunction" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(SharedLog.log, + "testDefaultImportedFunction call", + "defaultSharedMemoFunction", + "testDefaultImportedFunction call", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(SharedLog.log, + "testDefaultImportedFunction call", + "defaultSharedMemoFunction", + "testDefaultImportedFunction call", + "testDefaultImportedFunction call", + ) + }) +}) + +export const __ARKTEST__ = "arkts_test.test" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/AnimationRange.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/arkts_run.ts similarity index 59% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/AnimationRange.ets rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/arkts_run.ts index 236cd721e18..e91ec0051a3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/AnimationRange.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/arkts_run.ts @@ -13,7 +13,15 @@ * limitations under the License. */ -import { float64 } from "../common" -export type AnimationRange = (value: float64) => Value -export declare function ArrayAnimationRange(from: ReadonlyArray, to: ReadonlyArray, compute: (array: ReadonlyArray) => Value): AnimationRange -export declare function NumberAnimationRange(from: float64, to: float64): AnimationRange +import { suite } from "@koalaui/harness" +import { Language, setLanguage, setTransformPlugin, TransformPlugin } from "./testUtils" +import { __ARKTEST__ as Basic } from "./common/basic.test" +import { __ARKTEST__ as ArktsTests } from "./arkts/arkts_test.test" + +setTransformPlugin(TransformPlugin.COMPILER_PLUGIN) +setLanguage(Language.ArkTS) + +suite("memo functionality", () => { + Array.of(Basic, ArktsTests) +}) + diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/basic.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/basic.test.ts new file mode 100644 index 00000000000..24d4f1471c9 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/basic.test.ts @@ -0,0 +1,1498 @@ +/* + * 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 { Assert, suite, test } from "@koalaui/harness" +import { asArray, int32 } from "@koalaui/common" +import { TestNode, testRoot, testTick, mutableState, GlobalStateManager, StateContext } from "@koalaui/runtime" +import { __id, __key, __context } from "@koalaui/runtime" + +import { + sharedMemoFunction, +} from "./main_test_module_to_import" +import { SharedLog } from "./test_module_to_import" +import * as ut from "./main_test_module_to_import" +import { isCompilerPlugin } from "../testUtils" + +function assertResultArray(actual: Array, ...expected: T[]) { + Assert.deepEqual(actual, asArray(expected)) +} + +class GlobalStateHolder { + static globalState = GlobalStateManager.instance.mutableState(0, true) +} + +class Log { + log = new Array() +} + +interface B { + /** @memo */ + interfaceMethod(): void + /** @memo */ + testInterfaceMethod(): void + + localLog: Array +} + +class A implements B { + static staticLog = new Array() + + /** @memo */ + static testStaticMethod(): void { + GlobalStateHolder.globalState.value + A.staticLog.push("staticMethod call") + A.staticMethod() + } + + /** @memo */ + static testGlobalFunction(): void { + GlobalStateHolder.globalState.value + globalLog.push("global function call") + globalFunction() + } + + localLog: Array = new Array() + constructor(localLogValue: Array) { + this.localLog = localLogValue + } + + /** @memo */ + testInterfaceMethod(): void { + GlobalStateHolder.globalState.value + this.localLog.push("interfaceMethod call") + this.interfaceMethod() + } + + /** @memo */ + static staticMethod(): void { + A.staticLog.push("staticMethod") + } + + /** @memo */ + interfaceMethod(): void { + this.localLog.push("interfaceMethod") + } + + /** @memo */ + testProp(): void { + GlobalStateHolder.globalState.value + this.localLog.push("propFunction call") + this.propFunction() + } + + /** @memo */ + propFunction = + /** @memo */ + () => { + this.localLog.push("propFunction") + } + + static returnMemoMethod(): + /** @memo */ + (log: Array, value: string) => void + { + return ( + /** @memo */ + (log: Array, value: string) => { + log.push("returnMemoMethod", value) + } + ) + } + +} + +type memoFunctionType = +/** @memo */ +() => void + +const globalLog = new Array() +/** @memo */ +function globalFunction(): void { + globalLog.push("global function") +} + +/** @memo */ +function callMemoFunction( + /** @memo */ + fun: + () => void +): void { + fun() +} + +function returnGlobalMemoFunction(): + /** @memo */ + (log: Array, value: string) => void +{ + return ( + /** @memo */ + (log: Array, value: string) => { + log.push("returnMemoFunction", value) + } + ) +} + +class TestReturnGlobalMemoFunction extends Log { + /** @memo */ + test() { + this.runReturnMemo(returnGlobalMemoFunction()) + } + + /** @memo */ + runReturnMemo( + /** @memo */ + parameter: (log: Array, value: string)=>void + ) { + GlobalStateHolder.globalState.value + this.log.push("returnMemoFunction call") + parameter(this.log, "arg") + } +} + +class TestReturnMethod extends Log { + /** @memo */ + test() { + this.runReturnMemo(A.returnMemoMethod()) + } + + /** @memo */ + runReturnMemo( + /** @memo */ + parameter: (log: Array, value: string)=>void + ) { + GlobalStateHolder.globalState.value + this.log.push("returnMemoMethod call") + parameter(this.log, "arg") + } +} + +function returnListMemoFunctions(): [ + /** @memo */ + () => void, + /** @memo */ + () => void +] { + return [ + /** @memo */ + () => { + globalLog.push('hi') + }, + /** @memo */ + () => { + GlobalStateHolder.globalState.value + globalLog.push('hello') + } + ] +} + +class TestLambdaDeduce { + static log = new Array() + + /** @memo */ + static testLambdaDeduce() { + TestLambdaDeduce.acceptsLambda( + /** @memo */ + (): void => { + TestLambdaDeduce.log.push("deduce lambda") + } + ) + } + + /** @memo */ + static acceptsLambda( + /** @memo */ + parameter: () => void + ): void { + GlobalStateHolder.globalState.value + TestLambdaDeduce.log.push("deduced lambda call") + parameter() + } +} + +class TestPropertyInitializerDeduce extends Log { + instance: TestPropertyInitializerDeduce|undefined = undefined + + /** @memo */ + initializedProperty = + /** @memo */ + () => { + this.log.push("parameter initializer deduce") + } + + /** @memo */ + testInitializerDeduce() { + GlobalStateHolder.globalState.value + this.log.push("deduced parameter call") + this.initializedProperty() + } +} + +/** @memo */ +const initializedVariableGlobal = +(log: Array) => { + log.push("variable global initializer deduce") +} + +class TestVariableInitializerDeduce extends Log { + + /** @memo */ + testInitializerDeduce() { + GlobalStateHolder.globalState.value + this.log.push("deduced variable call") + + /** @memo */ + const initializedVariable = (log: Array) => { + log.push("variable initializer deduce") + } + initializedVariable(this.log) + initializedVariableGlobal(this.log) + } +} + +interface DataClass { + value: number + message: string +} +class TestObjectLiteralMemoization extends Log { + /** @memo */ + test() { + this.log.push("method with object parameter call") + GlobalStateHolder.globalState.value + this.methodWithObjectParameter({message: "hello", value: 47} as DataClass) + } + + /** @memo */ + testWithParentheses() { + this.log.push("method with object parameter call with parentheses") + GlobalStateHolder.globalState.value + this.methodWithObjectParameter(((({message: "hello", value: 47}))) as DataClass) + } + + /** @memo */ + methodWithObjectParameter(data: DataClass) { + this.log.push("method with object parameter", data.message) + } +} + +class TestLambdaLiteralMemoization extends Log { + /** @memo */ + test(): void { + this.log.push("method with lambda parameter call") + GlobalStateHolder.globalState.value + this.methodWithLambdaParameter((): void => {}) + } + + /** @memo */ + methodWithLambdaParameter(param: () => void) { + param + this.log.push("method with lambda parameter") + } +} + +class Unstable { + /** @memo */ + method(log: Array) { + log.push("unstable class method") + } +} + +class UnstableUseReceiver { + /** @memo */ + method(log: Array) { + log.push("unstable class method use this") + const a = this + } +} + +/** @memo:stable */ +class Stable { + /** @memo */ + method(log: Array) { + log.push("stable class method") + } +} + +/** @memo:stable */ +class StableUseReceiver { + /** @memo */ + method(log: Array) { + log.push("stable class method use this") + const b = this + } +} + +class TestMethodReceiver extends Log { + + /** @memo */ + testUnstable() { + const unstableReceiver = new Unstable() + this.log.push("unstable class method call") + GlobalStateHolder.globalState.value + unstableReceiver.method(this.log) + } + + /** @memo */ + testUnstableUseReceiver() { + const unstableReceiver = new UnstableUseReceiver() + this.log.push("unstable class method use this call") + GlobalStateHolder.globalState.value + unstableReceiver.method(this.log) + } + + /** @memo */ + testStable() { + const stableReceiver = new Stable() + this.log.push("stable class method call") + GlobalStateHolder.globalState.value + stableReceiver.method(this.log) + } + + /** @memo */ + testStableUseReceiver() { + const stableReceiver = new StableUseReceiver() + this.log.push("stable class method use this call") + GlobalStateHolder.globalState.value + stableReceiver.method(this.log) + } +} + +class TestArrowFunction extends Log { + /** @memo */ + test() { + this.testArrow( + + (log: Array): void => { + log.push("arrow function") + } + ) + } + /** @memo */ + testArrow( + /** @memo */ + parameter: (log: Array) => void + ): void { + this.log.push("arrow function call") + GlobalStateHolder.globalState.value + parameter(this.log) + } + + +} + +class TestOptionalProperties extends Log { + + constructor() { + super() + + this.initializedProperty = + /** @memo */ + () => { + this.log.push("initialized property") + } + + this.optionalInitializedProperty = + /** @memo */ + () => { + this.log.push("optional initialized property") + } + } + + /** @memo */ + initializedProperty: + () => void + + /** @memo */ + testProperty() { + GlobalStateHolder.globalState.value + this.log.push("property call"); + this.initializedProperty() + } + + /** @memo */ + optionalInitializedProperty?: + () => void + + /** @memo */ + testOptionalProperty() { + GlobalStateHolder.globalState.value + this.log.push("optional property call") + this.optionalInitializedProperty?.() + } + + /** @memo */ + testOptionalWithParentheses() { + GlobalStateHolder.globalState.value + this.log.push("optional parentheses property call"); + ((this.optionalInitializedProperty))?.() + } + + /** @memo */ + static foo() { + + } + + /** @memo */ + static testFoo() { + TestOptionalProperties.foo() + } +} + +class TestTrackingParameters { + static log: Array = new Array() + + static varValue: number = 10 + /** @memo */ + testParam() { + GlobalStateHolder.globalState.value + TestTrackingParameters.log.push(`methodWithParam: ${TestTrackingParameters.varValue} call`) + this.methodWithParam( + TestTrackingParameters.varValue + ) + } + + /** @memo */ + testSkipParam() { + GlobalStateHolder.globalState.value + TestTrackingParameters.log.push(`methodWithSkipParam: ${TestTrackingParameters.varValue} call`) + this.methodWithSkipParam( + TestTrackingParameters.varValue + ) + } + + static updateFlag: boolean = false + static instanceA = new TestTrackingParameters() + static instanceB = new TestTrackingParameters() + + /** @memo */ + testThisParam() { + GlobalStateHolder.globalState.value + TestTrackingParameters.log.push(`testThisParam call`) + let instance = TestTrackingParameters.updateFlag ? TestTrackingParameters.instanceB : TestTrackingParameters.instanceA + if (TestTrackingParameters.updateFlag) TestTrackingParameters.updateFlag = false + instance.method() + } + + /** @memo */ + testContentParam() { + GlobalStateHolder.globalState.value + TestTrackingParameters.log.push(`testContentParam call`) + this.methodWithContentParam( + TestTrackingParameters.updateFlag ? this.methodWithParamCopy : this.methodWithParam, + TestTrackingParameters.varValue + ) + if (TestTrackingParameters.updateFlag) TestTrackingParameters.updateFlag = false + } + + /** @memo */ + method() { + TestTrackingParameters.log.push(`method`) + this + } + + /** @memo */ + methodWithParam( + value: number + ) { + TestTrackingParameters.log.push(`methodWithParam: ${value}`) + } + + /** @memo */ + methodWithParamCopy( + value: number + ) { + TestTrackingParameters.log.push(`methodWithParamCopy: ${value}`) + } + + /** @memo */ + methodWithSkipParam( + /** @skip:memo */ + value: number + ) { + TestTrackingParameters.log.push(`methodWithSkipParam: ${value}`) + } + + /** @memo */ + methodWithContentParam( + /** @memo */ + content: (value: number) => void, + value: number + ) { + TestTrackingParameters.log.push(`methodWithContentParam`) + content(value) + } + +} + +// lala +export type Key = int32 +export class MutableState { + public value: T + constructor(value: T) { + this.value = value + } +} +export class Scope { + param(index: number, value: T): MutableState { + return new MutableState(value) + } + recache(value: T) { return value } + get cached(): T { + throw new Error("") + } + unchanged = false +} + +/** @memo */ +function memoFunction(log: Array) { + log.push('memo function') +} + +/** @memo:entry */ +function functionMemoEntry(__memo_context: StateContext, __memo_id: Key, log: Array): void { + log.push('test entry') + memoFunction(log) +} + +class TestEntry extends Log { + testEntry(): void { + functionMemoEntry(GlobalStateManager.instance, 10, this.log) + } +} + +/** @memo:intrinsic */ +function intrinsicFunction() { + let id = __id() + let context = __context() + TestIntrinsic.log.push('intrinsicFunction', `${context.node?.kind}`) +} + +class TestIntrinsic { + static log: Array = new Array() + + + /** @memo */ + static testIntrinsicMethod(): void { + GlobalStateHolder.globalState.value + TestIntrinsic.log.push('testIntrinsicMethod call') + TestIntrinsic.intrinsicMethod() + } + + /** @memo */ + static testIntrinsicFunction(): void { + GlobalStateHolder.globalState.value + TestIntrinsic.log.push('testIntrinsicFunction call') + intrinsicFunction() + } + + /** @memo */ + static testKeyAccessor(): void { + GlobalStateHolder.globalState.value + TestIntrinsic.log.push('testKeyAccessor call') + TestIntrinsic.intrinsicKeyAccessor() + } + + /** @memo:intrinsic */ + static intrinsicMethod(): void { + let id = __id() + let context = __context() + TestIntrinsic.log.push('intrinsicMethod', `${context.node?.kind}`) + } + + /** @memo:intrinsic */ + static intrinsicKeyAccessor(): void { + let key = __key() + TestIntrinsic.log.push('intrinsicKeyAccessor') + } +} + +class TestImportedMemo { + + /** @memo */ + static testImportedFunction(): void { + GlobalStateHolder.globalState.value + SharedLog.log.push('testImportedFunction call') + sharedMemoFunction() + ut.sharedMemoFunction() + } + +} + +suite("Basic memo semantic", () => { + test("Method declaration in class. Static method is not reinvoked", () => { + const root = testRoot(A.testStaticMethod) + assertResultArray(A.staticLog, + "staticMethod call", + "staticMethod" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(A.staticLog, + "staticMethod call", + "staticMethod", + "staticMethod call" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(A.staticLog, + "staticMethod call", + "staticMethod", + "staticMethod call", + "staticMethod call" + ) + }) + test("File scope function declaration. Function is not reinvoked", () => { + const root = testRoot(A.testGlobalFunction) + assertResultArray(globalLog, + "global function call", + "global function" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(globalLog, + "global function call", + "global function", + "global function call", + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(globalLog, + "global function call", + "global function", + "global function call", + "global function call", + ) + }) + + test("Property of functional type in class", () => { + const instance: A = new A(new Array()) + const root = testRoot( + /** @memo */ + () => {instance.testProp()} + ) + assertResultArray(instance.localLog, + "propFunction call", + "propFunction" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(instance.localLog, + "propFunction call", + "propFunction", + "propFunction call", + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(instance.localLog, + "propFunction call", + "propFunction", + "propFunction call", + "propFunction call", + ) + + }) + + test("Method declaration in interface", () => { + const instance: B = new A(new Array()) + const root = testRoot( + /** @memo */ + () => { instance.testInterfaceMethod() } + ) + assertResultArray(instance.localLog, + "interfaceMethod call", + "interfaceMethod" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(instance.localLog, + "interfaceMethod call", + "interfaceMethod", + "interfaceMethod call" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(instance.localLog, + "interfaceMethod call", + "interfaceMethod", + "interfaceMethod call", + "interfaceMethod call" + ) + }) + test("Type alias of function type", () => { + let fun: memoFunctionType = + /** @memo */ + () => { + GlobalStateHolder.globalState.value + globalLog.push("typeAlias") + } + + globalLog.length = 0 + const root = testRoot(fun) + assertResultArray(globalLog, "typeAlias") + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(globalLog, "typeAlias", "typeAlias") + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(globalLog, "typeAlias", "typeAlias", "typeAlias") + }) + test("Arrow function", () => { + const instance = new TestArrowFunction() + const root = testRoot( + /** @memo */ + () => { instance.test() } + ) + assertResultArray(instance.log, + "arrow function call", + "arrow function" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "arrow function call", + "arrow function", + "arrow function call", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "arrow function call", + "arrow function", + "arrow function call", + "arrow function call", + ) + }) + + test("Return type of functional type in function", () => { + const instance = new TestReturnGlobalMemoFunction() + const root = testRoot( + /** @memo */ + () => { instance.test() } + ) + assertResultArray(instance.log, + "returnMemoFunction call", + "returnMemoFunction", + "arg" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "returnMemoFunction call", + "returnMemoFunction", + "arg", + "returnMemoFunction call", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "returnMemoFunction call", + "returnMemoFunction", + "arg", + "returnMemoFunction call", + "returnMemoFunction call", + ) + }) + + test("Return type of functional type in method", () => { + const instance = new TestReturnMethod() + const root = testRoot( + /** @memo */ + () => { instance.test() } + ) + assertResultArray(instance.log, + "returnMemoMethod call", + "returnMemoMethod", + "arg" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "returnMemoMethod call", + "returnMemoMethod", + "arg", + "returnMemoMethod call", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "returnMemoMethod call", + "returnMemoMethod", + "arg", + "returnMemoMethod call", + "returnMemoMethod call", + ) + }) + + test.expectFailure("Return type of functional type in lambda", () => { + Assert.fail('implement me') + }) + + test("Parameter of function type", () => { + globalLog.length = 0 + const root = testRoot( + /** @memo */ + () => { + callMemoFunction( + /** @memo */ + (): void => { + GlobalStateHolder.globalState.value + globalLog.push("functionParam") + }) + } + ) + + assertResultArray(globalLog, "functionParam") + + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(globalLog, "functionParam", "functionParam") + + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(globalLog, "functionParam", "functionParam", "functionParam") + }) + + test("Return array of memo functional type", () => { + globalLog.length = 0 + const functions = returnListMemoFunctions() + const root = testRoot( + functions[1] + ) + assertResultArray(globalLog, "hello") + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(globalLog, "hello", "hello") + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(globalLog, "hello", "hello", "hello") + }) +}) + +suite("Auto-deducing memo annotation", () => { + test("memo is assumed when pasing a lambda argument to a memo parameter", () => { + const root = testRoot(TestLambdaDeduce.testLambdaDeduce) + assertResultArray(TestLambdaDeduce.log, + "deduced lambda call", + "deduce lambda" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(TestLambdaDeduce.log, + "deduced lambda call", + "deduce lambda", + "deduced lambda call", + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(TestLambdaDeduce.log, + "deduced lambda call", + "deduce lambda", + "deduced lambda call", + "deduced lambda call", + ) + }) + test("memo is assumed when initializing a property", () => { + const test = new TestPropertyInitializerDeduce() + const root = testRoot( + /** @memo */ + () => { test.testInitializerDeduce() } + ) + assertResultArray(test.log, + "deduced parameter call", + "parameter initializer deduce" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "deduced parameter call", + "parameter initializer deduce", + "deduced parameter call" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "deduced parameter call", + "parameter initializer deduce", + "deduced parameter call", + "deduced parameter call" + ) + }) + test("memo is assumed when initializing a variable of functional type", () => { + const test = new TestVariableInitializerDeduce() + const root = testRoot( + /** @memo */ + () => { test.testInitializerDeduce() } + ) + assertResultArray(test.log, + "deduced variable call", + "variable initializer deduce", + "variable global initializer deduce" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "deduced variable call", + "variable initializer deduce", + "variable global initializer deduce", + "deduced variable call" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "deduced variable call", + "variable initializer deduce", + "variable global initializer deduce", + "deduced variable call", + "deduced variable call" + ) + }) + test.expectFailure("memo is assumed when pasing a TRAILING lambda argument to a memo parameter", () => { + Assert.fail("implement me") + }) +}) + +suite("Calls are eligible to memo transformation if...", () => { + test("property access refers to a memo entity", () => { + const test = new TestOptionalProperties() + const root = testRoot( + /** @memo */ + () => { test.testProperty() } + ) + assertResultArray(test.log, + "property call", + "initialized property" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "property call", + "initialized property", + "property call" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "property call", + "initialized property", + "property call", + "property call" + ) + }) + test("nullable property access `bar.foo?.()` refers to a memo entity", () => { + const test = new TestOptionalProperties() + const root = testRoot( + /** @memo */ + () => { test.testOptionalProperty() } + ) + assertResultArray(test.log, + "optional property call", + "optional initialized property" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "optional property call", + "optional initialized property", + "optional property call" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "optional property call", + "optional initialized property", + "optional property call", + "optional property call" + ) + }) + test("parenthesized expression of the above", () => { + const test = new TestOptionalProperties() + const root = testRoot( + /** @memo */ + () => { test.testOptionalWithParentheses() } + ) + assertResultArray(test.log, + "optional parentheses property call", + "optional initialized property" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "optional parentheses property call", + "optional initialized property", + "optional parentheses property call" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "optional parentheses property call", + "optional initialized property", + "optional parentheses property call", + "optional parentheses property call" + ) + }) + test("the memo entity can be of type:\n\tfunction\n\tfunction|undefined\n\tparenthesized function|undefined", () => { + /** @memo */ + const x1: + () => void + = TestOptionalProperties.testFoo + + /** @memo */ + const x2: + () => void + = + () => { console.log('test') } + + /** @memo */ + const x3: + (/** @memo */ (() => void)) | undefined + = undefined + + /** @memo */ + const x4: + (/** @memo */ () => void) | undefined + = TestOptionalProperties.testFoo + + /** @memo */ + const x5: + ((/** @memo */ (() => void))) + = TestOptionalProperties.testFoo + }) +}) + +suite("Tracking parameters", () => { + test("Parameters of memo functions trigger recomputation", () => { + const test = new TestTrackingParameters() + const root = testRoot( + /** @memo */ + () => { test.testParam() } + ) + assertResultArray(TestTrackingParameters.log, + `methodWithParam: 10 call`, + `methodWithParam: 10` + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(TestTrackingParameters.log, + `methodWithParam: 10 call`, + `methodWithParam: 10`, + `methodWithParam: 10 call`, + ) + TestTrackingParameters.varValue = 50 + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(TestTrackingParameters.log, + `methodWithParam: 10 call`, + `methodWithParam: 10`, + `methodWithParam: 10 call`, + `methodWithParam: 50 call`, + `methodWithParam: 50`, + ) + }) + test("Class receiver `this` is included among parameters", () => { + TestTrackingParameters.log.length = 0 + const test = new TestTrackingParameters() + const root = testRoot( + /** @memo */ + () => { test.testThisParam() } + ) + assertResultArray(TestTrackingParameters.log, + `testThisParam call`, + `method` + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(TestTrackingParameters.log, + `testThisParam call`, + `method`, + `testThisParam call`, + ) + TestTrackingParameters.updateFlag = true + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(TestTrackingParameters.log, + `testThisParam call`, + `method`, + `testThisParam call`, + `testThisParam call`, + `method`, + ) + }) + test("@skip:memo excludes parameter from the list of tracked", () => { + TestTrackingParameters.log.length = 0 + TestTrackingParameters.varValue = 10 + const test = new TestTrackingParameters() + const root = testRoot( + /** @memo */ + () => { test.testSkipParam() } + ) + assertResultArray(TestTrackingParameters.log, + `methodWithSkipParam: 10 call`, + `methodWithSkipParam: 10` + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(TestTrackingParameters.log, + `methodWithSkipParam: 10 call`, + `methodWithSkipParam: 10`, + `methodWithSkipParam: 10 call`, + ) + TestTrackingParameters.varValue = 50 + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(TestTrackingParameters.log, + `methodWithSkipParam: 10 call`, + `methodWithSkipParam: 10`, + `methodWithSkipParam: 10 call`, + `methodWithSkipParam: 50 call`, + ) + }) + test.expectFailure("Parameters (same as states) are compared as ===", () => { + Assert.fail("implement me") + }) + test.expectFailure("By convention a lambda parameter with name `content` is not tracked", () => { + // This is to be addressed later when the compiler provides ability to compare + // lambdas by code, not by closure object equality. + + TestTrackingParameters.log.length = 0 + TestTrackingParameters.varValue = 10 + TestTrackingParameters.updateFlag = false + const test = new TestTrackingParameters() + const root = testRoot( + /** @memo */ + () => { test.testContentParam() } + ) + assertResultArray(TestTrackingParameters.log, + `testContentParam call`, + `methodWithContentParam`, + `methodWithParam: 10` + ) + GlobalStateHolder.globalState.value ++ + TestTrackingParameters.updateFlag = true + testTick(root) + assertResultArray(TestTrackingParameters.log, + `testContentParam call`, + `methodWithContentParam`, + `methodWithParam: 10`, + `testContentParam call`, + `methodWithContentParam`, + ) + GlobalStateHolder.globalState.value ++ + TestTrackingParameters.varValue = 50 + testTick(root) + assertResultArray(TestTrackingParameters.log, + `testContentParam call`, + `methodWithContentParam`, + `methodWithParam: 10`, + `testContentParam call`, + `methodWithContentParam`, + `testContentParam call`, + `methodWithContentParam`, + `methodWithParam: 50` + ) + }) +}) + +suite("Memoizing non-primitive arguments", () => { + test("Object literal memoization", () => { + const test = new TestObjectLiteralMemoization() + const root = testRoot( + /** @memo */ + () => { test.test() } + ) + assertResultArray(test.log, + "method with object parameter call", + "method with object parameter", + "hello", + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "method with object parameter call", + "method with object parameter", + "hello", + "method with object parameter call" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "method with object parameter call", + "method with object parameter", + "hello", + "method with object parameter call", + "method with object parameter call" + ) + }) + test("Lambda literal memoization", () => { + const test = new TestLambdaLiteralMemoization() + const root = testRoot( + /** @memo */ + () => { test.test() } + ) + assertResultArray(test.log, + "method with lambda parameter call", + "method with lambda parameter" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "method with lambda parameter call", + "method with lambda parameter", + "method with lambda parameter call" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "method with lambda parameter call", + "method with lambda parameter", + "method with lambda parameter call", + "method with lambda parameter call" + ) + }) +}) + +suite("Method receivers", () => { + test("Non used method receiver does not trigger recomputation by default", () => { + const test = new TestMethodReceiver() + const root = testRoot( + /** @memo */ + () => { test.testUnstable() }) + assertResultArray(test.log, + "unstable class method call", + "unstable class method" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "unstable class method call", + "unstable class method", + "unstable class method call", + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "unstable class method call", + "unstable class method", + "unstable class method call", + "unstable class method call", + ) + }) + test("Used method receiver triggers recomputation by default", () => { + const test = new TestMethodReceiver() + const root = testRoot( + /** @memo */ + () => { test.testUnstableUseReceiver() }) + assertResultArray(test.log, + "unstable class method use this call", + "unstable class method use this" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "unstable class method use this call", + "unstable class method use this", + "unstable class method use this call", + "unstable class method use this" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "unstable class method use this call", + "unstable class method use this", + "unstable class method use this call", + "unstable class method use this", + "unstable class method use this call", + "unstable class method use this", + ) + }) + test("Non used method receiver doesn't trigger recomputation if class is stable", () => { + const test = new TestMethodReceiver() + const root = testRoot( + /** @memo */ + () => { test.testStable() }) + assertResultArray(test.log, + "stable class method call", + "stable class method" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "stable class method call", + "stable class method", + "stable class method call", + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "stable class method call", + "stable class method", + "stable class method call", + "stable class method call", + ) + }) + test("Used method receiver doesn't trigger recomputation if class is stable", () => { + const test = new TestMethodReceiver() + const root = testRoot( + /** @memo */ + () => { test.testStableUseReceiver() }) + assertResultArray(test.log, + "stable class method use this call", + "stable class method use this" + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "stable class method use this call", + "stable class method use this", + "stable class method use this call", + ) + GlobalStateHolder.globalState.value ++ + testTick(root) + assertResultArray(test.log, + "stable class method use this call", + "stable class method use this", + "stable class method use this call", + "stable class method use this call", + ) + }) + + test.expectFailure("lambda with receiver (ArkTS)", () => { + Assert.fail('implement me') + }) +}) + +suite("Regular code is allowed to enter memo realm with @memo:entry annotation", () => { + test("Memo entry", () => { + const instance = new TestEntry() + const root = testRoot( + /** @memo */ + () => { + instance.testEntry() + }) + assertResultArray(instance.log, + "test entry", + "memo function", + ) + }) +}) +suite("Functions marked with @memo:intrinsic", () => { + test("File scope @memo:intrinsic function declaration", () => { + TestIntrinsic.log.length = 0 + const root = testRoot(TestIntrinsic.testIntrinsicFunction) + assertResultArray(TestIntrinsic.log, + "testIntrinsicFunction call", + "intrinsicFunction", "1", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(TestIntrinsic.log, + "testIntrinsicFunction call", + "intrinsicFunction", "1", + "testIntrinsicFunction call", + "intrinsicFunction", "1", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(TestIntrinsic.log, + "testIntrinsicFunction call", + "intrinsicFunction", "1", + "testIntrinsicFunction call", + "intrinsicFunction", "1", + "testIntrinsicFunction call", + "intrinsicFunction", "1", + ) + }) + + test("Class @memo:intrinsic method declaration", () => { + TestIntrinsic.log.length = 0 + const root = testRoot(TestIntrinsic.testIntrinsicMethod) + assertResultArray(TestIntrinsic.log, + "testIntrinsicMethod call", + "intrinsicMethod", "1", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(TestIntrinsic.log, + "testIntrinsicMethod call", + "intrinsicMethod", "1", + "testIntrinsicMethod call", + "intrinsicMethod", "1", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(TestIntrinsic.log, + "testIntrinsicMethod call", + "intrinsicMethod", "1", + "testIntrinsicMethod call", + "intrinsicMethod", "1", + "testIntrinsicMethod call", + "intrinsicMethod", "1", + ) + }) + + test.expect(isCompilerPlugin() ? true : false, "__key() function expanded by the plugin during compilation", () => { + // NOTE: currently nor working for memo-plugin + TestIntrinsic.log.length = 0 + const root = testRoot(TestIntrinsic.testKeyAccessor) + assertResultArray(TestIntrinsic.log, + "testKeyAccessor call", + "intrinsicKeyAccessor", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(TestIntrinsic.log, + "testKeyAccessor call", + "intrinsicKeyAccessor", + "testKeyAccessor call", + "intrinsicKeyAccessor", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(TestIntrinsic.log, + "testKeyAccessor call", + "intrinsicKeyAccessor", + "testKeyAccessor call", + "intrinsicKeyAccessor", + "testKeyAccessor call", + "intrinsicKeyAccessor", + ) + }) +}) + +suite("Memo functions with all kinds of import and export statements", () => { + test("Named import and qualified import with `*` of memo function", () => { + SharedLog.log.length = 0 + const root = testRoot(TestImportedMemo.testImportedFunction) + assertResultArray(SharedLog.log, + "testImportedFunction call", + "sharedMemoFunction", "sharedMemoFunction", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(SharedLog.log, + "testImportedFunction call", + "sharedMemoFunction", "sharedMemoFunction", + "testImportedFunction call", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(SharedLog.log, + "testImportedFunction call", + "sharedMemoFunction", "sharedMemoFunction", + "testImportedFunction call", + "testImportedFunction call", + ) + }) +}) + +export const __ARKTEST__ = "common/basic.test" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/main_test_module_to_import.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/main_test_module_to_import.ts new file mode 100644 index 00000000000..7d423d6992e --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/main_test_module_to_import.ts @@ -0,0 +1,28 @@ +/* + * 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 { SharedLog, separatedMemoFunction } from "./test_module_to_import" + +/** @memo */ +export function sharedMemoFunction() { + SharedLog.log.push("sharedMemoFunction") +} + +/** @memo */ +export default function defaultSharedMemoFunction() { + SharedLog.log.push("defaultSharedMemoFunction") +} + +export { SharedLog, separatedMemoFunction } \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/test_module_to_import.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/test_module_to_import.ts new file mode 100644 index 00000000000..711d7cd6283 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/common/test_module_to_import.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +export class SharedLog { + static log = new Array() +} + +/** @memo */ +export function separatedMemoFunction() { + SharedLog.log.push("separatedMemoFunction") +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/testUtils.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/testUtils.ts new file mode 100644 index 00000000000..6586d7b629a --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/testUtils.ts @@ -0,0 +1,77 @@ +/* + * 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 { int32, KoalaCallsiteKey, UniqueId, asArray } from "@koalaui/common" +import { Assert } from "@koalaui/harness" +import { GlobalStateManager, MutableState } from "@koalaui/runtime" + + +export function assertResultArray(actual: Array, ...expected: T[]) { + Assert.deepEqual(actual, asArray(expected)) +} + +export class GlobalStateHolder { + static globalState: MutableState = GlobalStateManager.instance.mutableState(0, true) +} + +export enum TransformPlugin { + MEMO_PLUGIN, + COMPILER_PLUGIN +} + +export enum Language { + TS, + ArkTS +} + +let TRANSFORM_PLUGIN: TransformPlugin = TransformPlugin.COMPILER_PLUGIN + +export function setTransformPlugin(plugin: TransformPlugin) { + TRANSFORM_PLUGIN = plugin +} + +export function isMemoPlugin(): boolean { + return TRANSFORM_PLUGIN == TransformPlugin.MEMO_PLUGIN +} + +export function isCompilerPlugin(): boolean { + return TRANSFORM_PLUGIN == TransformPlugin.COMPILER_PLUGIN +} + +let TEST_LANGUAGE: Language = Language.TS + +export function setLanguage(language: Language) { + TEST_LANGUAGE = language +} + +export function isArktsTest() { + return TEST_LANGUAGE == Language.ArkTS +} + +export function isTSTest() { + return TEST_LANGUAGE == Language.TS +} + +export function key(name: string): KoalaCallsiteKey { + if (isArktsTest()) { + let key: KoalaCallsiteKey = 0 + for (let i = 0; i < name.length; i++) { + key = (key << 3) | (key >> 29) ^ (name[i] as int32) + } + return key + } else { + return parseInt(new UniqueId().addString(name).compute().slice(0, 10), 16) as KoalaCallsiteKey + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ts/ts_test.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ts/ts_test.test.ts new file mode 100644 index 00000000000..38e54dbe100 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ts/ts_test.test.ts @@ -0,0 +1,167 @@ +/* + * 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 { Assert, suite, test } from "@koalaui/harness" +import { asArray, int32 } from "@koalaui/common" +import { TestNode, testRoot, testTick, mutableState, GlobalStateManager, StateContext } from "@koalaui/runtime" +import { __id, __key, __context } from "@koalaui/runtime" + +import { separatedMemoFunction, SharedLog } from "../common/main_test_module_to_import" + + +function assertResultArray(actual: Array, ...expected: T[]) { + Assert.deepEqual(actual, asArray(expected)) +} + +class GlobalStateHolder { + static globalState = GlobalStateManager.instance.mutableState(0, true) +} + +const globalLog = new Array() + + +function returnListMemoFunctions(): [ + /** @memo */ + () => void, + /** @memo */ + () => void +] { + return [ + /** @memo */ + () => { + globalLog.push('hi') + }, + /** @memo */ + () => { + GlobalStateHolder.globalState.value + globalLog.push('hello') + } + ] +} + +/** @memo */ +const globalFunctionExpression = function () { + globalLog.push("globalFunctionExpression") +} + +/** @memo */ +function testGlobalFunctionExpression() { + GlobalStateHolder.globalState.value + globalLog.push("globalFunctionExpression call") + globalFunctionExpression() +} + +const globalObjectLiteral = { + /** @memo */ + objectLiteralMethod(): void { + GlobalStateHolder.globalState.value + globalLog.push("objectLiteralMethod") + } +} + +class TestImportedMemo { + + /** @memo */ + static testSeparatedImport(): void { + GlobalStateHolder.globalState.value + SharedLog.log.push('testSeparatedImport call') + separatedMemoFunction() + } + +} + +suite("[TS] Basic memo semantic", () => { + test("Variable list member of functional type", () => { + globalLog.length = 0 + const [fun1, fun2] = returnListMemoFunctions() + const root = testRoot( + fun2 + ) + assertResultArray(globalLog, "hello") + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(globalLog, "hello", "hello") + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(globalLog, "hello", "hello", "hello") + }) + + test("Function expression declaration", () => { + globalLog.length = 0 + const root = testRoot(testGlobalFunctionExpression) + assertResultArray(globalLog, + "globalFunctionExpression call", + "globalFunctionExpression" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(globalLog, + "globalFunctionExpression call", + "globalFunctionExpression", + "globalFunctionExpression call", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(globalLog, + "globalFunctionExpression call", + "globalFunctionExpression", + "globalFunctionExpression call", + "globalFunctionExpression call", + ) + }) + + test("Method declaration in object literal", () => { + globalLog.length = 0 + const root = testRoot( + /** @memo */ + () => { globalObjectLiteral.objectLiteralMethod() } + ) + assertResultArray(globalLog, "objectLiteralMethod") + + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(globalLog, "objectLiteralMethod", "objectLiteralMethod") + + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(globalLog, "objectLiteralMethod", "objectLiteralMethod", "objectLiteralMethod") + }) +}) + +suite("[TS] Memo functions with all kinds of import and export statements", () => { + test("Separated import", () => { + SharedLog.log.length = 0 + const root = testRoot(TestImportedMemo.testSeparatedImport) + assertResultArray(SharedLog.log, + "testSeparatedImport call", + "separatedMemoFunction", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(SharedLog.log, + "testSeparatedImport call", + "separatedMemoFunction", + "testSeparatedImport call", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(SharedLog.log, + "testSeparatedImport call", + "separatedMemoFunction", + "testSeparatedImport call", + "testSeparatedImport call", + ) + }) +}) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ts_run.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ts_run.ts new file mode 100644 index 00000000000..12aa1eed21c --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ts_run.ts @@ -0,0 +1,18 @@ +/* + * 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 { Language, setLanguage } from "./testUtils" + +setLanguage(Language.TS) \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/tsconfig.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/tsconfig.json new file mode 100644 index 00000000000..88dbc1ebee9 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/tsconfig.json @@ -0,0 +1,33 @@ +{ + "extends": "../../../incremental/build-common/tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "outDir": "../build/compiler-plugin-ts", + "rootDirs": ["."], + "module": "CommonJS", + "removeComments": false, + "paths": { + "@koalaui/runtime": ["../../incremental/runtime/src"], + "@koalaui/harness": ["../incremental/harness/src/typescript"] + }, + "plugins": [ + { + "transform": "@koalaui/compiler-plugin/build/lib/src/koala-transformer.js", + "trace": false, + } + ] + }, + "references": [ + { + "path": "../../../incremental/runtime" + }, + { + "path": "../../incremental/harness" + } + ], + "include": ["./**/*"], + "exclude": [ + "./ets/**/*", + "./unmemoized/**/*" + ], +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/arkts.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/arkts.test.ts new file mode 100644 index 00000000000..e5277197fd0 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/arkts.test.ts @@ -0,0 +1,80 @@ +/* + * 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. + */ + +/** + * Tests for specific arkts constructions + * separate file because of incompatibility with ts syntax + */ + +import { Assert, suite, test } from "@koalaui/harness" +import { asArray, int32 } from "@koalaui/common" +import { TestNode, testRoot, testTick, mutableState, GlobalStateManager, StateContext } from "@koalaui/runtime" +import { __id, __key, __context } from "@koalaui/runtime" + +import { + SharedLog, + sharedMemoFunction, + GlobalStateHolder, + Log, + assertResultArray, +} from "./utils" + +GlobalStateHolder.globalState = GlobalStateManager.instance.mutableState(0, true) +SharedLog.log = new Array() + +class Dummy {} + +/** @memo */ +function functionWithReceiver(this: Dummy, log: Array) { + log.push("function with receiver") +} + +class TestFunctionWithReceiver extends Log { + /** @memo */ + callFunctionWithReceiver(log: Array) { + let a = new Dummy() + functionWithReceiver(a, log) + a.functionWithReceiver(log) + } + + /** @memo */ + test() { + this.log.push("function with receiver call") + GlobalStateHolder.globalState.value + this.callFunctionWithReceiver(this.log) + } +} + +suite("Functions with receiver", () => { + test("Global function with receiver", () => { + const instance = new TestFunctionWithReceiver() + const root = testRoot(instance.test) + assertResultArray(instance.log, + "function with receiver call", + "function with receiver", + "function with receiver", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "function with receiver call", + "function with receiver", + "function with receiver", + "function with receiver call", + ) + }) +}) + +export const __ARKTEST__ = "basic.test" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/ui2abc_test.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/ui2abc_test.test.ts new file mode 100644 index 00000000000..bfe6d5ffca4 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/ui2abc_test.test.ts @@ -0,0 +1,210 @@ +/* + * 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 { Assert, suite, test } from "@koalaui/harness" +import { asArray, int32 } from "@koalaui/common" +import { TestNode, testRoot, testTick, mutableState, GlobalStateManager, StateContext } from "@koalaui/runtime" +import { __id, __key, __context } from "@koalaui/runtime" +import { assertResultArray, GlobalStateHolder } from "../testUtils" + +GlobalStateHolder.globalState = GlobalStateManager.instance.mutableState(0, true) +class Log { + log = new Array() +} + +interface DataClass { + value: number + message: string +} + +class TestObjectLiteralMemoization extends Log { + /** @memo */ + test() { + this.log.push("method with object parameter call") + GlobalStateHolder.globalState.value + this.methodWithObjectParameter({ message: "hello", value: 47 } as DataClass) + } + + /** @memo */ + testWithParentheses() { + this.log.push("method with object parameter call with parentheses") + GlobalStateHolder.globalState.value + this.methodWithObjectParameter(((({ message: "hello", value: 47 }))) as DataClass) + } + + /** @memo */ + methodWithObjectParameter(data: DataClass) { + this.log.push("method with object parameter", data.message) + } +} + +class TestMemoLambdaLiteralMemoization extends Log { + /** @memo */ + test() { + this.log.push("method with memo lambda parameter call") + GlobalStateHolder.globalState.value + this.methodWithMemoLambdaParameter((): void => { }) + } + + /** @memo */ + methodWithMemoLambdaParameter( + /** @memo */ + param: () => void + ) { + param + this.log.push("method with memo lambda parameter") + } +} + +class Dummy {} + +/** @memo */ +function functionWithReceiver(this: Dummy, log: Array) { + log.push("function with receiver") +} + +class TestFunctionWithReceiver extends Log { + /** @memo */ + callFunctionWithReceiver(log: Array) { + let a = new Dummy() + functionWithReceiver(a, log) + a.functionWithReceiver(log) + } + + /** @memo */ + test() { + this.log.push("function with receiver call") + GlobalStateHolder.globalState.value + this.callFunctionWithReceiver(this.log) + } +} + +class TestLambdaWithReceiver extends Log { + /** @memo */ + callFunctionWithReceiver(log: Array) { + let a = new Dummy() + type MemoT = @memo (this: Dummy, log: Array) => void + @memo let f: MemoT = (this: Dummy, log: Array): void => { + log.push("lambda with receiver") + } + f(a, log) + a.f(log) + } + + /** @memo */ + test() { + this.log.push("lambda with receiver call") + GlobalStateHolder.globalState.value + this.callFunctionWithReceiver(this.log) + } +} + +suite("[ARKTS+MEMO PLUGIN] Memoizing non-primitive arguments", () => { + test("Object literal memoization with parentheses", () => { + const test = new TestObjectLiteralMemoization() + const root = testRoot( + /** @memo */ + () => { test.testWithParentheses() } + ) + assertResultArray(test.log, + "method with object parameter call with parentheses", + "method with object parameter", + "hello", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(test.log, + "method with object parameter call with parentheses", + "method with object parameter", + "hello", + "method with object parameter call with parentheses" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(test.log, + "method with object parameter call with parentheses", + "method with object parameter", "hello", + "method with object parameter call with parentheses", + "method with object parameter call with parentheses" + ) + }) + + test("Memo-lambda literal memoization", () => { + const test = new TestMemoLambdaLiteralMemoization() + const root = testRoot( + /** @memo */ + () => { test.test() } + ) + assertResultArray(test.log, + "method with memo lambda parameter call", + "method with memo lambda parameter" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(test.log, + "method with memo lambda parameter call", + "method with memo lambda parameter", + "method with memo lambda parameter call" + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(test.log, + "method with memo lambda parameter call", + "method with memo lambda parameter", + "method with memo lambda parameter call", + "method with memo lambda parameter call" + ) + }) +}) + +suite("[ARKTS+MEMO PLUGIN] Functions with receiver", () => { + test("Global function with receiver", () => { + const instance = new TestFunctionWithReceiver() + const root = testRoot(instance.test) + assertResultArray(instance.log, + "function with receiver call", + "function with receiver", + "function with receiver", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "function with receiver call", + "function with receiver", + "function with receiver", + "function with receiver call", + ) + }) + + test.expectFailure("Lambda function with receiver", () => { + const instance = new TestLambdaWithReceiver() + const root = testRoot(instance.test) + assertResultArray(instance.log, + "lambda with receiver call", + "lambda with receiver", + "lambda with receiver", + ) + GlobalStateHolder.globalState.value++ + testTick(root) + assertResultArray(instance.log, + "lambda with receiver call", + "lambda with receiver", + "lambda with receiver", + "lambda with receiver call", + ) + }) +}) + +export const __ARKTEST__ = "ui2abc_test.test" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/utils.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/utils.ts new file mode 100644 index 00000000000..64eb9b8cc68 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc/utils.ts @@ -0,0 +1,40 @@ +/* + * 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 { Assert, suite, test } from "@koalaui/harness" +import { asArray, int32 } from "@koalaui/common" +import { TestNode, testRoot, testTick, mutableState, GlobalStateManager, StateContext, MutableState } from "@koalaui/runtime" +import { __id, __key, __context } from "@koalaui/runtime" + +export class SharedLog { + static log: Array = new Array() +} + +/** @memo */ +export function sharedMemoFunction() { + SharedLog.log.push("sharedMemoFunction") +} + +export class GlobalStateHolder { + static globalState: MutableState = GlobalStateManager.instance.mutableState(0, true) +} + +export class Log { + log: Array = new Array() +} + +export function assertResultArray(actual: Array, ...expected: T[]) { + Assert.deepEqual(actual, asArray(expected)) +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/GlobalTimer.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc_run.ts similarity index 59% rename from frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/GlobalTimer.ets rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc_run.ts index 446dd5c9a7b..a5ef92de132 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/recheck-bringup/runtime-api/animation/GlobalTimer.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/test/ui2abc_run.ts @@ -12,9 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { suite } from "@koalaui/harness" +import { Language, setLanguage, setTransformPlugin, TransformPlugin } from "./testUtils" +import { __ARKTEST__ as Basic } from "./common/basic.test" +import { __ARKTEST__ as Ui2abcTests } from "./ui2abc/ui2abc_test.test" + +setTransformPlugin(TransformPlugin.MEMO_PLUGIN) +setLanguage(Language.ArkTS) + +suite("memo functionality", () => { + Array.of(Basic, Ui2abcTests) +}) -import { int64 } from "../common" -import { GlobalStateManager } from "../states/GlobalStateManager" -import { MutableState, StateContext } from "../states/State" -export declare function getAnimationTimer(context: StateContext = GlobalStateManager.instance): MutableState | undefined -export declare function createAnimationTimer(context: StateContext, initial: int64 = 0): MutableState diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/tsconfig-compiler-plugin.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/tsconfig-compiler-plugin.json new file mode 100644 index 00000000000..ed89db11322 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/tests-memo/tsconfig-compiler-plugin.json @@ -0,0 +1,31 @@ +{ + "extends": "@koalaui/build-common/tsconfig.json", + "include": ["./test/**/*.ts"], + "exclude": [ + "./test/ts/**/*.ts", + "./test/ui2abc/**/*.ts", + "./test/unmemoized/**/*.ts", + "./test/ets/**/*.ts", + "./test/ui2abc_run.ts" + ], + "references": [ + { "path": "../../incremental/compiler-plugin" }, + { "path": "../../incremental/common" }, + { "path": "../../incremental/harness" } + ], + "compilerOptions": { + "outDir": "build/compiler-plugin/lib", + "rootDir": ".", + "module": "CommonJS", + "plugins": [ + { + "transform": "@koalaui/compiler-plugin/build/lib/src/koala-transformer.js", + "contextImport": "@koalaui/runtime", + "unmemoizeDir": "./test/unmemoized/", + "only_unmemoize": true, + "trace": false + } + ], + "baseUrl": ".", + }, +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/package.json b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/package.json index e2a9f033949..e825d1edca7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/package.json +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/package.json @@ -1,6 +1,5 @@ { "name": "@koalaui/ui-plugins", - "private": true, "exports": { "./*": "./lib/*.js" }, @@ -11,6 +10,9 @@ "scripts": { "clean": "rimraf build", "compile": "rollup -c ./rollup.config.mjs", - "compile:libarkts": "npm run compile --prefix ../libarkts" + "compile:libarkts": "npm run compile --prefix ../libarkts", + "check": "npm run compile && rm -rf ../../arkoala-arkts/trivial/user/build && npm run build:user:pure-ets:m3 --prefix ../../arkoala-arkts/trivial/user", + "check:run": "npm run check && npm run run:user:pure-ets:node:m3 --prefix ../../arkoala-arkts/trivial/user" + } } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/annotation-translator.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/annotation-translator.ts index 471ba91b260..108c510b2f9 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/annotation-translator.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/annotation-translator.ts @@ -25,23 +25,6 @@ export class AnnotationsTransformer extends arkts.AbstractVisitor { this.program = arkts.global.compilerContext.program } - insertImport(what: string, where: string) { - const source: arkts.StringLiteral = arkts.factory.createStringLiteral(where) - const imported: arkts.Identifier = arkts.factory.createIdentifier(what, undefined) - const importDecl: arkts.ETSImportDeclaration = arkts.factory.createETSImportDeclaration( - source, - [ - arkts.factory.createImportSpecifier( - imported, - imported - ) - ], - arkts.Es2pandaImportKinds.IMPORT_KINDS_TYPES, - arkts.global.compilerContext.program, - arkts.Es2pandaImportFlags.IMPORT_FLAGS_DEFAULT_IMPORT - ) - arkts.importDeclarationInsert(importDecl) - } inStruct = false @@ -52,9 +35,6 @@ export class AnnotationsTransformer extends arkts.AbstractVisitor { // console.log(`builder transform ${node.dumpSrc()} ${arkts.isAnnotationUsage(node)}`) const node = this.visitEachChild(beforeVisit) - if (arkts.isETSModule(node)) { - this.insertImport("memo", "@koalaui/runtime/annotations") - } if (arkts.isFunctionDeclaration(node) && hasDecorator(node, DecoratorNames.BUILDER)) { return arkts.factory.updateFunctionDeclaration(node, node.function, [ annotation(InternalAnnotations.MEMO)], node.isAnonymous) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/builder-lambda-transformer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/builder-lambda-transformer.ts index 9754d92cec9..b90cf1bbca8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/builder-lambda-transformer.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/builder-lambda-transformer.ts @@ -165,7 +165,7 @@ function transformBuilderLambdaCall(node: arkts.CallExpression): arkts.CallExpre } // TODO: for now it all works, but it is unclear -// if it will keep working under Rechek. +// if it will keep working under Recheck. // in theory we don't add new files to import here, // only the new names from the same file, // to it should be okay. diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/call-transformer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/call-transformer.ts new file mode 100644 index 00000000000..dc09c442ee5 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/call-transformer.ts @@ -0,0 +1,89 @@ +/* + * 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 arkts from "@koalaui/libarkts" +import { ApplicationInfo, ComponentTransformerOptions } from "./component-transformer" +import { Importer } from "./utils" + +export class CallTransformer extends arkts.AbstractVisitor { + + private applicationInfo?: ApplicationInfo + private classNode?: arkts.ClassDeclaration + private whiteList = ["$r", "$rawfile"] + + constructor(private imports: Importer, options?: ComponentTransformerOptions) { + super() + this.program = arkts.global.compilerContext.program + this.applicationInfo = options?.applicationInfo + } + + isDollarVariableAccess(identifier: arkts.Identifier): boolean { + if (!this.classNode || !this.classNode.definition) return false + const name = identifier.name + // identifier name starts with $ and not with $r or $rawfile + if (!name.startsWith("$")) return false + if (this.whiteList.includes(name)) return false + // the property is a member of the class + const propName = name.substring(1) + return this.classNode.definition.body + .some(it => arkts.isClassProperty(it) && it.id?.name == propName) + } + + transformDollarVariableAccess(node: arkts.Identifier): arkts.Expression { + return arkts.factory.createMemberExpression( + arkts.factory.createThisExpression(), + arkts.factory.createIdentifier(node.name.substring(1)), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + false + ) + } + + transformDollarCallExpression(callExpr: arkts.CallExpression): arkts.CallExpression { + const name = (callExpr.callee as arkts.Identifier).name.replace('$', '_') + // add import { _r, _rawfile } from "@ohos.arkui"; + this.imports.add(name, "@ohos.arkui") + const args = callExpr.arguments.slice() + return arkts.factory.updateCallExpression( + callExpr, + arkts.factory.createIdentifier(name), + [ + arkts.factory.createStringLiteral(this.applicationInfo?.bundleName ?? ""), + arkts.factory.createStringLiteral(this.applicationInfo?.moduleName ?? "entry"), + ...args, + ], + callExpr.typeParams + ) + } + + visitor(node: arkts.AstNode): arkts.AstNode { + if (arkts.isClassDeclaration(node)) { + this.classNode = node + const transformed = this.visitEachChild(node) + this.classNode = undefined + return transformed + } + if (arkts.isIdentifier(node)) { + if (this.isDollarVariableAccess(node)) { + return this.transformDollarVariableAccess(node) + } + } else if (arkts.isCallExpression(node) && arkts.isIdentifier(node.callee)) { + if (this.whiteList.includes(node.callee.name)) { + return this.transformDollarCallExpression(node) + } + } + return this.visitEachChild(node) + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/checked-stage-plugin.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/checked-stage-plugin.ts index de7bbe58d73..22bdad7e59b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/checked-stage-plugin.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/checked-stage-plugin.ts @@ -14,7 +14,6 @@ */ import * as arkts from "@koalaui/libarkts" -import { StructTransformer } from './struct-transformer' import { StyleTransformer } from "./style-transformer" import { EtsFirstArgTransformer } from "./ets-first-arg-transformer" import { BuilderLambdaTransformer } from "./builder-lambda-transformer" @@ -27,11 +26,10 @@ export default function checkedTransformer( userPluginOptions?: TransformerOptions ) { console.log("CHECKED: ", userPluginOptions) - return (node: arkts.ETSModule) => [ + return (program: arkts.Program) => [ new EtsFirstArgTransformer(), new StyleTransformer(), - new BuilderLambdaTransformer(), - new StructTransformer() + new BuilderLambdaTransformer() ] - .reduce((node: arkts.AstNode, transformer) => transformer.visitor(node), node) + .reduce((node: arkts.AstNode, transformer) => transformer.visitor(node), program.astNode) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/common/arkts-utils.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/common/arkts-utils.ts index 64c2ff6f507..7ec7bda68e6 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/common/arkts-utils.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/common/arkts-utils.ts @@ -71,3 +71,9 @@ export function matchPrefix(prefixCollection: string[], name: string): boolean { } return false; } + +export function classMethods(clazz: arkts.ClassDeclaration, predicate?: (method: arkts.MethodDefinition) => boolean): arkts.MethodDefinition[] { + const body = clazz.definition?.body ?? [] + const methods = body.filter(arkts.isMethodDefinition) + return predicate ? methods.filter(predicate) : methods +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/component-transformer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/component-transformer.ts index 19bb69596c7..90b16c226b4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/component-transformer.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/component-transformer.ts @@ -14,149 +14,217 @@ */ import * as arkts from "@koalaui/libarkts" -import { nullptr } from "@koalaui/interop" import { CustomComponentNames, getCustomComponentOptionsName, - createOptionalClassProperty + Importer, + InternalAnnotations } from "./utils"; +import { BuilderParamTransformer, ConsumeTransformer, LinkTransformer, LocalStorageLinkTransformer, LocalStoragePropTransformer, ObjectLinkTransformer, PropertyTransformer, PropTransformer, ProvideTransformer, StateTransformer, StorageLinkTransformer, StoragePropTransformer, PlainPropertyTransformer, fieldOf, isOptionBackedByProperty, isOptionBackedByPropertyName } from "./property-transformers"; +import { annotation, backingField, isAnnotation } from "./common/arkts-utils"; +import { DecoratorNames, hasDecorator } from "./property-translators/utils"; import { - isAnnotation -} from "./common/arkts-utils"; -import { hasDecorator, DecoratorNames } from "./property-translators/utils" -import { annotation } from "./common/arkts-utils"; -import { backingField, expectName } from "./common/arkts-utils"; -import { getStageManagmentType } from "./property-translators/utils"; + factory +} from "./ui-factory" +import { StructDescriptor, StructTable } from "./struct-recorder"; + +export interface ApplicationInfo { + bundleName: string, + moduleName: string +} export interface ComponentTransformerOptions { arkui?: string + applicationInfo?: ApplicationInfo } -type ScopeInfo = { - name: string, - isComponent?: boolean, +function computeOptionsName(clazz: arkts.ClassDeclaration): string { + return clazz.definition?.typeParams?.params?.[1]?.name?.name ?? + getCustomComponentOptionsName(clazz.definition?.ident?.name!) } -interface ComponentContext { - componentNames: string[], - structMembers: Map, -} -export class ComponentTransformer extends arkts.AbstractVisitor { - private scopeInfos: ScopeInfo[] = []; - private componentNames: string[] = []; - private arkui?: string; - private context: ComponentContext = { componentNames: [], structMembers: new Map() }; - - constructor(options?: ComponentTransformerOptions) { - const _options: ComponentTransformerOptions = options ?? {}; - super(); - this.arkui = _options.arkui; - } - - enter(node: arkts.AstNode) { - if (arkts.isETSStructDeclaration(node) && !!node.definition?.ident) { - const scopeInfo: ScopeInfo = { name: node.definition.ident.name }; - node.definition.annotations.forEach((anno) => { - scopeInfo.isComponent ||= isAnnotation(anno, DecoratorNames.COMPONENT) - }); - this.scopeInfos.push(scopeInfo) - } +class StructCallRewriter extends arkts.AbstractVisitor { + constructor(private structTable: StructTable) { + super() } - exit(node: arkts.AstNode) { - if (arkts.isETSStructDeclaration(node) || arkts.isClassDeclaration(node)) { - if (!node.definition || !node.definition.ident || this.scopeInfos.length === 0) return; - if (this.scopeInfos[this.scopeInfos.length - 1]?.name === node.definition.ident.name) { - this.scopeInfos.pop(); + currentStructRewritten: arkts.ETSStructDeclaration | undefined = undefined + currentStructCalled: StructDescriptor | undefined = undefined + + visitor(node: arkts.AstNode, options?: object): arkts.AstNode { + if (arkts.isCallExpression(node) && arkts.isIdentifier(node.callee)) { + const struct = this.structTable.findStruct(node.callee as arkts.Identifier) + let result: arkts.AstNode + if (struct) { + this.currentStructCalled = struct + result = this.visitEachChild(node) + this.currentStructCalled = undefined + } else { + result = this.visitEachChild(node) } + return result } + if (this.currentStructCalled != undefined && arkts.isObjectExpression(node)) { + // Iterate over all statements to properly use fields getters + let casted = arkts.factory.createTSAsExpression( + this.createObjectLiteralRewrite(node), + arkts.factory.createTSTypeReference(arkts.factory.createIdentifier( + getCustomComponentOptionsName(this.currentStructCalled.name))), + false + ) + return casted + } + return this.visitEachChild(node) } - isComponentStruct(): boolean { - if (this.scopeInfos.length === 0) return false; - const scopeInfo: ScopeInfo = this.scopeInfos[this.scopeInfos.length - 1]; - return !!scopeInfo.isComponent; - } - - createImportDeclaration(): void { - const source: arkts.StringLiteral = arkts.factory.createStringLiteral( - this.arkui ?? CustomComponentNames.COMPONENT_DEFAULT_IMPORT - ); - const imported: arkts.Identifier = arkts.factory.createIdentifier( - CustomComponentNames.COMPONENT_CLASS_NAME, undefined - ); - const importDecl: arkts.ETSImportDeclaration = arkts.factory.createETSImportDeclaration( - source, - [ - arkts.factory.createImportSpecifier( - imported, - imported - ) - ], - arkts.Es2pandaImportKinds.IMPORT_KINDS_TYPES, - arkts.global.compilerContext.program, - arkts.Es2pandaImportFlags.IMPORT_FLAGS_DEFAULT_IMPORT + private createObjectLiteralRewrite(expression: arkts.ObjectExpression): arkts.ObjectExpression { + return arkts.factory.createObjectExpression( + arkts.Es2pandaAstNodeType.AST_NODE_TYPE_OBJECT_EXPRESSION, + expression.properties.map(value => { + if (arkts.isProperty(value) && arkts.isMemberExpression(value.value)) { + return arkts.factory.createProperty( + arkts.Es2pandaPropertyKind.PROPERTY_KIND_INIT, + value.key, + this.createMemberRewrite(value.key as arkts.Identifier, value.value), false, false + ) + } else if (arkts.isProperty(value) && arkts.isIdentifier(value.value)) { + return arkts.factory.createProperty( + arkts.Es2pandaPropertyKind.PROPERTY_KIND_INIT, + value.key, + this.createDollarRewrite(value.key as arkts.Identifier, value.value), false, false + ) + } else if (arkts.isProperty(value) && arkts.isArrowFunctionExpression(value.value)) { + return arkts.factory.createProperty( + arkts.Es2pandaPropertyKind.PROPERTY_KIND_INIT, + value.key, + this.updateArrowFunctionExpression(value.key as arkts.Identifier, value.value), false, false + ) + } else { + return value + } + }), false ) - // Insert this import at the top of the script's statements. - arkts.importDeclarationInsert(importDecl) - return } - processEtsScript(node: arkts.ETSModule): arkts.ETSModule { - if (this.componentNames.length === 0) { - return node + private createMemberRewrite(targetPropertyNameId: arkts.Identifier, original: arkts.MemberExpression): arkts.MemberExpression { + if (!this.currentStructRewritten) return original + if (arkts.isThisExpression(original.object) && arkts.isIdentifier(original.property)) { + let thisPropertyName = original.property.name + let targetPropertyName = targetPropertyNameId.name + // Use backing field instead of property value, if using property. + let decorators = this.currentStructCalled?.decoratorsFor(targetPropertyName) + if (decorators?.find(it => isOptionBackedByPropertyName(it))) { + return fieldOf(arkts.factory.createThisExpression(), backingField(thisPropertyName)) + } } + return original + } - this.createImportDeclaration() - let updateStatements: arkts.AstNode[] = []; - updateStatements.push( - ...this.componentNames.map( - name => arkts.factory.createInterfaceDeclaration( - [], - arkts.factory.createIdentifier( - getCustomComponentOptionsName(name), undefined - ), - undefined, - arkts.factory.createTSInterfaceBody( - this.context.structMembers.has(name) - ? this.context.structMembers.get(name)! - : [] - ), - false, - false - ) - ) - ); - if (updateStatements.length > 0) { - return arkts.updateETSModuleByStatements( - node, - [ - ...node.statements, - ...updateStatements, - ] - ) + private createDollarRewrite(targetPropertyNameId: arkts.Identifier, original: arkts.Identifier): arkts.MemberExpression | arkts.Identifier { + if (!this.currentStructRewritten) return original + if (original.name.startsWith('$')) { + let targetPropertyName = targetPropertyNameId.name + let thisPropertyName = original.name.substring(1) + // Use backing field instead of property value, if using property. + let decorators = this.currentStructCalled?.decoratorsFor(targetPropertyName) + if (decorators?.find(it => isOptionBackedByPropertyName(it))) { + return fieldOf(arkts.factory.createThisExpression(), backingField(thisPropertyName)) + } } - return node; + return original } - processComponent(node: arkts.ClassDeclaration | arkts.ETSStructDeclaration): arkts.ClassDeclaration | arkts.ETSStructDeclaration { - const scopeInfo = this.scopeInfos[this.scopeInfos.length - 1]; - const className = node.definition?.ident?.name; - if (!className || scopeInfo?.name !== className) { - return node; + private updateArrowFunctionExpression(targetPropertyNameId: arkts.Identifier, original: arkts.ArrowFunctionExpression): arkts.ArrowFunctionExpression { + if (!this.currentStructRewritten) return original + let targetPropertyName = targetPropertyNameId.name + // Add @memo annotation if using @BuildParam decorated property + let decorators = this.currentStructCalled?.decoratorsFor(targetPropertyName) + if (decorators?.find(it => it == DecoratorNames.BUILDER_PARAM)) { + original.setAnnotations([annotation(InternalAnnotations.MEMO)]) } + return original + } +} - arkts.GlobalInfo.getInfoInstance().add(className); - this.componentNames.push(className); +export class ComponentTransformer extends arkts.AbstractVisitor { + private arkuiImport?: string + private callRewriter: StructCallRewriter + + constructor(private imports: Importer, private structTable: StructTable, options?: ComponentTransformerOptions) { + super() + this.arkuiImport = options?.arkui + this.callRewriter = new StructCallRewriter(structTable) + } + + private transformStatements(statements: readonly arkts.Statement[]): arkts.Statement[] { + let result: arkts.Statement[] = [] + this.parseEntryParameter(statements) + this.imports.add( + CustomComponentNames.COMPONENT_CLASS_NAME, + this.arkuiImport ?? CustomComponentNames.COMPONENT_DEFAULT_IMPORT) + this.imports.add(InternalAnnotations.MEMO, "@koalaui/runtime/annotations") + this.propertyTransformers.forEach(it => it.collectImports(this.imports)) + statements.forEach(statement => { + if (arkts.isETSStructDeclaration(statement)) { + this.rewriteStruct(statement, result) + } else if (arkts.isETSImportDeclaration(statement)) { + this.rewriteImport(statement) + result.push(statement) + } else { + result.push(statement) + } + }) + return result + } + + private rewriteImport(statement: arkts.ETSImportDeclaration) { + statement.specifiers.forEach(it => { + const name = (it as arkts.ImportSpecifier).imported + if (name && this.structTable.findStruct(name)) { + this.imports.add(getCustomComponentOptionsName(name.name), statement.source?.str!) + } + }) + } + + private rewriteModule(node: arkts.ETSModule): arkts.ETSModule { + return arkts.updateETSModuleByStatements(node, this.transformStatements(node.statements)) + } + + private optionsName(clazz: arkts.ClassDefinition): arkts.Identifier { + return arkts.factory.createIdentifier(getCustomComponentOptionsName(clazz.ident!.name)) + } + + private rewriteStructToOptions(node: arkts.ETSStructDeclaration): arkts.TSInterfaceDeclaration { + return arkts.factory.createInterfaceDeclaration( + [], + this.optionsName(node.definition!), + undefined, + arkts.factory.createTSInterfaceBody(this.rewriteOptionsBody(node)), + false, + false, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT, + ) + } + + private rewriteOptionsBody(node: arkts.ETSStructDeclaration): arkts.Statement[] { + let result: arkts.Statement[] = [] + node.definition?.body.forEach(node => { + if (arkts.isClassProperty(node)) { + let transformer = this.propertyTransformers.find(it => it.check(node)) + if (transformer == undefined) throw new Error(`Cannot find transformer for property ${node.id?.name}`) + transformer.applyOptions(node, result) + } + }) + return result + } - const definition: arkts.ClassDefinition = node.definition - const newDefinition = arkts.factory.updateClassDefinition( - definition, - definition.ident, + private rewriteStructToClass(node: arkts.ETSStructDeclaration): arkts.ClassDefinition { + return arkts.factory.createClassDefinition( + arkts.factory.createIdentifier(node.definition!.ident!.name), undefined, - undefined, // superTypeParams doen't work - definition.implements, + undefined, + node.definition?.implements ?? [], undefined, arkts.factory.createETSTypeReference( arkts.factory.createETSTypeReferencePart( @@ -165,77 +233,214 @@ export class ComponentTransformer extends arkts.AbstractVisitor { [ arkts.factory.createETSTypeReference( arkts.factory.createETSTypeReferencePart( - arkts.factory.createIdentifier(className, undefined), + arkts.factory.createIdentifier(node.definition!.ident!.name), undefined, undefined ) ), arkts.factory.createETSTypeReference( arkts.factory.createETSTypeReferencePart( - arkts.factory.createIdentifier( - `${CustomComponentNames.COMPONENT_INTERFACE_PREFIX}${className}`, undefined - ), undefined, undefined + this.optionsName(node.definition!), + undefined, undefined ) ), ] ), undefined ) ), - definition.body, - definition.modifiers, - arkts.classDefinitionFlags(definition) | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_FINAL | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT + this.rewriteStructMembers(node, (node.definition?.body as arkts.ClassElement[]) ?? []), + arkts.Es2pandaClassDefinitionModifiers.CLASS_DEFINITION_MODIFIERS_CLASS_DECL, + arkts.classDefinitionFlags(node.definition!) | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_FINAL | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT) + } + + private rewriteStructMembers(clazz: arkts.ClassDeclaration, body: readonly arkts.ClassElement[]): arkts.ClassElement[] { + let result: arkts.ClassElement[] = [] + body.forEach(node => { + if (arkts.isClassProperty(node)) { + let transformer = this.propertyTransformers.find(it => it.check(node)) + if (transformer == undefined) throw new Error(`Cannot find transformer for property ${node.id?.name}`) + transformer.applyStruct(clazz, node, result, this.pageLocalStorage) + } else if (arkts.isMethodDefinition(node)) { + let method = node as arkts.MethodDefinition + if (method.function?.id?.name == CustomComponentNames.COMPONENT_BUILD_ORI) { + result.push(this.rewriteBuild(clazz, node)) + } else if (hasDecorator(node, DecoratorNames.BUILDER)) { + result.push(this.rewriteBuilder(method)) + } else { + result.push(method) + } + } else { + throw new Error(`How to rewrite ${node}?`) + } + }) + result.push(this.createInitializer(clazz)) + return result + } + + private createInitializerBody(clazz: arkts.ClassDeclaration): arkts.Statement { + let result: arkts.Statement[] = [] + clazz.definition?.body.forEach(node => { + if (arkts.isClassProperty(node)) { + let transformer = this.propertyTransformers.find(it => it.check(node)) + if (transformer == undefined) throw new Error(`Cannot find transformer for property ${node.id?.name}`) + transformer.applyInitialization(node, result) + } + }) + return arkts.factory.createBlockStatement(result) + } + + private createInitializer(clazz: arkts.ClassDeclaration): arkts.MethodDefinition { + let methodName = arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_INITIALIZE_STRUCT) + const newFunction = arkts.factory.createScriptFunction( + this.createInitializerBody(clazz), + undefined, + [ + factory.createInitializersOptionsParameter(computeOptionsName(clazz)), + factory.createContentParameter(), + ], + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + false, + arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PROTECTED, + methodName, + [] + ) + return arkts.factory.createMethodDefinition( + arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, + methodName, + arkts.factory.createFunctionExpression(methodName, newFunction), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PROTECTED, + false ) + } + + private rewriteBuildBody(clazz: arkts.ClassDeclaration, oldBody: arkts.BlockStatement): arkts.BlockStatement { + let result: arkts.Statement[] = [] + clazz.definition!.body.forEach(node => { + if (arkts.isClassProperty(node)) { + let transformer = this.propertyTransformers.find(it => it.check(node)) + if (transformer == undefined) + throw new Error(`Cannot find transformer for property ${node.id?.name}`) + transformer.applyBuild(node, result) + } + }) + oldBody.statements.forEach((it) => { + result.push(it) + }) + return arkts.factory.createBlockStatement(result) + } - if (arkts.isETSStructDeclaration(node)) { - this.collectComponentMembers(node, className); - const _node = arkts.factory.createClassDeclaration(newDefinition); - _node.updateModifiers(node.modifierFlags); - return _node; - } else { - return arkts.factory.updateClassDeclaration( - node, - newDefinition + private rewriteBuild(clazz: arkts.ClassDeclaration, method: arkts.MethodDefinition): arkts.MethodDefinition { + let isDeclaration = arkts.hasModifierFlag(method, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE) + const newName: arkts.Identifier = arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_BUILD) + const className = clazz.definition?.ident?.name! + const classTypeName = clazz.definition?.typeParams?.params?.[0]?.name?.name ?? className + const classOptionsName = computeOptionsName(clazz) + const scriptFunction = method.function as arkts.ScriptFunction + const newFunction = arkts.factory.createScriptFunction( + this.rewriteBuildBody(clazz, scriptFunction.body! as arkts.BlockStatement), + scriptFunction.typeParams, + [ + factory.createStyleParameter(classTypeName), + factory.createContentParameter(), + factory.createInitializersOptionsParameter(classOptionsName) + ], + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + false, + scriptFunction.flags, + scriptFunction.modifierFlags, + newName, + [annotation(InternalAnnotations.MEMO)] + ) + const modifiers: arkts.Es2pandaModifierFlags = isDeclaration + ? arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_ABSTRACT + : arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC; + return arkts.factory.createMethodDefinition( + arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, + newName, + arkts.factory.createFunctionExpression(newName, newFunction), + modifiers, + false + ) + } + + private rewriteBuilder(method: arkts.MethodDefinition): arkts.MethodDefinition { + method.function!.setAnnotations([annotation(InternalAnnotations.MEMO)]) + return method + } + + private pageLocalStorage: arkts.Expression | undefined + + private parseLocalStorage(annotation: arkts.AnnotationUsage | undefined): arkts.Expression | undefined { + if (!annotation || annotation.properties.length === 0) { + return undefined + } + const properties: arkts.ClassProperty[] = annotation.properties.filter(property => { + return arkts.isClassProperty(property) + }).map(property => property as arkts.ClassProperty) + + // shared + const useSharedStorage = !!properties.find(property => { + return property.id?.name === "useSharedStorage" && arkts.isBooleanLiteral(property.value) && property.value.value + }) + if (useSharedStorage) { + return arkts.factory.createCallExpression( + fieldOf(arkts.factory.createIdentifier("LocalStorage"), "getShared"), [], undefined ) } - } - collectComponentMembers(node: arkts.ETSStructDeclaration, className: string): void { - if (!this.context.structMembers.has(className)) { - this.context.structMembers.set(className, []); + // concrete + const storage = properties.find(property => property.id?.name === "storage") + if (storage && storage.value) { + return storage.value + } + + // fallback to one string literal parameter + if (arkts.isStringLiteral(properties[0].value)) { + return arkts.factory.createIdentifier(properties[0].value.str) } - node.definition?.body.map(it => { - if (arkts.isClassProperty(it)) { - this.context.structMembers.get(className)!.push(...this.createInterfaceInnerMember(it)); + + return undefined + } + + private parseEntryParameter(statements: readonly arkts.Statement[]) { + for (const statement of statements) { + if (!arkts.isETSStructDeclaration(statement)) { + continue + } + const entryAnnotation = statement.definition?.annotations.filter(it => isAnnotation(it, DecoratorNames.ENTRY))[0] + this.pageLocalStorage = this.parseLocalStorage(entryAnnotation) + if (this.pageLocalStorage) { + break } - }); - } - - createInterfaceInnerMember(member: arkts.ClassProperty): arkts.ClassProperty[] { - const originalName: string = expectName(member.key); - const newName: string = backingField(originalName); - const originMember: arkts.ClassProperty = createOptionalClassProperty(originalName, member, - '', arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC); - // Complete BS. - if (member.annotations.length > 0 && !hasDecorator(member, DecoratorNames.BUILDER_PARAM)) { - const newMember: arkts.ClassProperty = createOptionalClassProperty(newName, member, - getStageManagmentType(member), arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC); - return [originMember, newMember] } - return [originMember]; + } + + propertyTransformers: PropertyTransformer[] = [ + new StateTransformer(), + new PlainPropertyTransformer(), + new LinkTransformer(), + new PropTransformer(), + new StorageLinkTransformer(), + new StoragePropTransformer(), + new LocalStorageLinkTransformer(), + new LocalStoragePropTransformer(), + new ObjectLinkTransformer(), + new ProvideTransformer(), + new ConsumeTransformer(), + new BuilderParamTransformer(), + ] + + private rewriteStruct(node: arkts.ETSStructDeclaration, result: arkts.Statement[]) { + this.callRewriter.currentStructRewritten = node + result.push(this.callRewriter.visitor(arkts.factory.createClassDeclaration(this.rewriteStructToClass(node)))) + result.push(this.rewriteStructToOptions(node)) + this.callRewriter.currentStructRewritten = undefined } visitor(node: arkts.AstNode): arkts.AstNode { - this.enter(node); - const newNode = this.visitEachChild(node) - if (arkts.isETSModule(newNode)) { - const updateNode = this.processEtsScript(newNode) - this.exit(newNode) - return updateNode + if (arkts.isETSModule(node)) { + return this.rewriteModule(node) } - if (arkts.isETSStructDeclaration(newNode) && this.isComponentStruct()) { - const updateNode = this.processComponent(newNode) - this.exit(newNode) - return updateNode - } - return newNode + throw new Error(`Must not be there`) } -} +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/get_napi.mjs b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/imports-transformer.ts similarity index 52% rename from frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/get_napi.mjs rename to frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/imports-transformer.ts index e663e3a24bd..b1eed018cbc 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/scripts/get_napi.mjs +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/imports-transformer.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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 @@ -13,20 +13,21 @@ * limitations under the License. */ -import { GitLab } from "../../tools/storage/gitlab/gitlab.mjs"; -import minimist from "minimist"; -import path from "path" +import { Importer } from "./utils" +import * as arkts from "@koalaui/libarkts" -let args = minimist(process.argv.slice(2)) +export class ImportsTransformer { + constructor(private program: arkts.Program, private imports: Importer) {} -const version = args.version -const apiVersion = version.split('-')[0] -const outDir = path.join('prebuilt', 'node-addon-api-'+ version) + private addImports() { + this.imports.emit(this.program) + } -const gitlab = new GitLab() -gitlab.downloadRawArchive( - 'node-addon-api', - apiVersion, - 'v' + version + '.tar.gz', - outDir -) + visitor(node: arkts.AstNode): arkts.AstNode { + if (arkts.isETSModule(node)) { + this.addImports() + return node + } + throw new Error(`Must not be there`) + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/parsed-stage-plugin.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/parsed-stage-plugin.ts index 2ae6e56ef51..80c9058bc16 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/parsed-stage-plugin.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/parsed-stage-plugin.ts @@ -16,14 +16,22 @@ import * as arkts from "@koalaui/libarkts" import { ComponentTransformer, ComponentTransformerOptions } from './component-transformer' import { AnnotationsTransformer } from "./annotation-translator" +import { CallTransformer } from "./call-transformer" +import { Importer } from "./utils" +import { ImportsTransformer } from "./imports-transformer" +import { StructRecorder, StructTable } from "./struct-recorder" export default function parsedTransformer( userPluginOptions?: ComponentTransformerOptions ) { - console.log(`PARSED: ${userPluginOptions}`) - return (node: arkts.ETSModule) => [ - new ComponentTransformer(userPluginOptions), - new AnnotationsTransformer() + const imports = new Importer() + const structTable = new StructTable() + return (program: arkts.Program) => [ + new StructRecorder(structTable), + new ComponentTransformer(imports, structTable, userPluginOptions), + new AnnotationsTransformer(), + new CallTransformer(imports, userPluginOptions), + new ImportsTransformer(program, imports) ] - .reduce((node: arkts.AstNode, transformer) => transformer.visitor(node), node) + .reduce((node: arkts.AstNode, transformer) => transformer.visitor(node), program.astNode) } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/property-transformers.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/property-transformers.ts new file mode 100644 index 00000000000..493af661bc8 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/property-transformers.ts @@ -0,0 +1,597 @@ +/* + * Copyright (c) 2022-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 arkts from "@koalaui/libarkts" +import { Es2pandaTokenType } from "@koalaui/libarkts" + +import { DecoratorNames, getValueInDecorator, hasDecorator } from "./property-translators/utils" +import { CustomComponentNames, Importer, ImportingTransformer, InternalAnnotations } from "./utils" +import { annotation, classMethods, isAnnotation } from "./common/arkts-utils" + +export interface PropertyTransformer extends ImportingTransformer { + check(property: arkts.ClassProperty): boolean + applyBuild(property: arkts.ClassProperty, result: arkts.Statement[]): void + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.Statement[], pageLocalStorage?: arkts.Expression): void + applyOptions(property: arkts.ClassProperty, result: arkts.Statement[]): void + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void +} + +function createOptionalClassProperty( + name: string, + property: arkts.ClassProperty +): arkts.ClassProperty { + let result = arkts.factory.createClassProperty( + arkts.factory.createIdentifier(name, undefined), + undefined, + property.typeAnnotation, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_OPTIONAL | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false + ) + return result +} + +function createWrapperType(name: string, type: arkts.TypeNode): arkts.ETSTypeReference { + return arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( + arkts.factory.createIdentifier(name), + arkts.factory.createTSTypeParameterInstantiation([type]), + undefined + ) + ) +} + +export function backingFieldName(name: string): string { + return "__backing_" + name +} + +function callBackingFieldMethod(method: string, property: arkts.ClassProperty, args: arkts.Expression[]): arkts.Statement { + return arkts.factory.createExpressionStatement( + arkts.factory.createCallExpression( + fieldOf(fieldOf(arkts.factory.createThisExpression(), backingFieldName(property.id!.name)), method), + args, undefined + )) +} + +function createWrappedProperty( + name: string, + clazz: arkts.ClassDeclaration, + property: arkts.ClassProperty, + wrapperTypeName: string, + ctorParams: arkts.Expression[] = [] +): arkts.ClassElement[] { + const wrapperType = createWrapperType(wrapperTypeName, property.typeAnnotation!) + const backingName = backingFieldName(name) + let ctorArguments: arkts.Expression[] = [...ctorParams, arkts.factory.createStringLiteral(name)] + if (property.value != undefined) { + ctorArguments.push(property.value) + } + const backingField = arkts.factory.createClassProperty( + arkts.factory.createIdentifier(backingName), + arkts.factory.createETSNewClassInstanceExpression(wrapperType, ctorArguments), + wrapperType, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, + false + ) + + const getterFunction = arkts.factory.createScriptFunction( + arkts.factory.createBlockStatement([ + arkts.factory.createReturnStatement( + arkts.factory.createCallExpression( + arkts.factory.createMemberExpression( + arkts.factory.createMemberExpression( + arkts.factory.createThisExpression(), + arkts.factory.createIdentifier(backingName), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + false + ), + arkts.factory.createIdentifier("get"), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + false + ), [], undefined + ) + ) + ]), + undefined, + [ + ], + property.typeAnnotation, + true, + arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD | arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_GETTER, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + arkts.factory.createIdentifier(name), + [] + ) + + const setterStatements: arkts.Statement[] = [ + arkts.factory.createExpressionStatement( + arkts.factory.createCallExpression( + arkts.factory.createMemberExpression( + arkts.factory.createMemberExpression( + arkts.factory.createThisExpression(), + arkts.factory.createIdentifier(backingName), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + false + ), + arkts.factory.createIdentifier("set"), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + false + ), + [ + arkts.factory.createIdentifier("value"), + ], + undefined + ) + ) + ] + const watchMethods = property.annotations.filter(isWatchDecorator).map(getWatchParameter) + for (let i = 0; i < watchMethods.length; i++) { + setterStatements.push(createWatchCall(clazz, watchMethods[i], name)) + } + + const setterFunction = arkts.factory.createScriptFunction( + arkts.factory.createBlockStatement(setterStatements), + undefined, + [ + arkts.factory.createETSParameterExpression( + arkts.factory.createIdentifier("value"), + false, + undefined, + property.typeAnnotation! + ) + ], + undefined, + true, + arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD | arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_SETTER | arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_OVERLOAD, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + arkts.factory.createIdentifier(name), + [] + ) + + let setter = arkts.factory.createMethodDefinition( + arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET, + arkts.factory.createIdentifier(name), + arkts.factory.createFunctionExpression(arkts.factory.createIdentifier(name), setterFunction), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false + ) + + let getter = arkts.factory.createMethodDefinition( + arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET, + arkts.factory.createIdentifier(name), + arkts.factory.createFunctionExpression(arkts.factory.createIdentifier(name), getterFunction), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false, + [setter] + ) + setter.parent = getter + + return [backingField, getter] +} + +function isWatchDecorator(usage: arkts.AnnotationUsage): boolean { + return isAnnotation(usage, DecoratorNames.WATCH) +} + +function getWatchParameter(usage: arkts.AnnotationUsage): string { + const properties = usage.properties + if (properties.length != 1) throw new Error("@Watch: only one parameter is expected") + const property = usage.properties[0] + if (!arkts.isClassProperty(property)) throw new Error("@Watch: expected class property") + const parameter = property.value + if (!arkts.isStringLiteral(parameter)) throw new Error("@Watch: expected string literal") + return parameter.str +} + +function isWatchMethod(method: arkts.MethodDefinition, methodName: string): boolean { + const f = method.function + return (f != undefined) + && (f.params.length == 1) + && (f.id?.name == methodName) +} + +function createWatchCall(clazz: arkts.ClassDeclaration, methodName: string, propertyName: string): arkts.Statement { + const parameters = new Array() + const methods = classMethods(clazz, method => isWatchMethod(method, methodName)) + if (methods.length > 0) parameters.push(arkts.factory.createStringLiteral(propertyName)) + return arkts.factory.createExpressionStatement( + arkts.factory.createCallExpression( + fieldOf(arkts.factory.createThisExpression(), methodName), + parameters, + undefined) + ) +} + +export abstract class PropertyTransformerBase implements PropertyTransformer { + abstract check(property: arkts.ClassProperty): boolean + + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void { } + applyBuild(property: arkts.ClassProperty, result: arkts.Statement[]): void { } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { } + collectImports(result: Importer): void { } +} + +function applyInitializer(property: arkts.ClassProperty, setter: string = "init"): arkts.Statement { + let name = property.id?.name! + return arkts.factory.createBlockStatement([ + arkts.factory.createExpressionStatement( + arkts.factory.createCallExpression( + fieldOf( + fieldOf( + arkts.factory.createThisExpression(), backingFieldName(name) + ), setter + ), + [ + fieldOf(arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_INITIALIZERS_NAME), name, true) + ], + undefined + ) + ) + ]) +} + +export class StateTransformer extends PropertyTransformerBase { + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void { + result.push(applyInitializer(property)) + } + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.STATE) + } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(createOptionalClassProperty(property.id!.name, property)) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(...createWrappedProperty(property.id!.name, clazz, property, "StateDecoratorProperty")) + } + collectImports(imports: Importer): void { + imports.add("StateDecoratorProperty", "@ohos.arkui") + } +} + +export class PlainPropertyTransformer extends PropertyTransformerBase { + check(property: arkts.ClassProperty): boolean { + return property.annotations.length == 0 + } + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void { + result.push(applyInitializer(property)) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(...createWrappedProperty(property.id!.name, clazz, property, "PlainStructProperty")) + } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(createOptionalClassProperty(property.id!.name, property)) + } + collectImports(imports: Importer): void { + imports.add("PlainStructProperty", "@ohos.arkui") + } +} + +export class LinkTransformer extends PropertyTransformerBase { + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void { + const init = fieldOf( + arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_INITIALIZERS_NAME), property.id?.name!, true) + result.push(arkts.factory.createIfStatement( + (arkts.factory.createBinaryExpression(init, arkts.factory.createUndefinedLiteral(), + Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_NOT_EQUAL)), + applyInitializer(property, "provide") + )) + } + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.LINK) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(...createWrappedProperty(property.id!.name, clazz, property, "LinkDecoratorProperty")) + } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(arkts.factory.createClassProperty( + arkts.factory.createIdentifier(property.id?.name!), + undefined, + createWrapperType("AbstractProperty", property.typeAnnotation!), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_OPTIONAL, + false + )) + } + applyBuild(property: arkts.ClassProperty, result: arkts.Statement[]): void { + } + collectImports(imports: Importer): void { + imports.add("LinkDecoratorProperty", "@ohos.arkui") + imports.add("AbstractProperty", "@ohos.arkui") + } +} + +export class StorageLinkTransformer extends PropertyTransformerBase { + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.STORAGE_LINK) + } + + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(...createWrappedProperty(property.id!.name, clazz, property, "StorageLinkDecoratorProperty", [ + arkts.factory.createStringLiteral(getValueInDecorator(property, DecoratorNames.STORAGE_LINK)!) + ])) + } + + collectImports(imports: Importer): void { + imports.add("StorageLinkDecoratorProperty", "@ohos.arkui") + imports.add("AbstractProperty", "@ohos.arkui") + } +} + + +export class LocalStorageLinkTransformer extends StorageLinkTransformer { + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.LOCAL_STORAGE_LINK) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[], pageLocalStorage?: arkts.Expression): void { + if (!pageLocalStorage) { + throw new Error(`@LocalStorageLink decorator requires storage or useSharedStorage to be set in @Entry decorator of the current file`) + } + result.push(...createWrappedProperty(property.id!.name, clazz, property, "LocalStorageLinkDecoratorProperty", + [ + pageLocalStorage, + arkts.factory.createStringLiteral( + annotationArgumentName(DecoratorNames.LOCAL_STORAGE_LINK, property)! + ) + ] + )) + } + collectImports(imports: Importer): void { + imports.add("LocalStorageLinkDecoratorProperty", "@ohos.arkui") + imports.add("AbstractProperty", "@ohos.arkui") + } +} + +export class PropTransformer extends PropertyTransformerBase { + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void { + result.push(applyInitializer(property)) + } + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.PROP) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(...createWrappedProperty(property.id!.name, clazz, property, "PropDecoratorProperty")) + } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(createOptionalClassProperty(property.id!.name, property)) + } + applyBuild(property: arkts.ClassProperty, result: arkts.Statement[]): void { + // Call backing.update(__context().scope(__id(), 3), initializers?.property) + result.push(callBackingFieldMethod("update", property, [ + // __context().scope(__id(), 1) + arkts.factory.createCallExpression( + fieldOf(memoContext(), "scope"), + [ + memoId(), arkts.factory.createNumberLiteral(3) + ], undefined, false), + fieldOf(arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_INITIALIZERS_NAME), property.id?.name!, true) + ])) + } + collectImports(imports: Importer): void { + imports.add("PropDecoratorProperty", "@ohos.arkui") + imports.add("__id", "@koalaui/runtime") + } +} + +export class StoragePropTransformer extends PropertyTransformerBase { + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.STORAGE_PROP) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(...createWrappedProperty(property.id!.name, clazz, property, "StoragePropDecoratorProperty", + [ + arkts.factory.createStringLiteral( + annotationArgumentName(DecoratorNames.STORAGE_PROP, property)! + ) + ] + )) + } + collectImports(imports: Importer): void { + imports.add("StoragePropDecoratorProperty", "@ohos.arkui") + imports.add("AbstractProperty", "@ohos.arkui") + } +} + +export class LocalStoragePropTransformer extends StoragePropTransformer { + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.LOCAL_STORAGE_PROP) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[], pageLocalStorage?: arkts.Expression): void { + if (!pageLocalStorage) { + throw new Error(`@LocalStorageProp decorator requires storage or useSharedStorage to be set in @Entry decorator of the current file`) + } + result.push(...createWrappedProperty(property.id!.name, clazz, property, "LocalStoragePropDecoratorProperty", + [ + pageLocalStorage, + arkts.factory.createStringLiteral( + annotationArgumentName(DecoratorNames.LOCAL_STORAGE_PROP, property)! + ) + ] + )) + } + collectImports(imports: Importer): void { + imports.add("LocalStoragePropDecoratorProperty", "@ohos.arkui") + imports.add("AbstractProperty", "@ohos.arkui") + } +} + +export class ObjectLinkTransformer extends PropertyTransformerBase { + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void { + result.push(applyInitializer(property)) + } + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.OBJECT_LINK) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + throw new Error(`Implement me`) + } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + throw new Error(`Implement me`) + } +} + +export function fieldOf(base: arkts.Expression, name: string, optional: boolean = false): arkts.MemberExpression { + return arkts.factory.createMemberExpression( + base, + arkts.factory.createIdentifier(name), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + optional) +} + +function annotationArgumentName(name: string, propertyOriginal: arkts.ClassProperty): string | undefined { + const property = propertyOriginal.annotations.find(it => arkts.isIdentifier(it.expr) && it.expr.name == name)!.properties[0] + if (property === undefined) { + return undefined + } + if (!arkts.isClassProperty(property)) { + return undefined + } + if (property.value === undefined) { + return undefined + } + if (!arkts.isStringLiteral(property.value)) { + return undefined + } + return property.value.str +} + +function memoContext(): arkts.Expression { + return arkts.factory.createCallExpression(arkts.factory.createIdentifier("__context"), [], undefined) +} + +function memoId(): arkts.Expression { + return arkts.factory.createCallExpression(arkts.factory.createIdentifier("__id"), [], undefined) +} + +export class ProvideTransformer extends PropertyTransformerBase { + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.PROVIDE) + } + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void { + result.push(applyInitializer(property)) + } + applyBuild(property: arkts.ClassProperty, result: arkts.Statement[]): void { + result.push(callBackingFieldMethod("provide", property, [memoContext()])) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(...createWrappedProperty(property.id!.name, clazz, property, "ProvideDecoratorProperty", + [ + arkts.factory.createStringLiteral( + annotationArgumentName(DecoratorNames.PROVIDE, property) ?? property.id?.name! + ) + ] + )) + } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(createOptionalClassProperty(property.id!.name, property)) + } + collectImports(imports: Importer): void { + imports.add("ProvideDecoratorProperty", "@ohos.arkui") + imports.add("__context", "@koalaui/runtime") + } +} + +export class ConsumeTransformer extends PropertyTransformerBase { + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.CONSUME) + } + applyBuild(property: arkts.ClassProperty, result: arkts.Statement[]): void { + result.push(callBackingFieldMethod("consume", property, [memoContext()])) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + result.push(...createWrappedProperty(property.id!.name, clazz, property, "ConsumeDecoratorProperty", + [ + arkts.factory.createStringLiteral( + annotationArgumentName(DecoratorNames.CONSUME, property) ?? property.id?.name! + ) + ] + )) + } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + } + collectImports(imports: Importer): void { + imports.add("ConsumeDecoratorProperty", "@ohos.arkui") + imports.add("__context", "@koalaui/runtime") + imports.add("StateContext", "@koalaui/runtime") + } +} + +export class BuilderParamTransformer extends PropertyTransformerBase { + check(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.BUILDER_PARAM) + } + applyInitialization(property: arkts.ClassProperty, result: arkts.Statement[]): void { + result.push(applyInitStatement(property)) + } + applyStruct(clazz: arkts.ClassDeclaration, property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + let backing = arkts.factory.createClassProperty( + property.id, + property.value, + undefined, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false + ) + backing.setAnnotations([annotation(InternalAnnotations.MEMO)]) + result.push(backing) + } + applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { + let backing = createOptionalClassProperty(property.id!.name, property) + backing.setAnnotations([annotation(InternalAnnotations.MEMO)]) + result.push(backing) + } +} + +function applyInitStatement(property: arkts.ClassProperty): arkts.Statement { + const name = property.id?.name! + const identifier = arkts.factory.createIdentifier(name, undefined) + const initDeclaration = arkts.factory.createVariableDeclaration( + arkts.Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST, + [ + arkts.factory.createVariableDeclarator( + arkts.Es2pandaVariableDeclaratorFlag.VARIABLE_DECLARATOR_FLAG_CONST, + identifier, + fieldOf(arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_INITIALIZERS_NAME), name, true) + ) + ] + ) + const initBlock = arkts.factory.createIfStatement( + arkts.factory.createBinaryExpression( + identifier, + arkts.factory.createUndefinedLiteral(), + Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_NOT_EQUAL + ), + arkts.factory.createBlockStatement([ + arkts.factory.createExpressionStatement( + arkts.factory.createAssignmentExpression( + fieldOf(arkts.factory.createThisExpression(), name), + identifier, + arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_SUBSTITUTION + ) + ) + ]) + ) + return arkts.factory.createBlockStatement([initDeclaration, initBlock]) +} + +export function isOptionBackedByProperty(property: arkts.ClassProperty): boolean { + return hasDecorator(property, DecoratorNames.LINK) +} + +export function isOptionBackedByPropertyName(decorator: string): boolean { + return decorator == DecoratorNames.LINK +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/property-translators/utils.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/property-translators/utils.ts index 86b8ac93de0..4143844d95f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/property-translators/utils.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/property-translators/utils.ts @@ -46,7 +46,7 @@ export function hasDecorator(property: arkts.ClassProperty | arkts.ClassDefiniti return property.function!.annotations.some((anno) => isDecoratorAnnotation(anno, decoratorName)); } if (arkts.isClassDeclaration(property)) { - return property.decorators.some((anno) => arkts.isIdentifier(anno.expr) && anno.expr.name === decoratorName); + return property.decorators.some((anno) => arkts.isIdentifier(anno.expr) && anno.expr.name === decoratorName) } return property.annotations.some((anno) => isDecoratorAnnotation(anno, decoratorName)); } @@ -215,7 +215,7 @@ function getAnnotationValue(anno: arkts.AnnotationUsage, decoratorName: Decorato return undefined; } -export function getValueInAnnotation(node: arkts.ClassProperty, decoratorName: DecoratorNames): string | undefined { +export function getValueInDecorator(node: arkts.ClassProperty, decoratorName: DecoratorNames): string | undefined { const annotations: readonly arkts.AnnotationUsage[] = node.annotations; for (let i = 0; i < annotations.length; i++) { const anno: arkts.AnnotationUsage = annotations[i]; diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/struct-recorder.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/struct-recorder.ts new file mode 100644 index 00000000000..d201837eaa8 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/struct-recorder.ts @@ -0,0 +1,96 @@ +/* + * 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 arkts from "@koalaui/libarkts" +import * as fs from "fs" + +export class PropertyDescriptor { + constructor(public name: string, public decorators: string[]) {} +} + +export class StructDescriptor { + constructor(public name: string, public properties: PropertyDescriptor[]) {} + static fromJSON(parsed: any): StructDescriptor[] { + return parsed.structs.map((struct: any) => new StructDescriptor(struct.name, + struct.properties.map((property: any) => + new PropertyDescriptor(property.name, property.decorators) + ) + )) + } + + decoratorsFor(name: string): string[] | undefined { + return this.properties.find(it => it.name == name)?.decorators + } +} + +export class StructTable { + structByName = new Map() + + findStruct(name: arkts.Identifier): StructDescriptor | undefined { + return this.structByName.get(name.name) + } + addStruct(declaration: arkts.ETSStructDeclaration) { + this.addDescriptor(this.toDescriptor(declaration)) + } + addDescriptor(descriptor: StructDescriptor) { + this.structByName.set(descriptor.name, descriptor) + } + addDescriptors(descriptors: StructDescriptor[]) { + descriptors.forEach(it => this.addDescriptor(it)) + } + + toDescriptor(declaration: arkts.ETSStructDeclaration): StructDescriptor { + return new StructDescriptor( + declaration.definition?.ident?.name!, + declaration.definition!.body + .filter(arkts.isClassProperty) + .map((classProperty: arkts.ClassProperty) => + new PropertyDescriptor((classProperty.key as arkts.Identifier).name!, + this.extractDecorators(classProperty)) + ) + ) + } + extractDecorators(property: arkts.ClassProperty): string[] { + let decorators = property.decorators + .filter(it => arkts.isIdentifier(it.expr)) + .map(it => (it.expr as arkts.Identifier).name!) + let annotations = property.annotations + .filter(it => arkts.isIdentifier(it.expr)) + .map(it => (it.expr as arkts.Identifier).name!) + return decorators.concat(annotations) + } +} + +export class StructRecorder extends arkts.AbstractVisitor { + constructor(private table: StructTable) { + super() + const database = "./structs.json" + if (fs.existsSync(database)) { + try { + table.addDescriptors(StructDescriptor.fromJSON(JSON.parse(fs.readFileSync(database, "utf-8")))) + } catch (e: any) { + console.log(e.stack) + } + } + } + + visitor(node: arkts.AstNode): arkts.AstNode { + if (arkts.isETSStructDeclaration(node)) { + this.table.addStruct(node) + } + this.visitEachChild(node) + return node + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/struct-transformer.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/struct-transformer.ts deleted file mode 100644 index 698a4d61d20..00000000000 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/struct-transformer.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (c) 2022-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 arkts from "@koalaui/libarkts" -import { - annotation, - collect, - filterDefined -} from "./common/arkts-utils"; -import { - classifyProperty, - PropertyTranslator -} from "./property-translators"; -import { - CustomComponentNames, - getCustomComponentOptionsName, - getTypeNameFromTypeParameter, - getTypeParamsFromClassDecl, -} from "./utils"; -import { - factory -} from "./ui-factory"; -import { DecoratorNames, hasDecorator } from "./property-translators/utils"; - -function isCustomComponentClass(node: arkts.ClassDeclaration): boolean { - if (!node.definition?.ident?.name) return false; - const name: string = node.definition.ident.name; - const structCollection: Set = arkts.GlobalInfo.getInfoInstance().getStructCollection(); - return structCollection.has(name) -} - -function isKnownMethodDefinition(method: arkts.MethodDefinition, name: string): boolean { - if (!method || !arkts.isMethodDefinition(method)) return false; - - // For now, we only considered matched method name. - const isNameMatched: boolean = method.id?.name === name; - return isNameMatched; -} - -function transformBuildMethod( - method: arkts.MethodDefinition, - typeName: string, - optionsName: string, - isDecl?: boolean -): arkts.MethodDefinition { - const updateKey: arkts.Identifier = arkts.factory.createIdentifier( - CustomComponentNames.COMPONENT_BUILD, undefined - ); - - const scriptFunction: arkts.ScriptFunction = method.function! - const updateScriptFunction = arkts.factory.createScriptFunction( - scriptFunction.body, - scriptFunction.typeParams, - [ - factory.createStyleParameter(typeName), - factory.createContentParameter(), - factory.createInitializersOptionsParameter(optionsName) - ], - arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), - false, - scriptFunction.flags, - scriptFunction.modifierFlags, - updateKey, - [annotation("memo")] - ); - - const modifiers: arkts.Es2pandaModifierFlags = isDecl - ? arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_ABSTRACT - : arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC; - return arkts.factory.createMethodDefinition( - arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, - updateKey, - arkts.factory.createFunctionExpression(updateKey, updateScriptFunction), - modifiers, - false - ); -} - -function createInitializeStruct( - structInfo: arkts.StructInfo, - optionsTypeName: string, - isDecl?: boolean -) { - const updateKey: arkts.Identifier = arkts.factory.createIdentifier( - CustomComponentNames.COMPONENT_INITIALIZE_STRUCT, undefined - ); - - let body: arkts.BlockStatement | undefined; - let modifiers: arkts.Es2pandaModifierFlags = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_ABSTRACT; - if (!isDecl) { - body = arkts.factory.createBlockStatement(structInfo.initializeBody); - modifiers = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC; - } - const scriptFunction: arkts.ScriptFunction = arkts.factory.createScriptFunction( - body, - undefined, - [ - factory.createInitializersOptionsParameter(optionsTypeName), - factory.createContentParameter() - ], - arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), - false, - arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - modifiers, - updateKey, - undefined - ); - - return arkts.factory.createMethodDefinition( - arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, - updateKey, - arkts.factory.createFunctionExpression(updateKey, scriptFunction), - modifiers, - false - ); -} - -function createUpdateStruct( - structInfo: arkts.StructInfo, - optionsTypeName: string, - isDecl?: boolean -) { - const updateKey: arkts.Identifier = arkts.factory.createIdentifier( - CustomComponentNames.COMPONENT_UPDATE_STRUCT, undefined - ) - - let body: arkts.BlockStatement | undefined; - let modifiers: arkts.Es2pandaModifierFlags = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_ABSTRACT; - if (!isDecl) { - body = arkts.factory.createBlockStatement(structInfo.updateBody); - modifiers = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC; - } - - const scriptFunction: arkts.ScriptFunction = arkts.factory.createScriptFunction( - body, - undefined, - [ - factory.createInitializersOptionsParameter(optionsTypeName) - ], - arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), - false, - arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - modifiers, - updateKey, - undefined - ); - - return arkts.factory.createMethodDefinition( - arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, - updateKey, - arkts.factory.createFunctionExpression(updateKey, scriptFunction), - modifiers, - false - ); -} - -function tranformPropertyMembers( - className: string, - propertyTranslators: PropertyTranslator[], - optionsTypeName: string, - isDecl?: boolean, - scope?: ScopeInfo -): arkts.AstNode[] { - const propertyMembers = propertyTranslators.map(translator => - translator.translateMember() - ); - const currentStructInfo: arkts.StructInfo = arkts.GlobalInfo - .getInfoInstance() - .getStructInfo(className); - const collections = []; - if (!scope?.hasInitializeStruct) { - collections.push(createInitializeStruct(currentStructInfo, optionsTypeName, isDecl)) - } - if (!scope?.hasUpdateStruct) { - collections.push(createUpdateStruct(currentStructInfo, optionsTypeName, isDecl)) - } - return collect(...collections, ...propertyMembers); -} - -function tranformClassMembers( - node: arkts.ClassDeclaration, - isDecl?: boolean, - scope?: ScopeInfo -): arkts.ClassDeclaration { - if (!node.definition) { - return node; - } - - let classTypeName: string | undefined; - let classOptionsName: string | undefined; - if (isDecl) { - const [classType, classOptions] = getTypeParamsFromClassDecl(node); - classTypeName = getTypeNameFromTypeParameter(classType); - classOptionsName = getTypeNameFromTypeParameter(classOptions); - } - - const definition: arkts.ClassDefinition = node.definition; - const className: string | undefined = node.definition.ident?.name; - if (!className) { - throw new Error("Non Empty className expected for Component") - } - - const propertyTranslators: PropertyTranslator[] = filterDefined( - definition.body.map(it => classifyProperty(it, className)) - ); - - const translatedMembers: arkts.AstNode[] = tranformPropertyMembers( - className, - propertyTranslators, - classOptionsName ?? getCustomComponentOptionsName(className), - isDecl, - scope - ); - - const updateMembers: arkts.AstNode[] = definition.body - .filter((member)=>!arkts.isClassProperty(member)) - .map((member: arkts.AstNode) => { - if (arkts.isMethodDefinition(member) && hasDecorator(member, DecoratorNames.BUILDER)) { - member.function!.setAnnotations([annotation("memo")]); - return member; - } - if ( - arkts.isMethodDefinition(member) - && isKnownMethodDefinition(member, CustomComponentNames.COMPONENT_CONSTRUCTOR_ORI) - && !isDecl - ) { - return arkts.factory.createMethodDefinition( - arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_CONSTRUCTOR, - member.id, - arkts.factory.createFunctionExpression(member.id, member.function), - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_CONSTRUCTOR, - false - ); - } - if ( - arkts.isMethodDefinition(member) - && isKnownMethodDefinition(member, CustomComponentNames.COMPONENT_BUILD_ORI) - ) { - const buildMethod = transformBuildMethod( - member, - classTypeName ?? className, - classOptionsName ?? getCustomComponentOptionsName(className), - isDecl - ); - return buildMethod; - } - - return member; - } - ); - - const updateClassDef: arkts.ClassDefinition = arkts.factory.updateClassDefinition( - definition, - definition.ident, - definition.typeParams, - definition.superTypeParams, - definition.implements, - undefined, - definition.super, - [...translatedMembers, ...updateMembers], - definition.modifiers, - arkts.classDefinitionFlags(definition) - ); - - return arkts.factory.updateClassDeclaration(node, updateClassDef); -} - -type ScopeInfo = { - name: string, - hasInitializeStruct?: boolean, - hasUpdateStruct?: boolean, -} - -export class StructTransformer extends arkts.AbstractVisitor { - private scopeInfos: ScopeInfo[] = []; - - enter(node: arkts.AstNode) { - if (arkts.isClassDeclaration(node) && isCustomComponentClass(node)) { - this.scopeInfos.push({ name: node.definition!.ident!.name }); - } - if (arkts.isMethodDefinition(node) && this.scopeInfos.length > 0) { - const name = node.id!.name - const scopeInfo = this.scopeInfos.pop()!; - scopeInfo.hasInitializeStruct ||= (name === CustomComponentNames.COMPONENT_INITIALIZE_STRUCT); - scopeInfo.hasUpdateStruct ||= (name === CustomComponentNames.COMPONENT_UPDATE_STRUCT); - this.scopeInfos.push(scopeInfo); - } - } - - exit(node: arkts.AstNode) { - if (arkts.isClassDeclaration(node) && isCustomComponentClass(node)) { - this.scopeInfos.pop(); - } - } - - visitor(beforeChildren: arkts.AstNode): arkts.AstNode { - this.enter(beforeChildren); - const node = this.visitEachChild(beforeChildren); - if (arkts.isClassDeclaration(node) && isCustomComponentClass(node)) { - let scope: ScopeInfo | undefined; - if (this.scopeInfos.length > 0) { - scope = this.scopeInfos[this.scopeInfos.length - 1]; - } - const newClass: arkts.ClassDeclaration = tranformClassMembers( - node, - arkts.hasModifierFlag(node, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE), - scope - ); - this.exit(beforeChildren); - return newClass; - } - return node - } -} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/utils.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/utils.ts index 7921366fcf0..138330e92f4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/utils.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/ui-plugins/src/utils.ts @@ -14,6 +14,7 @@ */ import * as arkts from "@koalaui/libarkts" +import { DecoratorNames, hasDecorator } from "./property-translators/utils" export const styledInstance = mangle("instance") @@ -82,7 +83,7 @@ export function createOptionalClassProperty( arkts.factory.createIdentifier(name, undefined), undefined, stageManagementIdent.length ? createStageManagementType(stageManagementIdent, property) : - newType, + newType, modifiers, false ); @@ -105,11 +106,76 @@ export function createStageManagementType(stageManagementIdent: string, property arkts.factory.createIdentifier(stageManagementIdent, undefined), arkts.factory.createTSTypeParameterInstantiation( [ - newType? newType: - arkts.factory.createETSUndefinedType(), + newType ? newType : + arkts.factory.createETSUndefinedType(), ] ), undefined ) ); -} \ No newline at end of file +} + +export function makeImport(program: arkts.Program, what: string, asWhat: string, where: string) { + const source: arkts.StringLiteral = arkts.factory.createStringLiteral(where) + arkts.factory.createETSImportDeclaration( + source, + [ + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier(what), + arkts.factory.createIdentifier(asWhat) + ) + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, + program, + arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE + ) +} + +export class Importer { + storage = new Map() + private defaultArkUIImports = [ + 'Color', 'Button', 'ButtonOptions', 'ClickEvent', 'FlexAlign', + 'Image', 'ListOptions', 'Scroller', 'SwiperController', + 'PageTransitionEnter', 'PageTransitionExit', 'PageTransitionOptions', + 'Column', 'ColumnOptions', 'Row', 'RowOptions', + 'FlexOptions', 'TabsOptions', 'StackOptions', 'ToggleOptions', 'TextInputOptions', + 'TestComponent', 'TestComponentOptions', 'ForEach', 'Text', + 'Margin', 'Padding', 'BorderOptions', 'Curve', 'RouteType', 'TextOverflowOptions', + 'Flex', 'FlexWrap', 'HorizontalAlign', 'Scroll', 'Tabs', 'TabsController', 'TabContent', + 'NavDestination', 'NavPathStack', 'Literal_String_target_NavigationType_type', + 'IDataSource', 'DataChangeListener', 'ItemAlign', 'ImageFit', 'FlexDirection', + 'FontWeight', 'Counter', 'Toggle', 'ToggleType', 'BarMode', 'TextAlign', 'VerticalAlign', + 'TextOverflow', 'BarState', 'NavPathInfo', 'Stack', 'Swiper', + 'List', 'ListItem', 'Grid', 'GridItem', 'Navigator', 'Position', 'Axis', + 'TextInput', 'Font', 'Alignment', 'Visibility', 'ImageRepeat', 'SizeOptions', 'Divider', + 'TabBarOptions', 'Navigation', 'Span', 'NavigationMode', 'BarPosition', 'EnterKeyType', + 'LazyForEach', + 'TestComponent', 'TestComponentOptions', 'ForEach', 'Text', 'AppStorage', 'LocalStorage', + 'SubscribedAbstractProperty', + ] + constructor() { + const withDefaultImports = true + if (withDefaultImports) { + this.defaultArkUIImports.forEach(it => { + this.add(it, '@ohos.arkui') + }) + } + } + add(what: string, where: string, asWhat?: string) { + const previous = this.storage.get(what) + if (!asWhat) + asWhat = what + if (previous != undefined && (previous[0] != where || previous[1] != asWhat)) + throw new Error(`Mismatching import ${what} from ${where}`) + this.storage.set(what, [where, asWhat]) + } + emit(program: arkts.Program): void { + this.storage.forEach(([where, asWhat], what) => { + makeImport(program, what, asWhat, where) + }) + } +} + +export interface ImportingTransformer { + collectImports(imports: Importer): void +} -- Gitee From 3905aa3ae049cb33ad11de09bcca0ee5a86625e0 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Thu, 22 May 2025 11:23:30 +0300 Subject: [PATCH 2/3] Fix code check Signed-off-by: Anton Tarasov --- .../incremental/runtime/oh-package.json5 | 14 +++++ .../tools/panda/arkts/std-lib/global.d.ts | 15 +++++ .../koala_mirror/interop/src/cpp/vmloader.cc | 60 +++++++++++-------- .../ui2abc/libarkts/generator/options.json5 | 14 +++++ .../ui2abc/libarkts/native/src/common.cc | 41 ++++++++----- .../ui2abc/libarkts/native/src/common.h | 18 ++++-- .../imports/recursive/one_recursive.ts | 15 +++++ .../imports/recursive/two_recursive.ts | 15 +++++ .../recheck/simple/add-variable/index.ts | 15 +++++ .../recheck/simple/add-variable/main.ts | 15 +++++ .../recheck/static/import-type/library.ts | 15 +++++ .../recheck/static/typed-property/main.ts | 15 +++++ .../ui2abc/memo-plugin/test/rewrite.test.ts | 15 ++++- 13 files changed, 221 insertions(+), 46 deletions(-) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/oh-package.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/oh-package.json5 index 5dc6bc9a7ee..1f773caeaeb 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/oh-package.json5 +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/oh-package.json5 @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2022-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. + */ { "name": "@koalaui/runtime", "version": "1.4.1+devel", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/arkts/std-lib/global.d.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/arkts/std-lib/global.d.ts index 15bfc962afb..4ea23bf1e38 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/arkts/std-lib/global.d.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/tools/panda/arkts/std-lib/global.d.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2022-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. + */ + declare type int32 = number declare type int8 = number declare type float32 = number diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/vmloader.cc b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/vmloader.cc index a5306f8fb25..689351f6968 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/vmloader.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/src/cpp/vmloader.cc @@ -185,7 +185,8 @@ enum PandaLog2MobileLog : int { SILENT, }; -int ArkMobileLog(int id, int level, const char *component, const char *fmt, const char *msg) { +int ArkMobileLog(int id, int level, const char *component, const char *fmt, const char *msg) +{ switch (level) { case PandaLog2MobileLog::DEFAULT: case PandaLog2MobileLog::VERBOSE: @@ -211,7 +212,8 @@ int ArkMobileLog(int id, int level, const char *component, const char *fmt, cons #ifdef KOALA_ANI static void AniMobileLog([[maybe_unused]] FILE *stream, int level, - const char *component, const char *msg) { + const char *component, const char *msg) +{ switch (level) { case ANI_LOGLEVEL_INFO: case ANI_LOGLEVEL_DEBUG: @@ -226,7 +228,8 @@ static void AniMobileLog([[maybe_unused]] FILE *stream, int level, } } -static std::string makeClasspath(const std::vector& files) { +static std::string makeClasspath(const std::vector& files) +{ std::stringstream stream; for (size_t index = 0, end = files.size(); index < end; ++index) { if (index > 0) { @@ -261,7 +264,8 @@ static std::pair GetBootAndAppPandaFiles(const VMLibIn return { makeClasspath(bootFiles), makeClasspath(files) }; } -static std::string GetAOTFiles(const char* appClassPath) { +static std::string GetAOTFiles(const char* appClassPath) +{ std::vector files; traverseDir(std::string(appClassPath), files, ".an"); return makeClasspath(files); @@ -280,7 +284,8 @@ static bool ResetErrorIfExists(ani_env *env) } #endif -extern "C" DLL_EXPORT KInt LoadVirtualMachine(KInt vmKind, const char* appClassPath, const char* appLibPath, const ForeignVMContext* foreignVMContext) { +extern "C" DLL_EXPORT KInt LoadVirtualMachine(KInt vmKind, const char* appClassPath, const char* appLibPath, const ForeignVMContext* foreignVMContext) +{ if (vmKind == ES2PANDA_KIND) { return loadES2Panda(appClassPath, appLibPath); } @@ -534,19 +539,19 @@ const AppInfo harnessAppInfo = { #endif #ifdef KOALA_ANI const AppInfo harnessAniAppInfo = { - "L@koalaui/ets-harness/src/EtsHarnessApplication/EtsHarnessApplication;", - "createApplication", - "Lstd/core/String;Lstd/core/String;ZI:L@koalaui/ets-harness/src/EtsHarnessApplication/EtsHarnessApplication;", - "start", - "J:J", - "enter", - "IIJ:Z", - "emitEvent", - "IIII:Lstd/core/String;", - "restartWith", - "Lstd/core/String;:V", - "UNUSED", - "I:I" + "L@koalaui/ets-harness/src/EtsHarnessApplication/EtsHarnessApplication;", + "createApplication", + "Lstd/core/String;Lstd/core/String;ZI:L@koalaui/ets-harness/src/EtsHarnessApplication/EtsHarnessApplication;", + "start", + "J:J", + "enter", + "IIJ:Z", + "emitEvent", + "IIII:Lstd/core/String;", + "restartWith", + "Lstd/core/String;:V", + "UNUSED", + "I:I" }; const AppInfo aniAppInfo = { "L@ohos/arkui/Application/Application;", @@ -565,7 +570,8 @@ const AppInfo aniAppInfo = { }; #endif -extern "C" DLL_EXPORT KNativePointer StartApplication(const char* appUrl, const char* appParams) { +extern "C" DLL_EXPORT KNativePointer StartApplication(const char* appUrl, const char* appParams) +{ const auto isTestEnv = std::string(appUrl) == "EtsHarness"; const AppInfo* appInfo = #ifdef KOALA_JNI @@ -770,7 +776,8 @@ extern "C" DLL_EXPORT KNativePointer StartApplication(const char* appUrl, const ani_method loadView {}; status = env->Class_FindMethod(appClass, appInfo->loadViewMethodName, appInfo->loadViewMethodSig, &loadView); if (status != ANI_OK) { - LOGE("Cannot find `%" LOG_PUBLIC "s` method %" LOG_PUBLIC "s", appInfo->loadViewMethodName, appInfo->loadViewMethodSig); + LOGE("Cannot find `%" LOG_PUBLIC "s` method %" LOG_PUBLIC "s", + appInfo->loadViewMethodName, appInfo->loadViewMethodSig); ResetErrorIfExists(env); return nullptr; } @@ -865,7 +872,8 @@ extern "C" DLL_EXPORT KBoolean RunApplication(const KInt arg0, const KInt arg1) return 1; } -extern "C" DLL_EXPORT const char* EmitEvent(const KInt type, const KInt target, const KInt arg0, const KInt arg1) { +extern "C" DLL_EXPORT const char* EmitEvent(const KInt type, const KInt target, const KInt arg0, const KInt arg1) +{ #ifdef KOALA_JNI if (g_vmEntry.vmKind == JAVA_VM_KIND) { JNIEnv* jEnv = (JNIEnv*)(g_vmEntry.env); @@ -956,7 +964,8 @@ extern "C" DLL_EXPORT const char* EmitEvent(const KInt type, const KInt target, return "-1"; } -extern "C" DLL_EXPORT void RestartWith(const char* page) { +extern "C" DLL_EXPORT void RestartWith(const char* page) +{ #ifdef KOALA_JNI if (g_vmEntry.vmKind == JAVA_VM_KIND) { JNIEnv* jEnv = (JNIEnv*)(g_vmEntry.env); @@ -1017,7 +1026,8 @@ extern "C" DLL_EXPORT void RestartWith(const char* page) { #endif } -extern "C" DLL_EXPORT const char* LoadView(const char* className, const char* params) { +extern "C" DLL_EXPORT const char* LoadView(const char* className, const char* params) +{ #if defined(KOALA_ANI) if (g_vmEntry.vmKind == PANDA_ANI_VM_KIND) { ani_env *env = reinterpret_cast(g_vmEntry.env); @@ -1049,7 +1059,6 @@ extern "C" DLL_EXPORT const char* LoadView(const char* className, const char* pa char* resultChars = (char*)malloc(resultStringLength); status = env->String_GetUTF8(resultString, resultChars, resultStringLength, &resultStringLength); return resultChars; - } #endif return strdup("Unsupported"); @@ -1062,7 +1071,8 @@ bool ends_with(std::string str, std::string suffix) return str.size() >= suffix.size() && str.compare(str.size()-suffix.size(), suffix.size(), suffix) == 0; } -void traverseDir(const std::string& root, std::vector& paths, std::string suffix, const std::vector& fallbackPaths) { +void traverseDir(const std::string& root, std::vector& paths, std::string suffix, const std::vector& fallbackPaths) +{ #ifdef KOALA_OHOS_ARM32 // selinux prohibits any access to "/system/framework" if (root == "/system/framework") { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/generator/options.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/generator/options.json5 index 86a22e00a80..3b5c1fa3bb0 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/generator/options.json5 +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/generator/options.json5 @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2022-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. + */ { "irHack": [ "AnnotationUsage", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.cc b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.cc index 1d87e90fe3f..73dddb02c7d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.cc +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.cc @@ -22,16 +22,19 @@ static es2panda_Impl *impl = nullptr; static thread_local StageArena currentArena; -StageArena* StageArena::instance() { +StageArena* StageArena::instance() +{ return ¤tArena; } -void StageArena::add(void* pointer) { +void StageArena::add(void* pointer) +{ if (pointer) allocated.push_back(pointer); } -void StageArena::cleanup() { +void StageArena::cleanup() +{ if (totalSize > 0 && false) printf("cleanup %d objects %d bytes\n", (int)allocated.size(), (int)totalSize); for (auto it : allocated) { @@ -41,15 +44,18 @@ void StageArena::cleanup() { allocated.clear(); } -StageArena::StageArena() { +StageArena::StageArena() +{ totalSize = 0; } -StageArena::~StageArena() { +StageArena::~StageArena() +{ cleanup(); } -char* StageArena::strdup(const char* string) { +char* StageArena::strdup(const char* string) +{ auto* arena = StageArena::instance(); auto size = strlen(string) + 1; char* memory = (char*)arena->alloc(size); @@ -57,7 +63,8 @@ char* StageArena::strdup(const char* string) { return memory; } -void* StageArena::alloc(size_t size) { +void* StageArena::alloc(size_t size) +{ void* result = malloc(size); totalSize += size; add(result); @@ -87,7 +94,8 @@ void* StageArena::alloc(size_t size) { const char* DEFAULT_SDK_PATH = "../../../incremental/tools/panda/node_modules/@panda/sdk" ; const char* NAME = LIB_PREFIX "es2panda-public" LIB_SUFFIX; -void* FindLibrary() { +void* FindLibrary() +{ char* envValue = getenv("PANDA_SDK_PATH"); if (!envValue) { std::cout << "PANDA_SDK_PATH not specified, assuming " << DEFAULT_SDK_PATH << std::endl; @@ -97,13 +105,14 @@ void* FindLibrary() { return loadLibrary(libraryName); } -es2panda_Impl *GetImpl() { +es2panda_Impl *GetImpl() +{ if (impl) { return impl; } auto library = FindLibrary(); if (!library) { - printf("No library (es2panda_lib.cc)"); // TODO: dont use throw for ohos build + printf("No library (es2panda_lib.cc)"); abort(); } auto symbol = findSymbol(library, "es2panda_GetImpl"); @@ -120,15 +129,18 @@ es2panda_ContextState intToState(KInt state) return es2panda_ContextState(state); } -string getString(KStringPtr ptr) { +string getString(KStringPtr ptr) +{ return ptr.data(); } -char* getStringCopy(KStringPtr& ptr) { +char* getStringCopy(KStringPtr& ptr) +{ return StageArena::strdup(ptr.c_str() ? ptr.c_str() : ""); } -inline KUInt unpackUInt(const KByte* bytes) { +inline KUInt unpackUInt(const KByte* bytes) +{ const KUInt BYTE_0 = 0; const KUInt BYTE_1 = 1; const KUInt BYTE_2 = 2; @@ -256,7 +268,8 @@ KOALA_INTEROP_2(AstNodeUpdateChildren, KNativePointer, KNativePointer, KNativePo std::vector cachedChildren; -static void visitChild(es2panda_AstNode *node) { +static void visitChild(es2panda_AstNode *node) +{ cachedChildren.emplace_back(node); } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.h b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.h index d08db0b23c2..3c908f52636 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.h +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/native/src/common.h @@ -44,38 +44,44 @@ class StageArena { ~StageArena(); static StageArena* instance(); template - static T* alloc() { + static T* alloc() + { auto* arena = StageArena::instance(); void* memory = arena->alloc(sizeof(T)); return new (memory) T(); } template - static T* alloc(T1 arg1) { + static T* alloc(T1 arg1) + { auto* arena = StageArena::instance(); void* memory = arena->alloc(sizeof(T)); return new (memory) T(std::forward(arg1)); } template - static T* alloc(T1 arg1, T2 arg2) { + static T* alloc(T1 arg1, T2 arg2) + { auto* arena = StageArena::instance(); void* memory = arena->alloc(sizeof(T)); return new (memory) T(arg1, arg2); } template - static T* allocArray(size_t count) { + static T* allocArray(size_t count) + { auto* arena = StageArena::instance(); // align? void* memory = arena->alloc(sizeof(T) * count); return new (memory) T(); } template - static T* clone(const T& arg) { + static T* clone(const T& arg) + { auto* arena = StageArena::instance(); void* memory = arena->alloc(sizeof(T)); return new (memory) T(arg); } template - static std::vector* cloneVector(const T* arg, size_t count) { + static std::vector* cloneVector(const T* arg, size_t count) + { return alloc, const T*, const T*>(arg, arg + count); } void* alloc(size_t size); diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/one_recursive.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/one_recursive.ts index fc837a57b0f..bbc749b1240 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/one_recursive.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/one_recursive.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2022-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 { Two } from "./two_recursive" export interface One { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/two_recursive.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/two_recursive.ts index a4d708b6428..ee28528bd7b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/two_recursive.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/two_recursive.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2022-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 { One } from "./one_recursive" export interface Two { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/index.ts index dd15eabbc8b..fd15fbbd215 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/index.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2022-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 arkts from "../../../../../src/arkts-api" export function addVariableDeclaration(node: arkts.ClassDefinition) { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/main.ts index 3a7a5ed929f..408125c2b4b 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/main.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2022-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. + */ + class C { f(): void { } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/library.ts index 514f6b6de0c..e76c034cae8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/library.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/library.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2022-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. + */ + export class Scope { static scope(): Scope { throw new Error("") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/main.ts index 175c1b31155..6cddab31224 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/main.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2022-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. + */ + interface I { prop: boolean } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/rewrite.test.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/rewrite.test.ts index 77af0c7696e..bdda588dcb6 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/rewrite.test.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/rewrite.test.ts @@ -1,4 +1,17 @@ - +/* + * Copyright (c) 2022-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 fs from "node:fs" import * as child_process from "node:child_process" -- Gitee From 03d35f7915a86307aeb994fb3d64ea5cb34242bb Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Thu, 22 May 2025 16:47:56 +0300 Subject: [PATCH 3/3] Add copyright's Signed-off-by: Anton Tarasov --- .../incremental/common/oh-package.json5 | 15 +++++++++++++++ .../incremental/compat/oh-package.json5 | 15 +++++++++++++++ .../incremental/runtime/annotations/index.ts | 15 +++++++++++++++ .../koala_mirror/interop/oh-package.json5 | 15 +++++++++++++++ .../libarkts/plugins/input/one_recursive.ts | 15 +++++++++++++++ .../libarkts/plugins/input/two_recursive.ts | 15 +++++++++++++++ .../test/arkts-api/recheck/constructor/index.ts | 15 +++++++++++++++ .../test/arkts-api/recheck/constructor/main.ts | 15 +++++++++++++++ .../recheck/imports/add-new-file/index.ts | 15 +++++++++++++++ .../recheck/imports/add-new-file/library.ts | 15 +++++++++++++++ .../recheck/imports/add-new-file/main.ts | 15 +++++++++++++++ .../imports/add-same-file/dump-src/main.ts | 15 +++++++++++++++ .../recheck/imports/add-same-file/index.ts | 15 +++++++++++++++ .../recheck/imports/add-same-file/library.ts | 15 +++++++++++++++ .../recheck/imports/add-same-file/main.ts | 15 +++++++++++++++ .../imports/add-use-same-file/dump-src/main.ts | 15 +++++++++++++++ .../recheck/imports/add-use-same-file/index.ts | 15 +++++++++++++++ .../recheck/imports/add-use-same-file/library.ts | 15 +++++++++++++++ .../recheck/imports/add-use-same-file/main.ts | 15 +++++++++++++++ .../recheck/imports/recursive/dump-src/main.ts | 15 +++++++++++++++ .../arkts-api/recheck/imports/recursive/index.ts | 15 +++++++++++++++ .../arkts-api/recheck/imports/recursive/main.ts | 15 +++++++++++++++ .../overloads/getter-setter/dump-src/main.ts | 15 +++++++++++++++ .../recheck/overloads/getter-setter/index.ts | 15 +++++++++++++++ .../recheck/overloads/getter-setter/main.ts | 15 +++++++++++++++ .../simple/add-class-method/dump-src/main.ts | 15 +++++++++++++++ .../recheck/simple/add-class-method/index.ts | 15 +++++++++++++++ .../recheck/simple/add-class-method/main.ts | 15 +++++++++++++++ .../recheck/simple/add-variable/dump-src/main.ts | 15 +++++++++++++++ .../test/arkts-api/recheck/simple/index.ts | 15 +++++++++++++++ .../recheck/simple/rename-class/dump-src/main.ts | 15 +++++++++++++++ .../recheck/simple/rename-class/index.ts | 15 +++++++++++++++ .../arkts-api/recheck/simple/rename-class/main.ts | 15 +++++++++++++++ .../recheck/static/constructor/dump-src/main.ts | 15 +++++++++++++++ .../arkts-api/recheck/static/constructor/main.ts | 15 +++++++++++++++ .../recheck/static/function/dump-src/main.ts | 15 +++++++++++++++ .../arkts-api/recheck/static/function/main.ts | 15 +++++++++++++++ .../recheck/static/import-type/dump-src/main.ts | 15 +++++++++++++++ .../arkts-api/recheck/static/import-type/main.ts | 15 +++++++++++++++ .../arkts-api/recheck/static/property/main.ts | 15 +++++++++++++++ .../recheck/static/public-setter/dump-src/main.ts | 15 +++++++++++++++ .../recheck/static/public-setter/library.ts | 15 +++++++++++++++ .../recheck/static/public-setter/main.ts | 15 +++++++++++++++ .../static/trailing-block/dump-src/main.ts | 15 +++++++++++++++ .../recheck/static/trailing-block/main.ts | 15 +++++++++++++++ .../static/typed-property/dump-src/main.ts | 15 +++++++++++++++ .../test/arkts-api/recheck/this/dump-src/main.ts | 15 +++++++++++++++ .../libarkts/test/arkts-api/recheck/this/index.ts | 15 +++++++++++++++ .../libarkts/test/arkts-api/recheck/this/main.ts | 15 +++++++++++++++ .../ui2abc/memo-plugin/demo/demo/demo.ets | 15 +++++++++++++++ .../ui2abc/memo-plugin/test/golden/test.ets | 15 +++++++++++++++ 51 files changed, 765 insertions(+) diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/oh-package.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/oh-package.json5 index a217907f839..002cc9ceb89 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/oh-package.json5 +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/common/oh-package.json5 @@ -1,3 +1,18 @@ +/* + * 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. + */ + { "name": "@koalaui/common", "version": "1.4.1+devel", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/oh-package.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/oh-package.json5 index 45b5a9768f2..2a282c4e7f9 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/oh-package.json5 +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/compat/oh-package.json5 @@ -1,3 +1,18 @@ +/* + * 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. + */ + { "name": "@koalaui/compat", "version": "1.4.0+devel", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/annotations/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/annotations/index.ts index 11ec0d27174..950b575cb1f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/annotations/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/incremental/runtime/annotations/index.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + @Retention({policy: "SOURCE"}) export @interface memo {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/interop/oh-package.json5 b/frameworks/bridge/arkts_frontend/koala_mirror/interop/oh-package.json5 index 96d62e6ba57..15670e65319 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/interop/oh-package.json5 +++ b/frameworks/bridge/arkts_frontend/koala_mirror/interop/oh-package.json5 @@ -1,3 +1,18 @@ +/* + * 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. + */ + { "name": "@koalaui/interop", "version": "1.4.1+devel", diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/one_recursive.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/one_recursive.ts index fc837a57b0f..6da908be790 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/one_recursive.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/one_recursive.ts @@ -1,3 +1,18 @@ +/* + * 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 { Two } from "./two_recursive" export interface One { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/two_recursive.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/two_recursive.ts index a4d708b6428..aa6255f9522 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/two_recursive.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/plugins/input/two_recursive.ts @@ -1,3 +1,18 @@ +/* + * 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 { One } from "./one_recursive" export interface Two { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/index.ts index 1b24ce7da8b..1306b0d764a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../src/arkts-api" class ConstructorWithOverload extends arkts.AbstractVisitor { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/main.ts index 975d1d79b36..8a2368ec05e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/constructor/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + class XXX { constructor(x: ()=>void, y?: ()=>void) { } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/index.ts index 2946c348503..83c1576ba7d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../../src/arkts-api" export function addImportNewFile(program: arkts.Program, options: arkts.CompilationOptions) { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/library.ts index 226253e9d76..1620606109d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/library.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/library.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + export function testFunction(): string { return "yes" } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/main.ts index 2a2392b9dc5..efe0df8d7d4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-new-file/main.ts @@ -1 +1,16 @@ +/* + * 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. + */ + console.log("test") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/dump-src/main.ts index 51d2896e435..a542224bb03 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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 { testFunction as testFunction } from "./library"; diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/index.ts index 5f77f7fb3b4..763afe01a35 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../../src/arkts-api" export function addImportSameFile(program: arkts.Program, options: arkts.CompilationOptions) { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/library.ts index 226253e9d76..1620606109d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/library.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/library.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + export function testFunction(): string { return "yes" } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/main.ts index efa3eceaeb9..898976f1961 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-same-file/main.ts @@ -1,2 +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. + */ + import { anotherFunction } from "./library" console.log("test") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/dump-src/main.ts index d6401c45269..bffe8e05540 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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 { testFunction as testFunction } from "./library"; diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/index.ts index 6da984d08a8..add6c77b8a3 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../../src/arkts-api" export function addUseImportSameFile(program: arkts.Program, options: arkts.CompilationOptions) { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/library.ts index 226253e9d76..1620606109d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/library.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/library.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + export function testFunction(): string { return "yes" } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/main.ts index efa3eceaeb9..898976f1961 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/add-use-same-file/main.ts @@ -1,2 +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. + */ + import { anotherFunction } from "./library" console.log("test") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/dump-src/main.ts index 093458f2ff8..cca825de903 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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 { One as One } from "./one_recursive"; diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/index.ts index 5925d2dab2e..a5a1943b98c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../../src/arkts-api" class InsertParameter extends arkts.AbstractVisitor { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/main.ts index 29cffa6f9e5..657e5b30221 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/imports/recursive/main.ts @@ -1,2 +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. + */ + import { One } from "./one_recursive" import { Two } from "./two_recursive" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/dump-src/main.ts index 5650ef6e54d..4acc62ff9c8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/index.ts index 2fd1bf9faf6..c281a07684e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../../src/arkts-api" class InsertParameterToType extends arkts.AbstractVisitor { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/main.ts index a75751fe367..f2ac2c1014a 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/overloads/getter-setter/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + interface I { set f(f: () => void) get f(): () => void diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/dump-src/main.ts index d15caa7a435..c3d0002b3c8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/index.ts index d8ec3449ca1..d4a24fa6ac8 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../../src/arkts-api" export function addClassMethod(node: arkts.ClassDefinition) { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/main.ts index 8ad54365639..1395993b24e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-class-method/main.ts @@ -1,2 +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. + */ + class C { } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/dump-src/main.ts index b180ebf3466..f5775f4f0a7 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/add-variable/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/index.ts index e384d03c391..20cc930b1cd 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../src/arkts-api" export function updateTopLevelClass( diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/dump-src/main.ts index 19141932f61..df48616f587 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/index.ts index 687e98b604e..e3c50f05362 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../../src/arkts-api" export function renameClass(node: arkts.ClassDefinition) { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/main.ts index 3a7a5ed929f..728f17f4700 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/simple/rename-class/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + class C { f(): void { } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/dump-src/main.ts index 19bfce52f3e..44e19172f81 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/main.ts index 975d1d79b36..8a2368ec05e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/constructor/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + class XXX { constructor(x: ()=>void, y?: ()=>void) { } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/dump-src/main.ts index 59bd2154e84..020001c6e86 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/main.ts index b0400ee9b26..04595586e42 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/function/main.ts @@ -1 +1,16 @@ +/* + * 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. + */ + function foo() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/dump-src/main.ts index e4df10838ff..412a51d0206 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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 { ExportedType as ExportedType } from "./library"; diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/main.ts index ed36fa34b94..34fc21ede14 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/import-type/main.ts @@ -1 +1,16 @@ +/* + * 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 { ExportedType } from "./library" diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/property/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/property/main.ts index 3ec35cab43f..32bf61de01f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/property/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/property/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + interface I { prop: boolean } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/dump-src/main.ts index 81e34015fe5..93e56592b44 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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 { AnimatedState as AnimatedState, one as one } from "./library"; diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/library.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/library.ts index 3f285d4cf5c..d7bbf1d284c 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/library.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/library.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + export interface AnimatedState { paused: boolean } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/main.ts index ff6230f6270..aebce5f39b4 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/public-setter/main.ts @@ -1,3 +1,18 @@ +/* + * 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 { AnimatedState, one } from "./library" let x: AnimatedState|undefined diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/dump-src/main.ts index b5ea13d894e..30f552449d9 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/main.ts index c16a244ace6..da09221e2dc 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/trailing-block/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + class C { f(arg: () => void): void { } diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/dump-src/main.ts index 47d87b20892..d65d9c9388d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/static/typed-property/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/dump-src/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/dump-src/main.ts index 5d580cf9c08..aa0f81d1b5e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/dump-src/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/dump-src/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + function main() {} diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/index.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/index.ts index e6c3f77195b..99b23c89d0d 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/index.ts @@ -1,3 +1,18 @@ +/* + * 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 arkts from "../../../../src/arkts-api" class AddThisReference extends arkts.AbstractVisitor { diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/main.ts b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/main.ts index 66ca6f5572d..61b88d9d81e 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/main.ts +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/libarkts/test/arkts-api/recheck/this/main.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + class A { no_this() { console.log("test") diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/demo/demo.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/demo/demo.ets index 7bc85bcd040..e0be4b9d692 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/demo/demo.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/demo/demo/demo.ets @@ -1,3 +1,18 @@ +/* + * 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 { IncrementalNode, NodeAttach, mutableState, contextLocalValue, ReadonlyTreeNode, memoRoot, updateStateManager, diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/golden/test.ets b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/golden/test.ets index 264235366b0..f2ec4b8cf10 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/golden/test.ets +++ b/frameworks/bridge/arkts_frontend/koala_mirror/ui2abc/memo-plugin/test/golden/test.ets @@ -1,3 +1,18 @@ +/* + * 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 { __memo_context_type as __memo_context_type, __memo_id_type as __memo_id_type, __hash as __hash } from "@koalaui/runtime"; -- Gitee