diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index c6c22bf1ea07d8e3830bbeab5264e833554ed80a..3b4f13b62f0d784bb53b2d7acd0817f1ad464cdc 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -675,8 +675,6 @@ public: ir::MethodDefinition *const accessor, ir::TSInterfaceDeclaration *const newTSInterfaceDefinition); ir::ClassProperty *CreateNullishPropertyFromAccessor(ir::MethodDefinition *const accessor, ir::ClassDefinition *newClassDefinition); - ir::MethodDefinition *CreateNullishAccessor(ir::MethodDefinition *const accessor, - ir::ClassDefinition *classDefinition); void CreatePartialClassDeclaration(ir::ClassDefinition *newClassDefinition, ir::ClassDefinition *classDef); ir::ETSTypeReference *BuildSuperPartialTypeReference(Type *superPartialType, ir::TSTypeParameterInstantiation *superPartialRefTypeParams); diff --git a/ets2panda/checker/ets/utilityTypeHandlers.cpp b/ets2panda/checker/ets/utilityTypeHandlers.cpp index 079bba82c05a66e2f085dea3b137faa472b737a4..090804708ee5dc31448c8624a44b336ea3be30a6 100644 --- a/ets2panda/checker/ets/utilityTypeHandlers.cpp +++ b/ets2panda/checker/ets/utilityTypeHandlers.cpp @@ -330,63 +330,6 @@ ir::ClassProperty *ETSChecker::CreateNullishProperty(ir::ClassProperty *const pr return propClone; } -ir::MethodDefinition *ETSChecker::CreateNullishAccessor(ir::MethodDefinition *const accessor, - ir::ClassDefinition *classDefinition) -{ - const auto interfaceCtx = varbinder::LexicalScope::Enter(VarBinder(), classDefinition->Scope()); - auto *paramScope = Allocator()->New(Allocator(), classDefinition->Scope()); - auto *functionScope = Allocator()->New(Allocator(), paramScope); - functionScope->BindParamScope(paramScope); - paramScope->BindFunctionScope(functionScope); - - { - auto paramScopeCtx = varbinder::LexicalScope::Enter(VarBinder(), paramScope); - VarBinder()->AddMandatoryParam(varbinder::TypedBinder::MANDATORY_PARAM_THIS); - } - - ir::MethodDefinition *nullishAccessor = accessor->Clone(Allocator(), classDefinition); - - auto *decl = Allocator()->New(Allocator(), nullishAccessor->Key()->AsIdentifier()->Name(), - nullishAccessor); - auto *var = Allocator()->New(decl, varbinder::VariableFlags::VAR); - var->AddFlag(varbinder::VariableFlags::METHOD); - nullishAccessor->Id()->SetVariable(var); - nullishAccessor->SetVariable(var); - - functionScope->BindName(classDefinition->InternalName()); - - auto *function = nullishAccessor->Function(); - - function->SetVariable(var); - function->SetIdent(nullishAccessor->Id()); - function->SetScope(functionScope); - paramScope->BindNode(function); - functionScope->BindNode(function); - - if (function->IsGetter()) { - auto *propTypeAnn = function->ReturnTypeAnnotation(); - - auto *unionType = AllocNode( - ArenaVector({propTypeAnn, AllocNode()}, Allocator()->Adapter())); - function->SetReturnTypeAnnotation(unionType); - } else { - for (auto *params : function->Params()) { - auto *paramExpr = params->AsETSParameterExpression(); - - auto *unionType = AllocNode(ArenaVector( - {paramExpr->Ident()->TypeAnnotation(), AllocNode()}, Allocator()->Adapter())); - paramExpr->Ident()->SetTsTypeAnnotation(unionType); - - auto *const paramVar = std::get<2>(paramScope->AddParamDecl(Allocator(), paramExpr)); - paramExpr->SetVariable(paramVar); - } - } - ArenaVector overloads(Allocator()->Adapter()); - nullishAccessor->SetOverloads(std::move(overloads)); - - return nullishAccessor; -} - ir::TSTypeParameterDeclaration *ETSChecker::ProcessTypeParamAndGenSubstitution( ir::TSTypeParameterDeclaration const *const thisTypeParams, ArenaMap *likeSubstitution, @@ -550,7 +493,7 @@ ir::MethodDefinition *ETSChecker::CreateNullishAccessor(ir::MethodDefinition *co auto *function = nullishAccessor->Function(); function->SetVariable(var); - function->SetIdent(nullishAccessor->Id()); + function->SetIdent(nullishAccessor->Id()->Clone(Allocator(), function)); function->SetScope(functionScope); paramScope->BindNode(function); functionScope->BindNode(function); @@ -568,6 +511,7 @@ ir::MethodDefinition *ETSChecker::CreateNullishAccessor(ir::MethodDefinition *co auto *unionType = AllocNode(ArenaVector( {paramExpr->Ident()->TypeAnnotation(), AllocNode()}, Allocator()->Adapter())); paramExpr->Ident()->SetTsTypeAnnotation(unionType); + unionType->SetParent(paramExpr->Ident()); auto *const paramVar = std::get<2>(paramScope->AddParamDecl(Allocator(), paramExpr)); paramExpr->SetVariable(paramVar); @@ -680,6 +624,7 @@ Type *ETSChecker::CreatePartialTypeInterfaceDecl(ir::TSInterfaceDeclaration *con ir::ETSTypeReference *superPartialRef = BuildSuperPartialTypeReference(superPartialType, superPartialRefTypeParams); partialInterface->Extends().push_back(AllocNode(superPartialRef)); + partialInterface->Extends().back()->SetParent(partialInterface); } }