diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index 2f82079f432a04b138555a74d7b098cf62a7e15f..fee157200d6b78b5a711a33583e959e6e8621944 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -81,24 +81,8 @@ void ImportDeclaration::Dump(ir::SrcDumper *dumper) const dumper->Add(" from "); - if (dumper->IsDeclgen()) { - auto fileName = Source()->Str(); - auto len = fileName.Length(); - if (fileName.EndsWith(".ets")) { - len -= 4U; - fileName = fileName.Substr(0, len); - } - - std::string importFile = '\"' + util::Helpers::CreateEscapedString(fileName.Utf8()); - if (fileName.Utf8().find('.', 1U) == std::string_view::npos) { - importFile += ".d"; - } - importFile += '\"'; + Source()->Dump(dumper); - dumper->Add(importFile); - } else { - Source()->Dump(dumper); - } dumper->Add(";"); dumper->Endl(); } diff --git a/ets2panda/test/unit/plugin/CMakeLists.txt b/ets2panda/test/unit/plugin/CMakeLists.txt index 7ba38739e11bf296e60f41d912be2e171d20901b..98157ab987a09b4e6ab5530fa3ceeb32314878db 100644 --- a/ets2panda/test/unit/plugin/CMakeLists.txt +++ b/ets2panda/test/unit/plugin/CMakeLists.txt @@ -123,6 +123,7 @@ set(PLUGIN_TESTS "plugin_proceed_to_state_setters_for_param_rewrite compile.ets ${COMPILE_MODE} cpp ${EXECUTABLE_PLUGIN}" "plugin_proceed_to_state_dump_src_for_etsglobal_test compile.ets ${COMPILE_MODE} cpp ${EXECUTABLE_PLUGIN}" "plugin_proceed_to_state_dump_decl_test compile.ets ${COMPILE_MODE} cpp ${EXECUTABLE_PLUGIN}" + "plugin_proceed_to_state_dump_src_after_check compile.ets ${COMPILE_MODE} cpp ${EXECUTABLE_PLUGIN}" ) set(RUNTIME_ARGUMENTS diff --git a/ets2panda/test/unit/plugin/plugin_proceed_to_state_dump_src_after_check.cpp b/ets2panda/test/unit/plugin/plugin_proceed_to_state_dump_src_after_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c8edeb011934af142773ef03ff5ca42945b8b28 --- /dev/null +++ b/ets2panda/test/unit/plugin/plugin_proceed_to_state_dump_src_after_check.cpp @@ -0,0 +1,116 @@ +/** + * 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 +#include +#include + +#include "os/library_loader.h" + +#include "public/es2panda_lib.h" +#include "util.h" + +// NOLINTBEGIN + +static es2panda_Impl *impl = nullptr; + +static std::string g_source = R"( +interface A { + xsx : ()=>void; +} +)"; + +static es2panda_AstNode *mySetter = nullptr; +static void FindMethodDef(es2panda_AstNode *ast, void *context) +{ + auto ctx = reinterpret_cast(context); + if (!impl->IsMethodDefinition(ast)) { + return; + } + auto *function = impl->MethodDefinitionFunction(ctx, ast); + if (function == nullptr) { + return; + } + + auto *ident = impl->ScriptFunctionId(ctx, function); + if (ident == nullptr) { + return; + } + auto name = std::string(impl->IdentifierName(ctx, ident)); + if (name == "xsx") { + mySetter = ast; + } +} + +static es2panda_AstNode *myParam = nullptr; +static void FindParamExpr(es2panda_AstNode *ast, void *context) +{ + auto ctx = reinterpret_cast(context); + if (!impl->IsETSParameterExpression(ast)) { + return; + } + auto *ident = impl->ETSParameterExpressionIdent(ctx, ast); + if (ident == nullptr) { + return; + } + auto name = std::string(impl->IdentifierName(ctx, ident)); + if (name == "xsx") { + myParam = ast; + } +} + +static es2panda_Context *context = nullptr; +static es2panda_AstNode *newAnno = nullptr; +void RewriteScriptFunctionParams(es2panda_AstNode *node, [[maybe_unused]] void *arg) +{ + if (impl->IsScriptFunction(node)) { + auto *type1 = impl->ETSParameterExpressionTypeAnnotation(context, myParam); + auto signature = impl->CreateFunctionSignature( + context, nullptr, nullptr, 0, impl->CreateETSPrimitiveType(context, PRIMITIVE_TYPE_DOUBLE), false); + newAnno = impl->UpdateETSFunctionTypeIr(context, type1, signature, SCRIPT_FUNCTION_FLAGS_NONE); + impl->ETSParameterExpressionSetTypeAnnotation(context, myParam, newAnno); + es2panda_AstNode *paramList[] = {myParam}; + impl->ScriptFunctionSetParams(context, node, paramList, 1); + } +} + +int main(int argc, char **argv) +{ + if (argc < MIN_ARGC) { + return INVALID_ARGC_ERROR_CODE; + } + + impl = GetImpl(); + if (impl == nullptr) { + return NULLPTR_IMPL_ERROR_CODE; + } + + const char **args = const_cast(&(argv[1])); + auto config = impl->CreateConfig(argc - 1, args); + context = impl->CreateContextFromString(config, g_source.data(), argv[argc - 1]); + auto *program = impl->ContextProgram(context); + impl->ProceedToState(context, ES2PANDA_STATE_CHECKED); + auto *entryAst = impl->ProgramAst(context, program); + impl->AstNodeForEach(entryAst, FindMethodDef, context); + impl->AstNodeForEach(mySetter, FindParamExpr, context); + std::cout << impl->AstNodeDumpEtsSrcConst(context, mySetter) << std::endl; + impl->AstNodeForEach(mySetter, RewriteScriptFunctionParams, nullptr); + std::cout << impl->AstNodeDumpEtsSrcConst(context, newAnno) << std::endl; + std::cout << impl->AstNodeDumpEtsSrcConst(context, mySetter) << std::endl; + return 0; +} + +// NOLINTEND