From d62846c940ad58f3f77af74032aba1439113b15e Mon Sep 17 00:00:00 2001 From: Igor Loginov Date: Tue, 15 Jul 2025 12:39:45 +0300 Subject: [PATCH] Reproduce trailing lambda bug --- ui2abc/libarkts/playground/src/playground.cc | 87 ++++++++++++-------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/ui2abc/libarkts/playground/src/playground.cc b/ui2abc/libarkts/playground/src/playground.cc index bf613acfe..02783624b 100644 --- a/ui2abc/libarkts/playground/src/playground.cc +++ b/ui2abc/libarkts/playground/src/playground.cc @@ -44,10 +44,51 @@ es2panda_Impl *GetImpl() { return impl; } -static const char* source = -"export class XXX {}" +static const char* source = R"( +function foo(param: () => void) {} +function bar() {} + +foo() { bar() } +)" ; -static es2panda_AstNode* newStatements[1]; + +es2panda_AstNode* contextAst(es2panda_Context* context) { + return GetImpl()->ProgramAst(context, GetImpl()->ContextProgram(context)); +} + +void showBarDecl(es2panda_AstNode *node, void *arg) { + es2panda_Context* context = reinterpret_cast(arg); + if (GetImpl()->IsCallExpression(node)) { + es2panda_AstNode* callee = GetImpl()->CallExpressionCallee(context, node); + if (GetImpl()->IsIdentifier(callee)) { + if (strcmp(GetImpl()->IdentifierName(context, callee), "bar") == 0) { + printf("%p is call expression, callee = %s, declaration = %p\n", + node, GetImpl()->IdentifierName(context, callee), GetImpl()->DeclarationFromIdentifier(context, callee)); + } + } + } +} + +void findBarDecl(es2panda_Context* context) { + es2panda_AstNode* ast = contextAst(context); + GetImpl()->AstNodeForEach(ast, showBarDecl, context); +} + +void setArrowFunctionReturnType(es2panda_AstNode *node, void *arg) { + es2panda_Context* context = reinterpret_cast(arg); + if (GetImpl()->IsArrowFunctionExpression(node)) { + es2panda_AstNode* function = GetImpl()->ArrowFunctionExpressionFunction(context, node); + GetImpl()->ScriptFunctionSetReturnTypeAnnotation(context, function, + GetImpl()->CreateETSPrimitiveType(context, static_cast(8)) // void + ); + printf("%p\n", function); + } +} + +void findArrowFunctionAndSetReturnType(es2panda_Context* context) { + es2panda_AstNode* ast = contextAst(context); + GetImpl()->AstNodeForEach(ast, setArrowFunctionReturnType, context); +} int main() { impl = GetImpl(); @@ -76,38 +117,6 @@ int main() { 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) { @@ -128,6 +137,14 @@ int main() { std::cout << "PROCEED TO CHECKED SUCCESS" << std::endl; } + findBarDecl(context); + + findArrowFunctionAndSetReturnType(context); + printf("%s\n", GetImpl()->AstNodeDumpEtsSrcConst(context, contextAst(context))); + GetImpl()->AstNodeRecheck(context, contextAst(context)); + + findBarDecl(context); + GetImpl()->ProceedToState(context, ES2PANDA_STATE_LOWERED); if(GetImpl()->ContextState(context) == ES2PANDA_STATE_ERROR) { -- Gitee