diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index 2a61c15828f14ccbd43dc1857dda8e4ecdf23d56..ed62cd4a7510eef180417b33d967c516c021f224 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -465,7 +465,6 @@ void ClassDefinition::Dump(ir::SrcDumper *dumper) const if (IsLocal()) { dumper->Add(";"); } - dumper->Endl(); } void ClassDefinition::Compile(compiler::PandaGen *pg) const diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 944a3462d52008b2cb6bf517d211aca844cf8ade..f762c252d0ea654f097a298d2eb47d97fb3c6d97 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -120,8 +120,6 @@ void ClassProperty::DumpModifiers(ir::SrcDumper *dumper) const dumper->Add("private "); } else if (IsProtected()) { dumper->Add("protected "); - } else { - dumper->Add("public "); } } diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index f3eb2b597872e29587ed1c240752a56519e68f19..09ea2268afacd9d172868dcfc0288705e3e04631 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -300,13 +300,22 @@ bool MethodDefinition::FilterForDeclGen() const static void DumpSingleOverload(const ir::MethodDefinition *m, ir::SrcDumper *dumper) { + auto value = m->Value(); + if (m->IsConstructor() && ((value->AsFunctionExpression()->Function()->Flags() & + ir::ScriptFunctionFlags::IMPLICIT_SUPER_CALL_NEEDED) != 0U)) { + return; + } + + if (m->IsDefaultAccessModifier() && m->Parent()->IsTSInterfaceBody()) { + dumper->Add("default "); + } + if (compiler::HasGlobalClassParent(m) && m->Id() != nullptr && m->Id()->Name().Is(compiler::Signatures::INIT_METHOD)) { m->Function()->Body()->Dump(dumper); return; } - auto value = m->Value(); if (value->AsFunctionExpression()->Function()->HasAnnotations()) { for (auto *anno : value->AsFunctionExpression()->Function()->Annotations()) { // NOTE(zhelyapov): workaround, see #26031 diff --git a/ets2panda/ir/base/overloadDeclaration.cpp b/ets2panda/ir/base/overloadDeclaration.cpp index 38122f80e32c6516467ef0c2578a17047329f421..39439a56802c2f2ba7d343dc628599ca949c5147 100644 --- a/ets2panda/ir/base/overloadDeclaration.cpp +++ b/ets2panda/ir/base/overloadDeclaration.cpp @@ -94,12 +94,16 @@ void OverloadDeclaration::Dump(ir::SrcDumper *dumper) const dumper->Add("overload "); dumper->Add(IsConstructor() ? "constructor " : key_->AsIdentifier()->Name().Mutf8()); dumper->Add("{"); + dumper->IncrIndent(); for (size_t i = 0; i < overloadedList_.size(); i++) { if (i != 0) { dumper->Add(", "); } + dumper->Endl(); overloadedList_[i]->Dump(dumper); } + dumper->DecrIndent(); + dumper->Endl(); dumper->Add("};"); } diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index b21230ed9952b02c7f56297ddd28b8d7e11d3eec..fbe49e5775d04a781360907bcbcadf4a6862b154 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -345,7 +345,6 @@ void ScriptFunction::Dump(ir::SrcDumper *dumper) const void ScriptFunction::DumpBody(ir::SrcDumper *dumper) const { if (!HasBody()) { - dumper->Endl(); return; } @@ -368,10 +367,6 @@ void ScriptFunction::DumpBody(ir::SrcDumper *dumper) const dumper->Add(" "); body_->Dump(dumper); } - - if (!IsArrow()) { - dumper->Endl(); - } } void ScriptFunction::Compile(compiler::PandaGen *pg) const diff --git a/ets2panda/ir/ets/etsFunctionType.cpp b/ets2panda/ir/ets/etsFunctionType.cpp index 73b0c3bc03ac022d736bf1d97c9b8c89d712ffd6..93507d954675e6b5f586e8f4fd38467cee1f022c 100644 --- a/ets2panda/ir/ets/etsFunctionType.cpp +++ b/ets2panda/ir/ets/etsFunctionType.cpp @@ -55,7 +55,7 @@ void ETSFunctionType::Dump(ir::AstDumper *dumper) const void ETSFunctionType::Dump(ir::SrcDumper *dumper) const { DumpAnnotations(dumper); - dumper->Add("(("); + dumper->Add("("); for (auto *param : Params()) { param->Dump(dumper); if (param != Params().back()) { @@ -73,7 +73,6 @@ void ETSFunctionType::Dump(ir::SrcDumper *dumper) const ReturnType()->Dump(dumper); } - dumper->Add(")"); } void ETSFunctionType::Compile(compiler::PandaGen *pg) const diff --git a/ets2panda/ir/ets/etsTuple.cpp b/ets2panda/ir/ets/etsTuple.cpp index 3012e89b118d2c08d04028b9c9ba06f00ce84d7d..4679b8658696480b3b8b42ba232c268ddc7d9a69 100644 --- a/ets2panda/ir/ets/etsTuple.cpp +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -52,12 +52,17 @@ void ETSTuple::Dump(ir::SrcDumper *const dumper) const { DumpAnnotations(dumper); dumper->Add("["); + dumper->IncrIndent(); + dumper->Endl(); for (const auto *const typeAnnot : typeAnnotationList_) { typeAnnot->Dump(dumper); if (typeAnnot != typeAnnotationList_.back()) { dumper->Add(", "); + dumper->Endl(); } } + dumper->DecrIndent(); + dumper->Endl(); dumper->Add("]"); } diff --git a/ets2panda/ir/ets/etsUnionType.cpp b/ets2panda/ir/ets/etsUnionType.cpp index 95f556c907df88cfa9b063707c7bbe3c9c27747d..7f17a4d6729543cfdc99d597f69f38f2434b6c04 100644 --- a/ets2panda/ir/ets/etsUnionType.cpp +++ b/ets2panda/ir/ets/etsUnionType.cpp @@ -48,14 +48,14 @@ void ETSUnionType::Dump(ir::AstDumper *dumper) const void ETSUnionType::Dump(ir::SrcDumper *dumper) const { DumpAnnotations(dumper); - dumper->Add("("); - for (auto type : Types()) { - type->Dump(dumper); - if (type != Types().back()) { + auto const &types = Types(); + auto size = Parent()->IsOptionalDeclaration() ? types.size() - 1 : types.size(); + for (size_t ix = 0; ix < size; ix++) { + types[ix]->Dump(dumper); + if (ix != size - 1) { dumper->Add(" | "); } } - dumper->Add(")"); } void ETSUnionType::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index b7de84484e0bdec1096887ee85f98a272f731918..8c5869b1dea4c7844953237db3c39fd14b25a5c6 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -51,13 +51,11 @@ void BinaryExpression::Dump(ir::SrcDumper *dumper) const { ES2PANDA_ASSERT(left_ != nullptr); ES2PANDA_ASSERT(right_ != nullptr); - dumper->Add("(("); left_->Dump(dumper); - dumper->Add(") "); + dumper->Add(" "); dumper->Add(TokenToString(operator_)); - dumper->Add(" ("); + dumper->Add(" "); right_->Dump(dumper); - dumper->Add("))"); } void BinaryExpression::Compile(compiler::PandaGen *pg) const diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index d3cf60f0268eb3424cf9edc204521889eb91fdbd..b8c075d249186935568a345ff080cce05df0c698 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -42,7 +42,7 @@ void NumberLiteral::Dump(ir::AstDumper *dumper) const void NumberLiteral::Dump(ir::SrcDumper *dumper) const { - if (std::string(number_.Str()).empty() || (parent_ != nullptr && parent_->IsTSEnumMember())) { + if (std::string(number_.Str()).empty()) { if (number_.IsInt()) { dumper->Add(number_.GetInt()); return; diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index 2dbd9f52c704c16a4da870211288254f04bcee2c..99e1b8c14746cd278a5ef7782823427ab78c9cb9 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -68,6 +68,9 @@ void ImportDeclaration::Dump(ir::SrcDumper *dumper) const return; } dumper->Add("import "); + if (IsTypeKind()) { + dumper->Add("type "); + } auto const &specifiers = Specifiers(); if (specifiers.size() == 1 && (specifiers[0]->IsImportNamespaceSpecifier() || specifiers[0]->IsImportDefaultSpecifier())) { diff --git a/ets2panda/ir/statements/annotationUsage.cpp b/ets2panda/ir/statements/annotationUsage.cpp index 2d22aed190e78bad6be6a27631fd2357ed62daaf..e91e1e525d83e1b4b9af8199472109f6d14db4b4 100644 --- a/ets2panda/ir/statements/annotationUsage.cpp +++ b/ets2panda/ir/statements/annotationUsage.cpp @@ -53,9 +53,9 @@ void AnnotationUsage::Dump(ir::SrcDumper *dumper) const ES2PANDA_ASSERT(expr_ != nullptr); dumper->Add("@"); expr_->Dump(dumper); - dumper->Add("("); if (!properties_.empty()) { + dumper->Add("("); dumper->Add("{"); for (auto elem : properties_) { ES2PANDA_ASSERT(elem->AsClassProperty()->Id() != nullptr); @@ -67,8 +67,9 @@ void AnnotationUsage::Dump(ir::SrcDumper *dumper) const } } dumper->Add("}"); + dumper->Add(") "); } - dumper->Add(") "); + dumper->Endl(); } AnnotationUsage *AnnotationUsage::Clone(ArenaAllocator *const allocator, AstNode *const parent) diff --git a/ets2panda/ir/statements/variableDeclaration.cpp b/ets2panda/ir/statements/variableDeclaration.cpp index ad2bc7f2e98675139f9b8dd8ddb0eff7684cbf0b..8cd9047718a481bb02cb80bb0b31b3076a397f9f 100644 --- a/ets2panda/ir/statements/variableDeclaration.cpp +++ b/ets2panda/ir/statements/variableDeclaration.cpp @@ -113,6 +113,9 @@ void VariableDeclaration::Dump(ir::SrcDumper *dumper) const if (IsDeclare()) { dumper->Add("declare "); } + if (IsExported()) { + dumper->Add("export "); + } switch (Kind()) { case VariableDeclarationKind::CONST: diff --git a/ets2panda/ir/ts/tsEnumDeclaration.cpp b/ets2panda/ir/ts/tsEnumDeclaration.cpp index e51a7d2896575c83960a65b84ccd4e768ca6f243..eccc5db721d8e1342452504dc49132f75e90435f 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.cpp +++ b/ets2panda/ir/ts/tsEnumDeclaration.cpp @@ -112,6 +112,9 @@ void TSEnumDeclaration::Dump(ir::SrcDumper *dumper) const } else if (IsDeclare()) { dumper->Add("declare "); } + if (IsExported()) { + dumper->Add("export "); + } dumper->Add("enum "); Key()->Dump(dumper); dumper->Add(" {"); @@ -130,7 +133,6 @@ void TSEnumDeclaration::Dump(ir::SrcDumper *dumper) const dumper->Endl(); } dumper->Add("}"); - dumper->Endl(); } // NOTE (csabahurton): this method has not been moved to TSAnalyizer.cpp, because it is not used. diff --git a/ets2panda/ir/ts/tsEnumMember.cpp b/ets2panda/ir/ts/tsEnumMember.cpp index f4f126095afdeed1b303c2dfceb7b419125489c3..770487dc9c7e45e93e9899c41de7c66ce9490f91 100644 --- a/ets2panda/ir/ts/tsEnumMember.cpp +++ b/ets2panda/ir/ts/tsEnumMember.cpp @@ -55,7 +55,7 @@ void TSEnumMember::Dump(ir::SrcDumper *dumper) const { ES2PANDA_ASSERT(key_ != nullptr); key_->Dump(dumper); - if (init_ != nullptr) { + if (init_ != nullptr && !(init_->IsBinaryExpression() && isGenerated_)) { dumper->Add(" = "); init_->Dump(dumper); } diff --git a/ets2panda/ir/ts/tsInterfaceBody.cpp b/ets2panda/ir/ts/tsInterfaceBody.cpp index c98011586e72d10d5c8542bde8639559aae31870..7bd5286ced66a315945c270b43eb61a538c533ad 100644 --- a/ets2panda/ir/ts/tsInterfaceBody.cpp +++ b/ets2panda/ir/ts/tsInterfaceBody.cpp @@ -49,6 +49,9 @@ void TSInterfaceBody::Dump(ir::SrcDumper *dumper) const { for (auto b : body_) { b->Dump(dumper); + if (b != body_.back()) { + dumper->Endl(); + } } } diff --git a/ets2panda/ir/ts/tsTypeParameter.cpp b/ets2panda/ir/ts/tsTypeParameter.cpp index 5e997562f4bfcccbc0a32f4216f4893292e57402..b4ecadac09fd75f53463b0cdd83089fed80fa853 100644 --- a/ets2panda/ir/ts/tsTypeParameter.cpp +++ b/ets2panda/ir/ts/tsTypeParameter.cpp @@ -109,14 +109,15 @@ void TSTypeParameter::Dump(ir::SrcDumper *dumper) const Name()->Dump(dumper); - if (DefaultType() != nullptr) { - dumper->Add(" = "); - DefaultType()->Dump(dumper); - } if (Constraint() != nullptr) { dumper->Add(" extends "); Constraint()->Dump(dumper); } + + if (DefaultType() != nullptr) { + dumper->Add(" = "); + DefaultType()->Dump(dumper); + } } void TSTypeParameter::Compile([[maybe_unused]] compiler::PandaGen *pg) const diff --git a/ets2panda/parser/ETSparserClasses.cpp b/ets2panda/parser/ETSparserClasses.cpp index 95d4e1b7596eb84073604ed2777acd82a6225524..ae606844fc4a6661bbebc29c3ca4b3fb0e9c83fc 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -1207,6 +1207,7 @@ ir::MethodDefinition *ETSParser::ParseInterfaceMethod(ir::ModifierFlags flags, i auto *method = AllocNode(methodKind, name->Clone(Allocator(), nullptr)->AsExpression(), funcExpr, flags, Allocator(), false); ES2PANDA_ASSERT(method != nullptr); + method->SetDefaultAccessModifier((flags & (ir::ModifierFlags::DEFAULT)) != 0); method->SetRange(funcExpr->Range()); ConsumeSemicolon(method);