diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index ad1b41851cc0af2da4a55f1360cd575c55a08a76..e61bda868e1d75bb05abdbc9319fc66437ceea22 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -156,6 +156,7 @@ libes2panda_sources = [ "compiler/function/functionBuilder.cpp", "compiler/function/generatorFunctionBuilder.cpp", "compiler/lowering/checkerPhase.cpp", + "compiler/lowering/ets/defaultParameterLowering.cpp", "compiler/lowering/ets/expandBrackets.cpp", "compiler/lowering/ets/generateDeclarations.cpp", "compiler/lowering/ets/interfacePropertyDeclarations.cpp", @@ -164,6 +165,10 @@ libes2panda_sources = [ "compiler/lowering/ets/opAssignment.cpp", "compiler/lowering/ets/promiseVoid.cpp", "compiler/lowering/ets/structLowering.cpp", + "compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp", + "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp", + "compiler/lowering/ets/topLevelStmts/importExportDecls.cpp", + "compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp", "compiler/lowering/ets/tupleLowering.cpp", "compiler/lowering/ets/unionLowering.cpp", "compiler/lowering/phase.cpp", @@ -203,6 +208,7 @@ libes2panda_sources = [ "ir/ets/etsPackageDeclaration.cpp", "ir/ets/etsParameterExpression.cpp", "ir/ets/etsPrimitiveType.cpp", + "ir/ets/etsReExportDeclaration.cpp", "ir/ets/etsScript.cpp", "ir/ets/etsStructDeclaration.cpp", "ir/ets/etsTuple.cpp", @@ -357,7 +363,9 @@ libes2panda_sources = [ "util/arktsconfig.cpp", "util/bitset.cpp", "util/declgenEts2Ts.cpp", + "util/error_handler.cpp", "util/helpers.cpp", + "util/importPathResolver.cpp", "util/path.cpp", "util/plugin.cpp", "util/ustring.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 6a662e36a53ab20d753d63248b583dbee691beb2..54293f61a8f0e99f9c0f76f5d7adadcf5f5dc0a8 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -150,6 +150,10 @@ set(ES2PANDA_LIB_SRC compiler/lowering/phase.cpp compiler/lowering/plugin_phase.cpp compiler/lowering/util.cpp + compiler/lowering/ets/topLevelStmts/importExportDecls.cpp + compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp + compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp + compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp compiler/lowering/ets/lambdaLowering.cpp compiler/lowering/ets/generateDeclarations.cpp compiler/lowering/ets/objectIndexAccess.cpp @@ -160,6 +164,7 @@ set(ES2PANDA_LIB_SRC compiler/lowering/ets/expandBrackets.cpp compiler/lowering/ets/promiseVoid.cpp compiler/lowering/ets/structLowering.cpp + compiler/lowering/ets/defaultParameterLowering.cpp ir/astDump.cpp ir/srcDump.cpp ir/astNode.cpp @@ -233,6 +238,7 @@ set(ES2PANDA_LIB_SRC ir/statements/breakStatement.cpp ir/statements/classDeclaration.cpp ir/ets/etsStructDeclaration.cpp + ir/ets/etsReExportDeclaration.cpp ir/statements/continueStatement.cpp ir/statements/debuggerStatement.cpp ir/statements/doWhileStatement.cpp @@ -435,7 +441,9 @@ set(ES2PANDA_LIB_SRC util/arktsconfig.cpp util/bitset.cpp util/declgenEts2Ts.cpp + util/error_handler.cpp util/helpers.cpp + util/importPathResolver.cpp util/path.cpp util/ustring.cpp ) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 653bcf2c2e63453c04dd8f104585377b7d8b75a2..2219e368b0ed0c8f1bf867b3be36a7b8af40f90a 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -506,9 +506,7 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewArrayInstanceExpression *expr) const checker->ValidateArrayIndex(expr->dimension_, true); if (!elementType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && !elementType->IsNullish() && - !elementType->HasTypeFlag(TypeFlag::GENERIC) && !elementType->HasTypeFlag(TypeFlag::ETS_ARRAY) && elementType->ToAssemblerName().str() != "Ball") { - // Check only valid for ETS_PRIMITIVE and IsNullish, GENERIC and ETS_ARRAY are workaround checks for stdlib // Ball is workaround for koala ui lib if (elementType->IsETSObjectType()) { auto *calleeObj = elementType->AsETSObjectType(); @@ -566,7 +564,6 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewClassInstanceExpression *expr) const auto *signature = checker->ResolveConstructExpression(calleeObj, expr->GetArguments(), expr->Start()); checker->CheckObjectLiteralArguments(signature, expr->GetArguments()); - checker->AddUndefinedParamsForDefaultParams(signature, expr->arguments_, checker); checker->ValidateSignatureAccessibility(calleeObj, nullptr, signature, expr->Start()); @@ -725,7 +722,7 @@ checker::Type *ETSAnalyzer::Check(ir::ArrayExpression *expr) const currentElement->Start()); } - const checker::CastingContext cast( + checker::AssignmentContext( checker->Relation(), currentElement, elementType, compareType, currentElement->Start(), {"Array initializer's type is not assignable to tuple type at index: ", idx}); @@ -823,18 +820,30 @@ checker::Type *ETSAnalyzer::Check(ir::AssignmentExpression *expr) const checker->ThrowTypeError("Setting the length of an array is not permitted", expr->Left()->Start()); } - if (expr->Left()->IsIdentifier()) { - expr->target_ = expr->Left()->AsIdentifier()->Variable(); - } else { - expr->target_ = expr->Left()->AsMemberExpression()->PropVar(); - } + expr->target_ = expr->Left()->IsIdentifier() ? expr->Left()->AsIdentifier()->Variable() + : expr->Left()->AsMemberExpression()->PropVar(); if (expr->target_ != nullptr) { checker->ValidateUnaryOperatorOperand(expr->target_); } + auto [sourceType, relationNode] = CheckAssignmentExprOperatorType(expr); + const checker::Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(leftType); + const checker::Type *rightType = checker->TryGettingFunctionTypeFromInvokeFunction(sourceType); + + checker::AssignmentContext(checker->Relation(), relationNode, sourceType, leftType, expr->Right()->Start(), + {"Type '", rightType, "' cannot be assigned to type '", targetType, "'"}); + + expr->SetTsType(expr->Left()->TsType()); + return expr->TsType(); +} + +std::tuple ETSAnalyzer::CheckAssignmentExprOperatorType(ir::AssignmentExpression *expr) const +{ + ETSChecker *checker = GetETSChecker(); checker::Type *sourceType {}; ir::Expression *relationNode = expr->Right(); + auto *leftType = expr->Left()->Check(checker); switch (expr->OperatorType()) { case lexer::TokenType::PUNCTUATOR_MULTIPLY_EQUAL: case lexer::TokenType::PUNCTUATOR_EXPONENTIATION_EQUAL: @@ -875,11 +884,7 @@ checker::Type *ETSAnalyzer::Check(ir::AssignmentExpression *expr) const } } - checker::AssignmentContext(checker->Relation(), relationNode, sourceType, leftType, expr->Right()->Start(), - {"Initializers type is not assignable to the target type"}); - - expr->SetTsType(expr->Left()->TsType()); - return expr->TsType(); + return {sourceType, relationNode}; } checker::Type *ETSAnalyzer::Check(ir::AwaitExpression *expr) const @@ -1081,7 +1086,6 @@ checker::Type *ETSAnalyzer::GetReturnType(ir::CallExpression *expr, checker::Typ ResolveSignature(checker, expr, calleeType, isFunctionalInterface, isUnionTypeWithFunctionalInterface); checker->CheckObjectLiteralArguments(signature, expr->Arguments()); - checker->AddUndefinedParamsForDefaultParams(signature, expr->Arguments(), checker); if (!isFunctionalInterface) { checker::ETSObjectType *calleeObj = ChooseCalleeObj(checker, expr, calleeType, isConstructorCall); @@ -1145,6 +1149,7 @@ checker::Type *ETSAnalyzer::Check(ir::CallExpression *expr) const } if (expr->Signature()->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { + checker::SavedCheckerContext savedCtx(checker, checker->Context().Status(), expr->Signature()->Owner()); expr->Signature()->OwnerVar()->Declaration()->Node()->Check(checker); returnType = expr->Signature()->ReturnType(); // NOTE(vpukhov): #14902 substituted signature is not updated @@ -1170,6 +1175,11 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ClassExpression *expr) co UNREACHABLE(); } +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ETSReExportDeclaration *expr) const +{ + UNREACHABLE(); +} + checker::Type *ETSAnalyzer::Check(ir::ConditionalExpression *expr) const { ETSChecker *checker = GetETSChecker(); @@ -1255,6 +1265,15 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ImportExpression *expr) c UNREACHABLE(); } +checker::Type *ETSAnalyzer::SetAndAdjustType(ETSChecker *checker, ir::MemberExpression *expr, + ETSObjectType *objectType) const +{ + expr->SetObjectType(objectType); + auto [resType, resVar] = expr->ResolveObjectMember(checker); + expr->SetPropVar(resVar); + return expr->AdjustType(checker, resType); +} + checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const { ETSChecker *checker = GetETSChecker(); @@ -1285,15 +1304,16 @@ checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const return expr->AdjustType(checker, expr->CheckComputed(checker, baseType)); } - if (baseType->IsETSArrayType() && expr->Property()->AsIdentifier()->Name().Is("length")) { - return expr->AdjustType(checker, checker->GlobalIntType()); + if (baseType->IsETSArrayType()) { + if (expr->Property()->AsIdentifier()->Name().Is("length")) { + return expr->AdjustType(checker, checker->GlobalIntType()); + } + + return SetAndAdjustType(checker, expr, checker->GlobalETSObjectType()); } if (baseType->IsETSObjectType()) { - expr->SetObjectType(baseType->AsETSObjectType()); - auto [resType, resVar] = expr->ResolveObjectMember(checker); - expr->SetPropVar(resVar); - return expr->AdjustType(checker, resType); + return SetAndAdjustType(checker, expr, baseType->AsETSObjectType()); } if (baseType->IsETSEnumType() || baseType->IsETSStringEnumType()) { @@ -1338,7 +1358,9 @@ checker::Type *ETSAnalyzer::Check(ir::ObjectExpression *expr) const checker->ThrowTypeError({"need to specify target type for class composite"}, expr->Start()); } if (!expr->PreferredType()->IsETSObjectType()) { - checker->ThrowTypeError({"target type for class composite needs to be an object type"}, expr->Start()); + checker->ThrowTypeError( + {"Target type for class composite needs to be an object type, found '", expr->PreferredType(), "'"}, + expr->Start()); } if (expr->PreferredType()->IsETSDynamicType()) { @@ -1372,6 +1394,17 @@ checker::Type *ETSAnalyzer::Check(ir::ObjectExpression *expr) const checker->ThrowTypeError({"type ", objType->Name(), " has no parameterless constructor"}, expr->Start()); } + CheckObjectExprProps(expr); + + expr->SetTsType(objType); + return objType; +} + +void ETSAnalyzer::CheckObjectExprProps(const ir::ObjectExpression *expr) const +{ + ETSChecker *checker = GetETSChecker(); + checker::ETSObjectType *objType = expr->PreferredType()->AsETSObjectType(); + for (ir::Expression *propExpr : expr->Properties()) { ASSERT(propExpr->IsProperty()); ir::Property *prop = propExpr->AsProperty(); @@ -1404,12 +1437,13 @@ checker::Type *ETSAnalyzer::Check(ir::ObjectExpression *expr) const value->AsObjectExpression()->SetPreferredType(propType); } value->SetTsType(value->Check(checker)); - checker::AssignmentContext(checker->Relation(), value, value->TsType(), propType, value->Start(), - {"value type is not assignable to the property type"}); - } - expr->SetTsType(objType); - return objType; + const checker::Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(propType); + + checker::AssignmentContext( + checker->Relation(), value, value->TsType(), propType, value->Start(), + {"Type '", value->TsType(), "' is not compatible with type '", targetType, "' at property '", pname, "'"}); + } } checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::OmittedExpression *expr) const @@ -2137,9 +2171,13 @@ void CheckReturnType(ETSChecker *checker, checker::Type *funcReturnType, checker stArgument->Start()); } } else { - checker::AssignmentContext(checker->Relation(), stArgument, argumentType, funcReturnType, stArgument->Start(), - {"Return statement type is not compatible with the enclosing method's return type."}, - checker::TypeRelationFlag::DIRECT_RETURN); + const Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(funcReturnType); + const Type *sourceType = checker->TryGettingFunctionTypeFromInvokeFunction(argumentType); + + checker::AssignmentContext( + checker->Relation(), stArgument, argumentType, funcReturnType, stArgument->Start(), + {"Type '", sourceType, "' is not compatible with the enclosing method's return type '", targetType, "'"}, + checker::TypeRelationFlag::DIRECT_RETURN); } } @@ -2167,10 +2205,13 @@ void InferReturnType(ETSChecker *checker, ir::ScriptFunction *containingFunc, ch auto arrowFunc = stArgument->AsArrowFunctionExpression(); auto typeAnnotation = arrowFunc->CreateTypeAnnotation(checker); funcReturnType = typeAnnotation->GetType(checker); - checker::AssignmentContext(checker->Relation(), arrowFunc, arrowFunc->TsType(), funcReturnType, - stArgument->Start(), - {"Return statement type is not compatible with the enclosing method's return type."}, - checker::TypeRelationFlag::DIRECT_RETURN); + const Type *sourceType = checker->TryGettingFunctionTypeFromInvokeFunction(arrowFunc->TsType()); + const Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(funcReturnType); + + checker::AssignmentContext( + checker->Relation(), arrowFunc, arrowFunc->TsType(), funcReturnType, stArgument->Start(), + {"Type '", sourceType, "' is not compatible with the enclosing method's return type '", targetType, "'"}, + checker::TypeRelationFlag::DIRECT_RETURN); } containingFunc->Signature()->SetReturnType(funcReturnType); @@ -2201,13 +2242,7 @@ void ProcessReturnStatements(ETSChecker *checker, ir::ScriptFunction *containing } const auto name = containingFunc->Scope()->InternalName().Mutf8(); - if (name.find(compiler::Signatures::ETS_MAIN_WITH_MANGLE_BEGIN) != std::string::npos) { - if (funcReturnType == checker->GlobalBuiltinVoidType()) { - funcReturnType = checker->GlobalVoidType(); - } else if (!funcReturnType->IsETSVoidType() && !funcReturnType->IsIntType()) { - checker->ThrowTypeError("Bad return type, main enable only void or int type.", st->Start()); - } - } + CheckArgumentVoidType(funcReturnType, checker, name, st); if (stArgument->IsObjectExpression()) { stArgument->AsObjectExpression()->SetPreferredType(funcReturnType); @@ -2353,16 +2388,17 @@ checker::Type *ETSAnalyzer::Check(ir::SwitchStatement *st) const } else { checker::AssignmentContext( checker->Relation(), st->discriminant_, caseType, unboxedDiscType, it->Test()->Start(), - {"Switch case type ", caseType, " is not comparable to discriminant type ", comparedExprType}, + {"Switch case type '", caseType, "' is not comparable to discriminant type '", comparedExprType, + "'"}, (comparedExprType->IsETSObjectType() ? checker::TypeRelationFlag::NO_WIDENING : checker::TypeRelationFlag::NO_UNBOXING) | checker::TypeRelationFlag::NO_BOXING); } if (!validCaseType) { - checker->ThrowTypeError( - {"Switch case type ", caseType, " is not comparable to discriminant type ", comparedExprType}, - it->Test()->Start()); + checker->ThrowTypeError({"Switch case type '", caseType, "' is not comparable to discriminant type '", + comparedExprType, "'"}, + it->Test()->Start()); } } diff --git a/ets2panda/checker/ETSAnalyzer.h b/ets2panda/checker/ETSAnalyzer.h index db1f0439fbbfc3eb902175fde718597be403eb58..0e4e717facca3ed035072064675190955728c6b3 100644 --- a/ets2panda/checker/ETSAnalyzer.h +++ b/ets2panda/checker/ETSAnalyzer.h @@ -36,6 +36,8 @@ public: #undef DECLARE_ETSANALYZER_CHECK_METHOD checker::Type *PreferredType(ir::ObjectExpression *expr) const; checker::Type *GetPreferredType(ir::ArrayExpression *expr) const; + void CheckObjectExprProps(const ir::ObjectExpression *expr) const; + std::tuple CheckAssignmentExprOperatorType(ir::AssignmentExpression *expr) const; private: ETSChecker *GetETSChecker() const; @@ -44,6 +46,7 @@ private: bool isFunctionalInterface, bool isUnionTypeWithFunctionalInterface) const; checker::Type *GetReturnType(ir::CallExpression *expr, checker::Type *calleeType) const; checker::Type *GetFunctionReturnType(ir::ReturnStatement *st, ir::ScriptFunction *containingFunc) const; + checker::Type *SetAndAdjustType(ETSChecker *checker, ir::MemberExpression *expr, ETSObjectType *objectType) const; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 60b5410d3c068174de3e3978929d5a445a07a674..ebedcb3f4774641c0cbaad713ca0d1c9f474f9ca 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -177,6 +177,7 @@ public: varbinder::Variable *ResolveInstanceExtension(const ir::MemberExpression *memberExpr); void CheckImplicitSuper(ETSObjectType *classType, Signature *ctorSig); void CheckValidInheritance(ETSObjectType *classType, ir::ClassDefinition *classDef); + void TransformProperties(ETSObjectType *classType); void CheckGetterSetterProperties(ETSObjectType *classType); void AddElementsToModuleObject(ETSObjectType *moduleObj, const util::StringView &str); Type *FindLeastUpperBound(Type *source, Type *target); @@ -313,20 +314,19 @@ public: Signature *ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *typeArguments, const ArenaVector &arguments, const lexer::SourcePosition &pos, TypeRelationFlag initialFlags, const std::vector &argTypeInferenceRequired); + bool ValidateSignatureRequiredParams(Signature *substitutedSig, const ArenaVector &arguments, + TypeRelationFlag flags, const std::vector &argTypeInferenceRequired, + bool throwError); + bool ValidateSignatureRestParams(Signature *substitutedSig, const ArenaVector &arguments, + TypeRelationFlag flags, bool throwError); Signature *ValidateSignatures(ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, const ArenaVector &arguments, const lexer::SourcePosition &pos, std::string_view signatureKind, TypeRelationFlag resolveFlags = TypeRelationFlag::NONE); - bool ValidateProxySignature(Signature *signature, const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, - const std::vector &argTypeInferenceRequired); Signature *ChooseMostSpecificSignature(ArenaVector &signatures, const std::vector &argTypeInferenceRequired, const lexer::SourcePosition &pos, size_t argumentsSize = ULONG_MAX); - Signature *ChooseMostSpecificProxySignature(ArenaVector &signatures, - const std::vector &argTypeInferenceRequired, - const lexer::SourcePosition &pos, size_t argumentsSize); Signature *ResolveCallExpression(ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, const ArenaVector &arguments, const lexer::SourcePosition &pos); @@ -533,14 +533,18 @@ public: util::StringView GetHashFromSubstitution(const Substitution *substitution); ETSObjectType *GetOriginalBaseType(Type *object); Type *GetTypeFromTypeAnnotation(ir::TypeNode *typeAnnotation); - void AddUndefinedParamsForDefaultParams(const Signature *signature, - ArenaVector &arguments, - ETSChecker *checker); void SetArrayPreferredTypeForNestedMemberExpressions(ir::MemberExpression *expr, Type *annotationType); bool ExtensionETSFunctionType(checker::Type *type); void ValidateTupleMinElementSize(ir::ArrayExpression *arrayExpr, ETSTupleType *tuple); void ModifyPreferredType(ir::ArrayExpression *arrayExpr, Type *newPreferredType); Type *SelectGlobalIntegerTypeForNumeric(Type *type); + const Type *TryGettingFunctionTypeFromInvokeFunction(const Type *type) const; + + void GenerateGetterSetterBody(ETSChecker *checker, ArenaVector &stmts, + ArenaVector ¶ms, ir::ClassProperty *field, + varbinder::FunctionParamScope *paramScope, bool isSetter); + static ir::MethodDefinition *GenerateDefaultGetterSetter(ir::ClassProperty *field, varbinder::ClassScope *scope, + bool isSetter, ETSChecker *checker); // Exception ETSObjectType *CheckExceptionOrErrorType(checker::Type *type, lexer::SourcePosition pos); @@ -592,9 +596,7 @@ public: template T *AllocNode(Args &&...args) { - auto *ret = Allocator()->New(std::forward(args)...); - ret->Iterate([ret](auto *child) { child->SetParent(ret); }); - return ret; + return util::NodeAllocator::ForceSetParent(Allocator(), std::forward(args)...); } private: @@ -677,14 +679,14 @@ private: ETSObjectType *AsETSObjectType(Type *(GlobalTypesHolder::*typeFunctor)()) const; Signature *GetMostSpecificSignature(ArenaVector &compatibleSignatures, - ArenaVector &proxySignatures, const ArenaVector &arguments, std::vector &argTypeInferenceRequired, const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags); - std::pair, ArenaVector> CollectSignatures( - ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, std::vector &argTypeInferenceRequired, - const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags); + ArenaVector CollectSignatures(ArenaVector &signatures, + const ir::TSTypeParameterInstantiation *typeArguments, + const ArenaVector &arguments, + std::vector &argTypeInferenceRequired, + const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags); // Trailing lambda void MoveTrailingBlockToEnclosingBlockStatement(ir::CallExpression *callExpr); void TransformTraillingLambda(ir::CallExpression *callExpr); diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 81909d5f754a71eb01b297dc7b5a71c6f1e03b64..9de796eb329ce02f105202f2f252cbdf2522cd01 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -1708,6 +1708,11 @@ checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSConditionalType *node) c UNREACHABLE(); } +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSReExportDeclaration *node) const +{ + UNREACHABLE(); +} + checker::Type *TSAnalyzer::Check(ir::TSConstructorType *node) const { TSChecker *checker = GetTSChecker(); diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 66b26f35397e8f1266ff9b6726e0840ab099c11b..b3df0dc49d157de997eea01066cfa934264b289c 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -291,6 +291,19 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: bool isEqualOp, checker::Type *const leftType, checker::Type *const rightType, Type *unboxedL, Type *unboxedR) { + // NOTE (mmartin): These need to be done for other binary expressions, but currently it's not defined precisely when + // to apply this conversion + + if (leftType->IsETSEnumType()) { + left->AddAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); + unboxedL = GlobalIntType(); + } + + if (rightType->IsETSEnumType()) { + right->AddAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); + unboxedR = GlobalIntType(); + } + if (leftType->IsETSUnionType() || rightType->IsETSUnionType()) { ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); } @@ -503,9 +516,9 @@ std::tuple ETSChecker::CheckBinaryOperatorInstanceOf(lexer::Sour } Type *ETSChecker::CheckBinaryOperatorNullishCoalescing(ir::Expression *right, lexer::SourcePosition pos, - checker::Type *const leftType, checker::Type *const rightType) + checker::Type *leftType, checker::Type *rightType) { - if (!leftType->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { + if (!leftType->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) && !leftType->IsETSTypeParameter()) { ThrowTypeError("Left-hand side expression must be a reference type.", pos); } @@ -519,12 +532,30 @@ Type *ETSChecker::CheckBinaryOperatorNullishCoalescing(ir::Expression *right, le if (rightType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { Relation()->SetNode(right); - auto boxedRightType = PrimitiveTypeAsETSBuiltinType(rightType); + auto *const boxedRightType = PrimitiveTypeAsETSBuiltinType(rightType); if (boxedRightType == nullptr) { ThrowTypeError("Invalid right-hand side expression", pos); } right->AddBoxingUnboxingFlags(GetBoxingFlag(boxedRightType)); - return FindLeastUpperBound(nonNullishLeftType, boxedRightType); + rightType = boxedRightType; + } + + if (rightType->IsETSNullType()) { + return CreateNullishType(nonNullishLeftType, TypeFlag::NULL_TYPE, Allocator(), Relation(), + GetGlobalTypesHolder()); + } + + if (rightType->IsETSUndefinedType()) { + return CreateNullishType(nonNullishLeftType, TypeFlag::UNDEFINED, Allocator(), Relation(), + GetGlobalTypesHolder()); + } + + if (nonNullishLeftType->IsETSTypeParameter()) { + nonNullishLeftType = nonNullishLeftType->AsETSTypeParameter()->GetConstraintType(); + } + + if (rightType->IsETSTypeParameter()) { + rightType = rightType->AsETSTypeParameter()->GetConstraintType(); } return FindLeastUpperBound(nonNullishLeftType, rightType); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 5c9d21647739838ded41ce81f5057f0470a51db9..0d1363bc56b54db92125ee8cb43329026fa4d15c 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -162,11 +162,6 @@ bool ETSChecker::EnhanceSubstitutionForObject(const ArenaVector &typePar return true; } -// NOLINTBEGIN(modernize-avoid-c-arrays) -static constexpr char const INVALID_CALL_ARGUMENT_1[] = "Call argument at index "; -static constexpr char const INVALID_CALL_ARGUMENT_2[] = " is not compatible with the signature's type at that index."; -static constexpr char const INVALID_CALL_ARGUMENT_3[] = " is not compatible with the signature's rest parameter type."; -// NOLINTEND(modernize-avoid-c-arrays) Signature *ETSChecker::ValidateParameterlessConstructor(Signature *signature, const lexer::SourcePosition &pos, TypeRelationFlag flags) { @@ -182,38 +177,14 @@ Signature *ETSChecker::ValidateParameterlessConstructor(Signature *signature, co return signature; } -Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, - const lexer::SourcePosition &pos, TypeRelationFlag flags, - const std::vector &argTypeInferenceRequired) +bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, + const ArenaVector &arguments, TypeRelationFlag flags, + const std::vector &argTypeInferenceRequired, bool throwError) { - if (signature->Function()->IsDefaultParamProxy() && ((flags & TypeRelationFlag::CHECK_PROXY) == 0)) { - return nullptr; - } - - Signature *substitutedSig = MaybeSubstituteTypeParameters(this, signature, typeArguments, arguments, pos, flags); - if (substitutedSig == nullptr) { - return nullptr; - } - - auto const hasRestParameter = substitutedSig->RestVar() != nullptr; std::size_t const argumentCount = arguments.size(); std::size_t const parameterCount = substitutedSig->MinArgCount(); - auto const throwError = (flags & TypeRelationFlag::NO_THROW) == 0; - - if (!signature->Function()->IsDefaultParamProxy()) { - if (argumentCount < parameterCount || (argumentCount > parameterCount && !hasRestParameter)) { - if (throwError) { - ThrowTypeError({"Expected ", parameterCount, " arguments, got ", argumentCount, "."}, pos); - } - return nullptr; - } - } - - // Check all required formal parameter(s) first - auto const count = std::min(parameterCount, argumentCount); - std::size_t index = 0U; - for (; index < count; ++index) { + auto count = std::min(parameterCount, argumentCount); + for (std::size_t index = 0; index < count; ++index) { auto &argument = arguments[index]; if (argument->IsObjectExpression()) { @@ -221,7 +192,7 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP // No chance to check the argument at this point continue; } - return nullptr; + return false; } if (argument->IsMemberExpression()) { @@ -231,7 +202,7 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP if (throwError) { ThrowTypeError("Spread argument cannot be passed for ordinary parameter.", argument->Start()); } - return nullptr; + return false; } if (argTypeInferenceRequired[index]) { @@ -241,7 +212,7 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP if (CheckLambdaAssignable(substitutedSig->Function()->Params()[index], lambda)) { continue; } - return nullptr; + return false; } if (argument->IsArrayExpression()) { @@ -250,78 +221,109 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP } auto *const argumentType = argument->Check(this); + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(substitutedSig->Params()[index]->TsType()); - if (auto const invocationCtx = checker::InvocationContext( - Relation(), argument, argumentType, substitutedSig->Params()[index]->TsType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_2}, flags); - !invocationCtx.IsInvocable()) { - return nullptr; + auto const invocationCtx = checker::InvocationContext( + Relation(), argument, argumentType, substitutedSig->Params()[index]->TsType(), argument->Start(), + {"Type '", argumentType, "' is not compatible with type '", targetType, "' at index ", index + 1}, flags); + if (!invocationCtx.IsInvocable()) { + return false; } } - // Check rest parameter(s) if any exists - if (hasRestParameter && index < argumentCount) { - auto const restCount = argumentCount - index; - - for (; index < argumentCount; ++index) { - auto &argument = arguments[index]; - - if (argument->IsSpreadElement()) { - if (restCount > 1U) { - if (throwError) { - ThrowTypeError("Spread argument for the rest parameter can be only one.", argument->Start()); - } - return nullptr; - } + return true; +} + +bool ETSChecker::ValidateSignatureRestParams(Signature *substitutedSig, const ArenaVector &arguments, + TypeRelationFlag flags, bool throwError) +{ + std::size_t const argumentCount = arguments.size(); + std::size_t const parameterCount = substitutedSig->MinArgCount(); + auto count = std::min(parameterCount, argumentCount); + auto const restCount = argumentCount - count; - auto *const restArgument = argument->AsSpreadElement()->Argument(); - auto *const argumentType = restArgument->Check(this); + for (std::size_t index = count; index < argumentCount; ++index) { + auto &argument = arguments[index]; - if (auto const invocationCtx = checker::InvocationContext( - Relation(), restArgument, argumentType, substitutedSig->RestVar()->TsType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); - !invocationCtx.IsInvocable()) { - return nullptr; - } - } else { - auto *const argumentType = argument->Check(this); - - if (auto const invocationCtx = checker::InvocationContext( - Relation(), argument, argumentType, - substitutedSig->RestVar()->TsType()->AsETSArrayType()->ElementType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); - !invocationCtx.IsInvocable()) { - return nullptr; - } + if (!argument->IsSpreadElement()) { + auto *const argumentType = argument->Check(this); + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction( + substitutedSig->RestVar()->TsType()->AsETSArrayType()->ElementType()); + const Type *sourceType = TryGettingFunctionTypeFromInvokeFunction(argumentType); + auto const invocationCtx = checker::InvocationContext( + Relation(), argument, argumentType, + substitutedSig->RestVar()->TsType()->AsETSArrayType()->ElementType(), argument->Start(), + {"Type '", sourceType, "' is not compatible with rest parameter type '", targetType, "' at index ", + index + 1}, + flags); + if (!invocationCtx.IsInvocable()) { + return false; } + continue; + } + + if (restCount > 1U) { + if (throwError) { + ThrowTypeError("Spread argument for the rest parameter can be only one.", argument->Start()); + } + return false; + } + + auto *const restArgument = argument->AsSpreadElement()->Argument(); + auto *const argumentType = restArgument->Check(this); + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(substitutedSig->RestVar()->TsType()); + const Type *sourceType = TryGettingFunctionTypeFromInvokeFunction(argumentType); + + auto const invocationCtx = checker::InvocationContext( + Relation(), restArgument, argumentType, substitutedSig->RestVar()->TsType(), argument->Start(), + {"Type '", sourceType, "' is not compatible with rest parameter type '", targetType, "' at index ", + index + 1}, + flags); + if (!invocationCtx.IsInvocable()) { + return false; } } - return substitutedSig; + return true; } -bool ETSChecker::ValidateProxySignature(Signature *const signature, - const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, - const std::vector &argTypeInferenceRequired) +Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *typeArguments, + const ArenaVector &arguments, + const lexer::SourcePosition &pos, TypeRelationFlag flags, + const std::vector &argTypeInferenceRequired) { - if (!signature->Function()->IsDefaultParamProxy()) { - return false; + Signature *substitutedSig = MaybeSubstituteTypeParameters(this, signature, typeArguments, arguments, pos, flags); + if (substitutedSig == nullptr) { + return nullptr; } - auto const *const proxyParam = signature->Function()->Params().back()->AsETSParameterExpression(); - if (!proxyParam->Ident()->Name().Is(ir::PROXY_PARAMETER_NAME)) { - return false; + auto const hasRestParameter = substitutedSig->RestVar() != nullptr; + std::size_t const argumentCount = arguments.size(); + std::size_t const parameterCount = substitutedSig->MinArgCount(); + auto const throwError = (flags & TypeRelationFlag::NO_THROW) == 0; + + if (argumentCount < parameterCount || (argumentCount > parameterCount && !hasRestParameter)) { + if (throwError) { + ThrowTypeError({"Expected ", parameterCount, " arguments, got ", argumentCount, "."}, pos); + } + return nullptr; } - if (arguments.size() < proxyParam->GetRequiredParams()) { - return false; + auto count = std::min(parameterCount, argumentCount); + // Check all required formal parameter(s) first + if (!ValidateSignatureRequiredParams(substitutedSig, arguments, flags, argTypeInferenceRequired, throwError)) { + return nullptr; + } + + // Check rest parameter(s) if any exists + if (!hasRestParameter || count >= argumentCount) { + return substitutedSig; + } + if (!ValidateSignatureRestParams(substitutedSig, arguments, flags, throwError)) { + return nullptr; } - return ValidateSignature(signature, typeArguments, arguments, signature->Function()->Start(), - TypeRelationFlag::CHECK_PROXY | TypeRelationFlag::NO_THROW | - TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_BOXING, - argTypeInferenceRequired) != nullptr; + return substitutedSig; } Signature *ETSChecker::CollectParameterlessConstructor(ArenaVector &signatures, @@ -355,26 +357,16 @@ Signature *ETSChecker::CollectParameterlessConstructor(ArenaVector return compatibleSignature; } -std::pair, ArenaVector> ETSChecker::CollectSignatures( - ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, - const ArenaVector &arguments, std::vector &argTypeInferenceRequired, - const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags) +ArenaVector ETSChecker::CollectSignatures(ArenaVector &signatures, + const ir::TSTypeParameterInstantiation *typeArguments, + const ArenaVector &arguments, + std::vector &argTypeInferenceRequired, + const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags) { ArenaVector compatibleSignatures(Allocator()->Adapter()); - ArenaVector proxySignatures(Allocator()->Adapter()); - - for (auto *sig : signatures) { - if (sig->Function()->IsDefaultParamProxy() && - ValidateProxySignature(sig, typeArguments, arguments, argTypeInferenceRequired)) { - proxySignatures.push_back(sig); - } - } auto collectSignatures = [&](TypeRelationFlag relationFlags) { for (auto *sig : signatures) { - if (sig->Function()->IsDefaultParamProxy()) { - continue; - } auto *concreteSig = ValidateSignature(sig, typeArguments, arguments, pos, relationFlags, argTypeInferenceRequired); if (concreteSig != nullptr) { @@ -403,11 +395,10 @@ std::pair, ArenaVector> ETSChecker::Collec } } } - return std::make_pair(compatibleSignatures, proxySignatures); + return compatibleSignatures; } Signature *ETSChecker::GetMostSpecificSignature(ArenaVector &compatibleSignatures, - ArenaVector &proxySignatures, const ArenaVector &arguments, std::vector &argTypeInferenceRequired, const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags) @@ -422,26 +413,6 @@ Signature *ETSChecker::GetMostSpecificSignature(ArenaVector &compat return nullptr; } - // Just to avoid extra nesting level - auto const checkAmbiguous = [this, mostSpecificSignature, &pos](Signature const *const proxySignature) -> void { - auto const *const proxyParam = proxySignature->Function()->Params().back()->AsETSParameterExpression(); - if (!proxyParam->Ident()->Name().Is(ir::PROXY_PARAMETER_NAME)) { - ThrowTypeError({"Proxy parameter '", proxyParam->Ident()->Name(), "' has invalid name."}, pos); - } - - if (mostSpecificSignature->Params().size() == proxyParam->GetRequiredParams()) { - ThrowTypeError({"Reference to ", mostSpecificSignature->Function()->Id()->Name(), " is ambiguous"}, pos); - } - }; - - if (!proxySignatures.empty()) { - auto *const proxySignature = - ChooseMostSpecificProxySignature(proxySignatures, argTypeInferenceRequired, pos, arguments.size()); - if (proxySignature != nullptr) { - checkAmbiguous(proxySignature); - } - } - return mostSpecificSignature; } @@ -452,20 +423,10 @@ Signature *ETSChecker::ValidateSignatures(ArenaVector &signatures, TypeRelationFlag resolveFlags) { std::vector argTypeInferenceRequired = FindTypeInferenceArguments(arguments); - auto [compatibleSignatures, proxySignatures] = + auto compatibleSignatures = CollectSignatures(signatures, typeArguments, arguments, argTypeInferenceRequired, pos, resolveFlags); - if (!compatibleSignatures.empty()) { - return GetMostSpecificSignature(compatibleSignatures, proxySignatures, arguments, argTypeInferenceRequired, pos, - resolveFlags); - } - - if (!proxySignatures.empty()) { - auto *const proxySignature = - ChooseMostSpecificProxySignature(proxySignatures, argTypeInferenceRequired, pos, arguments.size()); - if (proxySignature != nullptr) { - return proxySignature; - } + return GetMostSpecificSignature(compatibleSignatures, arguments, argTypeInferenceRequired, pos, resolveFlags); } if ((resolveFlags & TypeRelationFlag::NO_THROW) == 0 && !arguments.empty() && !signatures.empty()) { @@ -633,26 +594,6 @@ Signature *ETSChecker::ChooseMostSpecificSignature(ArenaVector &sig return mostSpecificSignature; } -Signature *ETSChecker::ChooseMostSpecificProxySignature(ArenaVector &signatures, - const std::vector &argTypeInferenceRequired, - const lexer::SourcePosition &pos, size_t argumentsSize) -{ - if (pos.index == 0 && pos.line == 0) { - return nullptr; - } - - const auto mostSpecificSignature = - ChooseMostSpecificSignature(signatures, argTypeInferenceRequired, pos, argumentsSize); - - if (mostSpecificSignature == nullptr) { - const auto str = signatures.front()->Function()->Id()->Name().Mutf8().substr( - 0, signatures.front()->Function()->Id()->Name().Length() - 6); - ThrowTypeError("Reference to " + str + " is ambiguous", pos); - } - - return mostSpecificSignature; -} - Signature *ETSChecker::ResolveCallExpression(ArenaVector &signatures, const ir::TSTypeParameterInstantiation *typeArguments, const ArenaVector &arguments, @@ -758,10 +699,6 @@ void ETSChecker::CheckIdenticalOverloads(ETSFunctionType *func, ETSFunctionType { SavedTypeRelationFlagsContext savedFlagsCtx(Relation(), TypeRelationFlag::NO_RETURN_TYPE_CHECK); - if (currentFunc->Function()->IsDefaultParamProxy()) { - return; - } - Relation()->IsIdenticalTo(func, overload); if (Relation()->IsTrue()) { ThrowTypeError("Function already declared.", currentFunc->Start()); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index e720f7b96fa157e5a4cd0bb4646e3e816827ef9f..b129ec3eca5b3e8176543e4aaedfb33cb3dfe0dc 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -586,7 +586,8 @@ void ETSChecker::ValidateAssignmentIdentifier(ir::Identifier *const ident, varbi if (targetType->IsETSObjectType() && targetType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { if (!type->IsETSFunctionType() && !(type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { - ThrowError(ident); + ThrowTypeError({"Assigning a non-functional variable \"", ident->Name(), "\" to a functional type"}, + ident->Start()); } return; @@ -1010,9 +1011,11 @@ void ETSChecker::ResolveReturnStatement(checker::Type *funcReturnType, checker:: containingFunc->Signature()->SetReturnType(funcReturnType); containingFunc->Signature()->AddSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE); } else if (!Relation()->IsAssignableTo(argumentType, funcReturnType)) { - ThrowTypeError( - "Return statement type is not compatible with previous method's return statement " - "type(s).", + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(funcReturnType); + const Type *sourceType = TryGettingFunctionTypeFromInvokeFunction(argumentType); + + Relation()->RaiseError( + {"Function cannot have different primitive return types, found '", targetType, "', '", sourceType, "'"}, st->Argument()->Start()); } } else { @@ -1129,8 +1132,11 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T } if (annotationType != nullptr) { + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(annotationType); + const Type *sourceType = TryGettingFunctionTypeFromInvokeFunction(initType); + AssignmentContext(Relation(), init, initType, annotationType, init->Start(), - {"Initializers type is not assignable to the target type"}); + {"Type '", sourceType, "' cannot be assigned to type '", targetType, "'"}); if (isConst && initType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && annotationType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { bindingVar->SetTsType(init->TsType()); @@ -1157,11 +1163,8 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T init->Start()); } - if (initType->IsNullish() || isConst) { - bindingVar->SetTsType(initType); - } else { - bindingVar->SetTsType(GetNonConstantTypeFromPrimitiveType(initType)); - } + (initType->IsNullish() || isConst) ? bindingVar->SetTsType(initType) + : bindingVar->SetTsType(GetNonConstantTypeFromPrimitiveType(initType)); return bindingVar->TsType(); } @@ -2540,48 +2543,19 @@ bool ETSChecker::TypeInference(Signature *signature, const ArenaVectorIsETSFunctionType()); InferTypesForLambda(lambda, typeAnn->AsETSFunctionType()); Type *const argType = arrowFuncExpr->Check(this); + const Type *targetType = TryGettingFunctionTypeFromInvokeFunction(signature->Params()[index]->TsType()); + const std::initializer_list msg = { + "Type '", argType, "' is not compatible with type '", targetType, "' at index ", index + 1}; - checker::InvocationContext invokationCtx( - Relation(), arguments[index], argType, signature->Params()[index]->TsType(), arrowFuncExpr->Start(), - {"Call argument at index ", index, " is not compatible with the signature's type at that index"}, flags); + checker::InvocationContext invokationCtx(Relation(), arguments[index], argType, + signature->Params()[index]->TsType(), arrowFuncExpr->Start(), msg, + flags); invocable &= invokationCtx.IsInvocable(); } return invocable; } -void ETSChecker::AddUndefinedParamsForDefaultParams(const Signature *const signature, - ArenaVector &arguments, - ETSChecker *checker) -{ - if (!signature->Function()->IsDefaultParamProxy() || signature->Function()->Params().size() <= arguments.size()) { - return; - } - - uint32_t num = 0; - for (size_t i = arguments.size(); i != signature->Function()->Params().size() - 1; i++) { - if (auto const *const param = signature->Function()->Params()[i]->AsETSParameterExpression(); - !param->IsRestParameter()) { - auto const *const typeAnn = param->Ident()->TypeAnnotation(); - if (typeAnn->IsETSPrimitiveType()) { - if (typeAnn->AsETSPrimitiveType()->GetPrimitiveType() == ir::PrimitiveType::BOOLEAN) { - arguments.push_back(checker->Allocator()->New(false)); - } else { - arguments.push_back(checker->Allocator()->New(lexer::Number(0))); - } - } else { - // A proxy-function is called, so default reference parameters - // are initialized with null instead of undefined - auto *const nullLiteral = checker->Allocator()->New(); - nullLiteral->SetTsType(checker->GlobalETSNullType()); - arguments.push_back(nullLiteral); - } - num |= (1U << (arguments.size() - 1)); - } - } - arguments.push_back(checker->Allocator()->New(lexer::Number(num))); -} - bool ETSChecker::ExtensionETSFunctionType(checker::Type *type) { if (!type->IsETSFunctionType()) { @@ -2632,6 +2606,108 @@ std::string GenerateImplicitInstantiateArg(varbinder::LocalVariable *instantiate return implicitInstantiateArgument; } +void ETSChecker::GenerateGetterSetterBody(ETSChecker *checker, ArenaVector &stmts, + ArenaVector ¶ms, ir::ClassProperty *const field, + varbinder::FunctionParamScope *paramScope, bool isSetter) +{ + if (!isSetter) { + stmts.push_back(checker->Allocator()->New(field->Key())); + return; + } + + auto *paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); + paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator(), nullptr)); + paramIdent->TypeAnnotation()->SetParent(paramIdent); + + auto *paramExpression = checker->AllocNode(paramIdent, nullptr); + paramExpression->SetRange(paramIdent->Range()); + auto *const paramVar = std::get<2>(paramScope->AddParamDecl(checker->Allocator(), paramExpression)); + + paramIdent->SetVariable(paramVar); + paramExpression->SetVariable(paramVar); + + params.push_back(paramExpression); + + auto *assignmentExpression = checker->AllocNode( + field->Key(), paramExpression, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + + assignmentExpression->SetRange({field->Start(), field->End()}); + + stmts.push_back(checker->AllocNode(assignmentExpression)); + stmts.push_back(checker->Allocator()->New(nullptr)); +} + +ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty *const field, + varbinder::ClassScope *classScope, bool isSetter, + ETSChecker *checker) +{ + auto *paramScope = checker->Allocator()->New(checker->Allocator(), classScope); + auto *functionScope = checker->Allocator()->New(checker->Allocator(), paramScope); + + functionScope->BindParamScope(paramScope); + paramScope->BindFunctionScope(functionScope); + + auto flags = ir::ModifierFlags::PUBLIC; + + ArenaVector params(checker->Allocator()->Adapter()); + ArenaVector stmts(checker->Allocator()->Adapter()); + checker->GenerateGetterSetterBody(checker, stmts, params, field, paramScope, isSetter); + + auto *body = checker->AllocNode(checker->Allocator(), std::move(stmts)); + auto funcFlags = isSetter ? ir::ScriptFunctionFlags::SETTER : ir::ScriptFunctionFlags::GETTER; + auto *const returnTypeAnn = isSetter ? nullptr : field->TypeAnnotation(); + auto *func = + checker->AllocNode(ir::FunctionSignature(nullptr, std::move(params), returnTypeAnn), body, + funcFlags, flags, true, Language(Language::Id::ETS)); + + func->SetRange(field->Range()); + func->SetScope(functionScope); + body->SetScope(functionScope); + + auto *methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); + auto *decl = checker->Allocator()->New( + checker->Allocator(), field->Key()->AsIdentifier()->Name(), + field->Key()->AsIdentifier()->Variable()->Declaration()->Node()); + auto *var = functionScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); + + methodIdent->SetVariable(var); + + auto *funcExpr = checker->AllocNode(func); + funcExpr->SetRange(func->Range()); + func->AddFlag(ir::ScriptFunctionFlags::METHOD); + + auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, methodIdent, funcExpr, + flags, checker->Allocator(), false); + + method->Id()->SetMutator(); + method->SetRange(field->Range()); + method->Function()->SetIdent(method->Id()); + method->Function()->AddModifier(method->Modifiers()); + method->SetVariable(var); + + paramScope->BindNode(func); + functionScope->BindNode(func); + + checker->VarBinder()->AsETSBinder()->ResolveMethodDefinition(method); + functionScope->BindName(classScope->Node()->AsClassDefinition()->InternalName()); + method->Check(checker); + + return method; +} + +const Type *ETSChecker::TryGettingFunctionTypeFromInvokeFunction(const Type *type) const +{ + if (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + auto const propInvoke = type->AsETSObjectType()->GetProperty(util::StringView("invoke"), + PropertySearchFlags::SEARCH_INSTANCE_METHOD); + ASSERT(propInvoke != nullptr); + + return propInvoke->TsType(); + } + + return type; +} + bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, const Type *resolvedType) { ASSERT(ident->Parent()->IsCallExpression()); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 6fbf90b9fc3ee1eb20dfc893dcf938277a578a04..8c06deccbc40e0c84799fcc304c753c462a02968 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -719,6 +719,7 @@ void ETSChecker::ValidateOverriding(ETSObjectType *classType, const lexer::Sourc if (isGetterSetter && !functionOverridden) { for (auto *field : classType->Fields()) { if (field->Name() == (*it)->Name()) { + field->Declaration()->Node()->AddModifier(ir::ModifierFlags::SETTER); it = abstractsToBeImplemented.erase(it); functionOverridden = true; break; @@ -813,6 +814,7 @@ void ETSChecker::CheckClassDefinition(ir::ClassDefinition *classDef) } ValidateOverriding(classType, classDef->Start()); + TransformProperties(classType); CheckValidInheritance(classType, classDef); CheckConstFields(classType); CheckGetterSetterProperties(classType); @@ -1248,8 +1250,10 @@ PropertySearchFlags ETSChecker::GetSearchFlags(const ir::MemberExpression *const { auto searchFlag = GetInitialSearchFlags(memberExpr); searchFlag |= PropertySearchFlags::SEARCH_IN_BASE | PropertySearchFlags::SEARCH_IN_INTERFACES; - - if (targetRef != nullptr && targetRef->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)) { + if (targetRef != nullptr && + (targetRef->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE) || + (targetRef->HasFlag(varbinder::VariableFlags::TYPE_ALIAS) && + targetRef->TsType()->Variable()->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)))) { searchFlag &= ~(PropertySearchFlags::SEARCH_INSTANCE); } else if (memberExpr->Object()->IsThisExpression() || (memberExpr->Object()->IsIdentifier() && memberExpr->ObjType()->GetDeclNode() != nullptr && @@ -1441,7 +1445,7 @@ void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefini continue; } - if (!IsSameDeclarationType(it, found)) { + if (!IsSameDeclarationType(it, found) && !it->HasFlag(varbinder::VariableFlags::GETTER_SETTER)) { const char *targetType {}; if (it->HasFlag(varbinder::VariableFlags::PROPERTY)) { @@ -1468,6 +1472,64 @@ void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefini } } +void ETSChecker::TransformProperties(ETSObjectType *classType) +{ + auto propertyList = classType->Fields(); + auto *const classDef = classType->GetDeclNode()->AsClassDefinition(); + + for (auto *const field : propertyList) { + ASSERT(field->Declaration()->Node()->IsClassProperty()); + auto *const classProp = field->Declaration()->Node()->AsClassProperty(); + + if ((field->Declaration()->Node()->Modifiers() & ir::ModifierFlags::SETTER) == 0U) { + continue; + } + + field->AddFlag(varbinder::VariableFlags::GETTER_SETTER); + + auto *const scope = this->Scope(); + ASSERT(scope->IsClassScope()); + + ir::MethodDefinition *getter = GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), false, this); + classDef->Body().push_back(getter); + classType->AddProperty(getter->Variable()->AsLocalVariable()); + + auto *const methodScope = scope->AsClassScope()->InstanceMethodScope(); + auto name = getter->Key()->AsIdentifier()->Name(); + + auto *const decl = Allocator()->New(Allocator(), name, getter); + auto *const var = methodScope->AddDecl(Allocator(), decl, ScriptExtension::ETS); + var->AddFlag(varbinder::VariableFlags::METHOD); + + if (var == nullptr) { + auto *const prevDecl = methodScope->FindDecl(name); + ASSERT(prevDecl->IsFunctionDecl()); + prevDecl->Node()->AsMethodDefinition()->AddOverload(getter); + + if (!classProp->IsReadonly()) { + ir::MethodDefinition *const setter = + GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), true, this); + + classType->AddProperty(setter->Variable()->AsLocalVariable()); + prevDecl->Node()->AsMethodDefinition()->AddOverload(setter); + } + + getter->Function()->Id()->SetVariable( + methodScope->FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS)); + continue; + } + + if (!classProp->IsReadonly()) { + ir::MethodDefinition *const setter = + GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), true, this); + + classType->AddProperty(setter->Variable()->AsLocalVariable()); + getter->AddOverload(setter); + } + getter->Function()->Id()->SetVariable(var); + } +} + void ETSChecker::CheckGetterSetterProperties(ETSObjectType *classType) { auto const checkGetterSetter = [this](varbinder::LocalVariable *var, util::StringView name) { diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index e28b250c73a4ad3094decc2f95fbe186f1fab436..b74e3dcbc3d95865bb962bcb7149645200f2b575 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -32,9 +32,12 @@ void AssignmentContext::ValidateArrayTypeInitializerByElement(TypeRelation *rela for (uint32_t index = 0; index < node->Elements().size(); index++) { ir::Expression *currentArrayElem = node->Elements()[index]; + auto *const currentArrayElementType = currentArrayElem->Check(relation->GetChecker()->AsETSChecker()); + AssignmentContext(relation, currentArrayElem, currentArrayElem->Check(relation->GetChecker()->AsETSChecker()), target->ElementType(), currentArrayElem->Start(), - {"Array element at index ", index, " is not compatible with the target array element type."}); + {"Array element at index ", index, " with type '", currentArrayElementType, + "' is not compatible with the target array element type '", target->ElementType(), "'"}); } } diff --git a/ets2panda/checker/ets/typeRelationContext.h b/ets2panda/checker/ets/typeRelationContext.h index 155aa6ae64e565c312d00decacc7a97f1e336c29..b4a9b19a73f3e41d9ac384f10f8fb9a091580362 100644 --- a/ets2panda/checker/ets/typeRelationContext.h +++ b/ets2panda/checker/ets/typeRelationContext.h @@ -47,6 +47,8 @@ public: flags_ |= flags; relation->SetNode(node); + // NOTE (oeotvos) The narrowing flag will be applied here. It means, that the result of "let tmp: int = 1.5" + // will be 1, which could cause problems. if (source->HasTypeFlag(TypeFlag::CONSTANT)) { flags_ |= TypeRelationFlag::NARROWING; } diff --git a/ets2panda/checker/types/ets/etsArrayType.cpp b/ets2panda/checker/types/ets/etsArrayType.cpp index 91989dc86e1d45b3b8ad09cfd7a13a1a13125445..9b0e9403aad8cc4a0cc7699c4f027367add94ac6 100644 --- a/ets2panda/checker/types/ets/etsArrayType.cpp +++ b/ets2panda/checker/types/ets/etsArrayType.cpp @@ -25,6 +25,11 @@ void ETSArrayType::ToString(std::stringstream &ss) const { element_->ToString(ss); ss << "[]"; + + if (IsNullish()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::LITERAL_NULL); + } } void ETSArrayType::ToAssemblerType(std::stringstream &ss) const diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 4dfa0dba6fe0f5ac9b33e0cb6d8b3d8dc2a0f253..5891c506419167fd360e3a1807ec48e13b105b0c 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -272,38 +272,51 @@ std::vector ETSObjectType::ForeignProperties() return foreignProps; } -std::unordered_map ETSObjectType::CollectAllProperties() const +ArenaMap ETSObjectType::CollectAllProperties() const { - std::unordered_map propMap; + ArenaMap propMap(allocator_->Adapter()); EnsurePropertiesInstantiated(); - propMap.reserve(properties_.size()); - Iterate([&propMap](const varbinder::LocalVariable *var) { propMap.insert({var->Name(), var}); }); + Iterate([&propMap](const varbinder::LocalVariable *var) { propMap.emplace(var->Name(), var); }); return propMap; } void ETSObjectType::ToString(std::stringstream &ss) const { - ss << name_; + if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && + !name_.Empty()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); + } + GetFunctionalInterfaceInvokeType()->ToString(ss); + } else { + ss << name_; + } if (!typeArguments_.empty()) { - auto const typeArgumentsSize = typeArguments_.size(); ss << compiler::Signatures::GENERIC_BEGIN; - typeArguments_[0]->ToString(ss); - for (std::size_t i = 1U; i < typeArgumentsSize; ++i) { - ss << ','; - typeArguments_[i]->ToString(ss); + for (auto arg = typeArguments_.cbegin(); arg != typeArguments_.cend(); ++arg) { + (*arg)->ToString(ss); + + if (next(arg) != typeArguments_.cend()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_COMMA); + } } ss << compiler::Signatures::GENERIC_END; } if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && !name_.Empty()) { + if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS); + } if (ContainsNull()) { - ss << "|null"; + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::LITERAL_NULL); } if (ContainsUndefined()) { - ss << "|undefined"; + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::KEYW_UNDEFINED); } } } @@ -321,7 +334,7 @@ void ETSObjectType::IdenticalUptoNullability(TypeRelation *relation, Type *other return; } - if (relation->IgnoreTypeParameters() || (this == other)) { + if ((relation->IgnoreTypeParameters() && !HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) || (this == other)) { relation->Result(true); return; } @@ -392,16 +405,18 @@ void ETSObjectType::Identical(TypeRelation *relation, Type *other) IdenticalUptoNullability(relation, other); } -bool ETSObjectType::CheckIdenticalFlags(ETSObjectFlags target) const +bool ETSObjectType::CheckIdenticalFlags(const ETSObjectFlags target) const { - auto cleanedTargetFlags = static_cast(target & (~ETSObjectFlags::COMPLETELY_RESOLVED)); - cleanedTargetFlags &= ~ETSObjectFlags::INCOMPLETE_INSTANTIATION; - cleanedTargetFlags &= ~ETSObjectFlags::CHECKED_COMPATIBLE_ABSTRACTS; - cleanedTargetFlags &= ~ETSObjectFlags::CHECKED_INVOKE_LEGITIMACY; - auto cleanedSelfFlags = static_cast(ObjectFlags() & (~ETSObjectFlags::COMPLETELY_RESOLVED)); - cleanedSelfFlags &= ~ETSObjectFlags::INCOMPLETE_INSTANTIATION; - cleanedSelfFlags &= ~ETSObjectFlags::CHECKED_COMPATIBLE_ABSTRACTS; - cleanedSelfFlags &= ~ETSObjectFlags::CHECKED_INVOKE_LEGITIMACY; + constexpr auto FLAGS_TO_REMOVE = ETSObjectFlags::COMPLETELY_RESOLVED | ETSObjectFlags::INCOMPLETE_INSTANTIATION | + ETSObjectFlags::CHECKED_COMPATIBLE_ABSTRACTS | + ETSObjectFlags::CHECKED_INVOKE_LEGITIMACY; + + auto cleanedTargetFlags = target; + cleanedTargetFlags &= ~FLAGS_TO_REMOVE; + + auto cleanedSelfFlags = ObjectFlags(); + cleanedSelfFlags &= ~FLAGS_TO_REMOVE; + return cleanedSelfFlags == cleanedTargetFlags; } @@ -604,46 +619,57 @@ void ETSObjectType::Cast(TypeRelation *const relation, Type *const target) conversion::Forbidden(relation); } -void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) +bool ETSObjectType::DefaultObjectTypeChecks(const ETSChecker *const etsChecker, TypeRelation *const relation, + Type *const source) { - relation->Result(false); - auto *const etsChecker = relation->GetChecker()->AsETSChecker(); - - if (source->IsETSUnionType()) { - bool res = std::all_of(source->AsETSUnionType()->ConstituentTypes().begin(), - source->AsETSUnionType()->ConstituentTypes().end(), [this, relation](Type *ct) { - relation->Result(false); - IsSupertypeOf(relation, ct); - return relation->IsTrue(); - }); - relation->Result(res); - return; - } - // 3.8.3 Subtyping among Array Types auto const *const base = GetConstOriginalBaseType(); if (base == etsChecker->GlobalETSObjectType() && source->IsETSArrayType()) { relation->Result(true); - return; + return true; + } + + if (source->IsETSTypeParameter()) { + IsSupertypeOf(relation, source->AsETSTypeParameter()->GetConstraintType()); + return true; } if (!source->IsETSObjectType() || !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::CLASS | ETSObjectFlags::INTERFACE | ETSObjectFlags::NULL_TYPE)) { - return; + return true; } if ((!ContainsNull() && source->ContainsNull()) || (!ContainsUndefined() && source->ContainsUndefined())) { - return; + return true; } // All classes and interfaces are subtypes of Object if (base == etsChecker->GlobalETSObjectType() || base == etsChecker->GlobalETSNullishObjectType()) { relation->Result(true); - return; + return true; } IdenticalUptoNullability(relation, source); - if (relation->IsTrue()) { + return relation->IsTrue(); +} + +void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) +{ + relation->Result(false); + auto *const etsChecker = relation->GetChecker()->AsETSChecker(); + + if (source->IsETSUnionType()) { + bool res = std::all_of(source->AsETSUnionType()->ConstituentTypes().begin(), + source->AsETSUnionType()->ConstituentTypes().end(), [this, relation](Type *ct) { + relation->Result(false); + IsSupertypeOf(relation, ct); + return relation->IsTrue(); + }); + relation->Result(res); + return; + } + + if (DefaultObjectTypeChecks(etsChecker, relation, source)) { return; } @@ -769,7 +795,8 @@ static varbinder::LocalVariable *CopyPropertyWithTypeArguments(varbinder::LocalV const Substitution *substitution) { auto *const checker = relation->GetChecker()->AsETSChecker(); - auto *const copiedPropType = checker->GetTypeOfVariable(prop)->Substitute(relation, substitution); + auto *const varType = ETSChecker::IsVariableGetterSetter(prop) ? prop->TsType() : checker->GetTypeOfVariable(prop); + auto *const copiedPropType = varType->Substitute(relation, substitution); auto *const copiedProp = prop->Copy(checker->Allocator(), prop->Declaration()); copiedPropType->SetVariable(copiedProp); copiedProp->SetTsType(copiedPropType); diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 548bacce30ef4b012966a0a8b491ca662f0392ec..c59e37eb679af296ad1c42556dfef7ddd35f646d 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -389,7 +389,7 @@ public: return (flags_ & flag) != 0; } - ETSFunctionType *GetFunctionalInterfaceInvokeType() + ETSFunctionType *GetFunctionalInterfaceInvokeType() const { ASSERT(HasObjectFlag(ETSObjectFlags::FUNCTIONAL)); auto *invoke = GetOwnProperty("invoke"); @@ -482,6 +482,7 @@ public: Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; void Cast(TypeRelation *relation, Type *target) override; bool CastNumericObject(TypeRelation *relation, Type *target); + bool DefaultObjectTypeChecks(const ETSChecker *etsChecker, TypeRelation *relation, Type *source); void IsSupertypeOf(TypeRelation *relation, Type *source) override; Type *AsSuper(Checker *checker, varbinder::Variable *sourceVar) override; @@ -544,7 +545,7 @@ private: propertiesInstantiated_ = true; } } - std::unordered_map CollectAllProperties() const; + ArenaMap CollectAllProperties() const; void IdenticalUptoNullability(TypeRelation *relation, Type *other); bool CastWideningNarrowing(TypeRelation *relation, Type *target, TypeFlag unboxFlags, TypeFlag wideningFlags, TypeFlag narrowingFlags); diff --git a/ets2panda/checker/types/ets/etsTupleType.cpp b/ets2panda/checker/types/ets/etsTupleType.cpp index 99afd7bf641ee9b7c2c3e7d7841f86c531ae4623..1f79e6f99724de0d5f1c2820f9543ee17b0e1085 100644 --- a/ets2panda/checker/types/ets/etsTupleType.cpp +++ b/ets2panda/checker/types/ets/etsTupleType.cpp @@ -14,14 +14,22 @@ */ #include "etsTupleType.h" + +#include "checker/ETSchecker.h" #include "checker/ets/conversion.h" +#include "ir/ets/etsTuple.h" namespace panda::es2panda::checker { void ETSTupleType::ToString(std::stringstream &ss) const { ss << "["; - for (const auto *const type : typeList_) { - type->ToString(ss); + + for (auto it = typeList_.begin(); it != typeList_.end(); it++) { + (*it)->ToString(ss); + + if (std::next(it) != typeList_.end()) { + ss << ", "; + } } if (spreadType_ != nullptr) { @@ -129,6 +137,20 @@ void ETSTupleType::AssignmentTarget(TypeRelation *const relation, Type *const so relation->Result(true); } +Type *ETSTupleType::Substitute(TypeRelation *relation, const Substitution *substitution) +{ + auto *const checker = relation->GetChecker()->AsETSChecker(); + ArenaVector newTypeList(checker->Allocator()->Adapter()); + + for (auto *const tupleTypeListElement : GetTupleTypesList()) { + newTypeList.emplace_back(tupleTypeListElement->Substitute(relation, substitution)); + } + + auto *newSpreadType = spreadType_ == nullptr ? nullptr : spreadType_->Substitute(relation, substitution); + auto *newElementType = ir::ETSTuple::CalculateLUBForTuple(checker, newTypeList, newSpreadType); + return checker->Allocator()->New(std::move(newTypeList), newElementType, newSpreadType); +} + void ETSTupleType::Cast(TypeRelation *const relation, Type *const target) { // NOTE(mmartin): Might be not the correct casting rules, as these aren't defined yet @@ -185,7 +207,8 @@ void ETSTupleType::Cast(TypeRelation *const relation, Type *const target) Type *ETSTupleType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, [[maybe_unused]] GlobalTypesHolder *globalTypes) { - return this; + return allocator->New(GetTupleTypesList(), + ElementType()->Instantiate(allocator, relation, globalTypes), GetSpreadType()); } } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsTupleType.h b/ets2panda/checker/types/ets/etsTupleType.h index 7e84e5f87aa3a24e4722d526b4bc97d330c008c9..249dbe58cfb3991dfd171a6c4a632c3d61f7946d 100644 --- a/ets2panda/checker/types/ets/etsTupleType.h +++ b/ets2panda/checker/types/ets/etsTupleType.h @@ -85,6 +85,7 @@ public: void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; + Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; diff --git a/ets2panda/compiler/core/ASTVerifier.h b/ets2panda/compiler/core/ASTVerifier.h index 6602c533f90092723a3f7341b4c60f7a06627dc8..f6f3d5a83bfbb7dd0ce785713429fb02425bc817 100644 --- a/ets2panda/compiler/core/ASTVerifier.h +++ b/ets2panda/compiler/core/ASTVerifier.h @@ -183,7 +183,9 @@ public: }}; } const std::set withoutAdditionalChecks = {"PromiseVoidInferencePhase", + "TopLevelStatements", "StructLowering", + "DefaultParameterLowering", "GenerateTsDeclarationsPhase", "InterfacePropertyDeclarationsPhase", "LambdaConstructionPhase", diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index c95eceb6d3d2226e2f3ff62d8d0dd434685a198a..6a2a1a6c14b396186e9c7277dc40334dc8bf312d 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -870,6 +870,11 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ClassExpression *expr) cons UNREACHABLE(); } +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSReExportDeclaration *stmt) const +{ + UNREACHABLE(); +} + void ETSCompiler::Compile(const ir::ConditionalExpression *expr) const { ETSGen *etsg = GetETSGen(); @@ -1189,8 +1194,11 @@ void ETSCompiler::Compile(const ir::UpdateExpression *expr) const const auto argumentUnboxingFlags = static_cast(expr->Argument()->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG); + // workaround so argument_ does not get auto unboxed by lref.GetValue() + expr->Argument()->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); + lref.GetValue(); + if (expr->IsPrefix()) { - lref.GetValue(); expr->Argument()->SetBoxingUnboxingFlags(argumentUnboxingFlags); etsg->ApplyConversion(expr->Argument(), nullptr); @@ -1209,10 +1217,6 @@ void ETSCompiler::Compile(const ir::UpdateExpression *expr) const return; } - // workaround so argument_ does not get auto unboxed by lref.GetValue() - expr->Argument()->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); - lref.GetValue(); - compiler::RegScope rs(etsg); compiler::VReg originalValueReg = etsg->AllocReg(); etsg->StoreAccumulator(expr->Argument(), originalValueReg); diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 1949eabc5105e22b080ea15b364fbca0706cd0e5..9e444048a54b27709335fae1e4e2df44bc48a680 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -144,6 +144,7 @@ void ETSGen::StoreAccumulator(const ir::AstNode *const node, const VReg vreg) { const auto *const accType = GetAccumulatorType(); + ASSERT(accType != nullptr); if (accType->HasTypeFlag(TYPE_FLAG_BYTECODE_REF)) { Ra().Emit(node, vreg); } else if (accType->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { @@ -159,6 +160,7 @@ void ETSGen::LoadAccumulator(const ir::AstNode *node, VReg vreg) { const auto *const vregType = GetVRegType(vreg); + ASSERT(vregType != nullptr); if (vregType->HasTypeFlag(TYPE_FLAG_BYTECODE_REF)) { Ra().Emit(node, vreg); } else if (vregType->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { @@ -982,6 +984,13 @@ void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *targe { auto ttctx = TargetTypeContext(this, targetType); + if (node->HasAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE)) { + Ra().Emit( + node, node->AsExpression()->TsType()->AsETSEnumType()->GetValueMethod().globalSignature->InternalName(), + dummyReg_, 0); + node->RemoveAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); + } + if ((node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::BOXING_FLAG) != 0U) { ApplyBoxingConversion(node); return; @@ -2380,8 +2389,12 @@ void ETSGen::StringBuilderAppend(const ir::AstNode *node, VReg builder) signature = Signatures::BUILTIN_STRING_BUILDER_APPEND_BUILTIN_STRING; } - if ((GetAccumulatorType()->IsETSObjectType() || GetAccumulatorType()->IsETSTypeParameter()) && - !GetAccumulatorType()->IsETSStringType()) { + const checker::Type *accumulatorType = GetAccumulatorType(); + bool isNullOrUndefined = accumulatorType->ContainsNull() || accumulatorType->ContainsUndefined(); + bool isETSRefType = accumulatorType->IsETSObjectType() || accumulatorType->IsETSTypeParameter() || + accumulatorType->IsETSArrayType(); + bool isStringType = accumulatorType->IsETSStringType(); + if (isETSRefType && (!isStringType || isNullOrUndefined)) { if (Checker()->MayHaveNullValue(GetAccumulatorType())) { Label *ifnull = AllocLabel(); Label *end = AllocLabel(); diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 456d8c01f517276df7b6da746b953f64e46b3263..0555fd0c60d60a4d768cdf6d2bf965970675ff01 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -974,7 +974,8 @@ private: auto ttctx = TargetTypeContext(this, arg->TsType()); VReg argReg = AllocReg(); arg->Compile(this); - StoreAccumulator(node, argReg); + ApplyConversion(arg, nullptr); + ApplyConversionAndStoreAccumulator(arg, argReg, arg->TsType()); } Rra().Emit(node, ctor, arguments.size() + 1, name, ctor); @@ -983,13 +984,67 @@ private: } } + template + bool ResolveStringFromNullishBuiltin(const ir::AstNode *node, checker::Signature *signature, + const ArenaVector &arguments) + { + if (signature->InternalName() != Signatures::BUILTIN_STRING_FROM_NULLISH_CTOR) { + return false; + } + auto argExpr = arguments[0]; + if (argExpr->IsExpression()) { + if (argExpr->AsExpression()->IsNullLiteral()) { + LoadAccumulatorString(node, "null"); + return true; + } + if (argExpr->AsExpression()->IsUndefinedLiteral()) { + LoadAccumulatorString(node, "undefined"); + return true; + } + } + + Label *isNull = AllocLabel(); + Label *end = AllocLabel(); +#ifdef PANDA_WITH_ETS + Label *isUndefined = AllocLabel(); +#endif + COMPILE_ARG(0); + LoadAccumulator(node, arg0); + if (argExpr->TsType()->IsNullish()) { + BranchIfNull(node, isNull); +#ifdef PANDA_WITH_ETS + Sa().Emit(node); + BranchIfTrue(node, isUndefined); +#endif + } + LoadAccumulator(node, arg0); + CastToString(node); + StoreAccumulator(node, arg0); + Ra().Emit(node, Signatures::BUILTIN_STRING_FROM_STRING_CTOR, arg0, dummyReg_); + JumpTo(node, end); + if (argExpr->TsType()->IsNullish()) { + SetLabel(node, isNull); + LoadAccumulatorString(node, "null"); +#ifdef PANDA_WITH_ETS + JumpTo(node, end); + SetLabel(node, isUndefined); + LoadAccumulatorString(node, "undefined"); +#endif + } + SetLabel(node, end); + return true; + } + template void CallImpl(const ir::AstNode *node, checker::Signature *signature, const ArenaVector &arguments) { RegScope rs(this); - const auto name = signature->InternalName(); + if (ResolveStringFromNullishBuiltin(node, signature, arguments)) { + return; + } + const auto name = signature->InternalName(); switch (arguments.size()) { case 0U: { Ra().Emit(node, name, dummyReg_, dummyReg_); @@ -1028,7 +1083,8 @@ private: auto ttctx = TargetTypeContext(this, arg->TsType()); VReg argReg = AllocReg(); arg->Compile(this); - StoreAccumulator(node, argReg); + ApplyConversion(arg, nullptr); + ApplyConversionAndStoreAccumulator(node, argReg, arg->TsType()); } Rra().Emit(node, argStart, arguments.size(), name, argStart); @@ -1080,6 +1136,7 @@ private: // + 2U since we need to skip first 2 args in signature; first args is obj, // second arg is param2 auto *argType = signature->Params()[index + 2U]->TsType(); + ApplyConversion(arg, nullptr); ApplyConversionAndStoreAccumulator(node, argReg, argType); index++; } diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index 04faea2890706e94394fa85e34fc51e579684d9e..116c3a74327331b1925d5da902f0d1b4d830fbbe 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -412,7 +412,7 @@ void ETSEmitter::GenInterfaceRecord(const ir::TSInterfaceDeclaration *interfaceD } interfaceRecord.metadata->SetAccessFlags(accessFlags); - interfaceRecord.sourceFile = Context()->VarBinder()->Program()->AbsoluteName().Mutf8(); + interfaceRecord.sourceFile = Context()->VarBinder()->Program()->SourceFile().GetAbsolutePath().Mutf8(); interfaceRecord.metadata->SetAttributeValue(Signatures::EXTENDS_ATTRIBUTE, Signatures::BUILTIN_OBJECT); for (auto *it : baseType->Interfaces()) { @@ -456,7 +456,7 @@ void ETSEmitter::GenClassRecord(const ir::ClassDefinition *classDef, bool extern } classRecord.metadata->SetAccessFlags(accessFlags); - classRecord.sourceFile = Context()->VarBinder()->Program()->AbsoluteName().Mutf8(); + classRecord.sourceFile = Context()->VarBinder()->Program()->SourceFile().GetAbsolutePath().Mutf8(); auto *baseType = classDef->TsType()->AsETSObjectType(); if (baseType->SuperType() != nullptr) { diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index e7099b97f770c7130fc28909701a701cf02e26d2..603e69fe1a28f9f2117840b179ca64303d035aa9 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -495,6 +495,11 @@ void JSCompiler::Compile([[maybe_unused]] const ir::ETSImportDeclaration *node) UNREACHABLE(); } +void JSCompiler::Compile([[maybe_unused]] const ir::ETSReExportDeclaration *node) const +{ + UNREACHABLE(); +} + void JSCompiler::Compile([[maybe_unused]] const ir::ETSLaunchExpression *expr) const { UNREACHABLE(); diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index a5bc7da17f8c88a8590f7f614c19c2cde78c9772..c9c54ce77864542e858cef5ad3ab86a5292f5205 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -160,10 +160,6 @@ static pandasm::Program *CreateCompiler(const CompilationUnit &unit, const Phase &parser, &context); parser.ParseScript(unit.input, unit.options.compilationMode == CompilationMode::GEN_STD_LIB); - if constexpr (std::is_same_v && std::is_same_v) { - reinterpret_cast(varbinder)->FillResolvedImportPathes(parser.ResolvedParsedSourcesMap(), - &allocator); - } for (auto *phase : getPhases(unit.ext)) { if (!phase->Apply(&publicContext, &program)) { return nullptr; diff --git a/ets2panda/compiler/core/emitter.cpp b/ets2panda/compiler/core/emitter.cpp index 6242436e0b1c7fb61bb080b4f544dbccfe50e844..bfc94a084dcb60c138b5da8d8f09cfc545edb339 100644 --- a/ets2panda/compiler/core/emitter.cpp +++ b/ets2panda/compiler/core/emitter.cpp @@ -257,7 +257,7 @@ void FunctionEmitter::GenFunctionCatchTables(pandasm::Function *func) void FunctionEmitter::GenSourceFileDebugInfo(pandasm::Function *func) { - func->sourceFile = std::string {cg_->VarBinder()->Program()->AbsoluteName()}; + func->sourceFile = std::string {cg_->VarBinder()->Program()->SourceFile().GetAbsolutePath()}; if (!cg_->IsDebug()) { return; diff --git a/ets2panda/compiler/core/envScope.cpp b/ets2panda/compiler/core/envScope.cpp index 7adc372f8f2b5d823c90dfcb5d561da80cc3860b..cb870fdce8a5d62d31318855433d1d864fb68746 100644 --- a/ets2panda/compiler/core/envScope.cpp +++ b/ets2panda/compiler/core/envScope.cpp @@ -60,7 +60,7 @@ void LoopEnvScope::CopyBindings(PandaGen *pg, varbinder::VariableScope *scope, v ASSERT(scope->NeedLexEnv()); - for (const auto &[_, variable] : scope_->Bindings()) { + for (const auto &[_, variable] : scope_->OrderedBindings(pg_->Allocator())) { (void)_; if (!variable->HasFlag(flag)) { continue; diff --git a/ets2panda/compiler/core/regScope.cpp b/ets2panda/compiler/core/regScope.cpp index 6109ffd80f0025ca04665362660c0f3f5d1a044a..9f7a6d7e41ba90dec829aad6a864de1fe74d5d52 100644 --- a/ets2panda/compiler/core/regScope.cpp +++ b/ets2panda/compiler/core/regScope.cpp @@ -52,7 +52,7 @@ LocalRegScope::LocalRegScope(CodeGen *cg, varbinder::Scope *scope) : RegScope(cg prevScope_ = cg_->scope_; cg_->scope_ = scope; - for (const auto &[_, var] : scope->Bindings()) { + for (const auto &[_, var] : scope->OrderedBindings(cg_->Allocator())) { (void)_; if (!var->LexicalBound() && var->IsLocalVariable()) { var->AsLocalVariable()->BindVReg(cg_->AllocReg()); @@ -99,7 +99,7 @@ void FunctionRegScope::InitializeParams(const StoreParamCb &cb) paramReg++; } - for (const auto it : funcScope->Bindings()) { + for (const auto it : funcScope->OrderedBindings(cg_->Allocator())) { auto *const var = std::get<1>(it); if (var->Declaration()->IsParameterDecl() || var->Declaration()->IsTypeAliasDecl()) { continue; diff --git a/ets2panda/compiler/lowering/checkerPhase.cpp b/ets2panda/compiler/lowering/checkerPhase.cpp index c787655b877c76434016f5f495b54142b1c9637d..df020fe882e3d15ae2fd57d45d46ba6f8603d269 100644 --- a/ets2panda/compiler/lowering/checkerPhase.cpp +++ b/ets2panda/compiler/lowering/checkerPhase.cpp @@ -16,11 +16,17 @@ #include "checkerPhase.h" #include "checker/checker.h" #include "compiler/core/ASTVerifier.h" +#include "varbinder/ETSBinder.h" #include "compiler/core/compilerContext.h" namespace panda::es2panda::compiler { bool CheckerPhase::Perform(public_lib::Context *ctx, [[maybe_unused]] parser::Program *program) { + auto varbinder = ctx->compilerContext->VarBinder(); + if (ctx->parser->IsETSParser() && varbinder->IsETSBinder()) { + varbinder->AsETSBinder()->FillResolvedImportPaths(ctx->parser->AsETSParser()->ResolvedParsedSourcesMap(), + ctx->allocator); + } return ctx->checker->StartChecker(ctx->compilerContext->VarBinder(), *ctx->compilerContext->Options()); } diff --git a/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba4e2892b2cf39c92193e702e76dc52c6efddcd6 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp @@ -0,0 +1,374 @@ +/** + * Copyright (c) 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. + */ + +#include "defaultParameterLowering.h" +#include +#include "checker/ETSchecker.h" +#include "parser/ETSparser.h" +#include "parser/parserImpl.h" +#include "lexer.h" +#include "utils/arena_containers.h" +#include "ir/statement.h" +#include "varbinder/ETSBinder.h" + +namespace panda::es2panda::compiler { + +std::string_view DefaultParameterLowering::Name() +{ + static std::string_view name = "DefaultParameterLowering"; + return name; +} + +std::pair DefaultParameterLowering::HasDefaultParam(const ir::ScriptFunction *function, + parser::Program *program) +{ + bool hasDefaultParameter = false; + bool hasRestParameter = false; + std::size_t requiredParametersNumber = 0U; + + for (auto *const it : function->Params()) { + auto const *const param = it->AsETSParameterExpression(); + + if (param->IsRestParameter()) { + hasRestParameter = true; + continue; + } + + if (hasRestParameter) { + ThrowSyntaxError("Rest parameter should be the last one.", param->Start(), program); + } + + if (param->IsDefault()) { + hasDefaultParameter = true; + continue; + } + + if (hasDefaultParameter) { + ThrowSyntaxError("Required parameter follows default parameter(s).", param->Start(), program); + } + + ++requiredParametersNumber; + } + + if (hasDefaultParameter && hasRestParameter) { + ThrowSyntaxError("Both optional and rest parameters are not allowed in function's parameter list.", + function->Start(), program); + } + + return std::make_pair(hasDefaultParameter, requiredParametersNumber); +} + +ir::TSTypeParameterDeclaration *DefaultParameterLowering::CreateParameterDeclaraion(ir::MethodDefinition *method, + CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + if (method->Function()->TypeParams() == nullptr || method->Function()->TypeParams()->Params().empty()) { + return nullptr; + } + + ArenaVector typeParams(checker->Allocator()->Adapter()); + + auto parentParams = method->Function()->TypeParams()->Params(); + std::for_each(parentParams.begin(), parentParams.end(), [&typeParams, checker](ir::TSTypeParameter *par) { + ir::Identifier *ident = par->Name()->Clone(checker->Allocator(), nullptr)->AsIdentifier(); + auto *constraint = par->Constraint() != nullptr + ? par->Constraint()->Clone(checker->Allocator(), nullptr)->AsTypeNode() + : nullptr; + auto *defaultType = par->DefaultType() != nullptr + ? par->DefaultType()->Clone(checker->Allocator(), nullptr)->AsTypeNode() + : nullptr; + typeParams.push_back(checker->AllocNode(ident, constraint, defaultType)); + }); + return checker->AllocNode(std::move(typeParams), typeParams.size()); +} + +ir::FunctionSignature DefaultParameterLowering::CreateFunctionSignature(ir::MethodDefinition *method, + ArenaVector funcParam, + CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + + ir::TSTypeParameterDeclaration *typeParamDecl = CreateParameterDeclaraion(method, ctx); + std::for_each(funcParam.begin(), funcParam.end(), [checker](ir::Expression *expr) { + if (expr->IsETSParameterExpression()) { + auto *typeAnnot = expr->AsETSParameterExpression()->TypeAnnotation()->Clone(checker->Allocator(), nullptr); + typeAnnot->SetParent(expr); + auto *parIdent = expr->AsETSParameterExpression()->Ident(); + parIdent->SetTsTypeAnnotation(typeAnnot); + } + }); + + auto *returnTypeAnnotation = + method->Function()->ReturnTypeAnnotation() != nullptr + ? method->Function()->ReturnTypeAnnotation()->Clone(checker->Allocator(), nullptr)->AsTypeNode() + : nullptr; + + return ir::FunctionSignature(typeParamDecl, std::move(funcParam), returnTypeAnnotation); +} + +ir::TSTypeParameterInstantiation *DefaultParameterLowering::CreateTypeParameterInstantiation( + ir::MethodDefinition *method, CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + ArenaVector params(checker->Allocator()->Adapter()); + + if (method->Function()->TypeParams() == nullptr || method->Function()->TypeParams()->Params().empty()) { + return nullptr; + } + ArenaVector selfParams(checker->Allocator()->Adapter()); + ir::ETSTypeReferencePart *referencePart = nullptr; + + for (const auto ¶m : method->Function()->TypeParams()->Params()) { + auto *identRef = + checker->AllocNode(param->AsTSTypeParameter()->Name()->Name(), checker->Allocator()); + identRef->AsIdentifier()->SetReference(); + + referencePart = checker->AllocNode(identRef, nullptr, nullptr); + + auto *typeReference = checker->AllocNode(referencePart); + + selfParams.push_back(typeReference); + } + + return checker->AllocNode(std::move(selfParams)); +} + +ir::AstNode *DefaultParameterLowering::CreateFunctionBody(ir::MethodDefinition *method, CompilerContext *ctx, + ArenaVector funcCallArgs) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + ArenaVector funcStatements(checker->Allocator()->Adapter()); + + ir::CallExpression *callExpression = nullptr; + ir::Expression *id = nullptr; + ir::Expression *accessor = nullptr; + auto *const callee = checker->AllocNode(method->Id()->Name(), checker->Allocator()); + callee->SetReference(); + + if (method->IsConstructor()) { + accessor = checker->AllocNode(); + } else { + if (method->Parent()->IsClassDefinition() && (!method->Parent()->AsClassDefinition()->IsGlobal())) { + if (method->IsStatic()) { + id = checker->AllocNode(method->Parent()->AsClassDefinition()->Ident()->Name(), + checker->Allocator()); + } else { + id = checker->AllocNode(); + } + accessor = checker->AllocNode(id, callee, ir::MemberExpressionKind::PROPERTY_ACCESS, + false, false); + } + } + auto *paramInst = CreateTypeParameterInstantiation(method, ctx); + callExpression = checker->AllocNode(accessor != nullptr ? accessor : callee, + std::move(funcCallArgs), paramInst, false, false); + + ir::Statement *stmt = nullptr; + if ((method->Function()->ReturnTypeAnnotation() != nullptr) || + ((method->Function()->AsScriptFunction()->Flags() & ir::ScriptFunctionFlags::HAS_RETURN) != 0)) { + stmt = checker->AllocNode(callExpression); + } else { + stmt = checker->AllocNode(callExpression); + } + funcStatements.push_back(stmt); + callExpression->SetParent(stmt); + + return checker->AllocNode(checker->Allocator(), std::move(funcStatements)); +} + +ir::FunctionExpression *DefaultParameterLowering::CreateFunctionExpression( + ir::MethodDefinition *method, CompilerContext *ctx, ArenaVector funcDefinitionArgs, + ArenaVector funcCallArgs) +{ + lexer::SourcePosition startLoc(method->Start().line, method->Start().index); + lexer::SourcePosition endLoc = startLoc; + ir::FunctionSignature signature = CreateFunctionSignature(method, std::move(funcDefinitionArgs), ctx); + + auto *checker = ctx->Checker()->AsETSChecker(); + ir::Identifier *id = nullptr; + + ir::AstNode *body = CreateFunctionBody(method, ctx, std::move(funcCallArgs)); + + ir::ScriptFunction *funcNode = nullptr; + id = method->Id()->Clone(checker->Allocator(), nullptr)->AsIdentifier(); + funcNode = checker->AllocNode(std::move(signature), body, method->Function()->Flags(), false, + method->Function()->Language()); + body->SetParent(funcNode); + funcNode->AddModifier(method->Function()->Modifiers()); + funcNode->SetRange({startLoc, endLoc}); + funcNode->SetIdent(id); + + auto *func = checker->AllocNode(funcNode); + id->SetParent(func); + funcNode->SetParent(func); + + return func; +} + +void DefaultParameterLowering::CreateOverloadFunction(ir::AstNode *ast, ArenaVector funcCallArgs, + ArenaVector funcDefinitionArgs, + CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + auto *method = ast->AsMethodDefinition(); + auto *funcExpression = CreateFunctionExpression(ast->AsMethodDefinition(), ctx, std::move(funcDefinitionArgs), + std::move(funcCallArgs)); + auto *const overloadMethod = + checker->AllocNode(ast->AsMethodDefinition()->Kind(), funcExpression->Function()->Id(), + funcExpression, method->Modifiers(), checker->Allocator(), false); + funcExpression->SetParent(overloadMethod); + + overloadMethod->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); + overloadMethod->SetRange(funcExpression->Range()); + method->AddOverload(overloadMethod); +} + +void DefaultParameterLowering::ProcessGlobalFunctionDefinition(ir::AstNode *ast, CompilerContext *ctx) +{ + auto *checker = ctx->Checker()->AsETSChecker(); + auto params = ast->AsMethodDefinition()->Function()->Params(); + + // go through default parameters list and create overloading for each combination of them + // i.e. each new overload method has less actual paramaters than previous one and more + // default parameters values used to call original method. + + // NOTE: args counter (i), intentionally starts with 1 as we would need to process at least 1 argument with + // initializer. + for (auto [it, i] = std::tuple {params.rbegin(), 1}; it != params.rend(); ++it, i++) { + if (!((*it)->AsETSParameterExpression()->IsDefault())) { + // do not process regular arguments; + break; + } + + ArenaVector defaultArgs(checker->Allocator()->Adapter()); // will have Initializers + ArenaVector funcDefinitionArgs( + checker->Allocator()->Adapter()); // will have ETSParameterExpression + ArenaVector funcCallArgs(checker->Allocator()->Adapter()); // will have ir::Identifier + + // crate funciton/method definition with less mandatory args than overloaded one + // 1. create copy of found function arguemnts + // 2. move out of them optional ones (one by one),and each time the one + // optional is moved out we need to create new overload method with the rest of + // arguments (as new method args) and move the optional one(s) to the explicit + // call to the original method + // + // foo(x : int = 0, y : int = 1, z : int = 2) + // + // 1. loop step 1 + // foo (x : int, y : int) + // calls foo(x, y, 2) + // 2. loop step 2 + // foo (x :int) + // calls foo(x, 1, 2) + // 3. loop step 3 + // foo () + // calls foo(0, 1, 2) + auto pt = it; + do { + // extract default value from pt and make the function call argument out of it + // for now simple put whole parameter node to vector + ir::Expression *clone = nullptr; + auto *par = (*pt)->AsETSParameterExpression(); + if (par->Initializer()->IsArrowFunctionExpression()) { + clone = par->Initializer(); + } else { + clone = par->Initializer()->Clone(checker->Allocator(), nullptr)->AsExpression(); + } + if (clone != nullptr) { + defaultArgs.push_back(clone); + } + } while (params.rbegin() != pt--); + + // ok, now we need to copy the 'valid' (for now) arguments from original function + // and make the arguments for current overload out of them. + + funcCallArgs.reserve(params.size()); + funcDefinitionArgs.reserve(params.size() - i); + std::for_each( + params.begin(), params.end() - i, [&funcCallArgs, &funcDefinitionArgs, checker](ir::Expression *expr) { + // NOTE: we don't need Initializer here, as overload-method will have strict list of parameters + // will reset all of them once parsing loop completes + auto *funcArg = + expr->AsETSParameterExpression()->Ident()->Clone(checker->Allocator(), nullptr)->AsIdentifier(); + + // update list of functional call arguments + funcCallArgs.push_back(funcArg); + + auto *ident = + expr->AsETSParameterExpression()->Ident()->Clone(checker->Allocator(), nullptr)->AsIdentifier(); + auto *funcParam = checker->Allocator()->New(ident->AsIdentifier(), nullptr); + + // it seems that Clone() didn't copy TypeAnnotaion section .. + // and this causes a problem later on the chcker phase, so set it explicitly + funcParam->AsETSParameterExpression()->Ident()->SetTsTypeAnnotation( + expr->AsETSParameterExpression() + ->TypeAnnotation() + ->Clone(checker->Allocator(), nullptr) + ->AsTypeNode()); + + // prepare args list for overloade method definition + funcDefinitionArgs.push_back(funcParam); + }); + + // finally append arguemnts list with hard-coded literals, + // so eventually we have list of call expression arguments + funcCallArgs.insert(funcCallArgs.end(), defaultArgs.begin(), defaultArgs.end()); + CreateOverloadFunction(ast, std::move(funcCallArgs), std::move(funcDefinitionArgs), ctx); + } + + // done with overloads, now need to cleanup all initializers, + // to make parent function signature strict + std::for_each(params.begin(), params.end(), [](ir::Expression *expr) { + if (expr->AsETSParameterExpression()->IsDefault()) { + expr->AsETSParameterExpression()->SetInitializer(); + } + }); +} + +bool DefaultParameterLowering::Perform(public_lib::Context *ctx, parser::Program *program) +{ + for (auto &[_, extPrograms] : program->ExternalSources()) { + (void)_; + for (auto *extProg : extPrograms) { + Perform(ctx, extProg); + } + } + + checker::ETSChecker *checker = ctx->checker->AsETSChecker(); + ArenaVector foundNodes(checker->Allocator()->Adapter()); + program->Ast()->TransformChildrenRecursively([&foundNodes, this, program](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsMethodDefinition()) { + auto [hasDefaultParam, requiredParamsCount] = + HasDefaultParam(ast->AsMethodDefinition()->Function(), program); + if (hasDefaultParam) { + // store all nodes (which is function definition with default/optional parameters) + // to specific list, to process them later, as for now we can't modify AST in the + // middle of walking through it + foundNodes.push_back(ast); + } + } + return ast; + }); + + if (!foundNodes.empty()) { + for (auto &it : foundNodes) { + ProcessGlobalFunctionDefinition(it, ctx->compilerContext); + } + } + + return true; +} + +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/defaultParameterLowering.h b/ets2panda/compiler/lowering/ets/defaultParameterLowering.h new file mode 100644 index 0000000000000000000000000000000000000000..49f66ec04a775edc9e3c6f56e4d26004808e555b --- /dev/null +++ b/ets2panda/compiler/lowering/ets/defaultParameterLowering.h @@ -0,0 +1,54 @@ +/** + * Copyright (c) 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. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_DEFAULT_PARAM_LOWERING_H +#define ES2PANDA_COMPILER_LOWERING_DEFAULT_PARAM_LOWERING_H + +#include "compiler/lowering/phase.h" + +namespace panda::es2panda::compiler { + +class DefaultParameterLowering : public Phase { + std::pair HasDefaultParam(const ir::ScriptFunction *function, parser::Program *program); + void ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos, + parser::Program *program) const + { + lexer::LineIndex index(program->SourceCode()); + lexer::SourceLocation loc = index.GetLocation(pos); + + throw Error {ErrorType::SYNTAX, program->SourceFilePath().Utf8(), errorMessage, loc.line, loc.col}; + } + ir::TSTypeParameterDeclaration *CreateParameterDeclaraion(ir::MethodDefinition *method, CompilerContext *ctx); + ir::FunctionSignature CreateFunctionSignature(ir::MethodDefinition *method, ArenaVector funcParam, + CompilerContext *ctx); + ir::TSTypeParameterInstantiation *CreateTypeParameterInstantiation(ir::MethodDefinition *method, + CompilerContext *ctx); + ir::AstNode *CreateFunctionBody(ir::MethodDefinition *method, CompilerContext *ctx, + ArenaVector funcCallArgs); + ir::FunctionExpression *CreateFunctionExpression(ir::MethodDefinition *method, CompilerContext *ctx, + ArenaVector funcDefinitionArgs, + ArenaVector funcCallArgs); + void CreateOverloadFunction(ir::AstNode *ast, ArenaVector funcCallArgs, + ArenaVector funcDefinitionArgs, CompilerContext *ctx); + void ProcessGlobalFunctionDefinition(ir::AstNode *ast, CompilerContext *ctx); + +public: + std::string_view Name() override; + bool Perform(public_lib::Context *ctx, parser::Program *program) override; +}; + +} // namespace panda::es2panda::compiler + +#endif // ES2PANDA_COMPILER_LOWERING_DEFAULT_PARAM_LOWERING_H diff --git a/ets2panda/compiler/lowering/ets/expandBrackets.cpp b/ets2panda/compiler/lowering/ets/expandBrackets.cpp index d8936fe26a9f60761cdbd080b6cac0bcf7a2114d..f5915b3187f19baaa32cad1bc7b456ff4a3204c6 100644 --- a/ets2panda/compiler/lowering/ets/expandBrackets.cpp +++ b/ets2panda/compiler/lowering/ets/expandBrackets.cpp @@ -61,7 +61,7 @@ bool ExpandBracketsPhase::Perform(public_lib::Context *ctx, parser::Program *pro " throw new TypeError(\"Index fractional part should not be different from 0.0\");" "};" "(@@E5);", - parser::DEFAULT_SOURCE_FILE, ident, dimension, exprType, ident->Clone(allocator), newExpression); + parser::DEFAULT_SOURCE_FILE, ident, dimension, exprType, ident->Clone(allocator, nullptr), newExpression); sequenceExpr->SetParent(newExpression->Parent()); InitScopesPhaseETS::RunExternalNode(sequenceExpr, ctx->compilerContext->VarBinder()); checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(sequenceExpr, scope); diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index 85ccf455cf9008b292dcdd6276e182dc32a5987c..23ca287fa4e3f97896b7ee4928b618fd23047aaa 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -45,18 +45,16 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c ArenaVector params(checker->Allocator()->Adapter()); if (isSetter) { - auto paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); - paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator())); + auto paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); + paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator(), nullptr)); paramIdent->TypeAnnotation()->SetParent(paramIdent); - auto paramExpression = checker->AllocNode(paramIdent, nullptr); + auto *const paramExpression = checker->AllocNode(paramIdent, nullptr); paramExpression->SetRange(paramIdent->Range()); - const auto [_, __, param_var] = paramScope->AddParamDecl(checker->Allocator(), paramExpression); - (void)_; - (void)__; + auto *const paramVar = std::get<2>(paramScope->AddParamDecl(checker->Allocator(), paramExpression)); - paramIdent->SetVariable(param_var); - paramExpression->SetVariable(param_var); + paramIdent->SetVariable(paramVar); + paramExpression->SetVariable(paramVar); params.push_back(paramExpression); } @@ -73,7 +71,7 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c func->SetScope(functionScope); - auto methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); + auto methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); auto *decl = checker->Allocator()->New(field->Key()->AsIdentifier()->Name()); auto var = functionScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); @@ -122,6 +120,7 @@ static ir::Expression *UpdateInterfacePropertys(checker::ETSChecker *const check auto *decl = checker->Allocator()->New(checker->Allocator(), name, getter); auto var = methodScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); + var->AddFlag(varbinder::VariableFlags::METHOD); if (var == nullptr) { auto prevDecl = methodScope->FindDecl(name); diff --git a/ets2panda/compiler/lowering/ets/opAssignment.cpp b/ets2panda/compiler/lowering/ets/opAssignment.cpp index 9b4bfa606ba31d881cd882c665d28ff3401a5bc1..eb49fd0b2cbb5d10633a22c2921728d273386a58 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.cpp +++ b/ets2panda/compiler/lowering/ets/opAssignment.cpp @@ -87,32 +87,51 @@ void AdjustBoxingUnboxingFlags(ir::Expression *newExpr, const ir::Expression *ol } } -ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker *checker, parser::ETSParser *parser, - ir::AssignmentExpression *assignment) +static ir::Expression *CreateLoweringResult([[maybe_unused]] public_lib::Context *ctx, + ir::AssignmentExpression *assignment, ir::Expression *loweringResult) { - if (assignment->TsType() == nullptr) { // hasn't been through checker - return assignment; - } + // Adjust [un]boxing flag + ir::AssignmentExpression *newAssignment = nullptr; - const auto opEqual = assignment->OperatorType(); - ASSERT(opEqual != lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - ASSERT(parser != nullptr); + if (loweringResult->IsAssignmentExpression()) { + newAssignment = loweringResult->AsAssignmentExpression(); + } else if (loweringResult->IsBlockExpression()) { + auto stmts = loweringResult->AsBlockExpression()->Statements(); + if (!stmts.empty() && stmts.back()->IsExpressionStatement() && + stmts.back()->AsExpressionStatement()->GetExpression()->IsAssignmentExpression()) { + newAssignment = stmts.back()->AsExpressionStatement()->GetExpression()->AsAssignmentExpression(); + } else { + UNREACHABLE(); + } + } else { + UNREACHABLE(); + } - auto *const allocator = checker->Allocator(); + // NOTE(gogabr): make sure that the checker never puts both a boxing and an unboxing flag on the same node. + // Then this code will become unnecessary. + AdjustBoxingUnboxingFlags(newAssignment, assignment); - auto *const left = assignment->Left(); - auto *const right = assignment->Right(); - auto *const scope = NearestScope(assignment); + return loweringResult; +} - std::string newAssignmentStatements {}; +ir::OpaqueTypeNode *CreateOpaqueTypeNode(public_lib::Context *ctx, checker::Type *lcType) +{ + auto checker = ctx->checker->AsETSChecker(); + // Create proxy TypeNode for left hand of assignment expression + if (auto *lcTypeAsPrimitive = checker->ETSBuiltinTypeAsPrimitiveType(lcType); lcTypeAsPrimitive != nullptr) { + lcType = lcTypeAsPrimitive; + } + return checker->AllocNode(lcType); +} - ir::Identifier *ident1; +std::tuple CreateTemporaryVar( + ir::Expression *left, ArenaAllocator *allocator) +{ + std::string newStatements {}; + ir::Identifier *ident1 = nullptr; ir::Identifier *ident2 = nullptr; ir::Expression *object = nullptr; ir::Expression *property = nullptr; - - checker::SavedCheckerContext scc {checker, checker::CheckerStatus::IGNORE_VISIBILITY}; - // Create temporary variable(s) if left hand of assignment is not defined by simple identifier[s] if (left->IsIdentifier()) { ident1 = left->AsIdentifier(); @@ -123,26 +142,23 @@ ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker ident1 = object->AsIdentifier(); } else { ident1 = Gensym(allocator); - newAssignmentStatements = "let @@I1 = (@@E2); "; + newStatements = "let @@I1 = (@@E2); "; } if (property = memberExpression->Property(); property->IsIdentifier()) { ident2 = property->AsIdentifier(); } else { ident2 = Gensym(allocator); - newAssignmentStatements += "let @@I3 = (@@E4); "; + newStatements += "let @@I3 = (@@E4); "; } } else { UNREACHABLE(); } + return std::make_tuple(ident1, ident2, object, property, newStatements); +} - // Create proxy TypeNode for left hand of assignment expression - auto *lcType = left->TsType(); - if (auto *lcTypeAsPrimitive = checker->ETSBuiltinTypeAsPrimitiveType(lcType); lcTypeAsPrimitive != nullptr) { - lcType = lcTypeAsPrimitive; - } - auto *exprType = checker->AllocNode(lcType); - +std::tuple GenerateCodeStringForExpression(ir::Identifier *ident2, ir::Expression *left) +{ // Generate ArkTS code string for new lowered assignment expression: std::string leftHand = "@@I5"; std::string rightHand = "@@I7"; @@ -158,51 +174,42 @@ ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker UNREACHABLE(); } } + return std::make_tuple(leftHand, rightHand); +} + +ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker *checker, parser::ETSParser *parser, + ArenaAllocator *allocator, ir::AssignmentExpression *assignment) +{ + const auto opEqual = assignment->OperatorType(); + ASSERT(opEqual != lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + + auto *const left = assignment->Left(); + auto *const right = assignment->Right(); + auto *const scope = NearestScope(assignment); + + checker::SavedCheckerContext scc {checker, checker::CheckerStatus::IGNORE_VISIBILITY}; + + // Create temporary variable(s) if left hand of assignment is not defined by simple identifier[s] + auto [ident1, ident2, object, property, newAssignmentStatements] = CreateTemporaryVar(left, allocator); + // Generate ArkTS code string for new lowered assignment expression: + auto [leftHand, rightHand] = GenerateCodeStringForExpression(ident2, left); newAssignmentStatements += leftHand + " = (" + rightHand + ' ' + std::string {lexer::TokenToString(OpEqualToOp(opEqual))} + " (@@E9)) as @@T10"; - // std::cout << "Lowering statements: " << new_assignment_statements << std::endl; - - // Parse ArkTS code string and create and process corresponding AST node(s) auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); auto *loweringResult = parser->CreateFormattedExpression( newAssignmentStatements, parser::DEFAULT_SOURCE_FILE, ident1, object, ident2, property, - ident1->Clone(allocator), ident2 != nullptr ? ident2->Clone(allocator) : nullptr, ident1->Clone(allocator), - ident2 != nullptr ? ident2->Clone(allocator) : nullptr, right, exprType); + ident1->Clone(allocator, nullptr), ident2 != nullptr ? ident2->Clone(allocator, nullptr) : nullptr, + ident1->Clone(allocator, nullptr), ident2 != nullptr ? ident2->Clone(allocator, nullptr) : nullptr, right, + CreateOpaqueTypeNode(ctx, left->TsType())); loweringResult->SetParent(assignment->Parent()); InitScopesPhaseETS::RunExternalNode(loweringResult, ctx->compilerContext->VarBinder()); checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(loweringResult, scope); loweringResult->Check(checker); - // Adjust [un]boxing flag - ir::AssignmentExpression *newAssignment; - if (loweringResult->IsAssignmentExpression()) { - newAssignment = loweringResult->AsAssignmentExpression(); - } else if (loweringResult->IsBlockExpression() && !loweringResult->AsBlockExpression()->Statements().empty() && - loweringResult->AsBlockExpression()->Statements().back()->IsExpressionStatement() && - loweringResult->AsBlockExpression() - ->Statements() - .back() - ->AsExpressionStatement() - ->GetExpression() - ->IsAssignmentExpression()) { - newAssignment = loweringResult->AsBlockExpression() - ->Statements() - .back() - ->AsExpressionStatement() - ->GetExpression() - ->AsAssignmentExpression(); - } else { - UNREACHABLE(); - } - - // NOTE(gogabr): make sure that the checker never puts both a boxing and an unboxing flag on the same node. - // Then this code will become unnecessary. - AdjustBoxingUnboxingFlags(newAssignment, assignment); - - return loweringResult; + return CreateLoweringResult(ctx, assignment, loweringResult); } bool OpAssignmentLowering::Perform(public_lib::Context *ctx, parser::Program *program) @@ -217,12 +224,15 @@ bool OpAssignmentLowering::Perform(public_lib::Context *ctx, parser::Program *pr } auto *const parser = ctx->parser->AsETSParser(); + ASSERT(parser != nullptr); checker::ETSChecker *checker = ctx->checker->AsETSChecker(); program->Ast()->TransformChildrenRecursively([ctx, checker, parser](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->OperatorType() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { - return HandleOpAssignment(ctx, checker, parser, ast->AsAssignmentExpression()); + if (ast->AsAssignmentExpression()->TsType() != nullptr) { // hasn't been through checker + return HandleOpAssignment(ctx, checker, parser, checker->Allocator(), ast->AsAssignmentExpression()); + } } return ast; diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..167913fa43bb13d019c2412bd69439eb19b6419f --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#include "compiler/lowering/ets/topLevelStmts/globalClassHandler.h" + +#include "ir/statements/classDeclaration.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/base/classStaticBlock.h" +#include "ir/base/scriptFunction.h" +#include "ir/base/methodDefinition.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/classExpression.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/callExpression.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/blockStatement.h" +#include "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h" +#include "util/helpers.h" + +namespace panda::es2panda::compiler { + +using util::NodeAllocator; + +void GlobalClassHandler::InitGlobalClass(const ArenaVector &programs) +{ + if (programs.empty()) { + return; + } + auto globalDecl = CreateGlobalClass(); + auto globalClass = globalDecl->Definition(); + + auto addCCtor = [this](ir::AstNode *node) { + if (node->IsClassDefinition()) { + auto classDef = node->AsClassDefinition(); + bool allowEmpty = false; + auto staticBlock = CreateCCtor(classDef->Body(), classDef->Start(), allowEmpty); + if (staticBlock != nullptr) { + classDef->Body().emplace_back(staticBlock); + staticBlock->SetParent(classDef); + } + } + }; + + ArenaVector statements(allocator_->Adapter()); + for (auto program : programs) { + program->Ast()->IterateRecursively(addCCtor); + auto stmts = MakeGlobalStatements(program->Ast(), globalClass, !program->GetPackageName().Empty()); + statements.emplace_back(GlobalStmts {program, std::move(stmts)}); + program->SetGlobalClass(globalClass); + } + InitCallToCCTOR(programs.front(), statements); +} + +ir::MethodDefinition *GlobalClassHandler::CreateAndFillInitMethod(const ArenaVector &initStatements) +{ + auto initMethod = CreateInitMethod(); + + for (const auto &stmts : initStatements) { + for (auto stmt : stmts.statements) { + initMethod->Function()->Body()->AsBlockStatement()->Statements().emplace_back(stmt); + stmt->SetParent(initMethod->Function()->Body()); + } + } + return initMethod; +} + +ir::MethodDefinition *GlobalClassHandler::CreateInitMethod() +{ + const auto functionFlags = ir::ScriptFunctionFlags::NONE; + const auto functionModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; + auto *initIdent = NodeAllocator::Alloc(allocator_, INIT_NAME, allocator_); + + ArenaVector params(allocator_->Adapter()); + + ArenaVector statements(allocator_->Adapter()); + auto *initBody = NodeAllocator::Alloc(allocator_, allocator_, std::move(statements)); + + auto *initFunc = + NodeAllocator::Alloc(allocator_, ir::FunctionSignature(nullptr, std::move(params), nullptr), + initBody, functionFlags, false, Language(Language::Id::ETS)); + + initFunc->SetIdent(initIdent); + initFunc->AddModifier(functionModifiers); + + auto *funcExpr = NodeAllocator::Alloc(allocator_, initFunc); + auto methodDef = NodeAllocator::Alloc(allocator_, ir::MethodDefinitionKind::METHOD, initIdent, + funcExpr, functionModifiers, allocator_, false); + return methodDef; +} + +void GlobalClassHandler::AddInitCall(ir::ClassDefinition *globalClass, ir::MethodDefinition *initMethod) +{ + ASSERT(initMethod != nullptr); + + auto &globalBody = globalClass->Body(); + auto maybeStaticBlock = std::find_if(globalBody.begin(), globalBody.end(), + [](ir::AstNode *cctor) { return cctor->IsClassStaticBlock(); }); + ASSERT(maybeStaticBlock != globalBody.end()); + + auto *staticBlock = (*maybeStaticBlock)->AsClassStaticBlock(); + auto *callee = RefIdent(initMethod->Id()->Name()); + + auto *const callExpr = NodeAllocator::Alloc( + allocator_, callee, ArenaVector(allocator_->Adapter()), nullptr, false, false); + + auto *blockBody = staticBlock->Function()->Body()->AsBlockStatement(); + auto exprStmt = NodeAllocator::Alloc(allocator_, callExpr); + exprStmt->SetParent(blockBody); + blockBody->Statements().emplace_back(exprStmt); +} + +ir::Identifier *GlobalClassHandler::RefIdent(const util::StringView &name) +{ + auto *const callee = NodeAllocator::Alloc(allocator_, name, allocator_); + callee->SetReference(); + return callee; +} + +ir::ClassStaticBlock *GlobalClassHandler::CreateCCtor(const ArenaVector &properties, + const lexer::SourcePosition &loc, bool allowEmptyCctor) +{ + bool hasStaticField = false; + for (const auto *prop : properties) { + if (prop->IsClassStaticBlock()) { + return nullptr; + } + + if (!prop->IsClassProperty()) { + continue; + } + + const auto *field = prop->AsClassProperty(); + + if (field->IsStatic()) { + hasStaticField = true; + } + } + + if (!hasStaticField && !allowEmptyCctor) { + return nullptr; + } + + ArenaVector params(allocator_->Adapter()); + + auto *id = NodeAllocator::Alloc(allocator_, compiler::Signatures::CCTOR, allocator_); + + ArenaVector statements(allocator_->Adapter()); + + auto *body = NodeAllocator::Alloc(allocator_, allocator_, std::move(statements)); + auto *func = NodeAllocator::Alloc( + allocator_, ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, ir::ModifierFlags::STATIC, false, + Language(Language::Id::ETS)); + func->SetIdent(id); + + auto *funcExpr = NodeAllocator::Alloc(allocator_, func); + auto *staticBlock = NodeAllocator::Alloc(allocator_, funcExpr, allocator_); + staticBlock->AddModifier(ir::ModifierFlags::STATIC); + staticBlock->SetRange({loc, loc}); + return staticBlock; +} + +ArenaVector GlobalClassHandler::MakeGlobalStatements(ir::BlockStatement *globalStmts, + ir::ClassDefinition *classDef, bool isPackage) +{ + auto globalDecl = GlobalDeclTransformer(allocator_); + auto statements = globalDecl.TransformStatements(globalStmts->Statements(), isPackage); + classDef->AddProperties(util::Helpers::ConvertVector(statements.classProperties)); + globalDecl.FilterDeclarations(globalStmts->Statements()); + return std::move(statements.initStatements); +} + +void GlobalClassHandler::InitGlobalClass(ir::ClassDefinition *classDef, parser::ScriptKind scriptKind) +{ + auto &globalProperties = classDef->Body(); + auto staticBlock = CreateCCtor(globalProperties, classDef->Start(), scriptKind != parser::ScriptKind::STDLIB); + if (staticBlock != nullptr) { + staticBlock->SetParent(classDef); + globalProperties.emplace_back(staticBlock); + } + classDef->SetGlobalInitialized(); +} + +ir::ClassDeclaration *GlobalClassHandler::CreateGlobalClass() +{ + auto *ident = NodeAllocator::Alloc(allocator_, compiler::Signatures::ETS_GLOBAL, allocator_); + + auto *classDef = + NodeAllocator::Alloc(allocator_, allocator_, ident, ir::ClassDefinitionModifiers::GLOBAL, + ir::ModifierFlags::ABSTRACT, Language(Language::Id::ETS)); + auto *classDecl = NodeAllocator::Alloc(allocator_, classDef, allocator_); + return classDecl; +} + +void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements) +{ + auto globalClass = program->GlobalClass(); + auto globalDecl = globalClass->Parent()->AsClassDeclaration(); + program->Ast()->Statements().emplace_back(globalDecl); + globalDecl->SetParent(program->Ast()); + InitGlobalClass(globalClass, program->Kind()); + auto &globalBody = globalClass->Body(); + if (program->GetPackageName().Empty() && program->Kind() != parser::ScriptKind::STDLIB) { + ir::MethodDefinition *initMethod = CreateAndFillInitMethod(initStatements); + if (initMethod != nullptr) { + initMethod->SetParent(program->GlobalClass()); + globalBody.insert(globalBody.begin(), initMethod); + if (!initMethod->Function()->Body()->AsBlockStatement()->Statements().empty()) { + AddInitCall(program->GlobalClass(), initMethod); + } + } + } +} + +} // namespace panda::es2panda::compiler \ No newline at end of file diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..4f9f0f0c0fb4e8037793d95aaf9bce1f86ca145f --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#ifndef PANDA_GLOBALCLASSHANDLER_H +#define PANDA_GLOBALCLASSHANDLER_H + +#include "parser/program/program.h" +#include "public/public.h" +#include "ir/astNode.h" + +namespace panda::es2panda::compiler { + +class GlobalClassHandler { + struct GlobalStmts { + parser::Program *program; + ArenaVector statements; + }; + +public: + GlobalClassHandler(ArenaAllocator *allocator) : allocator_(allocator) {}; + + /** + * Each "Module" has it's own global class, which contains all top level statements across "module" + * Result - creation of global class and _$init$_ method + * @param programs - vector of files in module + */ + void InitGlobalClass(const ArenaVector &programs); + +private: + /** + * Move top level statements to _$init$_ and + * @param program program of module + * @param init_statements statements which should be executed + */ + void InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements); + +private: + void InitGlobalClass(ir::ClassDefinition *classDef, parser::ScriptKind scriptKind); + ir::ClassDeclaration *CreateGlobalClass(); + ir::ClassStaticBlock *CreateCCtor(const ArenaVector &properties, const lexer::SourcePosition &loc, + bool allowEmptyCctor); + + /** + * + * @param global_stmts leave only declarations here + * @param class_def add new properties such as methods and fields + * @param is_package + * @return Statements, which should be executed before the start + */ + ArenaVector MakeGlobalStatements(ir::BlockStatement *globalStmts, ir::ClassDefinition *classDef, + bool isPackage); + + ir::MethodDefinition *CreateAndFillInitMethod(const ArenaVector &initStatements); + ir::MethodDefinition *CreateInitMethod(); + void AddInitCall(ir::ClassDefinition *globalClass, ir::MethodDefinition *initMethod); + + ir::Identifier *RefIdent(const util::StringView &name); + +private: + constexpr static std::string_view INIT_NAME = compiler::Signatures::INIT_METHOD; + ArenaAllocator *const allocator_; +}; +} // namespace panda::es2panda::compiler + +#endif // PANDA_GLOBALCLASSHANDLER_H diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ff4a8e88f013a768f6967db2adfa2786dd3ee48 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#include "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h" + +namespace panda::es2panda::compiler { + +void GlobalDeclTransformer::FilterDeclarations(ArenaVector &stmts) +{ + const auto isDeclCb = [&types = typeDecl_](const ir::AstNode *node) { + return types.count(node->Type()) == 0U || + (node->IsExportNamedDeclaration() && !node->AsExportNamedDeclaration()->Specifiers().empty()); + }; + stmts.erase(std::remove_if(stmts.begin(), stmts.end(), isDeclCb), stmts.end()); +} + +GlobalDeclTransformer::ResultT GlobalDeclTransformer::TransformStatements(const ArenaVector &stmts, + bool isPackage) +{ + isPackage_ = isPackage; + result_.classProperties.clear(); + result_.initStatements.clear(); + for (auto stmt : stmts) { + stmt->Accept(this); + } + return std::move(result_); +} + +void GlobalDeclTransformer::VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl) +{ + auto *funcExpr = util::NodeAllocator::ForceSetParent(allocator_, funcDecl->Function()); + funcDecl->Function()->SetStart(funcDecl->Function()->Id()->End()); + funcExpr->SetRange(funcDecl->Function()->Range()); + ir::MethodDefinitionKind methodKind; + if (funcDecl->Function()->IsExtensionMethod()) { + methodKind = ir::MethodDefinitionKind::EXTENSION_METHOD; + } else { + methodKind = ir::MethodDefinitionKind::METHOD; + } + auto *method = util::NodeAllocator::ForceSetParent( + allocator_, methodKind, funcDecl->Function()->Id(), funcExpr, funcDecl->Function()->Modifiers(), allocator_, + false); + method->SetRange(funcDecl->Range()); + result_.classProperties.emplace_back(method); +} + +void GlobalDeclTransformer::VisitVariableDeclaration(ir::VariableDeclaration *varDecl) +{ + for (auto declarator : varDecl->Declarators()) { + auto id = declarator->Id()->AsIdentifier(); + auto typeAnn = id->TypeAnnotation(); + id->SetTsTypeAnnotation(nullptr); + auto *field = util::NodeAllocator::ForceSetParent( + allocator_, id, declarator->Init(), typeAnn, varDecl->Modifiers(), allocator_, false); + field->SetRange(declarator->Range()); + result_.classProperties.emplace_back(field); + if (auto stmt = InitTopLevelProperty(field); stmt != nullptr) { + result_.initStatements.emplace_back(stmt); + } + } +} + +ir::Identifier *GlobalDeclTransformer::RefIdent(const util::StringView &name) +{ + auto *const callee = util::NodeAllocator::Alloc(allocator_, name, allocator_); + callee->SetReference(); + return callee; +} + +ir::ExpressionStatement *GlobalDeclTransformer::InitTopLevelProperty(ir::ClassProperty *classProperty) +{ + ir::ExpressionStatement *initStmt = nullptr; + const auto initializer = classProperty->Value(); + if (!isPackage_ && !classProperty->IsConst() && initializer != nullptr && + !initializer->IsArrowFunctionExpression()) { + auto *ident = RefIdent(classProperty->Id()->Name()); + ident->SetRange(classProperty->Id()->Range()); + + initializer->SetParent(nullptr); + auto *assignmentExpression = util::NodeAllocator::Alloc( + allocator_, ident, initializer, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + assignmentExpression->SetRange({ident->Start(), initializer->End()}); + + auto expressionStatement = + util::NodeAllocator::Alloc(allocator_, assignmentExpression); + expressionStatement->SetRange(classProperty->Range()); + + classProperty->SetRange({ident->Start(), initializer->End()}); + + if (classProperty->TypeAnnotation() != nullptr && !classProperty->TypeAnnotation()->IsETSFunctionType()) { + classProperty->SetValue(nullptr); + } else { + initializer->SetParent(classProperty); + } + initStmt = expressionStatement; + } else { + classProperty->SetStart(classProperty->Id()->Start()); + } + return initStmt; +} + +void GlobalDeclTransformer::HandleNode(ir::AstNode *node) +{ + ASSERT(node->IsStatement()); + if (typeDecl_.count(node->Type()) == 0U) { + ASSERT(!propertiesDecl_.count(node->Type())); + result_.initStatements.emplace_back(node->AsStatement()); + } +} + +} // namespace panda::es2panda::compiler \ No newline at end of file diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h new file mode 100644 index 0000000000000000000000000000000000000000..58d61110eff4359d898b4952a3ab041aaacef19b --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#ifndef PANDA_GLOBALDECLTRANSFORMER_H +#define PANDA_GLOBALDECLTRANSFORMER_H + +#include "util/helpers.h" +#include "compiler/lowering/phase.h" +#include "ir/visitor/IterateAstVisitor.h" + +namespace panda::es2panda::compiler { + +class GlobalDeclTransformer : public ir::visitor::CustomAstVisitor { + const std::unordered_set typeDecl_ = { + ir::AstNodeType::CLASS_DECLARATION, ir::AstNodeType::STRUCT_DECLARATION, + ir::AstNodeType::TS_ENUM_DECLARATION, ir::AstNodeType::TS_INTERFACE_DECLARATION, + ir::AstNodeType::ETS_PACKAGE_DECLARATION, ir::AstNodeType::ETS_IMPORT_DECLARATION, + ir::AstNodeType::TS_TYPE_ALIAS_DECLARATION, ir::AstNodeType::EXPORT_ALL_DECLARATION, + ir::AstNodeType::EXPORT_NAMED_DECLARATION, ir::AstNodeType::REEXPORT_STATEMENT, + }; + + const std::unordered_set propertiesDecl_ = { + ir::AstNodeType::FUNCTION_DECLARATION, + ir::AstNodeType::VARIABLE_DECLARATION, + }; + +public: + struct ResultT { + explicit ResultT(ArenaAllocator *alloc) : classProperties(alloc->Adapter()), initStatements(alloc->Adapter()) {} + + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + ArenaVector classProperties; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + ArenaVector initStatements; + }; + + explicit GlobalDeclTransformer(ArenaAllocator *allocator) : allocator_(allocator), result_(allocator) {} + + /** + * Removes top level statements, global variable declarations, global function declarations + * @param stmts + */ + void FilterDeclarations(ArenaVector &stmts); + + /** + * Creates ClassProperty for global variables and MethodFunction for global functions. + * Copy top level statements to vector. + * @param stmts top level statements + * @param is_package if current file is package. In package $init$ doesn't contain global variable initializers + * @return pair (class properties, init statements) + */ + ResultT TransformStatements(const ArenaVector &stmts, bool isPackage); + + void VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl) override; + void VisitVariableDeclaration(ir::VariableDeclaration *varDecl) override; + void HandleNode(ir::AstNode *node) override; + + ir::Identifier *RefIdent(const util::StringView &name); + + ir::ExpressionStatement *InitTopLevelProperty(ir::ClassProperty *classProperty); + +private: + ArenaAllocator *allocator_; + ResultT result_; + bool isPackage_ = false; +}; + +} // namespace panda::es2panda::compiler +#endif // PANDA_GLOBALDECLTRANSFORMER_H diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp new file mode 100644 index 0000000000000000000000000000000000000000..073a9563875ad9d191556150baa10a6d9d49b058 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#include "compiler/lowering/ets/topLevelStmts/importExportDecls.h" +#include "ir/ets/etsReExportDeclaration.h" + +namespace panda::es2panda::compiler { + +void ImportExportDecls::ParseDefaultSources() +{ + auto imports = parser_->ParseDefaultSources(DEFAULT_IMPORT_SOURCE_FILE, defaultImportSource_, + util::ImportPathResolver::StdLib()); + varbinder_->SetDefaultImports(std::move(imports)); +} + +void ImportExportDecls::HandleGlobalStmts(const ArenaVector &programs) +{ + VerifySingleExportDefault(programs); + for (const auto &program : programs) { + auto errorHandler = util::ErrorHandler(program); + fieldMap_.clear(); + exportNameMap_.clear(); + for (auto stmt : program->Ast()->Statements()) { + stmt->Accept(this); + } + for (auto &[exportName, startLoc] : exportNameMap_) { + if (fieldMap_.count(exportName) == 0) { + auto errorStr = "Cannot find name '" + std::string(exportName.Utf8()) + "' to export."; + errorHandler.ThrowSyntaxError(errorStr, startLoc); + } + auto field = fieldMap_[exportName]; + field->AddModifier(ir::ModifierFlags::EXPORT); + } + } +} + +void ImportExportDecls::VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl) +{ + auto id = funcDecl->Function()->Id(); + fieldMap_.emplace(id->Name(), funcDecl->Function()); +} + +void ImportExportDecls::VisitVariableDeclaration(ir::VariableDeclaration *varDecl) +{ + for (const auto &decl : varDecl->Declarators()) { + auto id = decl->Id()->AsIdentifier(); + fieldMap_.emplace(id->Name(), varDecl); + } +} + +void ImportExportDecls::VisitExportNamedDeclaration(ir::ExportNamedDeclaration *exportDecl) +{ + for (auto spec : exportDecl->Specifiers()) { + auto local = spec->Local(); + exportNameMap_.emplace(local->Name(), local->Start()); + } +} + +void ImportExportDecls::VerifySingleExportDefault(const ArenaVector &programs) +{ + bool metDefaultExport = false; + auto verifyDefault = [&metDefaultExport](ir::Statement *stmt, parser::Program *program) { + if ((stmt->Modifiers() & ir::ModifierFlags::DEFAULT_EXPORT) == 0) { + return; + } + if (metDefaultExport) { + util::ErrorHandler::ThrowSyntaxError(program, "Only one default export is allowed in a module", + stmt->Start()); + } + metDefaultExport = true; + }; + for (const auto &program : programs) { + for (auto stmt : program->Ast()->Statements()) { + verifyDefault(stmt, program); + } + metDefaultExport = false; + } +} + +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h new file mode 100644 index 0000000000000000000000000000000000000000..80f8a83d5304eefcba4fbf18950c0c9c01a4f922 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#ifndef PANDA_IMPORTEXPORTDECLS_H +#define PANDA_IMPORTEXPORTDECLS_H + +#include "util/error_handler.h" +#include +#include "varbinder/ETSBinder.h" +#include "compiler/lowering/phase.h" +#include "ir/visitor/IterateAstVisitor.h" +#include "globalClassHandler.h" + +namespace panda::es2panda::compiler { + +class ImportExportDecls : ir::visitor::EmptyAstVisitor { + static constexpr std::string_view DEFAULT_IMPORT_SOURCE_FILE = ".ets"; + + static std::string CreateDefaultImportSource(const std::vector &paths) + { + std::string importStdlibFile; + for (const auto &path : paths) { + importStdlibFile += "import * from \"" + path + "\";"; + } + return importStdlibFile; + } + + const std::string defaultImportSource_ = CreateDefaultImportSource(util::ImportPathResolver::StdLib()); + +public: + ImportExportDecls() = default; + ImportExportDecls(varbinder::ETSBinder *varbinder, parser::ETSParser *parser) + : varbinder_(varbinder), parser_(parser) + { + } + + /** + * Add stdlib names to default imports + */ + void ParseDefaultSources(); + + /** + * Verifies import errors, and add Exported flag to top level variables and methods + * @param global_stmts program global statements + */ + void HandleGlobalStmts(const ArenaVector &programs); + + void VerifySingleExportDefault(const ArenaVector &programs); + +private: + void VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl) override; + void VisitVariableDeclaration(ir::VariableDeclaration *varDecl) override; + void VisitExportNamedDeclaration(ir::ExportNamedDeclaration *exportDecl) override; + +private: + varbinder::ETSBinder *varbinder_ {nullptr}; + std::map fieldMap_; + std::map exportNameMap_; + parser::ETSParser *parser_ {nullptr}; +}; +} // namespace panda::es2panda::compiler + +#endif // PANDA_IMPORTEXPORTDECLS_H diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c654952b562c53392c0bc782283c66789c6df8dd --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#include "compiler/lowering/ets/topLevelStmts/topLevelStmts.h" + +#include "compiler/lowering/ets/topLevelStmts/globalClassHandler.h" + +namespace panda::es2panda::compiler { + +bool TopLevelStatements::Perform(public_lib::Context *ctx, parser::Program *program) +{ + GlobalClassHandler globalClass(program->Allocator()); + auto imports = ImportExportDecls(program->VarBinder()->AsETSBinder(), ctx->parser->AsETSParser()); + imports.ParseDefaultSources(); + auto extSrcs = program->ExternalSources(); + for (auto &[_, ext_programs] : extSrcs) { + (void)_; + imports.HandleGlobalStmts(ext_programs); + globalClass.InitGlobalClass(ext_programs); + } + ArenaVector mainModule(program->Allocator()->Adapter()); + mainModule.emplace_back(program); + imports.HandleGlobalStmts(mainModule); + globalClass.InitGlobalClass(mainModule); + return true; +} + +} // namespace panda::es2panda::compiler \ No newline at end of file diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.h b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.h new file mode 100644 index 0000000000000000000000000000000000000000..6a21e9ab87bfa4812f3d4d3f8a9d4c5d841b0f0a --- /dev/null +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_INITMETHOD_H +#define ES2PANDA_COMPILER_LOWERING_INITMETHOD_H + +#include "compiler/lowering/phase.h" +#include "util/helpers.h" +#include "parser/program/program.h" +#include "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h" +#include "compiler/lowering/ets/topLevelStmts/importExportDecls.h" + +namespace panda::es2panda::compiler { + +/** + * Purpose of this lowering to: + * Create _$init$_ method + * Add all top level statements to _$init$_ + * Add call of _$init$_ to ETSGLOBAL CCTOR + * Handle imports/exports (re_exports, add stdlib, check existance of named exports) + * + * Expected to be called before ScopesInitPhase + */ +class TopLevelStatements : public Phase { +public: + std::string_view Name() override + { + return "TopLevelStatements"; + } + + bool Perform(public_lib::Context *ctx, parser::Program *program) override; + +private: +}; + +} // namespace panda::es2panda::compiler +#endif \ No newline at end of file diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index ef64447b6944d8ca51ff118cfb8fa9bacefa6218..ecc6333715ecc13cd3448d4e35e552ccc49c8d4a 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -167,7 +167,7 @@ ir::TSAsExpression *HandleUnionCastToPrimitive(checker::ETSChecker *checker, ir: ir::BinaryExpression *GenInstanceofExpr(checker::ETSChecker *checker, ir::Expression *unionNode, checker::Type *constituentType) { - auto *const lhsExpr = unionNode->Clone(checker->Allocator())->AsExpression(); + auto *const lhsExpr = unionNode->Clone(checker->Allocator(), nullptr)->AsExpression(); lhsExpr->Check(checker); lhsExpr->SetBoxingUnboxingFlags(unionNode->GetBoxingUnboxingFlags()); auto *rhsType = constituentType; diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index ad5e543ef4c462570c22f989d4e505cbbbdb8398..c1e8c5306e23c02b58c4ce9b8369d3e3f3710a69 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -18,11 +18,13 @@ #include "compiler/core/ASTVerifier.h" #include "compiler/core/compilerContext.h" #include "compiler/lowering/ets/objectIndexAccess.h" +#include "ets/defaultParameterLowering.h" #include "lexer/token/sourceLocation.h" #include "compiler/lowering/checkerPhase.h" #include "compiler/lowering/plugin_phase.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/ets/expandBrackets.h" +#include "compiler/lowering/ets/topLevelStmts/topLevelStmts.h" #include "compiler/lowering/ets/generateDeclarations.h" #include "compiler/lowering/ets/lambdaLowering.h" #include "compiler/lowering/ets/interfacePropertyDeclarations.h" @@ -33,6 +35,7 @@ #include "public/es2panda_lib.h" #include "compiler/lowering/ets/promiseVoid.h" #include "utils/json_builder.h" +#include "compiler/lowering/ets/defaultParameterLowering.h" namespace panda::es2panda::compiler { @@ -55,6 +58,8 @@ static UnionLowering g_unionLowering; static ExpandBracketsPhase g_expandBracketsPhase; static PromiseVoidInferencePhase g_promiseVoidInferencePhase; static StructLowering g_structLowering; +static DefaultParameterLowering g_defaultParameterLowering; +static TopLevelStatements g_topLevelStatements; static PluginPhase g_pluginsAfterParse {"plugins-after-parse", ES2PANDA_STATE_PARSED, &util::Plugin::AfterParse}; static PluginPhase g_pluginsAfterCheck {"plugins-after-check", ES2PANDA_STATE_CHECKED, &util::Plugin::AfterCheck}; static PluginPhase g_pluginsAfterLowerings {"plugins-after-lowering", ES2PANDA_STATE_LOWERED, @@ -69,11 +74,23 @@ static InitScopesPhaseJs g_initScopesPhaseJs; std::vector GetETSPhaseList() { return { - &g_pluginsAfterParse, &g_initScopesPhaseEts, &g_promiseVoidInferencePhase, - &g_structLowering, &g_lambdaConstructionPhase, &g_interfacePropDeclPhase, - &g_checkerPhase, &g_pluginsAfterCheck, &g_generateTsDeclarationsPhase, - &g_opAssignmentLowering, &g_objectIndexLowering, &g_tupleLowering, - &g_unionLowering, &g_expandBracketsPhase, &g_pluginsAfterLowerings, + &g_pluginsAfterParse, + &g_topLevelStatements, + &g_defaultParameterLowering, + &g_initScopesPhaseEts, + &g_promiseVoidInferencePhase, + &g_structLowering, + &g_lambdaConstructionPhase, + &g_interfacePropDeclPhase, + &g_checkerPhase, + &g_pluginsAfterCheck, + &g_generateTsDeclarationsPhase, + &g_opAssignmentLowering, + &g_objectIndexLowering, + &g_tupleLowering, + &g_unionLowering, + &g_expandBracketsPhase, + &g_pluginsAfterLowerings, }; } diff --git a/ets2panda/compiler/lowering/scopesInit/savedBindingsCtx.cpp b/ets2panda/compiler/lowering/scopesInit/savedBindingsCtx.cpp index 72bab547bda732e570d593a0f017d6b5147fb0e3..c8197d78c21ca4e7a76e3322b4cec634b0c5328e 100644 --- a/ets2panda/compiler/lowering/scopesInit/savedBindingsCtx.cpp +++ b/ets2panda/compiler/lowering/scopesInit/savedBindingsCtx.cpp @@ -26,7 +26,7 @@ void ImportDeclarationContext::BindImportDecl(ir::ImportDeclaration *importDecl) { varbinder::ModuleScope::ImportDeclList declList(Allocator()->Adapter()); - for (const auto &[name, variable] : VarBinder()->GetScope()->Bindings()) { + for (const auto &[name, variable] : VarBinder()->GetScope()->OrderedBindings(Allocator())) { if (SavedBindings().find(name) != SavedBindings().end()) { continue; } diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 736ba8c6cdf4bc7beef7a3a4389db2618998c8e9..56eb2868ab0dd04a9037a9162792fa1402cc1a3e 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -13,12 +13,14 @@ * limitations under the License. */ +#include "util/error_handler.h" #include "scopesInitPhase.h" namespace panda::es2panda::compiler { bool ScopesInitPhase::Perform(PhaseContext *ctx, parser::Program *program) { Prepare(ctx, program); + program->VarBinder()->InitTopScope(); HandleBlockStmt(program->Ast(), GetScope()); Finalize(); return true; @@ -320,10 +322,7 @@ void ScopesInitPhase::IterateNoTParams(ir::ClassDefinition *classDef) void ScopesInitPhase::ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const { - lexer::LineIndex index(program_->SourceCode()); - lexer::SourceLocation loc = index.GetLocation(pos); - - throw Error {ErrorType::SYNTAX, program_->SourceFilePath().Utf8(), errorMessage, loc.line, loc.col}; + util::ErrorHandler::ThrowSyntaxError(Program(), errorMessage, pos); } void ScopesInitPhase::CreateFuncDecl(ir::ScriptFunction *func) @@ -740,7 +739,7 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) ASSERT(VarBinder()->GetScope()->IsClassScope()); - if (method->AsMethodDefinition()->Function()->IsDefaultParamProxy()) { + if ((method->AsMethodDefinition()->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD) != 0) { return; } @@ -774,7 +773,7 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) var->AddFlag(varbinder::VariableFlags::METHOD); methodName->SetVariable(var); for (auto *overload : method->Overloads()) { - ASSERT(overload->Function()->IsDefaultParamProxy()); + ASSERT((overload->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD)); overload->Id()->SetVariable(var); overload->SetParent(var->Declaration()->Node()); } @@ -785,15 +784,23 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) addOverload(method, found); method->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); - // default params proxy + // default params overloads for (auto *overload : method->Overloads()) { - ASSERT(overload->Function()->IsDefaultParamProxy()); + ASSERT((overload->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD)); addOverload(overload, found); } method->ClearOverloads(); } } +void InitScopesPhaseETS::VisitETSReExportDeclaration(ir::ETSReExportDeclaration *reExport) +{ + if (reExport->GetETSImportDeclarations()->Language().IsDynamic()) { + VarBinder()->AsETSBinder()->AddDynamicImport(reExport->GetETSImportDeclarations()); + } + VarBinder()->AsETSBinder()->AddReExportImport(reExport); +} + void InitScopesPhaseETS::VisitETSParameterExpression(ir::ETSParameterExpression *paramExpr) { auto *const var = std::get<1>(VarBinder()->AddParamDecl(paramExpr)); diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h index cd0f14acd381ab18556431ac47904f9974df6163..a0c467546b7eb5df1f78d60b9e96a371ee23dd09 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h @@ -131,6 +131,11 @@ protected: return program_; } + const parser::Program *Program() const + { + return program_; + } + PhaseContext *Context() { return ctx_; @@ -331,6 +336,7 @@ private: void VisitImportNamespaceSpecifier(ir::ImportNamespaceSpecifier *importSpec) override; void VisitImportSpecifier([[maybe_unused]] ir::ImportSpecifier *importSpec) override {}; void VisitImportDefaultSpecifier([[maybe_unused]] ir::ImportDefaultSpecifier *importSpec) override {}; + void VisitETSReExportDeclaration(ir::ETSReExportDeclaration *reExport) override; void VisitETSParameterExpression(ir::ETSParameterExpression *paramExpr) override; void VisitETSImportDeclaration(ir::ETSImportDeclaration *importDecl) override; void VisitTSEnumMember(ir::TSEnumMember *enumMember) override; diff --git a/ets2panda/compiler/scripts/signatures.yaml b/ets2panda/compiler/scripts/signatures.yaml index 37f0738757c257a7ea04a3478db691d63777b9e0..c0797950622c2fd8f0b8e17cf44e2c24bc607b68 100644 --- a/ets2panda/compiler/scripts/signatures.yaml +++ b/ets2panda/compiler/scripts/signatures.yaml @@ -304,6 +304,18 @@ signatures: return_type: PRIMITIVE_VOID ref: BUILTIN_OBJECT_CTOR + - callee: BUILTIN_STRING + method_name: $CTOR + params: [BUILTIN_STRING] + return_type: PRIMITIVE_VOID + ref: BUILTIN_STRING_FROM_STRING_CTOR + + - callee: BUILTIN_STRING + method_name: $CTOR + params: [BUILTIN_OBJECT] + return_type: PRIMITIVE_VOID + ref: BUILTIN_STRING_FROM_NULLISH_CTOR + - callee: BUILTIN_OBJECT method_name: toString params: [] diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index f6eedfb88e7aae97f6adb4fe243611a6f69f63d6..3075935b3a9af3f5d7a45d91fc64f3b552e27d28 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -450,7 +450,7 @@ public: { \ return ((member_name)&flag) != 0U; \ } \ - void Remove##flag_type(flag_type flag) noexcept \ + void Remove##flag_type(flag_type flag) const noexcept \ { \ (member_name) &= ~flag; \ } @@ -484,9 +484,8 @@ public: [[nodiscard]] ir::BlockStatement *GetTopStatement(); [[nodiscard]] const ir::BlockStatement *GetTopStatement() const; - // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] virtual AstNode *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) + [[maybe_unused]] AstNode *const parent) { UNREACHABLE(); } diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index f6420bb131169df655c2d9ce113a41c983aa62a6..ab3b2b157f78de5735ba7290d8872f95ebdaea3e 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -22,6 +22,7 @@ namespace panda::es2panda::ir { enum class AstNodeFlags { NO_OPTS = 0, CHECKCAST = 1U << 0U, + ENUM_GET_VALUE = 1U << 1U, }; enum class ModifierFlags : uint32_t { @@ -79,10 +80,9 @@ enum class ScriptFunctionFlags : uint32_t { RETHROWS = 1U << 14U, GETTER = 1U << 15U, SETTER = 1U << 16U, - DEFAULT_PARAM_PROXY = 1U << 17U, - ENTRY_POINT = 1U << 18U, - INSTANCE_EXTENSION_METHOD = 1U << 19U, - HAS_RETURN = 1U << 20U + ENTRY_POINT = 1U << 17U, + INSTANCE_EXTENSION_METHOD = 1U << 18U, + HAS_RETURN = 1U << 19U }; enum class TSOperatorType { READONLY, KEYOF, UNIQUE }; diff --git a/ets2panda/ir/astNodeMapping.h b/ets2panda/ir/astNodeMapping.h index 94ad053988f63309c9fbf4ce6a132a28d7c48d63..652e7fed7aed02a6d7caf1432e511b3cf9543a1f 100644 --- a/ets2panda/ir/astNodeMapping.h +++ b/ets2panda/ir/astNodeMapping.h @@ -72,6 +72,7 @@ _(PREFIX_ASSERTION_EXPRESSION, PrefixAssertionExpression) \ _(PROPERTY, Property) \ _(REGEXP_LITERAL, RegExpLiteral) \ + _(REEXPORT_STATEMENT, ETSReExportDeclaration) \ _(RETURN_STATEMENT, ReturnStatement) \ _(SCRIPT_FUNCTION, ScriptFunction) \ _(SEQUENCE_EXPRESSION, SequenceExpression) \ diff --git a/ets2panda/ir/base/classElement.cpp b/ets2panda/ir/base/classElement.cpp index 62b0ebb1003ff02519fe98bdc74c1bd7df759be1..bcf983816ebe116a3c2103c7e7089c77d1b7b6b8 100644 --- a/ets2panda/ir/base/classElement.cpp +++ b/ets2panda/ir/base/classElement.cpp @@ -20,6 +20,14 @@ namespace panda::es2panda::ir { +void ClassElement::SetValue(Expression *value) noexcept +{ + if (value != nullptr) { + value->SetParent(this); + } + value_ = value; +} + Identifier *ClassElement::Id() noexcept { return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; diff --git a/ets2panda/ir/base/classElement.h b/ets2panda/ir/base/classElement.h index b937cbf84e7dd2fab15ad93d4e301f2ab45d9e3e..ab2771fcf4079349be5f091c05a82ebcfd458f8b 100644 --- a/ets2panda/ir/base/classElement.h +++ b/ets2panda/ir/base/classElement.h @@ -58,6 +58,8 @@ public: return value_; } + void SetValue(Expression *value) noexcept; + [[nodiscard]] const Expression *Value() const noexcept { return value_; diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 9d97cafadaaca1b8a9b4419360f297fc280b21e9..6c70b74bef0c066b72d665c0a729507617e0e95f 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -136,11 +136,10 @@ checker::Type *ClassProperty::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ClassProperty *ClassProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_->Clone(allocator)->AsExpression(); - auto *const value = value_->Clone(allocator)->AsExpression(); + auto *const key = key_->Clone(allocator, nullptr)->AsExpression(); + auto *const value = value_->Clone(allocator, nullptr)->AsExpression(); auto *const typeAnnotation = typeAnnotation_->Clone(allocator, this); if (auto *const clone = allocator->New(key, value, typeAnnotation, flags_, allocator, isComputed_); diff --git a/ets2panda/ir/base/classProperty.h b/ets2panda/ir/base/classProperty.h index 25ac075f90cbaa9e1067f59b33793e39b4782f2b..0f2c7d5ba3e7209501f2321143cb631403433c6b 100644 --- a/ets2panda/ir/base/classProperty.h +++ b/ets2panda/ir/base/classProperty.h @@ -51,8 +51,7 @@ public: return isStatic ? PrivateFieldKind::STATIC_FIELD : PrivateFieldKind::FIELD; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/decorator.cpp b/ets2panda/ir/base/decorator.cpp index eed3b5f6db795245ea5de04beba6a767083be7d1..4ae382fa2522f2d26eb74ffc4cbcd88a0aa40244 100644 --- a/ets2panda/ir/base/decorator.cpp +++ b/ets2panda/ir/base/decorator.cpp @@ -65,10 +65,9 @@ checker::Type *Decorator::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) Decorator *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsExpression() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/base/decorator.h b/ets2panda/ir/base/decorator.h index dfbcc9027c1a169d64f2a3ca4333b90588b76964..779e08c90c021fce01569291af01d97c444ff6bb 100644 --- a/ets2panda/ir/base/decorator.h +++ b/ets2panda/ir/base/decorator.h @@ -36,8 +36,7 @@ public: return expr_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index a5208db90f2428856a38f8611feab9b44c39c97d..bf4cb3a214e08eca54977902b3f6ad861ee613e0 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -71,7 +71,6 @@ checker::Type *MetaProperty::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MetaProperty *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(kind_); clone != nullptr) { diff --git a/ets2panda/ir/base/metaProperty.h b/ets2panda/ir/base/metaProperty.h index c5eb1bb8448c390cfcb2393bddb5107357585de5..369b6ba66bab9b54992b9b087cd70aa31899cafe 100644 --- a/ets2panda/ir/base/metaProperty.h +++ b/ets2panda/ir/base/metaProperty.h @@ -43,8 +43,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index 9ab31f5844ea2a82ebc8dc12763a240f4dac9829..c30e7536cf8b9cec1f213c0b3bb60eb56026cbff 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -192,11 +192,10 @@ checker::Type *MethodDefinition::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MethodDefinition *MethodDefinition::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(kind_, key, value, flags_, allocator, isComputed_); clone != nullptr) { diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index d3a314df0bfbbeccde183a29cf17a35367026937..906301cac4afa9094b5071a462d22e6421bfbe11 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -104,8 +104,7 @@ public: const ScriptFunction *Function() const; PrivateFieldKind ToPrivateFieldKind(bool isStatic) const override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/property.cpp b/ets2panda/ir/base/property.cpp index c6811cba023796fca9a5ae456c424d75ddf66dcc..d70ba1108c4dd066706e7287d9a42585739a189e 100644 --- a/ets2panda/ir/base/property.cpp +++ b/ets2panda/ir/base/property.cpp @@ -31,11 +31,10 @@ Property::Property([[maybe_unused]] Tag const tag, Property const &other, Expres value_ = value; } -// NOLINTNEXTLINE(google-default-arguments) Property *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, key, value); clone != nullptr) { if (key != nullptr) { diff --git a/ets2panda/ir/base/property.h b/ets2panda/ir/base/property.h index d643644cfb1c6931e1955b05b4aeade0024680e3..ccfdde132f384de1ccd30baa191da01f4d877a79 100644 --- a/ets2panda/ir/base/property.h +++ b/ets2panda/ir/base/property.h @@ -102,8 +102,7 @@ public: return kind == PropertyKind::GET || kind == PropertyKind::SET; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent) override; bool ConvertibleToPatternProperty(); ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 36e35e5461e0e9b8b7cf6c4d8f4a4b28e538a428..afbc8ebbd883facb6e16a3a17877ff60649d53ad 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -224,16 +224,6 @@ public: return (funcFlags_ & ir::ScriptFunctionFlags::RETHROWS) != 0; } - [[nodiscard]] bool IsDefaultParamProxy() const noexcept - { - return (funcFlags_ & ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY) != 0; - } - - void SetDefaultParamProxy() noexcept - { - AddFlag(ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY); - } - [[nodiscard]] bool IsDynamic() const noexcept { return lang_.IsDynamic(); diff --git a/ets2panda/ir/base/spreadElement.cpp b/ets2panda/ir/base/spreadElement.cpp index f66d00367927fc317b84b8286791c4d5ac87997f..c9d519118ee99bf463612d87d32de69e77149e69 100644 --- a/ets2panda/ir/base/spreadElement.cpp +++ b/ets2panda/ir/base/spreadElement.cpp @@ -42,7 +42,6 @@ SpreadElement::SpreadElement([[maybe_unused]] Tag const tag, SpreadElement const } } -// NOLINTNEXTLINE(google-default-arguments) SpreadElement *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/base/spreadElement.h b/ets2panda/ir/base/spreadElement.h index 939f60c97555d0ea9f290adb29a3f10ebf7ee7cf..40c8b0dbe6cb8d1a1933c7cf388ab9ad8504798b 100644 --- a/ets2panda/ir/base/spreadElement.h +++ b/ets2panda/ir/base/spreadElement.h @@ -78,8 +78,7 @@ public: optional_ = optional; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent) override; ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToRest(bool isDeclaration, bool allowPattern = true); diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index 8816ba413cc58502d302ef49f5cb7e747013707e..09a61236abb4273092028aaf38ca63b0df794dc4 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -58,7 +58,6 @@ checker::Type *TemplateElement::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TemplateElement *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(raw_, cooked_); clone != nullptr) { diff --git a/ets2panda/ir/base/templateElement.h b/ets2panda/ir/base/templateElement.h index 85154cdd14255dc18b8e3572d3d5ba44e9bac7aa..45f96e6202073b2f8e28b472abed0b7c5333bd0b 100644 --- a/ets2panda/ir/base/templateElement.h +++ b/ets2panda/ir/base/templateElement.h @@ -44,8 +44,7 @@ public: return cooked_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/tsIndexSignature.cpp b/ets2panda/ir/base/tsIndexSignature.cpp index c85adb93c74056577ed34accc8c954f0cd8097b4..a878eeb13a400fcb470413c7fdfa467b696f7e12 100644 --- a/ets2panda/ir/base/tsIndexSignature.cpp +++ b/ets2panda/ir/base/tsIndexSignature.cpp @@ -72,11 +72,10 @@ checker::Type *TSIndexSignature::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TSIndexSignature *TSIndexSignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const param = param_ != nullptr ? param_->Clone(allocator)->AsExpression() : nullptr; - auto *const typeAnnotation = typeAnnotation_->Clone(allocator); + auto *const param = param_ != nullptr ? param_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const typeAnnotation = typeAnnotation_->Clone(allocator, nullptr); if (auto *const clone = allocator->New(param, typeAnnotation, readonly_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/tsIndexSignature.h b/ets2panda/ir/base/tsIndexSignature.h index cff8d5fd215fb78e5d876c5e5f03a42397813caf..9b1b1c1d29b4f5af3c0c05dfa4703f775442be45 100644 --- a/ets2panda/ir/base/tsIndexSignature.h +++ b/ets2panda/ir/base/tsIndexSignature.h @@ -60,8 +60,7 @@ public: [[nodiscard]] TSIndexSignatureKind Kind() const noexcept; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/tsPropertySignature.cpp b/ets2panda/ir/base/tsPropertySignature.cpp index 4dd052b5d6dedbe87310d771da7c4df6aa0c02a2..49c0ac995c3382d5f0c7f5bb1a14933143734235 100644 --- a/ets2panda/ir/base/tsPropertySignature.cpp +++ b/ets2panda/ir/base/tsPropertySignature.cpp @@ -74,11 +74,10 @@ checker::Type *TSPropertySignature::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TSPropertySignature *TSPropertySignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const typeAnnotation = TypeAnnotation()->Clone(allocator); + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const typeAnnotation = TypeAnnotation()->Clone(allocator, nullptr); if (auto *const clone = allocator->New(key, typeAnnotation, computed_, optional_, readonly_); clone != nullptr) { diff --git a/ets2panda/ir/base/tsPropertySignature.h b/ets2panda/ir/base/tsPropertySignature.h index c3a0f73429f7d6bb7dfa5d5fc4eee149dcee43e3..8171be38e4d6550beaaaceb22c50c3d0bd6e7266 100644 --- a/ets2panda/ir/base/tsPropertySignature.h +++ b/ets2panda/ir/base/tsPropertySignature.h @@ -63,8 +63,7 @@ public: return readonly_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index ad0eabe30565db726b6ce609ef4152c5157c70ad..787e96b37780c004b53ede450dd43332c772ee64 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -62,10 +62,9 @@ checker::Type *ETSClassLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSClassLiteral *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index 592f3536fdab61e8af1a6f23c36c7db931883e49..d52bf955f66ec2cf059fc0eef2bb0f707fa553d8 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -38,8 +38,7 @@ public: explicit ETSClassLiteral(ir::TypeNode *const expr) : Expression(AstNodeType::ETS_CLASS_LITERAL), expr_(expr) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields friend class checker::ETSAnalyzer; diff --git a/ets2panda/ir/ets/etsFunctionType.cpp b/ets2panda/ir/ets/etsFunctionType.cpp index 0eec9494ff1873f520f4a08759076ad54634a057..d2e0888bae7d5cce8a9c2a135c4bce0f5f03ef35 100644 --- a/ets2panda/ir/ets/etsFunctionType.cpp +++ b/ets2panda/ir/ets/etsFunctionType.cpp @@ -97,20 +97,20 @@ checker::Type *ETSFunctionType::GetType(checker::ETSChecker *checker) return Check(checker); } -// NOLINTNEXTLINE(google-default-arguments) ETSFunctionType *ETSFunctionType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { ArenaVector paramsClone(allocator->Adapter()); for (auto *const param : signature_.Params()) { - paramsClone.emplace_back(param->Clone(allocator)->AsExpression()); + paramsClone.emplace_back(param->Clone(allocator, nullptr)->AsExpression()); } - auto *const typeParamsClone = signature_.TypeParams() != nullptr - ? signature_.TypeParams()->Clone(allocator)->AsTSTypeParameterDeclaration() - : nullptr; + auto *const typeParamsClone = + signature_.TypeParams() != nullptr + ? signature_.TypeParams()->Clone(allocator, nullptr)->AsTSTypeParameterDeclaration() + : nullptr; auto *const returnTypeClone = - signature_.ReturnType() != nullptr ? signature_.ReturnType()->Clone(allocator)->AsTypeNode() : nullptr; + signature_.ReturnType() != nullptr ? signature_.ReturnType()->Clone(allocator, nullptr)->AsTypeNode() : nullptr; if (auto *const clone = allocator->New( FunctionSignature(typeParamsClone, std::move(paramsClone), returnTypeClone), funcFlags_); diff --git a/ets2panda/ir/ets/etsFunctionType.h b/ets2panda/ir/ets/etsFunctionType.h index 42f7323db5f68c696d1a719df092521ba6937f1c..027a6941fc4612f14d8b8baeeb2f67d924e2c098 100644 --- a/ets2panda/ir/ets/etsFunctionType.h +++ b/ets2panda/ir/ets/etsFunctionType.h @@ -109,8 +109,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSFunctionType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSFunctionType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: varbinder::Scope *scope_ {}; diff --git a/ets2panda/ir/ets/etsLaunchExpression.cpp b/ets2panda/ir/ets/etsLaunchExpression.cpp index a492c7c3f23c6b867d27358dcac6bb5403e62d73..3805370754697036f4dd341e173fb5a8e289fa2d 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.cpp +++ b/ets2panda/ir/ets/etsLaunchExpression.cpp @@ -75,10 +75,9 @@ bool ETSLaunchExpression::IsStaticCall() const return expr_->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); } -// NOLINTNEXTLINE(google-default-arguments) ETSLaunchExpression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsLaunchExpression.h b/ets2panda/ir/ets/etsLaunchExpression.h index 5f41d342c81945a35e8e70c640bd38d2c7cb8000..eee51886e92688ef25ccd9806ffbc6c771844bd3 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.h +++ b/ets2panda/ir/ets/etsLaunchExpression.h @@ -44,8 +44,7 @@ public: friend class checker::ETSAnalyzer; friend class compiler::ETSCompiler; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index 71277d93848ce75adca9d42bbcadc2042662cfce..b5f892f7e16ee9d1d18efe5507c59272af7f0b3e 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -72,12 +72,11 @@ checker::Type *ETSNewArrayInstanceExpression::Check(checker::ETSChecker *checker return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSNewArrayInstanceExpression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const typeRef = typeReference_ != nullptr ? typeReference_->Clone(allocator) : nullptr; - auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator)->AsExpression() : nullptr; + auto *const typeRef = typeReference_ != nullptr ? typeReference_->Clone(allocator, nullptr) : nullptr; + auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(allocator, typeRef, dimension); clone != nullptr) { diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h index e1f121eaee960d5a1ac0edbecfac12e2509e5c72..b44afebdd03ac39ba5f398c9cabfa548942c6107 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h @@ -74,8 +74,7 @@ public: dimension_ = dimension; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index c85d7639ca48255dc4d9caa5bcc9e3cd9d1b88fd..f8e3233845305a9a2ecdc43df526ab751f113e97 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -97,14 +97,15 @@ ETSNewClassInstanceExpression::ETSNewClassInstanceExpression(ETSNewClassInstance : Expression(static_cast(other)), arguments_(allocator->Adapter()), signature_(other.signature_) { typeReference_ = other.typeReference_->Clone(allocator, this)->AsExpression(); - classDef_ = other.classDef_->Clone(allocator, this)->AsClassDefinition(); + if (other.classDef_ != nullptr) { + classDef_ = other.classDef_->Clone(allocator, this)->AsClassDefinition(); + } for (auto *const argument : other.arguments_) { arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } } -// NOLINTNEXTLINE(google-default-arguments) ETSNewClassInstanceExpression *ETSNewClassInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index 6cbef0d1232afe31ba19868368b88596ad34beda..4df829352a1597312b223aa52e0a7f1dcd1749e6 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -85,8 +85,7 @@ public: signature_ = signature; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index 4b2bc1500d9ce02d0b8257bc60374f03ae65a900..a4ab86f94465dc851a4f19048179cbb43fe922fc 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -90,7 +90,6 @@ ETSNewMultiDimArrayInstanceExpression::ETSNewMultiDimArrayInstanceExpression( } } -// NOLINTNEXTLINE(google-default-arguments) ETSNewMultiDimArrayInstanceExpression *ETSNewMultiDimArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h index 825aae727d29910e573c58d102a043e7587c9a61..993a655807c7ba8c30798d856f47891fca6c5693 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h @@ -81,9 +81,7 @@ public: return signature_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, - AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index 27a44e419c25a17abcac4bbef2d311b10f7f4661..d321134e910637464fe6d2d65629b8d8095f2083 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -64,7 +64,6 @@ checker::Type *ETSPackageDeclaration::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSPackageDeclaration *ETSPackageDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto const name = name_ != nullptr ? name_->Clone(allocator, this)->AsExpression() : nullptr; diff --git a/ets2panda/ir/ets/etsPackageDeclaration.h b/ets2panda/ir/ets/etsPackageDeclaration.h index 88d51f0c08ef9f2c1672532ca4b3abb1334fda04..98463a9102685ec3e2b08b86bd4b463fad11f98f 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.h +++ b/ets2panda/ir/ets/etsPackageDeclaration.h @@ -33,8 +33,7 @@ public: { } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index 7b808c79c3d5db489990c301f5855ed7d6747d6a..7ffa81c823fd4083fdca48fb430e71ecc887cfa5 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -187,12 +187,12 @@ checker::Type *ETSParameterExpression::Check(checker::ETSChecker *const checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const identOrSpread = spread_ != nullptr ? spread_->Clone(allocator)->AsAnnotatedExpression() - : ident_->Clone(allocator)->AsAnnotatedExpression(); - auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator)->AsExpression() : nullptr; + auto *const identOrSpread = spread_ != nullptr ? spread_->Clone(allocator, nullptr)->AsAnnotatedExpression() + : ident_->Clone(allocator, nullptr)->AsAnnotatedExpression(); + auto *const initializer = + initializer_ != nullptr ? initializer_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(identOrSpread, initializer); clone != nullptr) { identOrSpread->SetParent(clone); diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index aedc3e7166a1c3079d162b5d2c8793cfc041ced6..0cc2ba1701341c906ab1b42ecb32ed1bb528bf77 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -23,9 +23,6 @@ class ETSAnalyzer; } // namespace panda::es2panda::checker namespace panda::es2panda::ir { -// NOLINTBEGIN(modernize-avoid-c-arrays) -inline constexpr char const PROXY_PARAMETER_NAME[] = "$proxy_mask$"; -// NOLINTEND(modernize-avoid-c-arrays) class ETSParameterExpression final : public Expression { public: @@ -78,8 +75,7 @@ public: extraValue_ = value; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void TransformChildren(const NodeTransformer &cb) override; @@ -89,6 +85,10 @@ public: void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; checker::Type *Check(checker::ETSChecker *checker) override; + void SetInitializer(Expression *initExpr = nullptr) + { + initializer_ = initExpr; + }; void Accept(ASTVisitorT *v) override { diff --git a/ets2panda/ir/ets/etsPrimitiveType.cpp b/ets2panda/ir/ets/etsPrimitiveType.cpp index bfc3562cfad72ea422ce2db83a378064d1a62ae3..c4d2449538c0829a0587f759834b00fb3b504d0a 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.cpp +++ b/ets2panda/ir/ets/etsPrimitiveType.cpp @@ -132,7 +132,6 @@ checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::ETSChecker *c } } -// NOLINTNEXTLINE(google-default-arguments) ETSPrimitiveType *ETSPrimitiveType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(type_); clone != nullptr) { diff --git a/ets2panda/ir/ets/etsPrimitiveType.h b/ets2panda/ir/ets/etsPrimitiveType.h index b2ad1451dfa0abbb2cc0729962d0a5fa69004057..2fb0d551728ddcd9b49d157b8c885ce960b89b19 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.h +++ b/ets2panda/ir/ets/etsPrimitiveType.h @@ -46,8 +46,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSPrimitiveType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSPrimitiveType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: PrimitiveType type_; diff --git a/ets2panda/ir/ets/etsReExportDeclaration.cpp b/ets2panda/ir/ets/etsReExportDeclaration.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a085ad98271a5803b6bab10e4ef020f3dc0c3f7e --- /dev/null +++ b/ets2panda/ir/ets/etsReExportDeclaration.cpp @@ -0,0 +1,51 @@ +/** + * Copyright (c) 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. + */ + +#include "ir/ets/etsReExportDeclaration.h" +#include "ir/astDump.h" + +namespace panda::es2panda::ir { + +ETSReExportDeclaration::ETSReExportDeclaration(ETSImportDeclaration *etsImportDeclarations, + const std::vector &userPaths, util::StringView programPath, + ArenaAllocator *allocator) + : Statement(AstNodeType::REEXPORT_STATEMENT), + etsImportDeclarations_(etsImportDeclarations), + userPaths_(allocator->Adapter()), + programPath_(programPath) +{ + for (const auto &path : userPaths) { + userPaths_.emplace_back(util::UString(path, allocator).View()); + } +} + +void ETSReExportDeclaration::TransformChildren(const NodeTransformer &cb) +{ + if (etsImportDeclarations_ != nullptr) { + etsImportDeclarations_ = cb(etsImportDeclarations_)->AsETSImportDeclaration(); + } +} + +void ETSReExportDeclaration::Iterate(const NodeTraverser &cb) const +{ + etsImportDeclarations_->Iterate(cb); +} + +void ETSReExportDeclaration::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSReExportDeclaration"}, {"ets_import_declarations", etsImportDeclarations_}}); +} + +} // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsReExportDeclaration.h b/ets2panda/ir/ets/etsReExportDeclaration.h index cc56e21a8d94fc22e4ce5e0b49bd36c27e70375e..e12e244ee47242b9d2c1dce20b5965d94861f238 100644 --- a/ets2panda/ir/ets/etsReExportDeclaration.h +++ b/ets2panda/ir/ets/etsReExportDeclaration.h @@ -23,17 +23,11 @@ namespace panda::es2panda::ir { -class ETSReExportDeclaration { +class ETSReExportDeclaration : public Statement { public: - explicit ETSReExportDeclaration(ETSImportDeclaration *const etsImportDeclarations, - std::vector const &userPaths, util::StringView programPath, - ArenaAllocator *allocator) - : etsImportDeclarations_(etsImportDeclarations), userPaths_(allocator->Adapter()), programPath_(programPath) - { - for (const auto &path : userPaths) { - userPaths_.emplace_back(util::UString(path, allocator).View()); - } - } + explicit ETSReExportDeclaration(ETSImportDeclaration *etsImportDeclarations, + const std::vector &userPaths, util::StringView programPath, + ArenaAllocator *allocator); ETSImportDeclaration *GetETSImportDeclarations() const { @@ -55,6 +49,32 @@ public: return programPath_; } + void TransformChildren(const NodeTransformer &cb) override; + + void Iterate(const NodeTraverser &cb) const override; + + void Dump(ir::AstDumper *dumper) const override; + void Dump([[maybe_unused]] ir::SrcDumper *dumper) const override {}; + + void Compile(compiler::PandaGen * /*pg*/) const override {} + + void Compile(compiler::ETSGen * /*gen*/) const override {} + + checker::Type *Check(checker::TSChecker * /*checker*/) override + { + return nullptr; + } + + checker::Type *Check(checker::ETSChecker * /*checker*/) override + { + return nullptr; + } + + void Accept(ASTVisitorT *v) override + { + v->Accept(this); + } + private: ETSImportDeclaration *etsImportDeclarations_; ArenaVector userPaths_; diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index 37026f4a624b1ec9c717e63a4a15b39a11ebd36d..8e5038efe79864e2a8503781a5a8a77516a8937b 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -75,7 +75,6 @@ checker::Type *ETSStructDeclaration::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSStructDeclaration *ETSStructDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const def = def_ != nullptr ? def_->Clone(allocator, this)->AsClassDefinition() : nullptr; diff --git a/ets2panda/ir/ets/etsStructDeclaration.h b/ets2panda/ir/ets/etsStructDeclaration.h index b7d6176e72ec0af562f262aed793e09b8c883c5b..f16200a8dd5ebc55b09299d331c855666bbbd9c5 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.h +++ b/ets2panda/ir/ets/etsStructDeclaration.h @@ -67,8 +67,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsTuple.cpp b/ets2panda/ir/ets/etsTuple.cpp index dcb984b54b589cb20ba940fce3df5f3a3746f7f9..929fce73a100541867a2a46ed767aaca7fcacac0 100644 --- a/ets2panda/ir/ets/etsTuple.cpp +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -15,7 +15,6 @@ #include "etsTuple.h" -#include "checker/ETSchecker.h" #include "checker/types/ets/etsTupleType.h" #include "ir/astDump.h" @@ -79,7 +78,36 @@ checker::Type *ETSTuple::Check([[maybe_unused]] checker::ETSChecker *const check return GetType(checker); } -void ETSTuple::SetNullUndefinedFlags(std::pair &containsNullOrUndefined, const checker::Type *const type) +checker::Type *ETSTuple::GetType(checker::ETSChecker *const checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + ArenaVector typeList(checker->Allocator()->Adapter()); + + for (auto *const typeAnnotation : GetTupleTypeAnnotationsList()) { + auto *const checkedType = checker->GetTypeFromTypeAnnotation(typeAnnotation); + typeList.emplace_back(checkedType); + } + + if (HasSpreadType()) { + ASSERT(spreadType_->IsTSArrayType()); + auto *const arrayType = spreadType_->GetType(checker); + ASSERT(arrayType->IsETSArrayType()); + spreadType_->SetTsType(arrayType->AsETSArrayType()->ElementType()); + } + + auto *const spreadElementType = spreadType_ != nullptr ? spreadType_->TsType() : nullptr; + + auto *const tupleType = checker->Allocator()->New( + typeList, CalculateLUBForTuple(checker, typeList, spreadElementType), spreadElementType); + + SetTsType(tupleType); + return TsType(); +} + +static void SetNullUndefinedFlags(std::pair &containsNullOrUndefined, const checker::Type *const type) { if (type->HasTypeFlag(checker::TypeFlag::NULLISH)) { containsNullOrUndefined.first = true; @@ -101,7 +129,7 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker bool allElementsAreSame = std::all_of(typeList.begin(), typeList.end(), - [this, &checker, &typeList, &containsNullOrUndefined](checker::Type *const element) { + [&checker, &typeList, &containsNullOrUndefined](checker::Type *const element) { SetNullUndefinedFlags(containsNullOrUndefined, element); return checker->Relation()->IsIdenticalTo(typeList[0], element); }); @@ -113,16 +141,13 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker // If only one type present in the tuple, that will be the holder array type. If any two not identical types // present, primitives will be boxed, and LUB is calculated for all of them. - // That makes it possible to assign eg. `[int, int, ...int[]]` tuple type to `int[]` array type. Because a `short[]` - // array already isn't assignable to `int[]` array, that preserve that the `[int, short, ...int[]]` tuple type's - // element type will be calculated to `Object[]`, which is not assignable to `int[]` array either. + // That makes it possible to assign eg. `[int, int, ...int[]]` tuple type to `int[]` array type. Because a + // `short[]` array already isn't assignable to `int[]` array, that preserve that the `[int, short, ...int[]]` + // tuple type's element type will be calculated to `Object[]`, which is not assignable to `int[]` array either. if (allElementsAreSame) { return typeList[0]; } - auto *const savedRelationNode = checker->Relation()->GetNode(); - checker->Relation()->SetNode(this); - auto getBoxedTypeOrType = [&checker](checker::Type *const type) { auto *const boxedType = checker->PrimitiveTypeAsETSBuiltinType(type); return boxedType == nullptr ? type : boxedType; @@ -131,11 +156,19 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker checker::Type *lubType = getBoxedTypeOrType(typeList[0]); for (std::size_t idx = 1; idx < typeList.size(); ++idx) { + if (typeList[idx]->IsETSTypeParameter()) { + lubType = typeList[idx]->AsETSTypeParameter()->GetConstraintType(); + continue; + } lubType = checker->FindLeastUpperBound(lubType, getBoxedTypeOrType(typeList[idx])); } if (spreadType != nullptr) { - lubType = checker->FindLeastUpperBound(lubType, getBoxedTypeOrType(spreadType)); + if (spreadType->IsETSTypeParameter()) { + lubType = spreadType->AsETSTypeParameter()->GetConstraintType(); + } else { + lubType = checker->FindLeastUpperBound(lubType, getBoxedTypeOrType(spreadType)); + } } const auto nullishUndefinedFlags = @@ -148,38 +181,7 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker checker->GetGlobalTypesHolder()); } - checker->Relation()->SetNode(savedRelationNode); - return lubType; } -checker::Type *ETSTuple::GetType(checker::ETSChecker *const checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - ArenaVector typeList(checker->Allocator()->Adapter()); - - for (auto *const typeAnnotation : GetTupleTypeAnnotationsList()) { - auto *const checkedType = checker->GetTypeFromTypeAnnotation(typeAnnotation); - typeList.emplace_back(checkedType); - } - - if (HasSpreadType()) { - ASSERT(spreadType_->IsTSArrayType()); - auto *const arrayType = spreadType_->GetType(checker); - ASSERT(arrayType->IsETSArrayType()); - spreadType_->SetTsType(arrayType->AsETSArrayType()->ElementType()); - } - - auto *const spreadElementType = spreadType_ != nullptr ? spreadType_->TsType() : nullptr; - - auto *const tupleType = checker->Allocator()->New( - typeList, CalculateLUBForTuple(checker, typeList, spreadElementType), spreadElementType); - - SetTsType(tupleType); - return TsType(); -} - } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsTuple.h b/ets2panda/ir/ets/etsTuple.h index ab4eff12f4ab88f41a5cd2904501b3bfdaa7301d..43379d92130bbf0729b773276bc80a71aa5b6f3c 100644 --- a/ets2panda/ir/ets/etsTuple.h +++ b/ets2panda/ir/ets/etsTuple.h @@ -16,6 +16,7 @@ #ifndef ES2PANDA_IR_ETS_TUPLE_H #define ES2PANDA_IR_ETS_TUPLE_H +#include "checker/ETSchecker.h" #include "ir/typeNode.h" namespace panda::es2panda::ir { @@ -75,9 +76,8 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; - void SetNullUndefinedFlags(std::pair &containsNullOrUndefined, const checker::Type *type); - checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector &typeList, - checker::Type *spreadType); + static checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector &typeList, + checker::Type *spreadType); void Accept(ASTVisitorT *v) override { diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index b65b9a68d67e56a5f28b6f68eefde831004ba563..1f9adbd3c93468275f2b407fddaf674bbb8813b8 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -107,10 +107,9 @@ checker::Type *ETSTypeReference::GetType(checker::ETSChecker *checker) return type; } -// NOLINTNEXTLINE(google-default-arguments) ETSTypeReference *ETSTypeReference::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const partClone = part_ != nullptr ? part_->Clone(allocator)->AsETSTypeReferencePart() : nullptr; + auto *const partClone = part_ != nullptr ? part_->Clone(allocator, nullptr)->AsETSTypeReferencePart() : nullptr; if (auto *const clone = allocator->New(partClone); clone != nullptr) { if (partClone != nullptr) { diff --git a/ets2panda/ir/ets/etsTypeReference.h b/ets2panda/ir/ets/etsTypeReference.h index d67d7f49ac4b51c2789cc6f603fe0248791bcace..dfcecf74bbe2f6483a52a11907108d84f483a634 100644 --- a/ets2panda/ir/ets/etsTypeReference.h +++ b/ets2panda/ir/ets/etsTypeReference.h @@ -53,8 +53,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSTypeReference *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSTypeReference *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: ir::ETSTypeReferencePart *part_; diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 792e942e8ce8737c4f2060ac5b61480a38a2ef19..d3efd9574b630fb9c2fd605207c6d0540f8de796 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -110,13 +110,12 @@ checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) return checker->GetReferencedTypeFromBase(baseType, name_); } -// NOLINTNEXTLINE(google-default-arguments) ETSTypeReferencePart *ETSTypeReferencePart::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const nameClone = name_ != nullptr ? name_->Clone(allocator)->AsExpression() : nullptr; + auto *const nameClone = name_ != nullptr ? name_->Clone(allocator, nullptr)->AsExpression() : nullptr; auto *const typeParamsClone = - typeParams_ != nullptr ? typeParams_->Clone(allocator)->AsTSTypeParameterInstantiation() : nullptr; - auto *const prevClone = prev_ != nullptr ? prev_->Clone(allocator)->AsETSTypeReferencePart() : nullptr; + typeParams_ != nullptr ? typeParams_->Clone(allocator, nullptr)->AsTSTypeParameterInstantiation() : nullptr; + auto *const prevClone = prev_ != nullptr ? prev_->Clone(allocator, nullptr)->AsETSTypeReferencePart() : nullptr; if (auto *const clone = allocator->New(nameClone, typeParamsClone, prevClone); clone != nullptr) { if (nameClone != nullptr) { diff --git a/ets2panda/ir/ets/etsTypeReferencePart.h b/ets2panda/ir/ets/etsTypeReferencePart.h index ab785f6f9cb59cb1e429c112b870040cc4eed2cb..4493d5630783c65c83b9beeabd25ed87f029fc4a 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.h +++ b/ets2panda/ir/ets/etsTypeReferencePart.h @@ -70,8 +70,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSTypeReferencePart *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSTypeReferencePart *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: ir::Expression *name_; diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index 294f8f23ae7d769442d8c22f8aee5a36b4f8f615..653b922f980f3791b8163ece2f192c0e5caed914 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -53,7 +53,6 @@ ArrayExpression::ArrayExpression([[maybe_unused]] Tag const tag, ArrayExpression } } -// NOLINTNEXTLINE(google-default-arguments) ArrayExpression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/arrayExpression.h b/ets2panda/ir/expressions/arrayExpression.h index 34e834a7765ecab2b31dc9122a7088c3c31175fd..90dfd3e7aa86f1f043c075a51b04a5e7b8df96e0 100644 --- a/ets2panda/ir/expressions/arrayExpression.h +++ b/ets2panda/ir/expressions/arrayExpression.h @@ -119,8 +119,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] bool ConvertibleToArrayPattern(); [[nodiscard]] ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 3e4f53a46ed8095ae3767a5f02a07fc3ba4cf673..afb8ef46cf34b35f84d9e45ab3599fd43663a475 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -86,7 +86,6 @@ ArrowFunctionExpression::ArrowFunctionExpression(ArrowFunctionExpression const & } } -// NOLINTNEXTLINE(google-default-arguments) ArrowFunctionExpression *ArrowFunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index c1358a17226898a2ebb656b6b9d5b97251dc6fd5..79bc5b379f7f3fd5a3944986f3120bec6fb17408 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -83,8 +83,7 @@ public: propagateThis_ = true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index b4a288a8231c59ed255f5dee3f7c99dddd932a17..ffe10cc0f0c202f176020902205bfdab436479ef 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -174,11 +174,10 @@ AssignmentExpression::AssignmentExpression([[maybe_unused]] Tag const tag, Assig } } -// NOLINTNEXTLINE(google-default-arguments) AssignmentExpression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, left, right); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index ae8eea339769b2ea8d20abf12824dda0f4acba5f..4077716d10ce6512b5da4aeacfcdf22b7081c2b6 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -112,8 +112,7 @@ public: return target_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] bool ConvertibleToAssignmentPattern(bool mustBePattern = true); diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 5048bd86c4c62fe1875b9616575222fb9a2b907f..fa15d9662b2e2a042a601dd9d48b1650fca08d3a 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -66,10 +66,9 @@ checker::Type *AwaitExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) AwaitExpression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/awaitExpression.h b/ets2panda/ir/expressions/awaitExpression.h index ab1160ad375e45e0d074c89472bd8a47f42346fd..5754b7b9765130257aebd09c9ccf0dcaf1fa5a90 100644 --- a/ets2panda/ir/expressions/awaitExpression.h +++ b/ets2panda/ir/expressions/awaitExpression.h @@ -41,8 +41,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 69de43333363cff079a95bbcc10db776dccb20c6..27ba9aba9b3d782f124e0c9b431aa87ba8160d8b 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -75,11 +75,10 @@ checker::Type *BinaryExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BinaryExpression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(left, right, operator_); clone != nullptr) { if (operationType_ != nullptr) { diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index c4222f4db9ade7a1937bbe987dde6559c33f6caf..82b484185e9d58618d9ce4fb5b4aef2b20131e75 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -142,8 +142,7 @@ public: return operationType_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/blockExpression.cpp b/ets2panda/ir/expressions/blockExpression.cpp index 63b795532e49e71648cbe153cfa5cd339bb9dbb7..eaf53644da99ba43f555db33ff619b3159fb3e65 100644 --- a/ets2panda/ir/expressions/blockExpression.cpp +++ b/ets2panda/ir/expressions/blockExpression.cpp @@ -40,7 +40,6 @@ BlockExpression::BlockExpression([[maybe_unused]] Tag const tag, BlockExpression } } -// NOLINTNEXTLINE(google-default-arguments) BlockExpression *BlockExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/blockExpression.h b/ets2panda/ir/expressions/blockExpression.h index 6c6329ccd290328d853051c071a39ee337e183b7..0180304f97d4540dba35e327ec19420368432ebb 100644 --- a/ets2panda/ir/expressions/blockExpression.h +++ b/ets2panda/ir/expressions/blockExpression.h @@ -41,8 +41,7 @@ public: return statements_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index 577a4393b39525a3c6d9355de9ac034bf7bcfa73..e15dcb94a490ac9177595674e9914720b9531481 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -108,7 +108,9 @@ CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *cons isTrailingBlockInNewLine_(other.isTrailingBlockInNewLine_) { callee_ = other.callee_->Clone(allocator, this)->AsExpression(); - typeParams_ = other.typeParams_->Clone(allocator, this); + if (other.typeParams_ != nullptr) { + typeParams_ = other.typeParams_->Clone(allocator, this); + } for (auto *const argument : other.arguments_) { arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); @@ -119,7 +121,6 @@ CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *cons } } -// NOLINTNEXTLINE(google-default-arguments) CallExpression *CallExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index cd2e29cb97e968884b92241c1539e0b85ea7ca58..5cda890237fd31a758e663132df3c012d36e195a 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -151,8 +151,7 @@ public: return isTrailingBlockInNewLine_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/chainExpression.cpp b/ets2panda/ir/expressions/chainExpression.cpp index 7513d034fe0a30e3114d33369b798cd9caa48ef4..83f518121259a170040ff308aea9b6dd42df291f 100644 --- a/ets2panda/ir/expressions/chainExpression.cpp +++ b/ets2panda/ir/expressions/chainExpression.cpp @@ -76,10 +76,9 @@ checker::Type *ChainExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ChainExpression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expression = expression_ != nullptr ? expression_->Clone(allocator)->AsExpression() : nullptr; + auto *const expression = expression_ != nullptr ? expression_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expression); clone != nullptr) { if (expression != nullptr) { diff --git a/ets2panda/ir/expressions/chainExpression.h b/ets2panda/ir/expressions/chainExpression.h index 9c124c9c91ce4a2a818f8823c74efb209a624c42..0ee4506fc97f8aeeca00cdc998a09a0583783b14 100644 --- a/ets2panda/ir/expressions/chainExpression.h +++ b/ets2panda/ir/expressions/chainExpression.h @@ -45,8 +45,7 @@ public: return expression_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/classExpression.cpp b/ets2panda/ir/expressions/classExpression.cpp index 6caf00999f2954395085a8dabebfe401ab4859b4..7d8e14ddff37d0e6acd3ea057ba32aea108a1330 100644 --- a/ets2panda/ir/expressions/classExpression.cpp +++ b/ets2panda/ir/expressions/classExpression.cpp @@ -62,10 +62,9 @@ checker::Type *ClassExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ClassExpression *ClassExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const def = def_ != nullptr ? def_->Clone(allocator)->AsClassDefinition() : nullptr; + auto *const def = def_ != nullptr ? def_->Clone(allocator, nullptr)->AsClassDefinition() : nullptr; if (auto *const clone = allocator->New(def); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/classExpression.h b/ets2panda/ir/expressions/classExpression.h index 3277ec23ae89f68e4ca2ee43640cc600fc100ab3..2073d0690d5b9dc859f2c69d0b958c4423b58c70 100644 --- a/ets2panda/ir/expressions/classExpression.h +++ b/ets2panda/ir/expressions/classExpression.h @@ -36,8 +36,7 @@ public: return def_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index c75255d97188df4c7fbe4530b8f751ac084ef92d..ed82594bee96e312cd4f382e7066e308fc83fef6 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -82,12 +82,11 @@ checker::Type *ConditionalExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ConditionalExpression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const test = test_ != nullptr ? test_->Clone(allocator)->AsExpression() : nullptr; - auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator)->AsExpression() : nullptr; - auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator)->AsExpression() : nullptr; + auto *const test = test_ != nullptr ? test_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(test, consequent, alternate); clone != nullptr) { if (test != nullptr) { diff --git a/ets2panda/ir/expressions/conditionalExpression.h b/ets2panda/ir/expressions/conditionalExpression.h index f7e3bb822a3bf31d1ef8985ee8921e0fe79b148c..0095154c0e151b8ed3b0a9025977276f0e65464f 100644 --- a/ets2panda/ir/expressions/conditionalExpression.h +++ b/ets2panda/ir/expressions/conditionalExpression.h @@ -66,8 +66,7 @@ public: test_ = test; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index 243a94df429a4bdb343ce2627d78015975ed0efc..d677d21281122a8ebc34a58fd498a274065065d0 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -62,10 +62,9 @@ checker::Type *FunctionExpression::Check([[maybe_unused]] checker::ETSChecker *c return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) FunctionExpression *FunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const func = func_->Clone(allocator)->AsScriptFunction(); + auto *const func = func_->Clone(allocator, nullptr)->AsScriptFunction(); if (auto *const clone = allocator->New(func); clone != nullptr) { func->SetParent(clone); diff --git a/ets2panda/ir/expressions/functionExpression.h b/ets2panda/ir/expressions/functionExpression.h index ae284499ced5dd641e6d70974b0d5e6f3d6b2e09..ce81316c51dfbc190eaecc9ec860bef8fe2ab8a7 100644 --- a/ets2panda/ir/expressions/functionExpression.h +++ b/ets2panda/ir/expressions/functionExpression.h @@ -58,8 +58,7 @@ public: return exprName_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index 03d77fb78166ad73d985284bf04b022e10861904..a81d265c81937112087af13477d75e74d6988851 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -36,7 +36,6 @@ Identifier::Identifier([[maybe_unused]] Tag const tag, Identifier const &other, } } -// NOLINTNEXTLINE(google-default-arguments) Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index b91b01311f60a87343d224ad40c97d0e67ae2560..48196b964b056cc3da37e992cd51cfcc14a9c40c 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -190,8 +190,7 @@ public: decorators_ = std::move(decorators); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent) override; bool CanHaveDecorator([[maybe_unused]] bool inTs) const override { diff --git a/ets2panda/ir/expressions/importExpression.cpp b/ets2panda/ir/expressions/importExpression.cpp index 21a048c903dcaf08dab58a2b38a3546ee291101f..37a2df2530b2bb7a183045341cb46a8ca2530738 100644 --- a/ets2panda/ir/expressions/importExpression.cpp +++ b/ets2panda/ir/expressions/importExpression.cpp @@ -61,10 +61,9 @@ checker::Type *ImportExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ImportExpression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const source = source_ != nullptr ? source_->Clone(allocator)->AsExpression() : nullptr; + auto *const source = source_ != nullptr ? source_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(source); clone != nullptr) { if (source != nullptr) { diff --git a/ets2panda/ir/expressions/importExpression.h b/ets2panda/ir/expressions/importExpression.h index 4ac17ab18829b21685e1b5da20902fe239257cde..bb3a5fab15804ab1701224e7ec8e1851345483e5 100644 --- a/ets2panda/ir/expressions/importExpression.h +++ b/ets2panda/ir/expressions/importExpression.h @@ -34,8 +34,7 @@ public: return source_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp index 9b72a6a358ad482b3a68aafd4fc71e28f4862a51..ece9eecdfe676878f987d029e68067381f9cdcee 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -56,7 +56,6 @@ checker::Type *BigIntLiteral::Check([[maybe_unused]] checker::ETSChecker *checke return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BigIntLiteral *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(src_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.h b/ets2panda/ir/expressions/literals/bigIntLiteral.h index 6ac3d773856d79e9b3c2506673822667a22206ef..217e99057d3d88ff02f0cd45548ad19fe3645289 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.h +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.h @@ -35,8 +35,7 @@ public: return src_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.cpp b/ets2panda/ir/expressions/literals/booleanLiteral.cpp index 40bfa7bc655ee69bfa3c3dfc49ae8096f6ca392d..203fb259b502f7d63c7b0f0c1e003f73a099ed34 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/ets2panda/ir/expressions/literals/booleanLiteral.cpp @@ -56,7 +56,6 @@ checker::Type *BooleanLiteral::Check([[maybe_unused]] checker::ETSChecker *check return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BooleanLiteral *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(boolean_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.h b/ets2panda/ir/expressions/literals/booleanLiteral.h index 88f62c6bf7280a0a8810fb478c66b0eaf201f8c5..f3ede215ba13fda9f54b48bf3ab4c0fa6e15b6ec 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.h +++ b/ets2panda/ir/expressions/literals/booleanLiteral.h @@ -34,8 +34,7 @@ public: return boolean_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index ce4be05ffc2477b40d3f8b1285826beb78cb5d3c..2bbed46adfa1b6ccdde71a4df4e573b0fe622626 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -59,7 +59,6 @@ checker::Type *CharLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) CharLiteral *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(char_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/charLiteral.h b/ets2panda/ir/expressions/literals/charLiteral.h index 629e1a0d036151a3cbda6cc6a2bb4a19a3733274..003e922b4a9baf73c6b17cb59f788063c57f0d16 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.h +++ b/ets2panda/ir/expressions/literals/charLiteral.h @@ -40,8 +40,7 @@ public: return char_ == other.char_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/nullLiteral.cpp b/ets2panda/ir/expressions/literals/nullLiteral.cpp index 74c0e578162e27db70a51af734be3e39f602404a..0d266b8335c37b5411579fe291dafd4d41ede26e 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.cpp +++ b/ets2panda/ir/expressions/literals/nullLiteral.cpp @@ -55,7 +55,6 @@ checker::Type *NullLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) NullLiteral *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/nullLiteral.h b/ets2panda/ir/expressions/literals/nullLiteral.h index 4fb46bb414389a8f35e34285f693b6f90e81dd47..40a5f7b299ff8f582af5cf1221c89ef0aa04fdac 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.h +++ b/ets2panda/ir/expressions/literals/nullLiteral.h @@ -28,8 +28,7 @@ public: explicit NullLiteral() : Literal(AstNodeType::NULL_LITERAL) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index dc7e40501b5050e86919f7ca6ca722669a150878..ca4bb4c4e09bb38e37117ffd5da623003eecf21b 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -74,7 +74,6 @@ checker::Type *NumberLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) NumberLiteral *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(number_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/numberLiteral.h b/ets2panda/ir/expressions/literals/numberLiteral.h index 0abcbbce6ddbe60216a9803378b4413654f47078..7a4412d2f39fa6844770ff8e2785f87cbe80a1e1 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.h +++ b/ets2panda/ir/expressions/literals/numberLiteral.h @@ -49,8 +49,7 @@ public: [[nodiscard]] bool HasFloatingPoint() const; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index e14f0fad2da61127d333ca7580bc1f299dae8bc2..400e4b5155c1e9c6c2a78a4d6dbd8f6fb20c007a 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -57,7 +57,6 @@ checker::Type *RegExpLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) RegExpLiteral *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(pattern_, flags_, flagsStr_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.h b/ets2panda/ir/expressions/literals/regExpLiteral.h index 9666670fe75038b2d2f231e7ba3add4555716a7f..9e21afa71f3448a5347108e721de953b45f344d8 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.h +++ b/ets2panda/ir/expressions/literals/regExpLiteral.h @@ -44,8 +44,7 @@ public: return flags_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index 11bc091825b5792eea11813beff594fc8b514802..209a143480595aa54dffc1946be1c7cbad56644b 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -87,7 +87,6 @@ checker::Type *StringLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) StringLiteral *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(str_); clone != nullptr) { diff --git a/ets2panda/ir/expressions/literals/stringLiteral.h b/ets2panda/ir/expressions/literals/stringLiteral.h index 081eed374fde1f4fce86bef53f75795b3a9095b7..3183fd6cd3d76fed67ff93a7dc9a7570f9f8b0d1 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.h +++ b/ets2panda/ir/expressions/literals/stringLiteral.h @@ -41,8 +41,7 @@ public: return str_ == other.str_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 9f2c98d44fc9c1e37c9efeea1de7814163bdb9bf..ed040ff31863ab28540ba1b1b3eb7ae71d3c3702 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -330,14 +330,7 @@ checker::Type *MemberExpression::CheckTupleAccessMethod(checker::ETSChecker *che // NOTE(mmartin): this can be replaced with the general type mapper, once implemented if ((GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U) { - auto *const savedNode = checker->Relation()->GetNode(); - if (savedNode == nullptr) { - checker->Relation()->SetNode(this); - } - SetTupleConvertedType(checker->PrimitiveTypeAsETSBuiltinType(tupleTypeAtIdx)); - - checker->Relation()->SetNode(savedNode); } if (tupleTypeAtIdx->IsETSObjectType() && baseType->AsETSArrayType()->ElementType()->IsETSObjectType()) { @@ -391,11 +384,10 @@ checker::Type *MemberExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MemberExpression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const object = object_ != nullptr ? object_->Clone(allocator)->AsExpression() : nullptr; - auto *const property = property_ != nullptr ? property_->Clone(allocator)->AsExpression() : nullptr; + auto *const object = object_ != nullptr ? object_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const property = property_ != nullptr ? property_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(object, property, kind_, computed_, MaybeOptionalExpression::IsOptional()); diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index b59a73b4097f5ae6b818081e7af80ca1c5098045..fd366244030667f789023b8cc8a41f6b67865f26 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -172,8 +172,7 @@ public: [[nodiscard]] bool IsPrivateReference() const noexcept; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index f56cdeb805147dc9c04dea64b87a01bb9811a501..8fb67ccc9fb8b484177c50868f8f12657e4aaa67 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -36,7 +36,6 @@ NewExpression::NewExpression([[maybe_unused]] Tag const tag, NewExpression const } } -// NOLINTNEXTLINE(google-default-arguments) NewExpression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/newExpression.h b/ets2panda/ir/expressions/newExpression.h index a1d974cd3fee0d1a0cf847f28f432304e68b5677..883e310a292a25c1e01439089b852581484b2520 100644 --- a/ets2panda/ir/expressions/newExpression.h +++ b/ets2panda/ir/expressions/newExpression.h @@ -53,8 +53,7 @@ public: return arguments_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index 6ebf574910a112e74a06bc44f39cc501ccf5d8c0..4ba78c48b3c5ea0b3f2afae22badf44943d95371 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -65,7 +65,6 @@ ObjectExpression::ObjectExpression([[maybe_unused]] Tag const tag, ObjectExpress } } -// NOLINTNEXTLINE(google-default-arguments) ObjectExpression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/objectExpression.h b/ets2panda/ir/expressions/objectExpression.h index 0beef0b780c051665b6f3c5622a7d42f1207772e..758a46c1613b7c809d39ac83798dad6f0a3efd00 100644 --- a/ets2panda/ir/expressions/objectExpression.h +++ b/ets2panda/ir/expressions/objectExpression.h @@ -96,8 +96,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToObjectPattern(); diff --git a/ets2panda/ir/expressions/omittedExpression.cpp b/ets2panda/ir/expressions/omittedExpression.cpp index 0ab3d1f33203eefd29e3f44e8ed5442c0d3860c3..abbfdd6774d751c50053adf9386671e3a7c31a7b 100644 --- a/ets2panda/ir/expressions/omittedExpression.cpp +++ b/ets2panda/ir/expressions/omittedExpression.cpp @@ -55,7 +55,6 @@ checker::Type *OmittedExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) OmittedExpression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/omittedExpression.h b/ets2panda/ir/expressions/omittedExpression.h index 4f1f340b78dfb90e6b0069d7a7b7ece85daf6c68..b29553d7c48099536533db51ccf9aa58696f7414 100644 --- a/ets2panda/ir/expressions/omittedExpression.h +++ b/ets2panda/ir/expressions/omittedExpression.h @@ -30,8 +30,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index 3830204255e2be254704e1b1fe96b17c82716c14..d4f37ffaef3de9a5bd586c75dcfea6d72c8be935 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -32,7 +32,6 @@ SequenceExpression::SequenceExpression([[maybe_unused]] Tag const tag, SequenceE } } -// NOLINTNEXTLINE(google-default-arguments) SequenceExpression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/sequenceExpression.h b/ets2panda/ir/expressions/sequenceExpression.h index 98c53be093291a81d397b3d45e3b209a0c983248..4c46022aad2d2a65e6ebf0d5da972434c1c1e54e 100644 --- a/ets2panda/ir/expressions/sequenceExpression.h +++ b/ets2panda/ir/expressions/sequenceExpression.h @@ -47,8 +47,7 @@ public: return sequence_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index 02e8244316ccb7c986413dbf8c83ae0aaa67a39e..8707b2b35ef2d32a2f3fc1a2ddaa2edc2cefdf83 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -57,7 +57,6 @@ checker::Type *SuperExpression::Check([[maybe_unused]] checker::ETSChecker *chec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) SuperExpression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/superExpression.h b/ets2panda/ir/expressions/superExpression.h index 29d12a994de0bed32b421f17ac355291e97b3b7e..a3d33a1f187cec7bf7fafa05845850390c612b94 100644 --- a/ets2panda/ir/expressions/superExpression.h +++ b/ets2panda/ir/expressions/superExpression.h @@ -28,8 +28,7 @@ public: explicit SuperExpression() : Expression(AstNodeType::SUPER_EXPRESSION) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 238deecd3736e289f7ab88d65ef9623d3d23ec5c..bd0bce7063074c909906e8c496b07c7733fc3b3b 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -81,12 +81,11 @@ checker::Type *TaggedTemplateExpression::Check([[maybe_unused]] checker::ETSChec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TaggedTemplateExpression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const tag = tag_ != nullptr ? tag_->Clone(allocator)->AsExpression() : nullptr; - auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator) : nullptr; - auto *const typeParams = typeParams_ != nullptr ? typeParams_->Clone(allocator) : nullptr; + auto *const tag = tag_ != nullptr ? tag_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator, nullptr) : nullptr; + auto *const typeParams = typeParams_ != nullptr ? typeParams_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(tag, quasi, typeParams); clone != nullptr) { if (tag != nullptr) { diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.h b/ets2panda/ir/expressions/taggedTemplateExpression.h index d8853db8a91e549b4363ff92411fef3cb8398b36..2f70a9451a0a351e1916012e1f636f10c792d9ef 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.h +++ b/ets2panda/ir/expressions/taggedTemplateExpression.h @@ -50,8 +50,7 @@ public: return typeParams_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index 732c96706b0a4377f457ba7407123afc62fb755e..30e37189f82c37e0b08ff1c5cd815d7133d81483 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -39,7 +39,6 @@ TemplateLiteral::TemplateLiteral([[maybe_unused]] Tag const tag, TemplateLiteral } } -// NOLINTNEXTLINE(google-default-arguments) TemplateLiteral *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/templateLiteral.h b/ets2panda/ir/expressions/templateLiteral.h index 046ea69c4f13e5e228751330bf8f09d6872b2433..0b7b58711633734476225f6c6c16da164469c7af 100644 --- a/ets2panda/ir/expressions/templateLiteral.h +++ b/ets2panda/ir/expressions/templateLiteral.h @@ -48,8 +48,7 @@ public: return expressions_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 9598cea01a9637091955cd6b91a2cb479a84da51..7ab66d905ce236004c1411cd436afb457bd92365 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -63,7 +63,6 @@ checker::Type *ThisExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ThisExpression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/thisExpression.h b/ets2panda/ir/expressions/thisExpression.h index 51ab0411293e170091a9ea594be62454044870ef..c1db0af614090524188647b8708224117ca62e87 100644 --- a/ets2panda/ir/expressions/thisExpression.h +++ b/ets2panda/ir/expressions/thisExpression.h @@ -28,8 +28,7 @@ public: explicit ThisExpression() : Expression(AstNodeType::THIS_EXPRESSION) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index 835456d9c4d10eba065554631f9af6119032b3a4..c04d856395debd43e0fbbeeacaac5abe3a032cbf 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -71,10 +71,9 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) UnaryExpression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/unaryExpression.h b/ets2panda/ir/expressions/unaryExpression.h index bbb261d3a0582bdadd7493c5b0a8c0191c970893..af060bca824a5f0fe3443e10eeb8e9212d99f39a 100644 --- a/ets2panda/ir/expressions/unaryExpression.h +++ b/ets2panda/ir/expressions/unaryExpression.h @@ -58,8 +58,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index 5453e7543cf9303ea6550a828cedc953f6978fcd..b3c39981e15742992a4f58c0fbf7f1436028b82d 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -78,10 +78,9 @@ checker::Type *UpdateExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) UpdateExpression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_, prefix_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/updateExpression.h b/ets2panda/ir/expressions/updateExpression.h index 312a73df3306da2da2f1e1a7ae21f1c753dac93c..51539cccf5f8fbb3df53464a7c5e4695c5cafaa0 100644 --- a/ets2panda/ir/expressions/updateExpression.h +++ b/ets2panda/ir/expressions/updateExpression.h @@ -62,8 +62,7 @@ public: return prefix_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index 36ce163da7007580178c8b8e8f8caf8c804930a2..3c8400649d31a0dc6430f52ed4f900d150330cee 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -67,10 +67,9 @@ checker::Type *YieldExpression::Check([[maybe_unused]] checker::ETSChecker *chec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) YieldExpression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, delegate_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/yieldExpression.h b/ets2panda/ir/expressions/yieldExpression.h index 793843063c900c0ac63c43014cbbd40c37258dbd..c7e2f278f9e50fb0ef497f633b164edb2451a8b8 100644 --- a/ets2panda/ir/expressions/yieldExpression.h +++ b/ets2panda/ir/expressions/yieldExpression.h @@ -46,8 +46,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ts/tsArrayType.cpp b/ets2panda/ir/ts/tsArrayType.cpp index b4c9d27caea08b929459d42482688d807dcc4c90..328476307bef27d9f4a754e5288eff7c993e8518 100644 --- a/ets2panda/ir/ts/tsArrayType.cpp +++ b/ets2panda/ir/ts/tsArrayType.cpp @@ -78,10 +78,9 @@ checker::Type *TSArrayType::GetType(checker::ETSChecker *checker) return checker->CreateETSArrayType(elementType); } -// NOLINTNEXTLINE(google-default-arguments) TSArrayType *TSArrayType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const elementTypeClone = elementType_ != nullptr ? elementType_->Clone(allocator) : nullptr; + auto *const elementTypeClone = elementType_ != nullptr ? elementType_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(elementTypeClone); clone != nullptr) { if (elementTypeClone != nullptr) { diff --git a/ets2panda/ir/ts/tsArrayType.h b/ets2panda/ir/ts/tsArrayType.h index 12752a30046a61ffc28895d56c02ab5bcfa5b9db..131d10a5d0339925179a21bbef0eb1eb68462377 100644 --- a/ets2panda/ir/ts/tsArrayType.h +++ b/ets2panda/ir/ts/tsArrayType.h @@ -53,8 +53,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSArrayType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSArrayType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: TypeNode *elementType_; diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp index ef538c9bcf72eee3a1a702979bec167a0f0163f1..84496dcd92e2889b2426dc65cc4fa70d628bc348 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -35,7 +35,6 @@ TSTypeParameterInstantiation::TSTypeParameterInstantiation([[maybe_unused]] Tag } } -// NOLINTNEXTLINE(google-default-arguments) TSTypeParameterInstantiation *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.h b/ets2panda/ir/ts/tsTypeParameterInstantiation.h index be57a1c502e38aa4e83c37d498263212135bfbe5..e6c02c9e585dee7d228d5f808e6f26bb259d807d 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.h @@ -42,8 +42,7 @@ public: return params_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/typeNode.cpp b/ets2panda/ir/typeNode.cpp index be22e10ee704a4131e7b904c37bcbe46245b34a3..c90e0234ae5e3f4a3bc3403da01b03c431176bc4 100644 --- a/ets2panda/ir/typeNode.cpp +++ b/ets2panda/ir/typeNode.cpp @@ -20,7 +20,6 @@ namespace panda::es2panda::ir { -// NOLINTNEXTLINE(google-default-arguments) TypeNode *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const type = TsType(); type != nullptr) { diff --git a/ets2panda/ir/typeNode.h b/ets2panda/ir/typeNode.h index 7933f9b5e407daaa0898bc2b39b20c5107b542c4..72f4ceb54011618bdab613b38036c72fe9749a47 100644 --- a/ets2panda/ir/typeNode.h +++ b/ets2panda/ir/typeNode.h @@ -47,8 +47,7 @@ public: return nullptr; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent) override; protected: explicit TypeNode(AstNodeType const type) : Expression(type) {} diff --git a/ets2panda/ir/visitor/IterateAstVisitor.h b/ets2panda/ir/visitor/IterateAstVisitor.h index a6aad93b01a49df8f1f40d9abbb933baff38ca36..d259b3d1688538a7e8ea635e44fe8b39a94a8218 100644 --- a/ets2panda/ir/visitor/IterateAstVisitor.h +++ b/ets2panda/ir/visitor/IterateAstVisitor.h @@ -21,20 +21,56 @@ #include "ir/expressions/blockExpression.h" #include "ir/ets/etsUnionType.h" #include "ir/ets/etsTuple.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/expressions/functionExpression.h" +#include "ir/base/scriptFunction.h" +#include "ir/base/methodDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/expressions/identifier.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" namespace panda::es2panda::ir::visitor { +namespace detail { +class DefaultBehaviourAstVisitor : public ASTAbstractVisitor { +public: + DefaultBehaviourAstVisitor() = default; + virtual ~DefaultBehaviourAstVisitor() = 0; + NO_COPY_SEMANTIC(DefaultBehaviourAstVisitor); + NO_MOVE_SEMANTIC(DefaultBehaviourAstVisitor); + + virtual void HandleNode(ir::AstNode *node) = 0; + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DECLARE_CLASSES(nodeType, className) \ + void Visit##className(className *node) override \ + { \ + HandleNode(static_cast(node)); \ + } + + AST_NODE_MAPPING(DECLARE_CLASSES) + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DECLARE_AST_NODE_CHECK_METHOD(nodeType1, nodeType2, baseClass, reinterpretClass) \ + DECLARE_CLASSES(nodeType1, baseClass); + + AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD) +#undef DECLARE_AST_NODE_CHECK_METHOD + +#undef DECLARE_CLASSES +}; +inline DefaultBehaviourAstVisitor::~DefaultBehaviourAstVisitor() = default; +} // namespace detail + /** * Children should declare VisitNode methods (might be virtual might be not) * for all classes or provide default behaviour using * template VisitNode(T *t) {} */ -class IterateAstVisitor : public ASTAbstractVisitor { +class IterateAstVisitor : public detail::DefaultBehaviourAstVisitor { public: IterateAstVisitor() = default; - virtual ~IterateAstVisitor() = 0; - NO_COPY_SEMANTIC(IterateAstVisitor); - NO_MOVE_SEMANTIC(IterateAstVisitor); void Iterate(ir::AstNode *node) { @@ -43,25 +79,30 @@ public: } } -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DECLARE_CLASSES(nodeType, className) \ - void Visit##className(className *node) override \ - { \ - Iterate(static_cast(node)); \ + void HandleNode(ir::AstNode *node) final + { + Iterate(node); } +}; - AST_NODE_MAPPING(DECLARE_CLASSES) +class EmptyAstVisitor : public detail::DefaultBehaviourAstVisitor { +public: + EmptyAstVisitor() = default; -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DECLARE_AST_NODE_CHECK_METHOD(nodeType1, nodeType2, baseClass, reinterpretClass) \ - DECLARE_CLASSES(nodeType1, baseClass); + void HandleNode(ir::AstNode * /*node*/) final {} +}; - AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD) -#undef DECLARE_AST_NODE_CHECK_METHOD +class AbortAstVisitor : public detail::DefaultBehaviourAstVisitor { +public: + AbortAstVisitor() = default; -#undef DECLARE_CLASSES + void HandleNode(ir::AstNode * /*node*/) final + { + UNREACHABLE(); + } }; -inline IterateAstVisitor::~IterateAstVisitor() = default; + +using CustomAstVisitor = detail::DefaultBehaviourAstVisitor; } // namespace panda::es2panda::ir::visitor diff --git a/ets2panda/lexer/lexer.h b/ets2panda/lexer/lexer.h index 77e28f6b10853b4b7e3308af079e9f63fb173683..9824cbb151c0558e722d263014cc26d9f979982b 100644 --- a/ets2panda/lexer/lexer.h +++ b/ets2panda/lexer/lexer.h @@ -114,6 +114,26 @@ public: const Token &GetToken() const; size_t Line() const; + bool TryEatTokenType(lexer::TokenType type) + { + auto token = GetToken(); + if (token.Type() == type) { + NextToken(); + return true; + } + return false; + } + + std::optional TryEatTokenKeyword(lexer::TokenType type) + { + auto token = GetToken(); + if (token.KeywordType() == type) { + NextToken(); + return token; + } + return std::nullopt; + } + LexerPosition Save() const; void Rewind(const LexerPosition &pos); void BackwardToken(TokenType type, size_t offset); diff --git a/ets2panda/lexer/scripts/keywords.yaml b/ets2panda/lexer/scripts/keywords.yaml index e437a74c86ef070257cd8999feac3d91b4d110e4..d6f8a5540f9ba6d9753201318a4ceb857c971eba 100644 --- a/ets2panda/lexer/scripts/keywords.yaml +++ b/ets2panda/lexer/scripts/keywords.yaml @@ -430,8 +430,7 @@ keywords: - name: 'type' token: KEYW_TYPE - keyword: [ets] - keyword_like: [js, ts] + keyword_like: [ets, js, ts] - name: 'typeof' token: KEYW_TYPEOF diff --git a/ets2panda/lexer/token/token.cpp b/ets2panda/lexer/token/token.cpp index cf4e3e30337f97d6a3d3e715a0d097643d4ce638..1135f0f0a3b622bb69f65a5d817d3c8e832d5165 100644 --- a/ets2panda/lexer/token/token.cpp +++ b/ets2panda/lexer/token/token.cpp @@ -107,6 +107,7 @@ bool Token::IsDefinableTypeName() const case TokenType::KEYW_INT: case TokenType::KEYW_CHAR: case TokenType::KEYW_LONG: + case TokenType::KEYW_TYPE: return true; default: return false; diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index b6d884410d2e0075d3627003cf5eb999df9db38a..fb20adabb9caa952148dc2dafefc5bdff09ea379 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -67,6 +67,8 @@ #include "ir/module/importDeclaration.h" #include "ir/module/importDefaultSpecifier.h" #include "ir/module/importSpecifier.h" +#include "ir/module/exportSpecifier.h" +#include "ir/module/exportNamedDeclaration.h" #include "ir/statements/assertStatement.h" #include "ir/statements/blockStatement.h" #include "ir/statements/emptyStatement.h" @@ -122,24 +124,6 @@ #include "libpandabase/os/file.h" #include "generated/signatures.h" -#if defined PANDA_TARGET_MOBILE -#define USE_UNIX_SYSCALL -#endif - -#ifdef USE_UNIX_SYSCALL -#include -#include -#include -#else -#if __has_include() -#include -namespace fs = std::filesystem; -#elif __has_include() -#include -namespace fs = std::experimental::filesystem; -#endif -#endif - namespace panda::es2panda::parser { using namespace std::literals::string_literals; @@ -161,449 +145,112 @@ void ETSParser::ParseProgram(ScriptKind kind) // NOTE(user): handle multiple sourceFiles } - auto statements = PrepareGlobalClass(); - ParseDefaultSources(); - - ParseETSGlobalScript(startLoc, statements); -} - -void ETSParser::ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements) -{ - auto paths = ParseImportDeclarations(statements); - - // clang-format off - auto removeParsedSources = [this](std::vector &items) { - items.erase(remove_if(begin(items), end(items), - [this](auto x) { - auto resolved = ResolveImportPath(x); - auto pathIter = - std::find_if(resolvedParsedSources_.begin(), resolvedParsedSources_.end(), - [resolved](const auto &p) { return p.second == resolved; }); - auto found = pathIter != resolvedParsedSources_.end(); - if (found) { - resolvedParsedSources_.emplace(x, resolved); - } - return found; - }), - end(items)); - - for (const auto &item : items) { - auto resolved = ResolveImportPath(item); - resolvedParsedSources_.emplace(item, resolved); - parsedSources_.push_back(resolved); - } - }; - // clang-format on - - removeParsedSources(paths); - - ParseSources(paths, false); - - if (!GetProgram()->VarBinder()->AsETSBinder()->ReExportImports().empty()) { - std::vector reExportPaths; - - for (auto reExport : GetProgram()->VarBinder()->AsETSBinder()->ReExportImports()) { - if (std::find(paths.begin(), paths.end(), reExport->GetProgramPath().Mutf8()) != paths.end()) { - auto path = - reExport->GetProgramPath().Mutf8().substr(0, reExport->GetProgramPath().Mutf8().find_last_of('/')); - for (auto item : reExport->GetUserPaths()) { - reExportPaths.push_back( - path + "/" + item.Mutf8().substr(item.Mutf8().find_first_of('/') + 1, item.Mutf8().length())); - } - } - } - - removeParsedSources(reExportPaths); - - ParseSources(reExportPaths, false); - } - - ParseTopLevelDeclaration(statements); - - auto *etsScript = AllocNode(Allocator(), std::move(statements), GetProgram()); - etsScript->SetRange({startLoc, Lexer()->GetToken().End()}); - GetProgram()->SetAst(etsScript); -} - -void ETSParser::CreateGlobalClass() -{ - auto *ident = AllocNode(compiler::Signatures::ETS_GLOBAL, Allocator()); - - auto *classDef = AllocNode(Allocator(), ident, ir::ClassDefinitionModifiers::GLOBAL, - ir::ModifierFlags::ABSTRACT, Language(Language::Id::ETS)); - GetProgram()->SetGlobalClass(classDef); - - [[maybe_unused]] auto *classDecl = AllocNode(classDef, Allocator()); -} - -ArenaVector ETSParser::PrepareGlobalClass() -{ ArenaVector statements(Allocator()->Adapter()); - ParsePackageDeclaration(statements); - CreateGlobalClass(); - - return statements; -} - -ArenaVector ETSParser::PrepareExternalGlobalClass([[maybe_unused]] const SourceFile &sourceFile) -{ - ArenaVector statements(Allocator()->Adapter()); - ParsePackageDeclaration(statements); - - if (statements.empty()) { - GetProgram()->SetGlobalClass(globalProgram_->GlobalClass()); - } - - auto &extSources = globalProgram_->ExternalSources(); - const util::StringView name = GetProgram()->SourceFileFolder(); - - auto res = extSources.end(); - if (!statements.empty()) { - res = extSources.find(name); - } else { - auto path = GetProgram()->SourceFileFolder().Mutf8() + panda::os::file::File::GetPathDelim().at(0) + - GetProgram()->GetPackageName().Mutf8(); - auto resolved = ResolveImportPath(path); - resolvedParsedSources_.emplace(path, resolved); - GetProgram()->SetSource(GetProgram()->SourceCode(), GetProgram()->SourceFilePath(), - util::UString(resolved, Allocator()).View()); - } - - if (res == extSources.end()) { - CreateGlobalClass(); - auto insRes = extSources.emplace(GetProgram()->SourceFileFolder(), Allocator()->Adapter()); - insRes.first->second.push_back(GetProgram()); - } else { - res->second.push_back(GetProgram()); - auto *extProg = res->second.front(); - GetProgram()->SetGlobalClass(extProg->GlobalClass()); - // NOTE(user): check nullptr cases and handle recursive imports + auto decl = ParsePackageDeclaration(); + if (decl != nullptr) { + statements.emplace_back(decl); } - - return statements; + auto script = ParseETSGlobalScript(startLoc, statements); + GetProgram()->SetAst(script); } -static bool IsCompitableExtension(const std::string &extension) +ir::ETSScript *ETSParser::ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements) { - return extension == ".ets" || extension == ".ts"; -} - -void ETSParser::CollectDefaultSources() -{ - std::vector paths; - std::vector stdlib = {"std/core", "std/math", "std/containers", - "std/time", "std/interop/js", "escompat"}; - -#ifdef USE_UNIX_SYSCALL - for (auto const &path : stdlib) { - auto resolvedPath = ResolveImportPath(path); - DIR *dir = opendir(resolvedPath.c_str()); + auto [imports, paths] = ParseImportDeclarations(); + pathResolver_.FilterParsedSources(paths, GetProgram()); + statements.insert(statements.end(), imports.begin(), imports.end()); - if (dir == nullptr) { - ThrowSyntaxError({"Cannot open folder: ", resolvedPath}); - } - - struct dirent *entry; - while ((entry = readdir(dir)) != nullptr) { - if (entry->d_type != DT_REG) { - continue; - } - - std::string fileName = entry->d_name; - std::string::size_type pos = fileName.find_last_of('.'); + AddExternalSource(ParseSources(paths)); - if (pos == std::string::npos || !IsCompitableExtension(fileName.substr(pos))) { - continue; - } - - std::string filePath = path + "/" + entry->d_name; - - if (fileName == "Object.ets") { - parsedSources_.emplace(parsedSources_.begin(), filePath); - } else { - parsedSources_.emplace_back(filePath); - } - } - - closedir(dir); + if (!reExports_.empty()) { + auto reExportPaths = pathResolver_.ReExportPaths(reExports_, paths); + pathResolver_.FilterParsedSources(reExportPaths, GetProgram()); + AddExternalSource(ParseSources(reExportPaths)); } -#else - for (auto const &path : stdlib) { - for (auto const &entry : fs::directory_iterator(ResolveImportPath(path))) { - if (!fs::is_regular_file(entry) || !IsCompitableExtension(entry.path().extension().string())) { - continue; - } - std::string baseName = path; - std::size_t pos = entry.path().string().find_last_of(panda::os::file::File::GetPathDelim()); + auto topLevelStatements = ParseTopLevelDeclaration(); - baseName.append(entry.path().string().substr(pos, entry.path().string().size())); - - if (entry.path().filename().string() == "Object.ets") { - parsedSources_.emplace(parsedSources_.begin(), baseName); - } else { - parsedSources_.emplace_back(baseName); - } - } - } -#endif -} - -ETSParser::ImportData ETSParser::GetImportData(const std::string &path) -{ - auto &dynamicPaths = ArkTSConfig()->DynamicPaths(); - auto key = panda::os::NormalizePath(path); - - auto it = dynamicPaths.find(key); - if (it == dynamicPaths.cend()) { - key = panda::os::RemoveExtension(key); - } - - while (it == dynamicPaths.cend() && !key.empty()) { - it = dynamicPaths.find(key); - if (it != dynamicPaths.cend()) { - break; - } - key = panda::os::GetParentDir(key); - } - - if (it != dynamicPaths.cend()) { - return {it->second.GetLanguage(), key, it->second.HasDecl()}; - } - return {ToLanguage(Extension()), path, true}; -} - -std::string ETSParser::ResolveFullPathFromRelative(const std::string &path) -{ - char pathDelimiter = panda::os::file::File::GetPathDelim().at(0); - auto resolvedFp = GetProgram()->ResolvedFilePath().Mutf8(); - auto sourceFp = GetProgram()->SourceFileFolder().Mutf8(); - if (resolvedFp.empty()) { - auto fp = sourceFp + pathDelimiter + path; - return util::Helpers::IsRealPath(fp) ? fp : path; - } - auto fp = resolvedFp + pathDelimiter + path; - if (util::Helpers::IsRealPath(fp)) { - return fp; - } - if (path.find(sourceFp) == 0) { - return resolvedFp + pathDelimiter + path.substr(sourceFp.size()); - } - return path; -} - -std::string ETSParser::ResolveImportPath(const std::string &path) -{ - char pathDelimiter = panda::os::file::File::GetPathDelim().at(0); - if (util::Helpers::IsRelativePath(path)) { - return util::Helpers::GetAbsPath(ResolveFullPathFromRelative(path)); - } - - std::string baseUrl; - // Resolve delimeter character to basePath. - if (path.find('/') == 0) { - baseUrl = ArkTSConfig()->BaseUrl(); - - baseUrl.append(path, 0, path.length()); - return baseUrl; - } - - auto &dynamicPaths = ArkTSConfig()->DynamicPaths(); - auto it = dynamicPaths.find(path); - if (it != dynamicPaths.cend() && !it->second.HasDecl()) { - return path; - } - - // Resolve the root part of the path. - // E.g. root part of std/math is std. - std::string::size_type pos = path.find('/'); - bool containsDelim = (pos != std::string::npos); - std::string rootPart = containsDelim ? path.substr(0, pos) : path; - - if (rootPart == "std" && !GetOptions().stdLib.empty()) { // Get std path from CLI if provided - baseUrl = GetOptions().stdLib + "/std"; - } else if (rootPart == "escompat" && !GetOptions().stdLib.empty()) { // Get escompat path from CLI if provided - baseUrl = GetOptions().stdLib + "/escompat"; - } else { - auto resolvedPath = ArkTSConfig()->ResolvePath(path); - if (resolvedPath.empty()) { - ThrowSyntaxError({"Can't find prefix for '", path, "' in ", ArkTSConfig()->ConfigPath()}); - } - return resolvedPath; - } - - if (containsDelim) { - baseUrl.append(1, pathDelimiter); - baseUrl.append(path, rootPart.length() + 1, path.length()); - } - - return baseUrl; + statements.insert(statements.end(), topLevelStatements.begin(), topLevelStatements.end()); + auto *etsScript = AllocNode(Allocator(), std::move(statements), GetProgram()); + etsScript->SetRange({startLoc, Lexer()->GetToken().End()}); + return etsScript; } -std::tuple ETSParser::GetSourceRegularPath(const std::string &path, const std::string &resolvedPath) +void ETSParser::AddExternalSource(const std::vector &programs) { - if (!panda::os::file::File::IsRegularFile(resolvedPath)) { - std::string importExtension = ".ets"; - - if (!panda::os::file::File::IsRegularFile(resolvedPath + importExtension)) { - importExtension = ".ts"; + for (auto *newProg : programs) { + auto &extSources = globalProgram_->ExternalSources(); - if (!panda::os::file::File::IsRegularFile(resolvedPath + importExtension)) { - ThrowSyntaxError("Incorrect path: " + resolvedPath); + if (extSources.count(newProg->SourceFileFolder()) == 0) { + auto isDeclPackage = newProg->Ast()->Statements().front()->IsETSPackageDeclaration(); + if (!isDeclPackage) { + auto path = newProg->PackagePath(); + auto resolved = ValidatePathResolver(pathResolver_.ResolveImportPath(path, GetProgram())); + newProg->SetSource(newProg->SourceCode(), newProg->SourceFilePath(), + util::UString(resolved, Allocator()).View()); } + extSources.emplace(newProg->SourceFileFolder(), Allocator()->Adapter()); } - return {path + importExtension, true}; + extSources.at(newProg->SourceFileFolder()).emplace_back(newProg); } - return {path, false}; } -void ETSParser::CollectUserSourcesFromIndex([[maybe_unused]] const std::string &path, - [[maybe_unused]] const std::string &resolvedPath, - [[maybe_unused]] std::vector &userPaths) +std::tuple, bool> ETSParser::CollectUserSources(const std::string &path) { -#ifdef USE_UNIX_SYSCALL - DIR *dir = opendir(resolvedPath.c_str()); - bool isIndex = false; - std::vector tmpPaths; - - if (dir == nullptr) { - ThrowSyntaxError({"Cannot open folder: ", resolvedPath}); - } - - struct dirent *entry; - while ((entry = readdir(dir)) != nullptr) { - if (entry->d_type != DT_REG) { - continue; - } - - std::string fileName = entry->d_name; - std::string::size_type pos = fileName.find_last_of('.'); - if (pos == std::string::npos || !IsCompitableExtension(fileName.substr(pos))) { - continue; - } - - std::string filePath = path + "/" + entry->d_name; - - if (fileName == "index.ets" || fileName == "index.ts") { - userPaths.emplace_back(filePath); - isIndex = true; - break; - } else if (fileName == "Object.ets") { - tmpPaths.emplace(userPaths.begin(), filePath); - } else { - tmpPaths.emplace_back(filePath); - } - } - - closedir(dir); - - if (!isIndex) { - userPaths.insert(userPaths.end(), tmpPaths.begin(), tmpPaths.end()); - } -#endif + const std::string resolvedPath = ValidatePathResolver(pathResolver_.ResolveImportPath(path, GetProgram())); + auto resolved = ValidatePathResolver(pathResolver_.CollectUserSources(path, GetProgram())); + return {std::move(resolved.sources), resolved.isModule}; } -std::tuple, bool> ETSParser::CollectUserSources(const std::string &path) +ArenaVector ETSParser::ParseDefaultSources(std::string_view srcFile, + std::string_view importSrc, + const std::vector &paths) { - std::vector userPaths; - - const std::string resolvedPath = ResolveImportPath(path); - resolvedParsedSources_.emplace(path, resolvedPath); - const auto data = GetImportData(resolvedPath); - - if (!data.hasDecl) { - return {userPaths, false}; - } - - if (!panda::os::file::File::IsDirectory(resolvedPath)) { - std::string regularPath; - bool isModule = false; - std::tie(regularPath, isModule) = GetSourceRegularPath(path, resolvedPath); - userPaths.emplace_back(regularPath); - return {userPaths, isModule}; - } - -#ifdef USE_UNIX_SYSCALL - CollectUserSourcesFromIndex(path, resolvedPath, userPaths); -#else - if (fs::exists(resolvedPath + "/index.ets")) { - userPaths.emplace_back(path + "/index.ets"); - } else if (fs::exists(resolvedPath + "/index.ts")) { - userPaths.emplace_back(path + "/index.ts"); - } else { - for (auto const &entry : fs::directory_iterator(resolvedPath)) { - if (!fs::is_regular_file(entry) || !IsCompitableExtension(entry.path().extension().string())) { - continue; - } + auto isp = InnerSourceParser(this); + SourceFile source(srcFile, importSrc); + auto lexer = InitLexer(source); - std::string baseName = path; - std::size_t pos = entry.path().string().find_last_of(panda::os::file::File::GetPathDelim()); + Lexer()->NextToken(); - baseName.append(entry.path().string().substr(pos, entry.path().string().size())); - userPaths.emplace_back(baseName); - } - } -#endif - return {userPaths, false}; + GetContext().Status() |= ParserStatus::IN_DEFAULT_IMPORTS; + auto [statements, real_paths] = ParseImportDeclarations(); + GetContext().Status() &= ~ParserStatus::IN_DEFAULT_IMPORTS; + (void)real_paths; + auto defaultSources = ValidatePathResolver(pathResolver_.CollectDefaultSources(paths, GetProgram())); + AddExternalSource(ParseSources(defaultSources)); + return statements; } -void ETSParser::ParseSources(const std::vector &paths, bool isExternal) +std::vector ETSParser::ParseSources(std::vector paths) { - GetContext().Status() |= isExternal ? ParserStatus::IN_EXTERNAL : ParserStatus::IN_IMPORT; - - const std::size_t pathCount = paths.size(); - for (std::size_t idx = 0; idx < pathCount; idx++) { - std::string resolvedPath = ResolveImportPath(paths[idx]); - resolvedParsedSources_.emplace(paths[idx], resolvedPath); + pathResolver_.FilterParsedSources(paths, GetProgram()); + std::vector programs; - const auto data = GetImportData(resolvedPath); + auto sources = ValidatePathResolver(pathResolver_.ParseSources(paths, GetProgram())); + for (const auto &source : sources) { + std::ifstream inputStream(source.resolvedPath.c_str()); - if (!data.hasDecl) { - continue; - } - - std::ifstream inputStream(resolvedPath.c_str()); - - if (GetProgram()->SourceFilePath().Is(resolvedPath)) { + if (GetProgram()->SourceFilePath().Is(source.resolvedPath)) { break; } if (inputStream.fail()) { - ThrowSyntaxError({"Failed to open file: ", resolvedPath.c_str()}); + ThrowSyntaxError({"Failed to open file: ", source.resolvedPath}); } std::stringstream ss; ss << inputStream.rdbuf(); auto externalSource = ss.str(); - auto currentLang = GetContext().SetLanguage(data.lang); - ParseSource({paths[idx].c_str(), externalSource.c_str(), resolvedPath.c_str(), false}); + auto currentLang = GetContext().SetLanguage(source.lang); + auto newProg = ParseSource({source.filePath, externalSource, source.resolvedPath, false}); + programs.emplace_back(newProg); GetContext().SetLanguage(currentLang); } - - GetContext().Status() &= isExternal ? ~ParserStatus::IN_EXTERNAL : ~ParserStatus::IN_IMPORT; -} - -void ETSParser::ParseDefaultSources() -{ - auto isp = InnerSourceParser(this); - SourceFile source(varbinder::ETSBinder::DEFAULT_IMPORT_SOURCE_FILE, varbinder::ETSBinder::DEFAULT_IMPORT_SOURCE); - auto lexer = InitLexer(source); - ArenaVector statements(Allocator()->Adapter()); - - Lexer()->NextToken(); - - GetContext().Status() |= ParserStatus::IN_DEFAULT_IMPORTS; - - ParseImportDeclarations(statements); - GetContext().Status() &= ~ParserStatus::IN_DEFAULT_IMPORTS; - - CollectDefaultSources(); - - ParseSources(parsedSources_, true); + return programs; } -void ETSParser::ParseSource(const SourceFile &sourceFile) +parser::Program *ETSParser::ParseSource(const SourceFile &sourceFile) { auto *program = Allocator()->New(Allocator(), GetProgram()->VarBinder()); auto esp = ExternalSourceParser(this, program); @@ -612,443 +259,143 @@ void ETSParser::ParseSource(const SourceFile &sourceFile) lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); Lexer()->NextToken(); - auto statements = PrepareExternalGlobalClass(sourceFile); - ParseETSGlobalScript(startLoc, statements); -} - -ir::ScriptFunction *ETSParser::AddInitMethod(ArenaVector &globalProperties) -{ - if (GetProgram()->Kind() == ScriptKind::STDLIB) { - return nullptr; + ArenaVector statements(Allocator()->Adapter()); + auto decl = ParsePackageDeclaration(); + if (decl != nullptr) { + statements.emplace_back(decl); } - - // Lambda to create empty function node with signature: func(): void - // NOTE: replace with normal createFunction call - auto const createFunction = - [this](std::string_view const functionName, ir::ScriptFunctionFlags functionFlags, - ir::ModifierFlags const functionModifiers) -> std::pair { - auto *initIdent = AllocNode(functionName, Allocator()); - ir::ScriptFunction *initFunc; - - { - ArenaVector params(Allocator()->Adapter()); - - ArenaVector statements(Allocator()->Adapter()); - auto *initBody = AllocNode(Allocator(), std::move(statements)); - - initFunc = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), - initBody, functionFlags, false, GetContext().GetLanguge()); - } - - initFunc->SetIdent(initIdent); - initFunc->AddModifier(functionModifiers); - - auto *funcExpr = AllocNode(initFunc); - - auto *initMethod = AllocNode(ir::MethodDefinitionKind::METHOD, initIdent, funcExpr, - functionModifiers, Allocator(), false); - - return std::make_pair(initFunc, initMethod); - }; - - // Create public method for module re-initialization. The assignments and statements are sequentially called inside. - auto [init_func, init_method] = createFunction(compiler::Signatures::INIT_METHOD, ir::ScriptFunctionFlags::NONE, - ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC); - globalProperties.emplace_back(init_method); - - return init_func; + auto script = ParseETSGlobalScript(startLoc, statements); + program->SetAst(script); + return program; } -void ETSParser::MarkNodeAsExported(ir::AstNode *node, lexer::SourcePosition startPos, bool defaultExport, - std::size_t numOfElements) +ArenaVector ETSParser::ParseTopLevelStatements() { - ir::ModifierFlags flag = defaultExport ? ir::ModifierFlags::DEFAULT_EXPORT : ir::ModifierFlags::EXPORT; - - if (UNLIKELY(flag == ir::ModifierFlags::DEFAULT_EXPORT)) { - if (numOfElements > 1) { - ThrowSyntaxError("Only one default export is allowed in a module", startPos); + ArenaVector statements(Allocator()->Adapter()); + while (Lexer()->GetToken().Type() != lexer::TokenType::EOS) { + if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_SEMI_COLON)) { + continue; } - } - - node->AddModifier(flag); -} - -ArenaVector ETSParser::ParseTopLevelStatements(ArenaVector &statements) -{ - ArenaVector globalProperties(Allocator()->Adapter()); - fieldMap_.clear(); - exportNameMap_.clear(); - - // Add special '_$init$_' method that will hold all the top-level variable initializations (as assignments) and - // statements. By default it will be called in the global class static constructor but also it can be called - // directly from outside using public '_$init$_' method call in global scope. - // NOTE: now only a single-file modules are supported. Such a technique can be implemented in packages directly. - ir::ScriptFunction *initFunction = nullptr; - if (GetProgram()->GetPackageName().Empty()) { - initFunction = AddInitMethod(globalProperties); - } - - ParseTopLevelNextToken(statements, globalProperties, initFunction); - - // Add export modifier flag to nodes exported in previous statements. - for (auto &iter : exportNameMap_) { - util::StringView exportName = iter.first; - lexer::SourcePosition startLoc = exportNameMap_[exportName]; - if (fieldMap_.count(exportName) == 0) { - ThrowSyntaxError("Cannot find name '" + std::string {exportName.Utf8()} + "' to export.", startLoc); + auto stmt = ParseTopLevelStatement(); + GetContext().Status() &= ~ParserStatus::IN_AMBIENT_CONTEXT; + if (stmt != nullptr) { + statements.emplace_back(stmt); } - auto field = fieldMap_[exportName]; - // selective export does not support default - MarkNodeAsExported(field, startLoc, false); } - return globalProperties; -} - -void ETSParser::ParseTopLevelType(ArenaVector &statements, bool &defaultExport, - std::size_t const currentPos, - std::function const &parserFunction) -{ - ir::Statement *node = nullptr; - node = parserFunction(this); - if (node != nullptr) { - if (currentPos != std::numeric_limits::max()) { - MarkNodeAsExported(node, node->Start(), defaultExport); - defaultExport = false; - } - statements.push_back(node); - } + return statements; } -void ETSParser::ParseTopLevelNextTokenDefault(ArenaVector &statements, - ir::ScriptFunction *initFunction, size_t currentPos, - lexer::TokenType tokenType, bool defaultExport) +ir::Statement *ETSParser::ParseTopLevelDeclStatement(StatementParsingFlags flags) { - if (IsStructKeyword()) { - ParseTopLevelType(statements, defaultExport, currentPos, - [](ETSParser *obj) { return obj->ParseTypeDeclaration(false); }); - return; + auto [memberModifiers, startLoc] = ParseMemberModifiers(); + if ((memberModifiers & ir::ModifierFlags::EXPORT) != 0U && + (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY || + Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE)) { + return ParseReExport(startLoc); } - if (initFunction != nullptr) { - if (auto *const statement = ParseTopLevelStatement(); statement != nullptr) { - statement->SetParent(initFunction->Body()); - initFunction->Body()->AsBlockStatement()->Statements().emplace_back(statement); + ir::Statement *result = nullptr; + auto token = Lexer()->GetToken(); + switch (token.Type()) { + case lexer::TokenType::KEYW_FUNCTION: { + result = ParseFunctionDeclaration(false, memberModifiers); + result->SetStart(startLoc); + break; } - return; - } - - ThrowUnexpectedToken(tokenType); -} - -ir::ModifierFlags ETSParser::ResolveMemberModifiers() -{ - auto memberModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; - - if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE) { - CheckDeclare(); - memberModifiers |= ir::ModifierFlags::DECLARE; - } - return memberModifiers; -} - -lexer::SourcePosition ETSParser::ParseTopLevelNextTokenResolution(ArenaVector &statements, - ArenaVector &globalProperties, - ir::ScriptFunction *initFunction, size_t currentPos, - bool defaultExport) -{ - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); - auto memberModifiers = ResolveMemberModifiers(); - - switch (auto const tokenType = Lexer()->GetToken().Type(); tokenType) { case lexer::TokenType::KEYW_CONST: { memberModifiers |= ir::ModifierFlags::CONST; [[fallthrough]]; } case lexer::TokenType::KEYW_LET: { - Lexer()->NextToken(); - ParseClassFieldDefinition(ExpectIdentifier(), memberModifiers, &globalProperties, initFunction, &startLoc); - break; - } - case lexer::TokenType::KEYW_ASYNC: - case lexer::TokenType::KEYW_NATIVE: { - ParseTokenOfNative(tokenType, memberModifiers); - [[fallthrough]]; - } - case lexer::TokenType::KEYW_FUNCTION: { - ParseTokenOfFunction(memberModifiers, startLoc, globalProperties); + result = ParseStatement(flags); break; } case lexer::TokenType::KEYW_NAMESPACE: - [[fallthrough]]; case lexer::TokenType::KEYW_STATIC: - [[fallthrough]]; case lexer::TokenType::KEYW_ABSTRACT: - [[fallthrough]]; case lexer::TokenType::KEYW_FINAL: - [[fallthrough]]; case lexer::TokenType::KEYW_ENUM: - [[fallthrough]]; case lexer::TokenType::KEYW_INTERFACE: - [[fallthrough]]; case lexer::TokenType::KEYW_CLASS: { - // NOLINTBEGIN(modernize-avoid-bind) - ParseTopLevelType(statements, defaultExport, currentPos, - std::bind(&ETSParser::ParseTypeDeclaration, std::placeholders::_1, false)); - // NOLINTEND(modernize-avoid-bind) + result = ParseTypeDeclaration(false); break; } - case lexer::TokenType::KEYW_TYPE: { - ParseTopLevelType(statements, defaultExport, currentPos, &ETSParser::ParseTypeAliasDeclaration); - break; - } - default: { - // If struct is a soft keyword, handle it here, otherwise it's an identifier. - ParseTopLevelNextTokenDefault(statements, initFunction, currentPos, tokenType, defaultExport); - } - } - return startLoc; -} - -void ETSParser::ParseTopLevelNextToken(ArenaVector &statements, - ArenaVector &globalProperties, ir::ScriptFunction *initFunction) -{ - bool defaultExport = false; - - while (Lexer()->GetToken().Type() != lexer::TokenType::EOS) { - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { - Lexer()->NextToken(); - continue; - } - - auto currentPos = std::numeric_limits::max(); - if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_EXPORT) { - Lexer()->NextToken(); - currentPos = globalProperties.size(); - - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY || - Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { - ParseExport(Lexer()->GetToken().Start()); - continue; - } - - if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_DEFAULT) { - defaultExport = true; - Lexer()->NextToken(); - } - } - - lexer::SourcePosition startLoc = - ParseTopLevelNextTokenResolution(statements, globalProperties, initFunction, currentPos, defaultExport); - - GetContext().Status() &= ~ParserStatus::IN_AMBIENT_CONTEXT; - - while (currentPos < globalProperties.size()) { - MarkNodeAsExported(globalProperties[currentPos], startLoc, defaultExport, - globalProperties.size() - currentPos); - defaultExport = false; - currentPos++; - } - } -} - -void ETSParser::ParseTokenOfNative(panda::es2panda::lexer::TokenType tokenType, ir::ModifierFlags &memberModifiers) -{ - bool isAsync = tokenType == lexer::TokenType::KEYW_ASYNC; - - if (isAsync) { - memberModifiers |= ir::ModifierFlags::ASYNC; - } else { - memberModifiers |= ir::ModifierFlags::NATIVE; - } - - Lexer()->NextToken(); - - if (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_FUNCTION) { - ThrowSyntaxError({isAsync ? "'async'" : "'native'", " flags must be used for functions at top-level."}); - } -} - -void ETSParser::ParseTokenOfFunction(ir::ModifierFlags memberModifiers, lexer::SourcePosition startLoc, - ArenaVector &globalProperties) -{ - Lexer()->NextToken(); - // check whether it is an extension function - ir::Identifier *className = nullptr; - if (Lexer()->Lookahead() == lexer::LEX_CHAR_DOT) { - className = ExpectIdentifier(); - Lexer()->NextToken(); - } - - auto *memberName = ExpectIdentifier(); - auto *classMethod = ParseClassMethodDefinition(memberName, memberModifiers, className); - classMethod->SetStart(startLoc); - if (!classMethod->Function()->IsOverload()) { - globalProperties.push_back(classMethod); - } -} - -// NOLINTNEXTLINE(google-default-arguments) -ir::Statement *ETSParser::ParseTopLevelStatement(StatementParsingFlags flags) -{ - switch (auto const tokenType = Lexer()->GetToken().Type(); tokenType) { - case lexer::TokenType::PUNCTUATOR_LEFT_BRACE: { - return ParseBlockStatement(); - } - case lexer::TokenType::PUNCTUATOR_SEMI_COLON: { - return ParseEmptyStatement(); - } - case lexer::TokenType::KEYW_ASSERT: { - return ParseAssertStatement(); - } - case lexer::TokenType::KEYW_IF: { - return ParseIfStatement(); - } - case lexer::TokenType::KEYW_DO: { - return ParseDoWhileStatement(); - } - case lexer::TokenType::KEYW_FOR: { - return ParseForStatement(); - } - case lexer::TokenType::KEYW_TRY: { - return ParseTryStatement(); - } - case lexer::TokenType::KEYW_WHILE: { - return ParseWhileStatement(); - } - case lexer::TokenType::KEYW_BREAK: { - return ParseBreakStatement(); - } - case lexer::TokenType::KEYW_CONTINUE: { - return ParseContinueStatement(); - } - case lexer::TokenType::KEYW_THROW: { - return ParseThrowStatement(); - } - case lexer::TokenType::KEYW_SWITCH: { - return ParseSwitchStatement(); - } - case lexer::TokenType::KEYW_DEBUGGER: { - return ParseDebuggerStatement(); - } - case lexer::TokenType::LITERAL_IDENT: { - if (Lexer()->Lookahead() == lexer::LEX_CHAR_COLON) { - const auto pos = Lexer()->Save(); - Lexer()->NextToken(); - return ParseLabelledStatement(pos); - } - - return ParseExpressionStatement(flags); - } - // These cases never can occur here! - case lexer::TokenType::KEYW_EXPORT: - [[fallthrough]]; - case lexer::TokenType::KEYW_IMPORT: - [[fallthrough]]; - case lexer::TokenType::KEYW_RETURN: { - ThrowUnexpectedToken(tokenType); + case lexer::TokenType::LITERAL_IDENT: { + result = ParseIdentKeyword(); + break; } - // Note: let's leave the default processing case separately, because it can be changed in the future. default: { - ThrowUnexpectedToken(tokenType); - // return ParseExpressionStatement(flags); + break; } } + if (result != nullptr) { + result->AddModifier(memberModifiers); + } + return result; } -void ETSParser::ParseTopLevelDeclaration(ArenaVector &statements) +ir::Statement *ETSParser::ParseTopLevelStatement() { - lexer::SourcePosition classBodyStartLoc = Lexer()->GetToken().Start(); - auto globalProperties = ParseTopLevelStatements(statements); - - auto *classDef = GetProgram()->GlobalClass(); + const auto flags = StatementParsingFlags::ALLOW_LEXICAL; + static const std::unordered_set ALLOWED_TOP_LEVEL_STMTS = { + lexer::TokenType::PUNCTUATOR_LEFT_BRACE, + lexer::TokenType::PUNCTUATOR_SEMI_COLON, + lexer::TokenType::KEYW_ASSERT, + lexer::TokenType::KEYW_IF, + lexer::TokenType::KEYW_DO, + lexer::TokenType::KEYW_FOR, + lexer::TokenType::KEYW_TRY, + lexer::TokenType::KEYW_WHILE, + lexer::TokenType::KEYW_BREAK, + lexer::TokenType::KEYW_CONTINUE, + lexer::TokenType::KEYW_THROW, + lexer::TokenType::KEYW_SWITCH, + lexer::TokenType::KEYW_DEBUGGER, + lexer::TokenType::LITERAL_IDENT, + }; - if (classDef->IsGlobalInitialized()) { - classDef->AddProperties(std::move(globalProperties)); - Lexer()->NextToken(); - return; + auto result = ParseTopLevelDeclStatement(flags); + if (result == nullptr) { + auto const tokenType = Lexer()->GetToken().Type(); + if (ALLOWED_TOP_LEVEL_STMTS.count(tokenType) != 0U) { + result = ParseStatement(flags); + } else { + ThrowUnexpectedToken(tokenType); + } } + return result; +} - CreateCCtor(globalProperties, classBodyStartLoc, GetProgram()->Kind() != ScriptKind::STDLIB); - classDef->AddProperties(std::move(globalProperties)); - auto *classDecl = classDef->Parent()->AsClassDeclaration(); - classDef->SetGlobalInitialized(); - classDef->SetRange(classDef->Range()); - - statements.push_back(classDecl); +ArenaVector ETSParser::ParseTopLevelDeclaration() +{ + auto topStatements = ParseTopLevelStatements(); Lexer()->NextToken(); + return topStatements; } -// NOLINTNEXTLINE(google-default-arguments) -void ETSParser::CreateCCtor(ArenaVector &properties, const lexer::SourcePosition &loc, - const bool inGlobalClass) +static bool IsClassModifier(lexer::TokenType type) { - bool hasStaticField = false; - for (const auto *prop : properties) { - if (prop->IsClassStaticBlock()) { - return; - } + return type == lexer::TokenType::KEYW_STATIC || type == lexer::TokenType::KEYW_ABSTRACT || + type == lexer::TokenType::KEYW_FINAL; +} - if (!prop->IsClassProperty()) { - continue; +ir::Statement *ETSParser::ParseIdentKeyword() +{ + const auto token = Lexer()->GetToken(); + ASSERT(token.Type() == lexer::TokenType::LITERAL_IDENT); + switch (token.KeywordType()) { + case lexer::TokenType::KEYW_STRUCT: { + return ParseTypeDeclaration(false); } - - const auto *field = prop->AsClassProperty(); - - if (field->IsStatic()) { - hasStaticField = true; + case lexer::TokenType::KEYW_TYPE: { + return ParseTypeAliasDeclaration(); } - } - - if (!hasStaticField && !inGlobalClass) { - return; - } - - ArenaVector params(Allocator()->Adapter()); - - auto *id = AllocNode(compiler::Signatures::CCTOR, Allocator()); - - ArenaVector statements(Allocator()->Adapter()); - - // Add the call to special '_$init$_' method containing all the top-level variable initializations (as assignments) - // and statements to the end of static constructor of the global class. - if (inGlobalClass) { - if (auto const it = std::find_if(properties.begin(), properties.end(), - [](ir::AstNode const *const item) { - return item->IsMethodDefinition() && - item->AsMethodDefinition()->Id()->Name() == - compiler::Signatures::INIT_METHOD; - }); - it != properties.end()) { - if (!(*it)->AsMethodDefinition()->Function()->Body()->AsBlockStatement()->Statements().empty()) { - auto *const callee = AllocNode(compiler::Signatures::INIT_METHOD, Allocator()); - callee->SetReference(); - - auto *const callExpr = AllocNode( - callee, ArenaVector(Allocator()->Adapter()), nullptr, false, false); - - statements.emplace_back(AllocNode(callExpr)); - } + default: { + break; } } - - auto *body = AllocNode(Allocator(), std::move(statements)); - auto *func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, - ir::ModifierFlags::STATIC, false, GetContext().GetLanguge()); - func->SetIdent(id); - - auto *funcExpr = AllocNode(func); - auto *staticBlock = AllocNode(funcExpr, Allocator()); - staticBlock->AddModifier(ir::ModifierFlags::STATIC); - staticBlock->SetRange({loc, loc}); - properties.push_back(staticBlock); -} - -static bool IsClassModifier(lexer::TokenType type) -{ - return type == lexer::TokenType::KEYW_STATIC || type == lexer::TokenType::KEYW_ABSTRACT || - type == lexer::TokenType::KEYW_FINAL; + return nullptr; } ir::ModifierFlags ETSParser::ParseClassModifiers() @@ -1312,10 +659,9 @@ ir::ModifierFlags ETSParser::ParseClassMethodModifiers(bool seenStatic) // NOLINTNEXTLINE(google-default-arguments) void ETSParser::ParseClassFieldDefinition(ir::Identifier *fieldName, ir::ModifierFlags modifiers, - ArenaVector *declarations, ir::ScriptFunction *initFunction, - lexer::SourcePosition *letLoc) + ArenaVector *declarations, lexer::SourcePosition *letLoc) { - lexer::SourcePosition startLoc = letLoc != nullptr ? *letLoc : Lexer()->GetToken().Start(); + lexer::SourcePosition startLoc = letLoc != nullptr ? *letLoc : fieldName->Start(); lexer::SourcePosition endLoc = startLoc; ir::TypeNode *typeAnnotation = nullptr; TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -1332,21 +678,12 @@ void ETSParser::ParseClassFieldDefinition(ir::Identifier *fieldName, ir::Modifie } else if (typeAnnotation == nullptr) { ThrowSyntaxError("Field type annotation expected"); } - - // Add initialization of top-level (global) variables to a special '_$init$_' function so that it could be - // performed multiple times. - if (initFunction != nullptr && (modifiers & ir::ModifierFlags::CONST) == 0U && initializer != nullptr && - !initializer->IsArrowFunctionExpression()) { - endLoc = InitializeGlobalVariable(fieldName, initializer, initFunction, startLoc, typeAnnotation); - } - bool isDeclare = (modifiers & ir::ModifierFlags::DECLARE) != 0; if (isDeclare && initializer != nullptr) { ThrowSyntaxError("Initializers are not allowed in ambient contexts."); } auto *field = AllocNode(fieldName, initializer, typeAnnotation, modifiers, Allocator(), false); - startLoc = fieldName->Start(); if (initializer != nullptr) { endLoc = initializer->End(); } else { @@ -1354,7 +691,6 @@ void ETSParser::ParseClassFieldDefinition(ir::Identifier *fieldName, ir::Modifie } field->SetRange({startLoc, endLoc}); - fieldMap_.insert({fieldName->Name(), field}); declarations->push_back(field); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { @@ -1396,7 +732,8 @@ lexer::SourcePosition ETSParser::InitializeGlobalVariable(ir::Identifier *fieldN } ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *methodName, ir::ModifierFlags modifiers, - ir::Identifier *className, ir::Identifier *identNode) + ir::Identifier *className, + [[maybe_unused]] ir::Identifier *identNode) { auto newStatus = ParserStatus::NEED_RETURN_TYPE | ParserStatus::ALLOW_SUPER; auto methodKind = ir::MethodDefinitionKind::METHOD; @@ -1430,10 +767,6 @@ ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *meth } auto *method = AllocNode(methodKind, methodName, funcExpr, modifiers, Allocator(), false); method->SetRange(funcExpr->Range()); - - fieldMap_.insert({methodName->Name(), method}); - AddProxyOverloadToMethodWithDefaultParams(method, identNode); - return method; } @@ -1903,12 +1236,10 @@ ir::TSTypeAliasDeclaration *ETSParser::ParseTypeAliasDeclaration() params->SetParent(typeAliasDecl); } - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { + if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_SUBSTITUTION)) { ThrowSyntaxError("'=' expected"); } - Lexer()->NextToken(); // eat '=' - TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; ir::TypeNode *typeAnnotation = ParseTypeAnnotation(&options); typeAliasDecl->SetTsTypeAnnotation(typeAnnotation); @@ -1950,7 +1281,7 @@ ir::TSInterfaceDeclaration *ETSParser::ParseInterfaceBody(ir::Identifier *name, auto *body = AllocNode(std::move(members)); body->SetRange({bodyStart, Lexer()->GetToken().End()}); - const auto isExternal = (GetContext().Status() & ParserStatus::IN_EXTERNAL); + const auto isExternal = IsExternal(); auto *interfaceDecl = AllocNode( Allocator(), name, typeParamDecl, body, std::move(extends), isStatic, isExternal, GetContext().GetLanguge()); @@ -2049,7 +1380,6 @@ ir::ClassDefinition *ETSParser::ParseClassDefinition(ir::ClassDefinitionModifier // Parse ClassBody auto [ctor, properties, bodyRange] = ParseClassBody(modifiers, flags, identNode); - CreateCCtor(properties, bodyRange.start); auto *classDefinition = AllocNode( util::StringView(), identNode, typeParamDecl, superTypeParams, std::move(implements), ctor, superClass, @@ -2113,17 +1443,16 @@ ir::ClassProperty *ETSParser::ParseInterfaceField() Lexer()->NextToken(); ir::TypeNode *typeAnnotation = nullptr; - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COLON) { - ThrowSyntaxError("Interface fields must have typeannotation."); + if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_COLON)) { + ThrowSyntaxError("Interface fields must have type annotation."); } - Lexer()->NextToken(); // eat ':' TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; typeAnnotation = ParseTypeAnnotation(&options); name->SetTsTypeAnnotation(typeAnnotation); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_EQUAL) { - ThrowSyntaxError("Initializers are not allowed on interface propertys."); + ThrowSyntaxError("Initializers are not allowed on interface properties."); } ir::ModifierFlags fieldModifiers = ir::ModifierFlags::PUBLIC; @@ -2231,119 +1560,6 @@ std::pair ETSParser::CheckDefaultParameters(const ir::ScriptF return std::make_pair(hasDefaultParameter, requiredParametersNumber); } -ir::MethodDefinition *ETSParser::CreateProxyConstructorDefinition(ir::MethodDefinition const *const method) -{ - ASSERT(method->IsConstructor()); - - const auto *const function = method->Function(); - std::string proxyMethod = function->Id()->Name().Mutf8() + '('; - - for (const auto *const it : function->Params()) { - auto const *const param = it->AsETSParameterExpression(); - proxyMethod += param->Ident()->Name().Mutf8() + ": " + GetNameForTypeNode(param->TypeAnnotation()) + ", "; - } - - proxyMethod += ir::PROXY_PARAMETER_NAME; - proxyMethod += ": int) { this("; - - auto const parametersNumber = function->Params().size(); - for (size_t i = 0U; i < parametersNumber; ++i) { - if (auto const *const param = function->Params()[i]->AsETSParameterExpression(); param->IsDefault()) { - std::string proxyIf = "(((" + std::string {ir::PROXY_PARAMETER_NAME} + " >> " + std::to_string(i) + - ") & 0x1) == 0) ? " + param->Ident()->Name().Mutf8() + " : (" + - param->LexerSaved().Mutf8() + "), "; - proxyMethod += proxyIf; - } else { - proxyMethod += function->Params()[i]->AsETSParameterExpression()->Ident()->Name().Mutf8() + ", "; - } - } - - proxyMethod.pop_back(); // Note: at least one parameter always should present! - proxyMethod.pop_back(); - proxyMethod += ") }"; - - return CreateConstructorDefinition(method->Modifiers(), proxyMethod, DEFAULT_PROXY_FILE); -} - -ir::MethodDefinition *ETSParser::CreateProxyMethodDefinition(ir::MethodDefinition const *const method, - ir::Identifier const *const identNode) -{ - ASSERT(!method->IsConstructor()); - - const auto *const function = method->Function(); - std::string proxyMethod = function->Id()->Name().Mutf8() + "_proxy("; - - for (const auto *const it : function->Params()) { - auto const *const param = it->AsETSParameterExpression(); - proxyMethod += param->Ident()->Name().Mutf8() + ": " + GetNameForTypeNode(param->TypeAnnotation()) + ", "; - } - - const bool hasFunctionReturnType = function->ReturnTypeAnnotation() != nullptr; - const std::string returnType = hasFunctionReturnType ? GetNameForTypeNode(function->ReturnTypeAnnotation()) : ""; - - proxyMethod += ir::PROXY_PARAMETER_NAME; - proxyMethod += ": int)"; - if (hasFunctionReturnType) { - proxyMethod += ": " + returnType; - } - proxyMethod += " { "; - - auto const parametersNumber = function->Params().size(); - for (size_t i = 0U; i < parametersNumber; ++i) { - if (auto const *const param = function->Params()[i]->AsETSParameterExpression(); param->IsDefault()) { - std::string proxyIf = "if (((" + std::string {ir::PROXY_PARAMETER_NAME} + " >> " + std::to_string(i) + - ") & 0x1) == 1) { " + param->Ident()->Name().Mutf8() + " = " + - param->LexerSaved().Mutf8() + " } "; - proxyMethod += proxyIf; - } - } - - proxyMethod += ' '; - if (returnType != "void") { - proxyMethod += "return "; - } - - if (identNode != nullptr) { - if (method->IsStatic()) { - ASSERT(identNode != nullptr); - proxyMethod += identNode->Name().Mutf8() + "."; - } else { - proxyMethod += "this."; - } - } - - proxyMethod += function->Id()->Name().Mutf8(); - proxyMethod += '('; - - for (const auto *const it : function->Params()) { - proxyMethod += it->AsETSParameterExpression()->Ident()->Name().Mutf8() + ", "; - } - proxyMethod.pop_back(); - proxyMethod.pop_back(); - proxyMethod += ") }"; - - return CreateMethodDefinition(method->Modifiers(), proxyMethod, DEFAULT_PROXY_FILE); -} - -void ETSParser::AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *identNode) -{ - if (auto const [has_default_parameters, required_parameters] = CheckDefaultParameters(method->Function()); - has_default_parameters) { - if (ir::MethodDefinition *proxyMethodDef = !method->IsConstructor() - ? CreateProxyMethodDefinition(method, identNode) - : CreateProxyConstructorDefinition(method); - proxyMethodDef != nullptr) { - auto *const proxyParam = proxyMethodDef->Function()->Params().back()->AsETSParameterExpression(); - proxyParam->SetRequiredParams(required_parameters); - - proxyMethodDef->Function()->SetDefaultParamProxy(); - proxyMethodDef->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); - method->AddOverload(proxyMethodDef); - proxyMethodDef->SetParent(method); - } - } -} - std::string ETSParser::PrimitiveTypeToName(ir::PrimitiveType type) { switch (type) { @@ -2489,8 +1705,7 @@ ir::AstNode *ETSParser::ParseTypeLiteralOrInterfaceMember() return ParseInterfaceGetterSetterMethod(methodFlags); } - if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_READONLY) { - Lexer()->NextToken(); // eat 'readonly' keyword + if (Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_READONLY)) { auto *field = ParseInterfaceField(); field->SetStart(startLoc); field->AddModifier(ir::ModifierFlags::READONLY); @@ -3057,7 +2272,7 @@ ir::DebuggerStatement *ETSParser::ParseDebuggerStatement() ThrowUnexpectedToken(lexer::TokenType::KEYW_DEBUGGER); } -void ETSParser::ParseExport(lexer::SourcePosition startLoc) +ir::Statement *ETSParser::ParseReExport(lexer::SourcePosition startLoc) { ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY || Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE); @@ -3066,11 +2281,18 @@ void ETSParser::ParseExport(lexer::SourcePosition startLoc) if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { ParseNameSpaceSpecifier(&specifiers, true); } else { - ParseNamedSpecifiers(&specifiers, true); + auto specs = ParseNamedSpecifiers(); - if (Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_FROM) { - // selective export directive - return; + if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_FROM) { + specifiers = util::Helpers::ConvertVector(specs); + } else { + ArenaVector exports(Allocator()->Adapter()); + for (auto spec : specs) { + exports.emplace_back(AllocNode(spec->Local(), spec->Imported())); + } + auto selectiveExport = AllocNode( + Allocator(), static_cast(nullptr), std::move(exports)); + return selectiveExport; } } @@ -3084,16 +2306,12 @@ void ETSParser::ParseExport(lexer::SourcePosition startLoc) auto *reExportDeclaration = AllocNode(reExportSource, specifiers); reExportDeclaration->SetRange({startLoc, endLoc}); - auto varbinder = GetProgram()->VarBinder()->AsETSBinder(); - if (reExportDeclaration->Language().IsDynamic()) { - varbinder->AddDynamicImport(reExportDeclaration); - } - ConsumeSemicolon(reExportDeclaration); - auto *reExport = Allocator()->New(reExportDeclaration, userPaths, - GetProgram()->SourceFilePath(), Allocator()); - varbinder->AddReExportImport(reExport); + auto *reExport = AllocNode(reExportDeclaration, userPaths, + GetProgram()->SourceFilePath(), Allocator()); + reExports_.emplace_back(reExport); + return reExport; } ir::Statement *ETSParser::ParseFunctionStatement([[maybe_unused]] const StatementParsingFlags flags) @@ -3102,13 +2320,13 @@ ir::Statement *ETSParser::ParseFunctionStatement([[maybe_unused]] const Statemen ThrowSyntaxError("Nested functions are not allowed"); } -void ETSParser::ParsePackageDeclaration(ArenaVector &statements) +ir::ETSPackageDeclaration *ETSParser::ParsePackageDeclaration() { auto startLoc = Lexer()->GetToken().Start(); if (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_PACKAGE) { if (!IsETSModule() && GetProgram()->IsEntryPoint()) { - return; + return nullptr; } auto baseName = GetProgram()->SourceFilePath().Utf8(); @@ -3120,7 +2338,7 @@ void ETSParser::ParsePackageDeclaration(ArenaVector &statements GetProgram()->SetPackageName(baseName); - return; + return nullptr; } Lexer()->NextToken(); @@ -3131,13 +2349,13 @@ void ETSParser::ParsePackageDeclaration(ArenaVector &statements packageDeclaration->SetRange({startLoc, Lexer()->GetToken().End()}); ConsumeSemicolon(packageDeclaration); - statements.push_back(packageDeclaration); if (name->IsIdentifier()) { GetProgram()->SetPackageName(name->AsIdentifier()->Name()); } else { GetProgram()->SetPackageName(name->AsTSQualifiedName()->ToString(Allocator())); } + return packageDeclaration; } std::tuple> ETSParser::ParseFromClause(bool requireFrom) @@ -3158,8 +2376,7 @@ std::tuple> ETSParser::ParseFromCla std::vector userPaths; bool isModule = false; auto importPath = Lexer()->GetToken().Ident(); - auto resolvedImportPath = ResolveImportPath(importPath.Mutf8()); - resolvedParsedSources_.emplace(importPath.Mutf8(), resolvedImportPath); + auto resolvedImportPath = ValidatePathResolver(pathResolver_.ResolveImportPath(importPath.Mutf8(), GetProgram())); ir::StringLiteral *resolvedSource; if (*importPath.Bytes() == '/') { @@ -3168,7 +2385,7 @@ std::tuple> ETSParser::ParseFromCla resolvedSource = AllocNode(importPath); } - auto importData = GetImportData(resolvedImportPath); + auto importData = pathResolver_.GetImportData(resolvedImportPath); if ((GetContext().Status() & ParserStatus::IN_DEFAULT_IMPORTS) == 0) { std::tie(userPaths, isModule) = CollectUserSources(importPath.Mutf8()); @@ -3197,11 +2414,11 @@ std::tuple> ETSParser::ParseFromCla return {importSource, userPaths}; } -std::vector ETSParser::ParseImportDeclarations(ArenaVector &statements) +std::pair, std::vector> ETSParser::ParseImportDeclarations() { std::vector allUserPaths; std::vector userPaths; - ArenaVector imports(Allocator()->Adapter()); + ArenaVector statements(Allocator()->Adapter()); while (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_IMPORT) { auto startLoc = Lexer()->GetToken().Start(); @@ -3213,7 +2430,8 @@ std::vector ETSParser::ParseImportDeclarations(ArenaVectorGetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { ParseNameSpaceSpecifier(&specifiers); } else if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { - ParseNamedSpecifiers(&specifiers); + auto specs = ParseNamedSpecifiers(); + specifiers = util::Helpers::ConvertVector(specs); } else { ParseImportDefaultSpecifier(&specifiers); } @@ -3228,37 +2446,28 @@ std::vector ETSParser::ParseImportDeclarations(ArenaVector bool { - return s1->IsETSImportDeclaration() && s2->IsETSImportDeclaration() && - s1->AsETSImportDeclaration()->Specifiers()[0]->IsImportNamespaceSpecifier() && - !s2->AsETSImportDeclaration()->Specifiers()[0]->IsImportNamespaceSpecifier(); + std::sort(statements.begin(), statements.end(), [](const auto *s1, const auto *s2) -> bool { + return s1->Specifiers()[0]->IsImportNamespaceSpecifier() && !s2->Specifiers()[0]->IsImportNamespaceSpecifier(); }); - if ((GetContext().Status() & ParserStatus::IN_DEFAULT_IMPORTS) != 0) { - static_cast(GetProgram()->VarBinder()) - ->SetDefaultImports(std::move(imports)); // get rid of it - } - - sort(allUserPaths.begin(), allUserPaths.end()); - allUserPaths.erase(unique(allUserPaths.begin(), allUserPaths.end()), allUserPaths.end()); + std::sort(allUserPaths.begin(), allUserPaths.end()); + allUserPaths.erase(std::unique(allUserPaths.begin(), allUserPaths.end()), allUserPaths.end()); - return allUserPaths; + return std::make_pair(statements, allUserPaths); } -void ETSParser::ParseNamedSpecifiers(ArenaVector *specifiers, bool isExport) +ArenaVector ETSParser::ParseNamedSpecifiers() { - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); // NOTE(user): handle qualifiedName in file bindings: qualifiedName '.' '*' - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { + if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_LEFT_BRACE)) { ThrowExpectedToken(lexer::TokenType::PUNCTUATOR_LEFT_BRACE); } - Lexer()->NextToken(); // eat '{' auto fileName = GetProgram()->SourceFilePath().Mutf8(); - std::vector exportedIdents; + + ArenaVector result(Allocator()->Adapter()); while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { @@ -3276,8 +2485,7 @@ void ETSParser::ParseNamedSpecifiers(ArenaVector *specifiers, boo Lexer()->NextToken(); // eat import/export name - if (CheckModuleAsModifier() && Lexer()->GetToken().Type() == lexer::TokenType::KEYW_AS) { - Lexer()->NextToken(); // eat `as` literal + if (CheckModuleAsModifier() && Lexer()->TryEatTokenType(lexer::TokenType::KEYW_AS)) { local = ParseNamedImport(Lexer()->GetToken()); Lexer()->NextToken(); // eat local name } else { @@ -3287,13 +2495,9 @@ void ETSParser::ParseNamedSpecifiers(ArenaVector *specifiers, boo auto *specifier = AllocNode(imported, local); specifier->SetRange({imported->Start(), local->End()}); - util::Helpers::CheckImportedName(specifiers, specifier, fileName); + util::Helpers::CheckImportedName(result, specifier, fileName); - if (isExport) { - util::StringView memberName = local->Name(); - exportedIdents.push_back(memberName); - } - specifiers->push_back(specifier); + result.emplace_back(specifier); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { Lexer()->NextToken(lexer::NextTokenFlags::KEYWORD_TO_IDENT); // eat comma @@ -3302,12 +2506,7 @@ void ETSParser::ParseNamedSpecifiers(ArenaVector *specifiers, boo Lexer()->NextToken(); // eat '}' - if (isExport && Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_FROM) { - // update exported idents to export name map when it is not the case of re-export - for (auto memberName : exportedIdents) { - exportNameMap_.insert({memberName, startLoc}); - } - } + return result; } void ETSParser::ParseNameSpaceSpecifier(ArenaVector *specifiers, bool isReExport) @@ -3415,40 +2614,37 @@ static constexpr char const ONLY_ARRAY_FOR_REST[] = "Rest parameter should be of static constexpr char const EXPLICIT_PARAM_TYPE[] = "Parameter declaration should have an explicit type annotation."; // NOLINTEND(modernize-avoid-c-arrays) -ir::Expression *ETSParser::ParseFunctionParameter() +std::pair ETSParser::TypeAnnotationValue(ir::TypeNode *typeAnnotation) { - ir::ETSParameterExpression *paramExpression; - auto *const paramIdent = GetAnnotatedExpressionFromParam(); - - bool defaultUndefined = false; - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { - if (paramIdent->IsRestElement()) { - ThrowSyntaxError(NO_DEFAULT_FOR_REST); - } - defaultUndefined = true; - Lexer()->NextToken(); // eat '?' + if (typeAnnotation == nullptr) { + return std::make_pair(nullptr, ""); } - - const bool isArrow = (GetContext().Status() & ParserStatus::ARROW_FUNCTION) != 0; - - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { - Lexer()->NextToken(); // eat ':' - - TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; - ir::TypeNode *typeAnnotation = ParseTypeAnnotation(&options); - - if (paramIdent->IsRestElement() && !typeAnnotation->IsTSArrayType()) { - ThrowSyntaxError(ONLY_ARRAY_FOR_REST); + if (!typeAnnotation->IsETSPrimitiveType()) { + return std::make_pair(AllocNode(), "undefined"); + } + // NOTE(ttamas) : after nullable fix, fix this scope + switch (typeAnnotation->AsETSPrimitiveType()->GetPrimitiveType()) { + case ir::PrimitiveType::BYTE: + case ir::PrimitiveType::INT: + case ir::PrimitiveType::LONG: + case ir::PrimitiveType::SHORT: + case ir::PrimitiveType::FLOAT: + case ir::PrimitiveType::DOUBLE: + return std::make_pair(AllocNode(lexer::Number(0)), "0"); + case ir::PrimitiveType::BOOLEAN: + return std::make_pair(AllocNode(false), "false"); + case ir::PrimitiveType::CHAR: + return std::make_pair(AllocNode(), "c'\\u0000'"); + default: { + UNREACHABLE(); } - - typeAnnotation->SetParent(paramIdent); - paramIdent->SetTsTypeAnnotation(typeAnnotation); - paramIdent->SetEnd(typeAnnotation->End()); - - } else if (!isArrow && !defaultUndefined) { - ThrowSyntaxError(EXPLICIT_PARAM_TYPE); } +} +ir::ETSParameterExpression *ETSParser::ParseFunctionParameterTail(ir::AnnotatedExpression *paramIdent, + bool defaultUndefined) +{ + ir::ETSParameterExpression *paramExpression; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { if (paramIdent->IsRestElement()) { ThrowSyntaxError(NO_DEFAULT_FOR_REST); @@ -3480,42 +2676,16 @@ ir::Expression *ETSParser::ParseFunctionParameter() paramExpression->SetRange({paramIdent->Start(), paramExpression->Initializer()->End()}); } else if (paramIdent->IsIdentifier()) { auto *const typeAnnotation = paramIdent->AsIdentifier()->TypeAnnotation(); - - const auto typeAnnotationValue = [this, typeAnnotation]() -> std::pair { - if (typeAnnotation == nullptr) { - return std::make_pair(nullptr, ""); - } - if (!typeAnnotation->IsETSPrimitiveType()) { - return std::make_pair(AllocNode(), "undefined"); - } - // NOTE(ttamas) : after nullable fix, fix this scope - switch (typeAnnotation->AsETSPrimitiveType()->GetPrimitiveType()) { - case ir::PrimitiveType::BYTE: - case ir::PrimitiveType::INT: - case ir::PrimitiveType::LONG: - case ir::PrimitiveType::SHORT: - case ir::PrimitiveType::FLOAT: - case ir::PrimitiveType::DOUBLE: - return std::make_pair(AllocNode(lexer::Number(0)), "0"); - case ir::PrimitiveType::BOOLEAN: - return std::make_pair(AllocNode(false), "false"); - case ir::PrimitiveType::CHAR: - return std::make_pair(AllocNode(), "c'\\u0000'"); - default: { - UNREACHABLE(); - } - } - }(); - + auto [literal, defaultValue] = TypeAnnotationValue(typeAnnotation); if (defaultUndefined && !typeAnnotation->IsETSPrimitiveType()) { typeAnnotation->AddModifier(ir::ModifierFlags::UNDEFINED_ASSIGNABLE); } - paramExpression = AllocNode( - paramIdent->AsIdentifier(), defaultUndefined ? std::get<0>(typeAnnotationValue) : nullptr); + paramExpression = + AllocNode(paramIdent->AsIdentifier(), defaultUndefined ? literal : nullptr); if (defaultUndefined) { - paramExpression->SetLexerSaved(util::UString(std::get<1>(typeAnnotationValue), Allocator()).View()); + paramExpression->SetLexerSaved(util::UString(defaultValue, Allocator()).View()); } paramExpression->SetRange({paramIdent->Start(), paramIdent->End()}); @@ -3523,10 +2693,43 @@ ir::Expression *ETSParser::ParseFunctionParameter() paramExpression = AllocNode(paramIdent->AsRestElement(), nullptr); paramExpression->SetRange({paramIdent->Start(), paramIdent->End()}); } - return paramExpression; } +ir::Expression *ETSParser::ParseFunctionParameter() +{ + auto *const paramIdent = GetAnnotatedExpressionFromParam(); + + bool defaultUndefined = false; + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { + if (paramIdent->IsRestElement()) { + ThrowSyntaxError(NO_DEFAULT_FOR_REST); + } + defaultUndefined = true; + Lexer()->NextToken(); // eat '?' + } + + const bool isArrow = (GetContext().Status() & ParserStatus::ARROW_FUNCTION) != 0; + + if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_COLON)) { + TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; + ir::TypeNode *typeAnnotation = ParseTypeAnnotation(&options); + + if (paramIdent->IsRestElement() && !typeAnnotation->IsTSArrayType()) { + ThrowSyntaxError(ONLY_ARRAY_FOR_REST); + } + + typeAnnotation->SetParent(paramIdent); + paramIdent->SetTsTypeAnnotation(typeAnnotation); + paramIdent->SetEnd(typeAnnotation->End()); + + } else if (!isArrow && !defaultUndefined) { + ThrowSyntaxError(EXPLICIT_PARAM_TYPE); + } + + return ParseFunctionParameterTail(paramIdent, defaultUndefined); +} + ir::Expression *ETSParser::CreateParameterThis(const util::StringView className) { auto *paramIdent = AllocNode(varbinder::TypedBinder::MANDATORY_PARAM_THIS, Allocator()); @@ -4704,7 +3907,6 @@ bool ETSParser::ParsePotentialNonNullExpression(ir::Expression **expression, con const auto nonNullExpr = AllocNode(*expression); nonNullExpr->SetRange({startLoc, Lexer()->GetToken().End()}); - nonNullExpr->SetParent(*expression); *expression = nonNullExpr; @@ -5126,6 +4328,92 @@ ir::TypeNode *ETSParser::CreateTypeAnnotation(TypeAnnotationParsingOptions *opti return ParseTypeAnnotation(options); } +ir::FunctionDeclaration *ETSParser::ParseFunctionDeclaration(bool canBeAnonymous, ir::ModifierFlags modifiers) +{ + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::KEYW_FUNCTION); + Lexer()->NextToken(); + auto newStatus = ParserStatus::NEED_RETURN_TYPE | ParserStatus::ALLOW_SUPER; + + if ((modifiers & ir::ModifierFlags::ASYNC) != 0) { + newStatus |= ParserStatus::ASYNC_FUNCTION; + } + if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_MULTIPLY)) { + newStatus |= ParserStatus::GENERATOR_FUNCTION; + } + + ir::Identifier *className = nullptr; + ir::Identifier *identNode = nullptr; + if (Lexer()->Lookahead() == lexer::LEX_CHAR_DOT) { + className = ExpectIdentifier(); + if (className != nullptr) { + newStatus |= ParserStatus::IN_EXTENSION_FUNCTION; + } + Lexer()->NextToken(); + identNode = ExpectIdentifier(); + } else if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { + identNode = ExpectIdentifier(); + } else if (!canBeAnonymous) { + ThrowSyntaxError("Unexpected token, expected identifier after 'function' keyword"); + } + newStatus |= ParserStatus::FUNCTION_DECLARATION; + if (identNode != nullptr) { + CheckRestrictedBinding(identNode->Name(), identNode->Start()); + } + ir::ScriptFunction *func = ParseFunction(newStatus, className); + func->SetIdent(identNode); + auto *funcDecl = AllocNode(Allocator(), func); + if (func->IsOverload() && Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { + Lexer()->NextToken(); + } + funcDecl->SetRange(func->Range()); + func->AddModifier(modifiers); + func->SetStart(startLoc); + + if (className != nullptr) { + func->AddFlag(ir::ScriptFunctionFlags::INSTANCE_EXTENSION_METHOD); + } + + return funcDecl; +} + +std::pair ETSParser::ParseMemberModifiers() +{ + auto memberModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; + + if (Lexer()->TryEatTokenType(lexer::TokenType::KEYW_EXPORT)) { + memberModifiers |= ir::ModifierFlags::EXPORT; + if (Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_DEFAULT)) { + memberModifiers |= ir::ModifierFlags::DEFAULT_EXPORT; + } + } + + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + + if (Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE) { + CheckDeclare(); + memberModifiers |= ir::ModifierFlags::DECLARE; + } + const auto tokenType = Lexer()->GetToken().KeywordType(); + if (tokenType == lexer::TokenType::KEYW_ASYNC || tokenType == lexer::TokenType::KEYW_NATIVE) { + bool isAsync = tokenType == lexer::TokenType::KEYW_ASYNC; + + if (isAsync) { + memberModifiers |= ir::ModifierFlags::ASYNC; + } else { + memberModifiers |= ir::ModifierFlags::NATIVE; + } + Lexer()->NextToken(); + + if (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_FUNCTION) { + ThrowSyntaxError( + {isAsync ? "'async'" : "'native'", " flags must be used for functions only at top-level."}); + } + } + return std::make_pair(memberModifiers, startLoc); +} + //================================================================================================// // ExternalSourceParser class //================================================================================================// @@ -5167,4 +4455,3 @@ InnerSourceParser::~InnerSourceParser() parser_->GetProgram()->SetSource(savedSourceCode_, savedSourceFile_, savedSourceFilePath_); } } // namespace panda::es2panda::parser -#undef USE_UNIX_SYSCALL diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index ca5fefcf6dd60b559a9ea6ce69c2d83dc8834f40..abb23f8f62e40587be36aa58d338a17cade16ed5 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -18,6 +18,8 @@ #include #include "parserFlags.h" +#include "ir/ets/etsReExportDeclaration.h" +#include "util/importPathResolver.h" #include "util/arktsconfig.h" #include "TypedParser.h" @@ -41,7 +43,10 @@ inline constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; class ETSParser final : public TypedParser { public: ETSParser(Program *program, const CompilerOptions &options, ParserStatus status = ParserStatus::NO_OPTS) - : TypedParser(program, options, status), globalProgram_(GetProgram()) + : TypedParser(program, options, status), + globalProgram_(GetProgram()), + pathResolver_(ArkTSConfig(), options.stdLib, Extension()), + reExports_(Allocator()->Adapter()) { } @@ -57,9 +62,6 @@ public: } // Methods to create AST node(s) from the specified string (part of valid ETS-code!) - // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, - // and correct parent and, probably, variable set to the node(s) after obtaining - ir::Expression *CreateExpression(std::string_view sourceCode, ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS, std::string_view fileName = DEFAULT_SOURCE_FILE); @@ -93,63 +95,34 @@ public: return CreateFormattedStatements(sourceCode, insertingNodes, fileName); } + ArenaVector ParseDefaultSources(std::string_view srcFile, std::string_view importSrc, + const std::vector &paths); + private: - struct ImportData { - Language lang; - std::string module; - bool hasDecl; - }; - - std::map fieldMap_; - std::map exportNameMap_; void ParseProgram(ScriptKind kind) override; [[nodiscard]] std::unique_ptr InitLexer(const SourceFile &sourceFile) override; - void ParsePackageDeclaration(ArenaVector &statements); - ArenaVector ParseTopLevelStatements(ArenaVector &statements); - void ParseTopLevelType(ArenaVector &statements, bool &defaultExport, std::size_t currentPos, - std::function const &parserFunction); - void ParseTopLevelNextToken(ArenaVector &statements, ArenaVector &globalProperties, - ir::ScriptFunction *initFunction); - void ParseTopLevelNextTokenDefault(ArenaVector &statements, ir::ScriptFunction *initFunction, - size_t currentPos, lexer::TokenType tokenType, bool defaultExport); - ir::ModifierFlags ResolveMemberModifiers(); - lexer::SourcePosition ParseTopLevelNextTokenResolution(ArenaVector &statements, - ArenaVector &globalProperties, - ir::ScriptFunction *initFunction, size_t currentPos, - bool defaultExport); - void ParseTokenOfNative(panda::es2panda::lexer::TokenType tokenType, ir::ModifierFlags &memberModifiers); - void ParseTokenOfFunction(ir::ModifierFlags memberModifiers, lexer::SourcePosition startLoc, - ArenaVector &globalProperties); + ir::ETSPackageDeclaration *ParsePackageDeclaration(); + ArenaVector ParseTopLevelStatements(); + #ifdef USE_FTW static int NFTWCallBack(const char *fpath, const struct stat * /*unused*/, int tflag, struct FTW * /*unused*/); #endif - void ParseTopLevelDeclaration(ArenaVector &statements); - void CollectDefaultSources(); - void CollectUserSourcesFromIndex(const std::string &path, const std::string &resolvedPath, - std::vector &userPaths); - std::string ResolveImportPath(const std::string &path); - std::string ResolveFullPathFromRelative(const std::string &path); - ImportData GetImportData(const std::string &path); + ArenaVector ParseTopLevelDeclaration(); std::tuple, bool> CollectUserSources(const std::string &path); - std::tuple GetSourceRegularPath(const std::string &path, const std::string &resolvedPath); - void ParseSources(const std::vector &paths, bool isExternal = true); + std::vector ParseSources(std::vector paths); std::tuple> ParseFromClause(bool requireFrom); - void ParseNamedSpecifiers(ArenaVector *specifiers, bool isExport = false); - void ParseNamedExportSpecifiers(ArenaVector *specifiers, bool defaultExport); - void ParseUserSources(std::vector userParths); - std::vector ParseImportDeclarations(ArenaVector &statements); - void ParseDefaultSources(); - void ParseSource(const SourceFile &sourceFile); - void CreateGlobalClass(); - ArenaVector PrepareGlobalClass(); - ArenaVector PrepareExternalGlobalClass(const SourceFile &sourceFile); - void ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements); + ArenaVector ParseNamedSpecifiers(); + std::pair, std::vector> ParseImportDeclarations(); + parser::Program *ParseSource(const SourceFile &sourceFile); + void AddExternalSource(const std::vector &programs); + ir::ETSScript *ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements); ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers) override; ir::MethodDefinition *ParseClassGetterSetterMethod(const ArenaVector &properties, ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags memberModifiers); ir::MethodDefinition *ParseInterfaceGetterSetterMethod(ir::ModifierFlags modifiers); + ir::Statement *ParseIdentKeyword(); ir::Statement *ParseTypeDeclaration(bool allowStatic = false); ir::Statement *ParseTypeDeclarationAbstractFinal(bool allowStatic, ir::ClassDefinitionModifiers modifiers); ir::ModifierFlags ParseClassModifiers(); @@ -176,8 +149,7 @@ private: // NOLINTNEXTLINE(google-default-arguments) void ParseClassFieldDefinition(ir::Identifier *fieldName, ir::ModifierFlags modifiers, - ArenaVector *declarations, ir::ScriptFunction *initFunction = nullptr, - lexer::SourcePosition *letLoc = nullptr); + ArenaVector *declarations, lexer::SourcePosition *letLoc = nullptr); lexer::SourcePosition InitializeGlobalVariable(ir::Identifier *fieldName, ir::Expression *&initializer, ir::ScriptFunction *initFunction, lexer::SourcePosition &startLoc, ir::TypeNode *typeAnnotation); @@ -193,10 +165,6 @@ private: ir::TypeNode *ParseFunctionType(); ir::TypeNode *ParseETSTupleType(TypeAnnotationParsingOptions *options); std::pair CheckDefaultParameters(const ir::ScriptFunction *function) const; - ir::MethodDefinition *CreateProxyMethodDefinition(ir::MethodDefinition const *const method, - ir::Identifier const *const identNode); - ir::MethodDefinition *CreateProxyConstructorDefinition(ir::MethodDefinition const *const method); - void AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *identNode = nullptr); static std::string PrimitiveTypeToName(ir::PrimitiveType type); std::string GetNameForTypeNode(const ir::TypeNode *typeAnnotation, bool adjust = true) const; std::string GetNameForETSUnionType(const ir::TypeNode *typeAnnotation) const; @@ -220,6 +188,7 @@ private: ir::Statement *ParseTryStatement() override; ir::DebuggerStatement *ParseDebuggerStatement() override; void ParseExport(lexer::SourcePosition startLoc); + ir::Statement *ParseReExport(lexer::SourcePosition startLoc); ir::Statement *ParseImportDeclaration(StatementParsingFlags flags) override; ir::Statement *ParseExportDeclaration(StatementParsingFlags flags) override; ir::AnnotatedExpression *ParseVariableDeclaratorKey(VariableParsingFlags flags) override; @@ -230,6 +199,8 @@ private: ir::AstNode *ParseTypeLiteralOrInterfaceMember() override; void ParseNameSpaceSpecifier(ArenaVector *specifiers, bool isReExport = false); bool CheckModuleAsModifier(); + std::pair TypeAnnotationValue(ir::TypeNode *typeAnnotation); + ir::ETSParameterExpression *ParseFunctionParameterTail(ir::AnnotatedExpression *paramIdent, bool defaultUndefined); ir::Expression *ParseFunctionParameter() override; ir::AnnotatedExpression *GetAnnotatedExpressionFromParam(); // NOLINTNEXTLINE(google-default-arguments) @@ -287,6 +258,7 @@ private: ir::ThisExpression *ParseThisExpression() override; ir::TypeNode *ParseThisType(TypeAnnotationParsingOptions *options); ir::Statement *ParseFunctionStatement(StatementParsingFlags flags) override; + ir::FunctionDeclaration *ParseFunctionDeclaration(bool canBeAnonymous, ir::ModifierFlags modifiers); std::tuple ParseClassImplementsElement() override; ir::TypeNode *ParseInterfaceExtendsElement() override; // NOLINTNEXTLINE(google-default-arguments) @@ -301,17 +273,32 @@ private: bool CheckClassElement(ir::AstNode *property, ir::MethodDefinition *&ctor, ArenaVector &properties) override; - // NOLINTNEXTLINE(google-default-arguments) - void CreateCCtor(ArenaVector &properties, const lexer::SourcePosition &loc, - bool inGlobalClass = false) override; void CreateImplicitConstructor(ir::MethodDefinition *&ctor, ArenaVector &properties, ir::ClassDefinitionModifiers modifiers, const lexer::SourcePosition &startLoc) override; bool ParsePotentialGenericFunctionCall(ir::Expression *primaryExpr, ir::Expression **returnExpression, const lexer::SourcePosition &startLoc, bool ignoreCallExpression) override; bool ParsePotentialNonNullExpression(ir::Expression **expression, lexer::SourcePosition startLoc) override; - void MarkNodeAsExported(ir::AstNode *node, lexer::SourcePosition startPos, bool defaultExport, - std::size_t numOfElements = 1); + + std::pair ParseMemberModifiers(); + + template + Value ValidatePathResolver(util::ImportPathResolver::ResultT result) + { + if (result.IsError()) { + const auto &[code, error] = result.ExpectError(); + using ErrorCode = util::ImportPathResolver::ErrorCode; + switch (code) { + case ErrorCode::ARKTS_PREFIX_FAIL: + ThrowSyntaxError({"Can't find prefix for '", error, "' in ", ArkTSConfig()->ConfigPath()}); + case ErrorCode::INCORRECT_PATH: + ThrowSyntaxError("Incorrect path: " + error); + default: + UNREACHABLE(); + } + } + return std::move(*result); + } std::shared_ptr ArkTSConfig() const { @@ -325,6 +312,11 @@ private: bool IsStructKeyword() const; + bool IsExternal() const override + { + return pathResolver_.IsStdLib(GetProgram()); + } + // NOLINTNEXTLINE(google-default-arguments) ir::Expression *ParseExpression(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS) override; @@ -332,19 +324,17 @@ private: ir::ModifierFlags ParseTypeVarianceModifier(TypeAnnotationParsingOptions *const options); - ir::ScriptFunction *AddInitMethod(ArenaVector &globalProperties); - ir::Statement *ParseTopLevelStatement(StatementParsingFlags flags = StatementParsingFlags::NONE); + ir::Statement *ParseTopLevelDeclStatement(StatementParsingFlags flags); + ir::Statement *ParseTopLevelStatement(); void ParseTrailingBlock([[maybe_unused]] ir::CallExpression *callExpr) override; void CheckDeclare(); // Methods to create AST node(s) from the specified string (part of valid ETS-code!) - // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, - // and correct parent and, probably, variable set to the node(s) after obtaining + // NOTE: ScopeInitPhase, SetParent should be called on created subtree after calling any of these methods, // NOLINTBEGIN(modernize-avoid-c-arrays) inline static constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; - inline static constexpr char const DEFAULT_PROXY_FILE[] = ".ets"; // NOLINTEND(modernize-avoid-c-arrays) // NOLINTBEGIN(google-default-arguments) @@ -377,14 +367,14 @@ private: public: const std::unordered_map &ResolvedParsedSourcesMap() const { - return resolvedParsedSources_; + return pathResolver_.ResolvedParsedSourcesMap(); } private: parser::Program *globalProgram_; - std::vector parsedSources_; + util::ImportPathResolver pathResolver_; + ArenaVector reExports_; std::vector insertingNodes_ {}; - std::unordered_map resolvedParsedSources_; }; class ExternalSourceParser { diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index a3018356f2b0dc8c995306197b600d68d79f8d2f..9ba010c6eecd132e8d9b1ffae7e26be30e1fd950 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -460,7 +460,7 @@ ir::Statement *TypedParser::ParseInterfaceDeclaration(bool isStatic) auto *body = AllocNode(std::move(members)); body->SetRange({bodyStart, Lexer()->GetToken().End()}); - const auto isExternal = (GetContext().Status() & ParserStatus::IN_EXTERNAL); + const auto isExternal = IsExternal(); auto *interfaceDecl = AllocNode( Allocator(), id, typeParamDecl, body, std::move(extends), isStatic, isExternal, GetContext().GetLanguge()); interfaceDecl->SetRange({interfaceStart, Lexer()->GetToken().End()}); diff --git a/ets2panda/parser/TypedParser.h b/ets2panda/parser/TypedParser.h index fc04ce492f5562801b1d42faeab0df957580c7cf..ab7f2fd145a8b974463242d7f69ce8906e924ddb 100644 --- a/ets2panda/parser/TypedParser.h +++ b/ets2panda/parser/TypedParser.h @@ -144,13 +144,6 @@ protected: { return false; } - - // NOLINTNEXTLINE(google-default-arguments) - virtual void CreateCCtor([[maybe_unused]] ArenaVector &properties, - [[maybe_unused]] const lexer::SourcePosition &loc, - [[maybe_unused]] bool inGlobalClass = false) - { - } }; } // namespace panda::es2panda::parser diff --git a/ets2panda/parser/context/parserContext.h b/ets2panda/parser/context/parserContext.h index 926fc510f0f3a3a425aa047e84bd55866d54c64e..45df25c965de0b520bce9149cdc41dac00c38033 100644 --- a/ets2panda/parser/context/parserContext.h +++ b/ets2panda/parser/context/parserContext.h @@ -60,8 +60,6 @@ enum class ParserStatus : uint64_t { IN_CLASS_BODY = 1U << 25U, NEED_RETURN_TYPE = 1U << 26U, - IN_EXTERNAL = 1U << 27U, - IN_IMPORT = 1U << 28U, IN_DEFAULT_IMPORTS = 1U << 29U, IN_EXTENSION_FUNCTION = 1U << 30U, FUNCTION_HAS_RETURN_STATEMENT = 1U << 31U, diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 5eaa24e774c206db6312bfb73a1e4122b46ab6c1..752073c32eb310ba4e6d7ac7623669987ad3b075 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -1193,6 +1193,7 @@ void ParserImpl::CreateAmendedBinaryExpression(ir::Expression *const left, ir::E { auto *amended = GetAmendedChildExpression(right); + amended->SetParent(nullptr); // Next line overwrite parent auto *binaryExpr = AllocNode(left, amended, operatorType); binaryExpr->SetRange({left->Start(), amended->End()}); diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 5f4d6b623c1ca9ad05b63236f238f0573b00a73c..00bd35c383c6afe7159394070e090f6c313bf86b 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -87,7 +87,6 @@ void ParserImpl::ParseProgram(ScriptKind kind) lexer::SourcePosition startLoc = lexer_->GetToken().Start(); lexer_->NextToken(); program_->SetKind(kind); - program_->VarBinder()->InitTopScope(); auto statements = ParseStatementList(StatementParsingFlags::STMT_GLOBAL_LEXICAL); @@ -945,13 +944,13 @@ ir::SpreadElement *ParserImpl::ParseSpreadElement(ExpressionParseFlags flags) return spreadElementNode; } -void ParserImpl::CheckRestrictedBinding() +void ParserImpl::CheckRestrictedBinding() const { ASSERT(lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT); CheckRestrictedBinding(lexer_->GetToken().KeywordType()); } -void ParserImpl::CheckRestrictedBinding(lexer::TokenType keywordType) +void ParserImpl::CheckRestrictedBinding(lexer::TokenType keywordType) const { if (keywordType == lexer::TokenType::KEYW_ARGUMENTS || keywordType == lexer::TokenType::KEYW_EVAL) { ThrowSyntaxError( @@ -961,7 +960,7 @@ void ParserImpl::CheckRestrictedBinding(lexer::TokenType keywordType) } } -void ParserImpl::CheckRestrictedBinding(const util::StringView &ident, const lexer::SourcePosition &pos) +void ParserImpl::CheckRestrictedBinding(const util::StringView &ident, const lexer::SourcePosition &pos) const { if (ident.Is("eval") || ident.Is("arguments")) { ThrowSyntaxError( diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index 7939cd0fcf620e89a85d817ce0037f15cc1137c2..64760bba1b3b833a07169b4368e6e4e0ff6653bb 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -30,6 +30,7 @@ #include "parser/program/program.h" #include "util/enumbitops.h" #include "util/ustring.h" +#include "util/helpers.h" #include #include @@ -199,6 +200,8 @@ public: return reinterpret_cast(this); } + [[noreturn]] void ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const; + protected: virtual void ParseProgram(ScriptKind kind); static ExpressionParseFlags CarryExpressionParserFlag(ExpressionParseFlags origin, ExpressionParseFlags carry); @@ -277,25 +280,14 @@ protected: [[noreturn]] void ThrowSyntaxError(std::initializer_list list, const lexer::SourcePosition &pos) const; - [[noreturn]] void ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const; - template - T *AllocNodeNoSetParent(Args &&...args) + T *AllocNode(Args &&...args) { - auto *ret = program_->Allocator()->New(std::forward(args)...); + auto *ret = util::NodeAllocator::ForceSetParent( + Allocator(), std::forward(args)...); // Note: replace with AllocNode if (ret == nullptr) { ThrowAllocationError("Unsuccessful allocation during parsing"); } - - return ret; - } - - template - T *AllocNode(Args &&...args) - { - auto *ret = AllocNodeNoSetParent(std::forward(args)...); - ret->Iterate([ret](auto *child) { child->SetParent(ret); }); - return ret; } @@ -306,6 +298,12 @@ protected: bool CheckModuleAsModifier(); + // ETS extension + virtual bool IsExternal() const + { + return false; + } + ir::Identifier *ExpectIdentifier(bool isReference = false, bool isUserDefinedType = false); void ExpectToken(lexer::TokenType tokenType, bool consumeToken = true); @@ -399,9 +397,9 @@ protected: ir::ExportNamedDeclaration *ParseExportNamedSpecifiers(const lexer::SourcePosition &startLoc); ir::Statement *ParseVariableDeclaration(VariableParsingFlags flags = VariableParsingFlags::NO_OPTS); void ValidateDeclaratorId(); - void CheckRestrictedBinding(); - void CheckRestrictedBinding(lexer::TokenType keywordType); - void CheckRestrictedBinding(const util::StringView &ident, const lexer::SourcePosition &pos); + void CheckRestrictedBinding() const; + void CheckRestrictedBinding(lexer::TokenType keywordType) const; + void CheckRestrictedBinding(const util::StringView &ident, const lexer::SourcePosition &pos) const; ir::VariableDeclarator *ParseVariableDeclarator(VariableParsingFlags flags); ir::FunctionDeclaration *ParseFunctionDeclaration(bool canBeAnonymous = false, diff --git a/ets2panda/parser/program/program.h b/ets2panda/parser/program/program.h index b1a29f3b1ff073f70aac1f14421dac822e998085..4f6f013d97b722c4d002b47dd256e214230cb5f4 100644 --- a/ets2panda/parser/program/program.h +++ b/ets2panda/parser/program/program.h @@ -94,24 +94,24 @@ public: return sourceCode_; } - util::StringView SourceFilePath() const + const util::StringView &SourceFilePath() const { - return sourceFilePath_.GetPath(); + return sourceFile_.GetPath(); } - util::StringView SourceFileFolder() const + const util::Path &SourceFile() const { - return sourceFileFolder_; + return sourceFile_; } - util::StringView FileName() const + util::StringView SourceFileFolder() const { - return fileName_; + return sourceFileFolder_; } - util::StringView AbsoluteName() const + std::string PackagePath() const { - return absoluteName_; + return SourceFileFolder().Mutf8() + panda::os::file::File::GetPathDelim().at(0) + GetPackageName().Mutf8(); } util::StringView ResolvedFilePath() const @@ -163,17 +163,15 @@ public: const util::StringView &sourceFileFolder) { sourceCode_ = sourceCode; - sourceFilePath_ = util::Path(sourceFilePath, Allocator()); + sourceFile_ = util::Path(sourceFilePath, Allocator()); sourceFileFolder_ = sourceFileFolder; - absoluteName_ = util::UString(os::GetAbsolutePath(sourceFilePath.Utf8()), Allocator()).View(); } void SetSource(const panda::es2panda::SourceFile &sourceFile) { sourceCode_ = util::UString(sourceFile.source, Allocator()).View(); - sourceFilePath_ = util::Path(sourceFile.filePath, Allocator()); + sourceFile_ = util::Path(sourceFile.filePath, Allocator()); sourceFileFolder_ = util::UString(sourceFile.fileFolder, Allocator()).View(); - absoluteName_ = sourceFilePath_.GetAbsolutePath(); resolvedFilePath_ = util::UString(sourceFile.resolvedPath, Allocator()).View(); } @@ -187,16 +185,6 @@ public: packageName_ = packageName; } - void SetFileName(util::StringView fileName) - { - fileName_ = util::UString(fileName, Allocator()).View(); - } - - void SetAbsoluteName(util::StringView absouleName) - { - absoluteName_ = util::UString(absouleName, Allocator()).View(); - } - const bool &IsEntryPoint() const { return entryPoint_; @@ -225,11 +213,9 @@ private: ir::BlockStatement *ast_ {}; ir::ClassDefinition *globalClass_ {}; util::StringView sourceCode_ {}; - util::Path sourceFilePath_ {}; + util::Path sourceFile_ {}; util::StringView sourceFileFolder_ {}; util::StringView packageName_ {}; - util::StringView fileName_ {}; - util::StringView absoluteName_ {}; util::StringView resolvedFilePath_ {}; ExternalSource externalSources_; ScriptKind kind_ {}; diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index e56be215f7f5839c8e1f84ddaaf86f0f0a6ad94a..180ef5706fc663c95c4dd08e218711f48f863536 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -268,7 +268,7 @@ ir::ETSStructDeclaration *ParserImpl::ParseStructDeclaration(ir::ClassDefinition { const lexer::SourcePosition startLoc = lexer_->GetToken().Start(); modifiers |= ir::ClassDefinitionModifiers::DECLARATION; - if ((GetContext().Status() & ParserStatus::IN_EXTERNAL) != 0) { + if (IsExternal()) { modifiers |= ir::ClassDefinitionModifiers::FROM_EXTERNAL; } @@ -292,7 +292,7 @@ ir::ClassDeclaration *ParserImpl::ParseClassDeclaration(ir::ClassDefinitionModif { const lexer::SourcePosition startLoc = lexer_->GetToken().Start(); modifiers |= ir::ClassDefinitionModifiers::DECLARATION; - if ((GetContext().Status() & ParserStatus::IN_EXTERNAL) != 0) { + if (IsExternal()) { modifiers |= ir::ClassDefinitionModifiers::FROM_EXTERNAL; } diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 4386ff754fa662041883a3db460aa90a65220c0f..0d36487ec90bfa3dbd55d05e1de495d4c4a6fa8f 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -303,9 +303,6 @@ static ir::ScriptFunctionFlags E2pToIrScriptFunctionFlags(es2panda_ScriptFunctio : ir::ScriptFunctionFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_SCRIPT_FUNCTION_RETHROWS) != 0 ? ir::ScriptFunctionFlags::RETHROWS : ir::ScriptFunctionFlags::NONE; - irFlags |= (e2pFlags & ES2PANDA_SCRIPT_FUNCTION_DEFAULT_PARAM_PROXY) != 0 - ? ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY - : ir::ScriptFunctionFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT) != 0 ? ir::ScriptFunctionFlags::ENTRY_POINT : ir::ScriptFunctionFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_SCRIPT_FUNCTION_HAS_RETURN) != 0 ? ir::ScriptFunctionFlags::HAS_RETURN @@ -368,9 +365,6 @@ static es2panda_ScriptFunctionFlags IrToE2pScriptFunctionFlags(ir::ScriptFunctio (irFlags & ir::ScriptFunctionFlags::THROWS) != 0 ? e2pFlags | ES2PANDA_SCRIPT_FUNCTION_THROWS : e2pFlags); e2pFlags = static_cast( (irFlags & ir::ScriptFunctionFlags::RETHROWS) != 0 ? e2pFlags | ES2PANDA_SCRIPT_FUNCTION_RETHROWS : e2pFlags); - e2pFlags = static_cast((irFlags & ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY) != 0 - ? e2pFlags | ES2PANDA_SCRIPT_FUNCTION_DEFAULT_PARAM_PROXY - : e2pFlags); e2pFlags = static_cast((irFlags & ir::ScriptFunctionFlags::ENTRY_POINT) != 0 ? e2pFlags | ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT : e2pFlags); diff --git a/ets2panda/public/es2panda_lib.h b/ets2panda/public/es2panda_lib.h index c28f1e708bb70b292dd0eea0e7751f6a3b7150be..29870ed03f40faf9e4ad49c431c1031cde07b73e 100644 --- a/ets2panda/public/es2panda_lib.h +++ b/ets2panda/public/es2panda_lib.h @@ -102,10 +102,9 @@ enum es2panda_ScriptFunctionFlags { ES2PANDA_SCRIPT_FUNCTION_RETHROWS = 1U << 14U, ES2PANDA_SCRIPT_FUNCTION_GETTER = 1U << 15U, ES2PANDA_SCRIPT_FUNCTION_SETTER = 1U << 16U, - ES2PANDA_SCRIPT_FUNCTION_DEFAULT_PARAM_PROXY = 1U << 17U, - ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT = 1U << 18U, - ES2PANDA_SCRIPT_FUNCTION_INSTANCE_EXTENSION_METHOD = 1U << 19U, - ES2PANDA_SCRIPT_FUNCTION_HAS_RETURN = 1U << 20U + ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT = 1U << 17U, + ES2PANDA_SCRIPT_FUNCTION_INSTANCE_EXTENSION_METHOD = 1U << 18U, + ES2PANDA_SCRIPT_FUNCTION_HAS_RETURN = 1U << 19U }; typedef enum es2panda_ScriptFunctionFlags es2panda_ScriptFunctionFlags; diff --git a/ets2panda/scripts/es2panda_pre_test.py b/ets2panda/scripts/es2panda_pre_test.py new file mode 100644 index 0000000000000000000000000000000000000000..217f955c949f548dd2103e96cfe70c0808690184 --- /dev/null +++ b/ets2panda/scripts/es2panda_pre_test.py @@ -0,0 +1,184 @@ +# +# 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 re +import argparse +import subprocess +import time + +from enum import Enum + + +class TestTypes(Enum): + NORMAL = 0 + CLANGTIDY = 1 + CLANGFORMAT = 2 + + +def print_summary(log_lines, searched_words, end_word=""): + was_any_log = False + should_print = False + + for line in log_lines: + for word in searched_words: + if any(word in line for word in searched_words): + should_print = True + was_any_log = True + + if end_word and end_word in line: + should_print=False + + if should_print: + print(line.strip()) + + if not was_any_log: + print("Problem occourd: ", was_any_log) + + print(f"\n") + + +def print_progress_to_console(line, test_type, pattern_progress_bar, pattern_clang_tidy, pattern_clang_format): + match test_type: + case TestTypes.NORMAL: + match = pattern_progress_bar.search(line) + if match: + print(line, end='') + case TestTypes.CLANGTIDY: + match = re.match(pattern_clang_tidy, line) + if match: + print(f"[{match.group(1)}/{match.group(2)}] {match.group(3)}") + case TestTypes.CLANGFORMAT: + match = re.match(pattern_clang_format, line) + if match: + print(f"[{match.group(1)}/{match.group(2)}] Clang-format: {match.group(3)} \n") + + +def test_process_runner(runtime_process, test_type): + pattern_progress_bar = re.compile(r'\b(\d{1,3}%)\|(.+?)\| (\d+)/(\d+) \[\d{2}:\d{2}<\d{2}:\d{2},\s*\d+\.\d+it/s\]$') + pattern_clang_tidy = re.compile(r"^\[(\d+)\/(\d+)\]\s+Done\s+clang-tidy:\s+.*?\/es2panda\/(.+\.cpp)$") + pattern_clang_format = re.compile(r"\[(\d+)/(\d+)\]\s+Running clang-format: (.+)") + + should_print = False + log_lines = [] + + for line in runtime_process.stdout: + log_lines.append(line) + print_progress_to_console(line, test_type, pattern_progress_bar, pattern_clang_tidy, pattern_clang_format) + + return log_lines + + +def command_runner(command_to_run, test_type): + try: + process = subprocess.Popen(command_to_run, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + process_log = test_process_runner(process, test_type) + + except subprocess.CalledProcessError as e: + process_log = str(e) + print("An error occurred during processing:", process_log) + + except Exception as e: + process_log = str(e) + print("An error occurred during processing:", process_log) + + return process_log + +def print_summary_to_file(log, file_name, word_for_success, word_for_fail, test_name): + has_to_write_out_the_log = False + + for line in log: + if word_for_fail in line: + has_to_write_out_the_log = True + elif word_for_success in line: + print(line) + + if has_to_write_out_the_log: + with open(file_name, "w") as file: + for line in log: + file.write(line) + + print(f"{test_name} is faild. Please check the log file: {file_name}") + + +def main(): + parser = argparse.ArgumentParser(description="Program description.") + parser.add_argument("--working-dir", required=False, help="Path to the working dir") + parser.add_argument("--build-root", required=False, help="Path to the working dir") + + args = parser.parse_args() + print(f"Argumentum: Working dir: {args.working_dir}") + print(f"Argumentum: Build root: {args.build_root}") + + command_helper = ["python3", f"{args.working_dir}/tests/tests-u-runner/main.py", "--build-dir", f"{args.build_root}", + "--processes", "all", "--show-progress", "--force-generate" + ] + + # Run Parser tests + parser_test_run_command = command_helper + ["--parser" ] + + parser_log = command_runner(parser_test_run_command, TestTypes.NORMAL) + + # Run Runtime tests + runtime_test_run_command = command_helper + ["--ets-runtime", "--timeout", "60"] + + runtime_log = command_runner(runtime_test_run_command, TestTypes.NORMAL) + + # Functional tests + functional_test_run_command = command_helper + ["--ets-func-tests"] + + functional_log = command_runner(functional_test_run_command, TestTypes.NORMAL) + + # Run Ets-cts test + ets_cts_test_run_command = command_helper + ["--ets-cts"] + + ets_cts_log = command_runner(ets_cts_test_run_command, TestTypes.NORMAL) + + # Run Clang-format + clang_format_run_command = ["ninja", "-C", f"{args.build_root}", "code-style-check"] + + clang_format_log = command_runner(clang_format_run_command, TestTypes.CLANGFORMAT) + + # Run Clang-tidy + clang_tidy_run_command = [f"{args.working_dir}/scripts/clang-tidy/clang_tidy_check.py", "--filename-filter=ets2panda", + f"{args.working_dir}", f"{args.build_root}" + ] + + clang_tidy_log = command_runner(clang_tidy_run_command,TestTypes.CLANGTIDY) + + print("\n\nTest results: \n") + + print(f"\nParser test results:") + print_summary(parser_log, ["New failures at", "Summary("]) + + print(f"\nRuntime test results:") + print_summary(runtime_log, ["New failures at", "Summary("]) + + print(f"\nFunctional test results:") + print_summary(functional_log, ["Summary("]) + + print(f"\nEts-cts test results:") + print_summary(ets_cts_log, ["New failures at", "Summary("]) + + print(f"\nClang-format results:") + print_summary_to_file(clang_format_log, "clang-format.log", "Clang-format was passed successfully!", "Failed:", "Clang-format") + + print(f"\nClang-tidy results:") + print_summary(clang_tidy_log,["Clang-tidy was passed successfully!", "Failed:"], "Done clang-tidy:") + + +if __name__ == "__main__": + start_time = time.perf_counter() + main() + end_time = time.perf_counter() + print("Runtime: ", (end_time - start_time)/60, " minute" ) diff --git a/ets2panda/test/compiler/ets/FunctionType1-expected.txt b/ets2panda/test/compiler/ets/FunctionType1-expected.txt index 067f0174687c1432a88946ef6160ecd645cca7f2..1350edd29309188e201ac5c3906545f11a9cd59a 100644 --- a/ets2panda/test/compiler/ets/FunctionType1-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType1-expected.txt @@ -599,7 +599,7 @@ }, "end": { "line": 16, - "column": 35 + "column": 9 } } }, @@ -1001,4 +1001,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [FunctionType1.ets:24:12] +TypeError: Type '(a: int, b: int) => int' cannot be assigned to type '(a: int, b: int) => void' [FunctionType1.ets:24:12] diff --git a/ets2panda/test/compiler/ets/FunctionType2-expected.txt b/ets2panda/test/compiler/ets/FunctionType2-expected.txt index 1dcaa7ce18cad300834afa778966c9f4f1368547..bc1ed8f6d6f6a6d08aafd5e0d724d4c21c080e29 100644 --- a/ets2panda/test/compiler/ets/FunctionType2-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType2-expected.txt @@ -258,7 +258,7 @@ }, "end": { "line": 16, - "column": 37 + "column": 9 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType3-expected.txt b/ets2panda/test/compiler/ets/FunctionType3-expected.txt index 9f4f79c8571bd80cc8786da052cf4cd025e27c3d..790eb2a0969c7b6788d3e9cc10a9f2418f546740 100644 --- a/ets2panda/test/compiler/ets/FunctionType3-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType3-expected.txt @@ -286,7 +286,7 @@ }, "end": { "line": 16, - "column": 36 + "column": 9 } } }, @@ -809,4 +809,4 @@ } } } -TypeError: Call argument at index 1 is not compatible with the signature's type at that index. [FunctionType3.ets:23:16] +TypeError: Type 'string' is not compatible with type 'int' at index 2 [FunctionType3.ets:23:16] diff --git a/ets2panda/test/compiler/ets/FunctionType4-expected.txt b/ets2panda/test/compiler/ets/FunctionType4-expected.txt index 8927a880696633a15427e3a077bcfc4fde64e7e0..13c0c3fbd0fbf6a04485b7b2ffdfdc2e7e826a56 100644 --- a/ets2panda/test/compiler/ets/FunctionType4-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType4-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 25 + "column": 24 } } } @@ -505,7 +505,7 @@ "loc": { "start": { "line": 22, - "column": 14 + "column": 13 }, "end": { "line": 24, @@ -516,7 +516,7 @@ "loc": { "start": { "line": 22, - "column": 14 + "column": 13 }, "end": { "line": 24, diff --git a/ets2panda/test/compiler/ets/FunctionType5-expected.txt b/ets2panda/test/compiler/ets/FunctionType5-expected.txt index c6c23c17deefe05dd99af1785a27875cdb188c55..1a02058a93a6d40f58b84960d59413d4d8a6392f 100644 --- a/ets2panda/test/compiler/ets/FunctionType5-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType5-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 14 + "column": 13 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt index f0c0cc7404ab428b7655774467d15325faa452dd..095a52a35d89e80681b94374e7a7bca876b14985 100644 --- a/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 46 + "column": 45 } } }, @@ -452,11 +452,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 42 + "column": 41 } } } @@ -593,7 +593,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 45 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 41 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt index d57bb4ddb5328082d29cbb6e3810a73d733160ec..391b654d2e849e7906d98d9985cfa28ebca003cf 100644 --- a/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 53 + "column": 52 } } }, @@ -452,11 +452,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 42 + "column": 41 } } } @@ -593,7 +593,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 52 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 41 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt index f66a8a148e1447b4c11345c8f135fd2d61c8fcfc..e3d9e2b92f4334f21e0a910015187130e5849b9c 100644 --- a/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_without_chaining_non_nullish-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 46 + "column": 45 } } }, @@ -452,11 +452,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 28 + "column": 27 } } } @@ -593,7 +593,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 45 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 27 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt index 771737bbd842586c93500fb0d517c443542c50f9..356739d3d52c8be1382b21b02ed3060ed4f82480 100644 --- a/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 53 + "column": 52 } } }, @@ -452,11 +452,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 40 + "column": 39 } } } @@ -593,7 +593,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 52 } } }, @@ -670,7 +670,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 39 } } } diff --git a/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt index b96e1faf4dde097c1ef641d56283fd4c9e94cee5..b4bf32c6330f22320bace84b0c62e0c4b4964444 100644 --- a/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt @@ -456,4 +456,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [conversion_Double-to-Int_typeerror.ets:17:17] +TypeError: Type 'Double' cannot be assigned to type 'Int' [conversion_Double-to-Int_typeerror.ets:17:17] diff --git a/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt index 96c8b5fd3ce0843ef07e0e138bf3a338319926e7..34209cbf2af7545dc5c20fa866881148d308108c 100644 --- a/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt @@ -718,4 +718,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [conversion_Double-to-Int_w_try_stmt_typerror.ets:17:18] +TypeError: Type 'Double' is not compatible with the enclosing method's return type 'Int' [conversion_Double-to-Int_w_try_stmt_typerror.ets:17:18] diff --git a/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt index 18cfe0261dac23bdba4b96cf0cac7a060b2145d1..af949c270615157730027a99372a76c77a20769b 100644 --- a/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt @@ -456,4 +456,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [conversion_Int-to-Double_typeerror.ets:17:20] +TypeError: Type 'Int' cannot be assigned to type 'Double' [conversion_Int-to-Double_typeerror.ets:17:20] diff --git a/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt index a4f0dff3f57cdd21a0e10bf2715d626c87ed8449..b811e85e80afc6aa1975fd6ebcad1bf8fe5e7f9c 100644 --- a/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt @@ -679,4 +679,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [conversion_call-context_Int-to-Double_typeerror.ets:20:7] +TypeError: Type 'Int' is not compatible with type 'Double' at index 1 [conversion_call-context_Int-to-Double_typeerror.ets:20:7] diff --git a/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0f8108b11a032fbee82ee649c1665fbd4958aaf8 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt @@ -0,0 +1,584 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "test", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "test", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'int' [etsObjectToString0.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString0.ets b/ets2panda/test/compiler/ets/etsObjectToString0.ets new file mode 100644 index 0000000000000000000000000000000000000000..8601ec1d893edf62d80ae2402c9d5b28efbd1176 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString0.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +class A{} + +function test(): int{ + let a: A|null; + return a; +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..da2b83b6cf7eb52623f4da056a18bca863a8dc47 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt @@ -0,0 +1,640 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "test0", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "test0", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'A' [etsObjectToString1.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString1.ets b/ets2panda/test/compiler/ets/etsObjectToString1.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6d7434f8cae070376f85ebb77d85dbb12f06d88 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString1.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +class A{} + +function test0(): A { + let a: A|null; + return a; +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..34fb46d94ac0fcd7e70f712fd1c35b922f77306e --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt @@ -0,0 +1,668 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "test1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "test1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 34 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'A|null' [etsObjectToString2.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString2.ets b/ets2panda/test/compiler/ets/etsObjectToString2.ets new file mode 100644 index 0000000000000000000000000000000000000000..07125b85a192171613c7167466d4762db87e3200 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString2.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +class A{} + +function test1(): A|null { + let a: A|null; + return a; +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b3fdc5aa267850baca3818bdd80b76e2e2bc73b3 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt @@ -0,0 +1,890 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "z", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 35 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} +TypeError: Type '() => A' cannot be assigned to type 'A' [etsObjectToString3.ets:18:17] diff --git a/ets2panda/test/compiler/ets/etsObjectToString3.ets b/ets2panda/test/compiler/ets/etsObjectToString3.ets new file mode 100644 index 0000000000000000000000000000000000000000..afd5cff9f14b5528701ab9c4c91f54ea8589fe70 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString3.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +class A{} + +let z: A = (): A => { + let b : A = new A(); + return b; +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..062a9fc0e7a989d705e9af710de10c5378945db9 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt @@ -0,0 +1,468 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} +TypeError: Type 'int' cannot be assigned to type '() => int' [etsObjectToString4.ets:18:29] diff --git a/ets2panda/test/compiler/ets/etsObjectToString4.ets b/ets2panda/test/compiler/ets/etsObjectToString4.ets new file mode 100644 index 0000000000000000000000000000000000000000..f957ea6d9405b63926b50a8d961fc89830352648 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString4.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 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. + */ + +class A{} + +let f: (() => int) | null = 5; diff --git a/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c96da27d618f81a70d048be77af960f521cdfca5 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt @@ -0,0 +1,848 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "g", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 46 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 54 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 46 + }, + "end": { + "line": 18, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 55 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 58 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 65 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 66 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 66 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 58 + }, + "end": { + "line": 18, + "column": 66 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 67 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 67 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "y", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 75 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Type '(y: A) => A|null' cannot be assigned to type '(y: A) => A|null' [etsObjectToString5.ets:18:42] diff --git a/ets2panda/test/compiler/ets/etsObjectToString5.ets b/ets2panda/test/compiler/ets/etsObjectToString5.ets new file mode 100644 index 0000000000000000000000000000000000000000..c4535d9f0f19e20c6c0d05cf976c1948a993aa28 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString5.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 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. + */ + +class A{} + +let g:((y:A) => A|null)|null = (y:A): A|null => { + return y; +} diff --git a/ets2panda/test/compiler/ets/generic_class_getter_setter-expected.txt b/ets2panda/test/compiler/ets/generic_class_getter_setter-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa42a0148543ad8df365f9c4a7caf62cc49624cd --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_class_getter_setter-expected.txt @@ -0,0 +1,1064 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "get", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 26 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "set", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 25 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 34 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "memb", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 28 + }, + "end": { + "line": 22, + "column": 29 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 29 + }, + "end": { + "line": 22, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 28 + }, + "end": { + "line": 22, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 28 + }, + "end": { + "line": 22, + "column": 38 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 40 + }, + "end": { + "line": 22, + "column": 44 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 44 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 45 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/generic_class_getter_setter.ets b/ets2panda/test/compiler/ets/generic_class_getter_setter.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ee99d0898d14ee0345ac69265071a44a6a120e6 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_class_getter_setter.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + +class A { + get memb(): number { return 1.0; } + set memb(a0: number): void {} +} + +function main(): void { + let memb: number = new A().memb; +} diff --git a/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt b/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt index d7f2b19147955e8a0c1b259fd76212c23baaec59..40b5c23fb504e7bd63203d5913b052865f4f643b 100644 --- a/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt +++ b/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt @@ -982,4 +982,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [generic_function_call_2.ets:24:9] +TypeError: Type 'B' is not compatible with type 'A' at index 1 [generic_function_call_2.ets:24:9] diff --git a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt index 981fbdf9d51da28140bb7735680829375e60846c..6fac876a48b7a60228347e682731066be9d7d6ec 100644 --- a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt @@ -902,4 +902,4 @@ } } } -TypeError: Switch case type Int is not comparable to discriminant type int [generics_primitive_type_param_neg_1.ets:25:14] +TypeError: Switch case type 'Int' is not comparable to discriminant type 'int' [generics_primitive_type_param_neg_1.ets:25:14] diff --git a/ets2panda/test/compiler/ets/identifierReference10-expected.txt b/ets2panda/test/compiler/ets/identifierReference10-expected.txt index c956b389498268a4a617309cf07097e15c35e852..ac3b7839e92d595485903d934a4c5eae2ef3e233 100644 --- a/ets2panda/test/compiler/ets/identifierReference10-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference10-expected.txt @@ -870,4 +870,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference10.ets:24:16] +TypeError: Type 'string' cannot be assigned to type 'int' [identifierReference10.ets:24:16] diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index 4f28a2426c9af4f5c3ec56e6aa866368b4e95e0d..3767a0035eefd31bfcb93a7bf3bb2b9793b9cc76 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 38 + "column": 37 } } } @@ -398,4 +398,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference2.ets:16:34] +TypeError: Type '(v: double, u: double) => double' cannot be assigned to type '(a: int, b: int) => void' [identifierReference2.ets:16:34] diff --git a/ets2panda/test/compiler/ets/identifierReference3-expected.txt b/ets2panda/test/compiler/ets/identifierReference3-expected.txt index 6e49f3f6047d4d305eb455b2495bc0e3260c1f38..a3d2d178bcb259d774f4897feb56ec92c6ac383c 100644 --- a/ets2panda/test/compiler/ets/identifierReference3-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference3-expected.txt @@ -447,11 +447,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 16 + "column": 15 } } } @@ -547,7 +547,7 @@ }, "end": { "line": 16, - "column": 11 + "column": 15 } } } @@ -586,4 +586,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference3.ets:20:9] +TypeError: Type 'string' cannot be assigned to type 'int' [identifierReference3.ets:20:9] diff --git a/ets2panda/test/compiler/ets/identifierReference4-expected.txt b/ets2panda/test/compiler/ets/identifierReference4-expected.txt index beb0f9de571c0db777b146fd15c7af262a494110..a1c5b3b57df06795d9af618a3c19688dfb89628a 100644 --- a/ets2panda/test/compiler/ets/identifierReference4-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference4-expected.txt @@ -701,11 +701,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 17 + "column": 16 } } } @@ -801,7 +801,7 @@ }, "end": { "line": 16, - "column": 11 + "column": 16 } } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt index ed3c6dd87d5fd3763b62d4bcef09dfb9a232888a..bd192ee2e370499a226715d154937f4522c7d7b2 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt @@ -118,7 +118,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, @@ -174,7 +174,7 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, @@ -245,7 +245,7 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, @@ -344,7 +344,7 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, @@ -513,7 +513,7 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, @@ -569,7 +569,7 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, @@ -683,7 +683,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt index 8f6bb0ae1d0975589b7f81984e15d40d629ba372..7d12e35a6e07b3eb8ccb7442aa1fd4df4216fcfb 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt @@ -161,7 +161,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt index be6fbf6957dc573b9d43b407d70f4a2a4be7deca..35a019dc887f16d3899fabce73dd16a56f4bb626 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt @@ -118,7 +118,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, @@ -432,7 +432,7 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt index 6b9887c2443957e1e61566b49f2c8077b5b809e5..054d89e7f5aac3fb886bf0c64d1c2694840895fc 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt @@ -161,7 +161,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, @@ -429,4 +429,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [inferTypeOfArrayNegative3.ets:17:8] +TypeError: Type 'string' cannot be assigned to type 'double' [inferTypeOfArrayNegative3.ets:17:8] diff --git a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt index 358b42f55c98e3292723a560ce566c272d53dcda..a17df28bb337b0d74b04879a1bb4e4a8890a0fd9 100644 --- a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt @@ -515,4 +515,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [lambdaExpressionWithoutBlockStatementDifferentType.ets:17:28] +TypeError: Type '() => String' cannot be assigned to type '() => int' [lambdaExpressionWithoutBlockStatementDifferentType.ets:17:28] diff --git a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt index 8d7e876115ad8ee8ae6cba16f7c3ea6c7ee8f5b2..c35a6a6a7b7dee5698dd3f674b20ff7fafdcbc30 100644 --- a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt @@ -666,4 +666,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [lambdaExpressionWithoutBlockStatementDifferentTypeInfunction.ets:21:39] +TypeError: Type 'String' is not compatible with the enclosing method's return type 'int' [lambdaExpressionWithoutBlockStatementDifferentTypeInfunction.ets:21:39] diff --git a/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt index 132a58cca84c259f538604a00d25b0fbf40fcfb9..61642d4c3b2633517a9cf37c52711f230d3fa659 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt @@ -795,11 +795,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 16 + "column": 15 } } } @@ -895,7 +895,7 @@ }, "end": { "line": 16, - "column": 11 + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt index 4fbb638c04df7d6451ec90527c05dca886a76e23..22b2a3c2f299f5bea005e116a3f713eede8dbe30 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt @@ -642,4 +642,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [lambdaFunction3.ets:18:39] +TypeError: Type '(b: int) => void' cannot be assigned to type '(b: String) => void' [lambdaFunction3.ets:18:39] diff --git a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt index 131a90f02e35ec70e1ef761fb09451a38ed0d508..5737ced2b4eaa0c3cb5614fd7a5e7a02b82a8e43 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt @@ -1705,4 +1705,4 @@ } } } -TypeError: Call argument at index 1 is not compatible with the signature's type at that index. [lambdaFunction5.ets:35:17] +TypeError: Type 'string' is not compatible with type 'int' at index 2 [lambdaFunction5.ets:35:17] diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt index 66623064bb646deeb7db12e1adc3ededdeeb58e6..0c0b9647866639f77fec8e981ece37580c4a5bfd 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt @@ -450,7 +450,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 19, @@ -461,7 +461,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 19, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt index 0d17b84dd6da9b8564c36814a05327b557e43f34..27ff957b76457d2303e85a0800eb84de85d6e1c3 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt @@ -688,7 +688,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 19, @@ -699,7 +699,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 19, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt index ae8e7882a3ae83b53ad296853d9f6675ff890a4c..18ef5aa299d561e6b84b76c5f57b34c235949767 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt @@ -656,7 +656,7 @@ "loc": { "start": { "line": 17, - "column": 15 + "column": 14 }, "end": { "line": 23, @@ -667,7 +667,7 @@ "loc": { "start": { "line": 17, - "column": 15 + "column": 14 }, "end": { "line": 23, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt index a333dff5f00ce6439187d32ea22f7ab848617bc8..a3aa7c7921f45697878273cef0b83cdb74feb34e 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt @@ -579,7 +579,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 20, @@ -590,7 +590,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 20, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt index 2237eae3ae1026548f75c9359fbb11ddc2c4cabc..fea46aa2f9d38bb3d34915ba2f6d41e721bf1386 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt @@ -134,7 +134,7 @@ "loc": { "start": { "line": 23, - "column": 1 + "column": 5 }, "end": { "line": 23, @@ -369,7 +369,7 @@ "loc": { "start": { "line": 16, - "column": 16 + "column": 15 }, "end": { "line": 22, @@ -380,7 +380,7 @@ "loc": { "start": { "line": 16, - "column": 16 + "column": 15 }, "end": { "line": 22, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt index 84d4b4848292a682b19f803ab7071a66ab5ed25e..904969d6458c1517140c0e48080aa35992296c3b 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt @@ -410,7 +410,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 21, @@ -421,7 +421,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 21, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt index 191ba526c8b13f49e8da175acde31cee783aa65d..0a5f2826a76247096e3259cd00f08878b8a80796 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt @@ -622,7 +622,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 22, @@ -633,7 +633,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 14 }, "end": { "line": 22, diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt index 1034ff0fdf3ac0adaf2f09094330126ec92db18d..a5cc56b6ac95ef607ed8bf18f4f808b75117d6e3 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } } @@ -554,7 +554,7 @@ "loc": { "start": { "line": 18, - "column": 15 + "column": 14 }, "end": { "line": 20, @@ -565,7 +565,7 @@ "loc": { "start": { "line": 18, - "column": 15 + "column": 14 }, "end": { "line": 20, diff --git a/ets2panda/test/compiler/ets/launch_expression-expected.txt b/ets2panda/test/compiler/ets/launch_expression-expected.txt index ef4e77e94292a46fcb1550c006cc52d5d3b59384..b96b8b3e39f9bb432d749275edb68388b0f03306 100644 --- a/ets2panda/test/compiler/ets/launch_expression-expected.txt +++ b/ets2panda/test/compiler/ets/launch_expression-expected.txt @@ -1,6 +1,131 @@ { "type": "Program", "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "P", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, { "type": "ClassDeclaration", "definition": { @@ -118,7 +243,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, @@ -174,7 +299,7 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, @@ -257,11 +382,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 31 + "column": 30 } } }, @@ -340,11 +465,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 31 + "column": 30 } } } @@ -553,7 +678,7 @@ }, "end": { "line": 18, - "column": 15 + "column": 30 } } }, @@ -615,7 +740,7 @@ }, "end": { "line": 19, - "column": 15 + "column": 30 } } }, @@ -627,11 +752,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 10 }, "end": { - "line": 20, + "line": 21, "column": 19 } } @@ -651,11 +776,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 10 }, "end": { - "line": 20, + "line": 21, "column": 19 } } @@ -673,11 +798,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 20, + "line": 21, "column": 28 }, "end": { - "line": 20, + "line": 21, "column": 31 } } @@ -685,22 +810,22 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 20 }, "end": { - "line": 20, + "line": 21, "column": 31 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 20 }, "end": { - "line": 20, + "line": 21, "column": 31 } } @@ -714,11 +839,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 20, + "line": 21, "column": 41 }, "end": { - "line": 20, + "line": 21, "column": 44 } } @@ -726,22 +851,22 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 33 }, "end": { - "line": 20, + "line": 21, "column": 44 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 33 }, "end": { - "line": 20, + "line": 21, "column": 44 } } @@ -757,33 +882,33 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 47 }, "end": { - "line": 20, + "line": 21, "column": 51 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 47 }, "end": { - "line": 20, + "line": 21, "column": 53 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 47 }, "end": { - "line": 20, + "line": 21, "column": 53 } } @@ -802,11 +927,11 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 22, "column": 9 }, "end": { - "line": 21, + "line": 22, "column": 15 } } @@ -817,22 +942,22 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 22, "column": 19 }, "end": { - "line": 21, + "line": 22, "column": 25 } } }, "loc": { "start": { - "line": 21, + "line": 22, "column": 9 }, "end": { - "line": 21, + "line": 22, "column": 25 } } @@ -845,11 +970,11 @@ "argument": null, "loc": { "start": { - "line": 22, + "line": 23, "column": 9 }, "end": { - "line": 22, + "line": 23, "column": 16 } } @@ -857,11 +982,11 @@ ], "loc": { "start": { - "line": 21, + "line": 22, "column": 27 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -869,11 +994,11 @@ "alternate": null, "loc": { "start": { - "line": 21, + "line": 22, "column": 5 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -890,11 +1015,11 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 5 }, "end": { - "line": 24, + "line": 25, "column": 12 } } @@ -905,11 +1030,11 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 13 }, "end": { - "line": 24, + "line": 25, "column": 20 } } @@ -918,11 +1043,11 @@ "optional": false, "loc": { "start": { - "line": 24, + "line": 25, "column": 5 }, "end": { - "line": 24, + "line": 25, "column": 20 } } @@ -942,11 +1067,11 @@ "value": "Values of type int are not equal: ", "loc": { "start": { - "line": 24, + "line": 25, "column": 21 }, "end": { - "line": 24, + "line": 25, "column": 57 } } @@ -957,22 +1082,22 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 60 }, "end": { - "line": 24, + "line": 25, "column": 66 } } }, "loc": { "start": { - "line": 24, + "line": 25, "column": 21 }, "end": { - "line": 24, + "line": 25, "column": 66 } } @@ -982,22 +1107,22 @@ "value": " != ", "loc": { "start": { - "line": 24, + "line": 25, "column": 69 }, "end": { - "line": 24, + "line": 25, "column": 75 } } }, "loc": { "start": { - "line": 24, + "line": 25, "column": 21 }, "end": { - "line": 24, + "line": 25, "column": 75 } } @@ -1008,22 +1133,22 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 78 }, "end": { - "line": 24, + "line": 25, "column": 84 } } }, "loc": { "start": { - "line": 24, + "line": 25, "column": 21 }, "end": { - "line": 24, + "line": 25, "column": 84 } } @@ -1032,22 +1157,22 @@ "optional": false, "loc": { "start": { - "line": 24, + "line": 25, "column": 5 }, "end": { - "line": 24, + "line": 25, "column": 85 } } }, "loc": { "start": { - "line": 24, + "line": 25, "column": 5 }, "end": { - "line": 24, + "line": 25, "column": 86 } } @@ -1066,33 +1191,33 @@ "decorators": [], "loc": { "start": { - "line": 25, + "line": 26, "column": 15 }, "end": { - "line": 25, + "line": 26, "column": 20 } } }, "loc": { "start": { - "line": 25, + "line": 26, "column": 15 }, "end": { - "line": 25, + "line": 26, "column": 21 } } }, "loc": { "start": { - "line": 25, + "line": 26, "column": 15 }, "end": { - "line": 25, + "line": 26, "column": 21 } } @@ -1100,22 +1225,22 @@ "arguments": [], "loc": { "start": { - "line": 25, + "line": 26, "column": 11 }, "end": { - "line": 25, + "line": 26, "column": 23 } } }, "loc": { "start": { - "line": 25, + "line": 26, "column": 5 }, "end": { - "line": 25, + "line": 26, "column": 23 } } @@ -1123,33 +1248,33 @@ ], "loc": { "start": { - "line": 20, + "line": 21, "column": 52 }, "end": { - "line": 26, + "line": 27, "column": 2 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 19 }, "end": { - "line": 26, + "line": 27, "column": 2 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 19 }, "end": { - "line": 26, + "line": 27, "column": 2 } } @@ -1158,11 +1283,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 1 }, "end": { - "line": 26, + "line": 27, "column": 2 } } @@ -1175,11 +1300,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 10 }, "end": { - "line": 27, + "line": 28, "column": 14 } } @@ -1199,11 +1324,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 10 }, "end": { - "line": 27, + "line": 28, "column": 14 } } @@ -1221,11 +1346,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 27, + "line": 28, "column": 18 }, "end": { - "line": 27, + "line": 28, "column": 21 } } @@ -1233,22 +1358,22 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 15 }, "end": { - "line": 27, + "line": 28, "column": 21 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 15 }, "end": { - "line": 27, + "line": 28, "column": 21 } } @@ -1264,33 +1389,33 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 25 }, "end": { - "line": 27, + "line": 28, "column": 28 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 25 }, "end": { - "line": 27, + "line": 28, "column": 30 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 25 }, "end": { - "line": 27, + "line": 28, "column": 30 } } @@ -1312,11 +1437,11 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 29, "column": 9 }, "end": { - "line": 28, + "line": 29, "column": 10 } } @@ -1326,22 +1451,22 @@ "value": 0, "loc": { "start": { - "line": 28, + "line": 29, "column": 14 }, "end": { - "line": 28, + "line": 29, "column": 15 } } }, "loc": { "start": { - "line": 28, + "line": 29, "column": 9 }, "end": { - "line": 28, + "line": 29, "column": 15 } } @@ -1355,11 +1480,11 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 29, "column": 19 }, "end": { - "line": 28, + "line": 29, "column": 20 } } @@ -1370,33 +1495,33 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 29, "column": 23 }, "end": { - "line": 28, + "line": 29, "column": 28 } } }, "loc": { "start": { - "line": 28, + "line": 29, "column": 19 }, "end": { - "line": 28, + "line": 29, "column": 28 } } }, "loc": { "start": { - "line": 28, + "line": 29, "column": 9 }, "end": { - "line": 28, + "line": 29, "column": 28 } } @@ -1414,11 +1539,11 @@ "decorators": [], "loc": { "start": { - "line": 29, + "line": 30, "column": 16 }, "end": { - "line": 29, + "line": 30, "column": 17 } } @@ -1429,11 +1554,11 @@ "decorators": [], "loc": { "start": { - "line": 29, + "line": 30, "column": 18 }, "end": { - "line": 29, + "line": 30, "column": 19 } } @@ -1442,22 +1567,22 @@ "optional": false, "loc": { "start": { - "line": 29, + "line": 30, "column": 16 }, "end": { - "line": 29, + "line": 30, "column": 20 } } }, "loc": { "start": { - "line": 29, + "line": 30, "column": 9 }, "end": { - "line": 29, + "line": 30, "column": 21 } } @@ -1465,11 +1590,11 @@ ], "loc": { "start": { - "line": 28, + "line": 29, "column": 30 }, "end": { - "line": 30, + "line": 31, "column": 6 } } @@ -1477,11 +1602,11 @@ "alternate": null, "loc": { "start": { - "line": 28, + "line": 29, "column": 5 }, "end": { - "line": 30, + "line": 31, "column": 6 } } @@ -1502,116 +1627,60 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Promise", + "name": "P", "decorators": [], "loc": { "start": { - "line": 31, + "line": 32, "column": 12 }, "end": { - "line": 31, - "column": 19 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 20 - }, - "end": { - "line": 31, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 20 - }, - "end": { - "line": 31, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 20 - }, - "end": { - "line": 31, - "column": 24 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 19 - }, - "end": { - "line": 31, - "column": 24 + "line": 32, + "column": 13 } } }, "loc": { "start": { - "line": 31, + "line": 32, "column": 12 }, "end": { - "line": 31, - "column": 25 + "line": 32, + "column": 14 } } }, "loc": { "start": { - "line": 31, + "line": 32, "column": 12 }, "end": { - "line": 31, - "column": 25 + "line": 32, + "column": 14 } } }, "loc": { "start": { - "line": 31, - "column": 27 + "line": 32, + "column": 16 }, "end": { - "line": 31, - "column": 28 + "line": 32, + "column": 17 } } }, "decorators": [], "loc": { "start": { - "line": 31, + "line": 32, "column": 9 }, "end": { - "line": 31, + "line": 32, "column": 10 } } @@ -1624,94 +1693,38 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Promise", + "name": "P", "decorators": [], "loc": { "start": { - "line": 31, - "column": 33 + "line": 32, + "column": 22 }, "end": { - "line": 31, - "column": 40 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 41 - }, - "end": { - "line": 31, - "column": 44 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 41 - }, - "end": { - "line": 31, - "column": 45 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 41 - }, - "end": { - "line": 31, - "column": 45 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 40 - }, - "end": { - "line": 31, - "column": 45 + "line": 32, + "column": 23 } } }, "loc": { "start": { - "line": 31, - "column": 33 + "line": 32, + "column": 22 }, "end": { - "line": 31, - "column": 46 + "line": 32, + "column": 24 } } }, "loc": { "start": { - "line": 31, - "column": 33 + "line": 32, + "column": 22 }, "end": { - "line": 31, - "column": 46 + "line": 32, + "column": 24 } } }, @@ -1721,34 +1734,34 @@ "decorators": [], "loc": { "start": { - "line": 31, - "column": 46 + "line": 32, + "column": 24 }, "end": { - "line": 31, - "column": 51 + "line": 32, + "column": 29 } } }, "loc": { "start": { - "line": 31, - "column": 29 + "line": 32, + "column": 18 }, "end": { - "line": 31, - "column": 52 + "line": 32, + "column": 30 } } }, "loc": { "start": { - "line": 31, + "line": 32, "column": 9 }, "end": { - "line": 31, - "column": 52 + "line": 32, + "column": 30 } } } @@ -1756,12 +1769,12 @@ "kind": "let", "loc": { "start": { - "line": 31, + "line": 32, "column": 5 }, "end": { - "line": 31, - "column": 52 + "line": 32, + "column": 30 } } }, @@ -1778,11 +1791,11 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 14 }, "end": { - "line": 32, + "line": 33, "column": 15 } } @@ -1792,22 +1805,22 @@ "value": 0, "loc": { "start": { - "line": 32, + "line": 33, "column": 18 }, "end": { - "line": 32, + "line": 33, "column": 19 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 14 }, "end": { - "line": 32, + "line": 33, "column": 19 } } @@ -1816,11 +1829,11 @@ "kind": "let", "loc": { "start": { - "line": 32, + "line": 33, "column": 10 }, "end": { - "line": 32, + "line": 33, "column": 19 } } @@ -1834,11 +1847,11 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 21 }, "end": { - "line": 32, + "line": 33, "column": 22 } } @@ -1849,22 +1862,22 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 25 }, "end": { - "line": 32, + "line": 33, "column": 30 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 21 }, "end": { - "line": 32, + "line": 33, "column": 30 } } @@ -1879,22 +1892,22 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 34 }, "end": { - "line": 32, + "line": 33, "column": 35 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 32 }, "end": { - "line": 32, + "line": 33, "column": 35 } } @@ -1915,11 +1928,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 9 }, "end": { - "line": 33, + "line": 34, "column": 10 } } @@ -1930,11 +1943,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 11 }, "end": { - "line": 33, + "line": 34, "column": 12 } } @@ -1943,11 +1956,11 @@ "optional": false, "loc": { "start": { - "line": 33, + "line": 34, "column": 9 }, "end": { - "line": 33, + "line": 34, "column": 13 } } @@ -1962,11 +1975,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 23 }, "end": { - "line": 33, + "line": 34, "column": 27 } } @@ -1984,11 +1997,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 28 }, "end": { - "line": 33, + "line": 34, "column": 29 } } @@ -1998,22 +2011,22 @@ "value": 1, "loc": { "start": { - "line": 33, + "line": 34, "column": 30 }, "end": { - "line": 33, + "line": 34, "column": 31 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 28 }, "end": { - "line": 33, + "line": 34, "column": 31 } } @@ -2024,22 +2037,22 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 34, "column": 32 }, "end": { - "line": 33, + "line": 34, "column": 33 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 28 }, "end": { - "line": 33, + "line": 34, "column": 33 } } @@ -2048,44 +2061,44 @@ "optional": false, "loc": { "start": { - "line": 33, + "line": 34, "column": 23 }, "end": { - "line": 33, + "line": 34, "column": 34 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 16 }, "end": { - "line": 33, + "line": 34, "column": 34 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 9 }, "end": { - "line": 33, + "line": 34, "column": 34 } } }, "loc": { "start": { - "line": 33, + "line": 34, "column": 9 }, "end": { - "line": 33, + "line": 34, "column": 35 } } @@ -2093,22 +2106,22 @@ ], "loc": { "start": { - "line": 32, + "line": 33, "column": 37 }, "end": { - "line": 34, + "line": 35, "column": 6 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 5 }, "end": { - "line": 34, + "line": 35, "column": 6 } } @@ -2124,11 +2137,11 @@ "decorators": [], "loc": { "start": { - "line": 35, + "line": 36, "column": 9 }, "end": { - "line": 35, + "line": 36, "column": 15 } } @@ -2138,22 +2151,22 @@ "value": 0, "loc": { "start": { - "line": 35, + "line": 36, "column": 18 }, "end": { - "line": 35, + "line": 36, "column": 19 } } }, "loc": { "start": { - "line": 35, + "line": 36, "column": 9 }, "end": { - "line": 35, + "line": 36, "column": 19 } } @@ -2162,11 +2175,11 @@ "kind": "let", "loc": { "start": { - "line": 35, + "line": 36, "column": 5 }, "end": { - "line": 35, + "line": 36, "column": 19 } } @@ -2184,11 +2197,11 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 37, "column": 14 }, "end": { - "line": 36, + "line": 37, "column": 15 } } @@ -2198,22 +2211,22 @@ "value": 0, "loc": { "start": { - "line": 36, + "line": 37, "column": 18 }, "end": { - "line": 36, + "line": 37, "column": 19 } } }, "loc": { "start": { - "line": 36, + "line": 37, "column": 14 }, "end": { - "line": 36, + "line": 37, "column": 19 } } @@ -2222,11 +2235,11 @@ "kind": "let", "loc": { "start": { - "line": 36, + "line": 37, "column": 10 }, "end": { - "line": 36, + "line": 37, "column": 19 } } @@ -2240,11 +2253,11 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 37, "column": 21 }, "end": { - "line": 36, + "line": 37, "column": 22 } } @@ -2255,22 +2268,22 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 37, "column": 25 }, "end": { - "line": 36, + "line": 37, "column": 30 } } }, "loc": { "start": { - "line": 36, + "line": 37, "column": 21 }, "end": { - "line": 36, + "line": 37, "column": 30 } } @@ -2285,22 +2298,22 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 37, "column": 34 }, "end": { - "line": 36, + "line": 37, "column": 35 } } }, "loc": { "start": { - "line": 36, + "line": 37, "column": 32 }, "end": { - "line": 36, + "line": 37, "column": 35 } } @@ -2319,11 +2332,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 9 }, "end": { - "line": 37, + "line": 38, "column": 15 } } @@ -2337,11 +2350,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 18 }, "end": { - "line": 37, + "line": 38, "column": 24 } } @@ -2361,11 +2374,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 28 } } @@ -2376,11 +2389,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 29 }, "end": { - "line": 37, + "line": 38, "column": 30 } } @@ -2389,11 +2402,11 @@ "optional": false, "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 31 } } @@ -2404,11 +2417,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 32 }, "end": { - "line": 37, + "line": 38, "column": 47 } } @@ -2417,11 +2430,11 @@ "optional": false, "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 47 } } @@ -2430,11 +2443,11 @@ "optional": false, "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 49 } } @@ -2447,11 +2460,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 52 }, "end": { - "line": 37, + "line": 38, "column": 53 } } @@ -2462,11 +2475,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 38, "column": 54 }, "end": { - "line": 37, + "line": 38, "column": 55 } } @@ -2475,55 +2488,55 @@ "optional": false, "loc": { "start": { - "line": 37, + "line": 38, "column": 52 }, "end": { - "line": 37, + "line": 38, "column": 56 } } }, "loc": { "start": { - "line": 37, + "line": 38, "column": 27 }, "end": { - "line": 37, + "line": 38, "column": 56 } } }, "loc": { "start": { - "line": 37, + "line": 38, "column": 18 }, "end": { - "line": 37, + "line": 38, "column": 56 } } }, "loc": { "start": { - "line": 37, + "line": 38, "column": 9 }, "end": { - "line": 37, + "line": 38, "column": 56 } } }, "loc": { "start": { - "line": 37, + "line": 38, "column": 9 }, "end": { - "line": 37, + "line": 38, "column": 57 } } @@ -2531,22 +2544,22 @@ ], "loc": { "start": { - "line": 36, + "line": 37, "column": 37 }, "end": { - "line": 38, + "line": 39, "column": 6 } } }, "loc": { "start": { - "line": 36, + "line": 37, "column": 5 }, "end": { - "line": 38, + "line": 39, "column": 6 } } @@ -2559,22 +2572,22 @@ "decorators": [], "loc": { "start": { - "line": 39, + "line": 40, "column": 12 }, "end": { - "line": 39, + "line": 40, "column": 18 } } }, "loc": { "start": { - "line": 39, + "line": 40, "column": 5 }, "end": { - "line": 39, + "line": 40, "column": 19 } } @@ -2582,33 +2595,33 @@ ], "loc": { "start": { - "line": 27, + "line": 28, "column": 29 }, "end": { - "line": 40, + "line": 41, "column": 2 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 14 }, "end": { - "line": 40, + "line": 41, "column": 2 } } }, "loc": { "start": { - "line": 27, + "line": 28, "column": 14 }, "end": { - "line": 40, + "line": 41, "column": 2 } } @@ -2617,11 +2630,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 28, "column": 1 }, "end": { - "line": 40, + "line": 41, "column": 2 } } @@ -2634,11 +2647,11 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 42, "column": 10 }, "end": { - "line": 41, + "line": 42, "column": 18 } } @@ -2658,11 +2671,11 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 42, "column": 10 }, "end": { - "line": 41, + "line": 42, "column": 18 } } @@ -2680,11 +2693,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 41, + "line": 42, "column": 22 }, "end": { - "line": 41, + "line": 42, "column": 25 } } @@ -2692,22 +2705,22 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 42, "column": 19 }, "end": { - "line": 41, + "line": 42, "column": 25 } } }, "loc": { "start": { - "line": 41, + "line": 42, "column": 19 }, "end": { - "line": 41, + "line": 42, "column": 25 } } @@ -2717,11 +2730,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 41, + "line": 42, "column": 29 }, "end": { - "line": 41, + "line": 42, "column": 32 } } @@ -2743,11 +2756,11 @@ "decorators": [], "loc": { "start": { - "line": 42, + "line": 43, "column": 9 }, "end": { - "line": 42, + "line": 43, "column": 10 } } @@ -2757,22 +2770,22 @@ "value": 0, "loc": { "start": { - "line": 42, + "line": 43, "column": 14 }, "end": { - "line": 42, + "line": 43, "column": 15 } } }, "loc": { "start": { - "line": 42, + "line": 43, "column": 9 }, "end": { - "line": 42, + "line": 43, "column": 15 } } @@ -2786,11 +2799,11 @@ "decorators": [], "loc": { "start": { - "line": 42, + "line": 43, "column": 19 }, "end": { - "line": 42, + "line": 43, "column": 20 } } @@ -2801,33 +2814,33 @@ "decorators": [], "loc": { "start": { - "line": 42, + "line": 43, "column": 23 }, "end": { - "line": 42, + "line": 43, "column": 28 } } }, "loc": { "start": { - "line": 42, + "line": 43, "column": 19 }, "end": { - "line": 42, + "line": 43, "column": 28 } } }, "loc": { "start": { - "line": 42, + "line": 43, "column": 9 }, "end": { - "line": 42, + "line": 43, "column": 28 } } @@ -2845,11 +2858,11 @@ "decorators": [], "loc": { "start": { - "line": 43, + "line": 44, "column": 16 }, "end": { - "line": 43, + "line": 44, "column": 17 } } @@ -2860,11 +2873,11 @@ "decorators": [], "loc": { "start": { - "line": 43, + "line": 44, "column": 18 }, "end": { - "line": 43, + "line": 44, "column": 19 } } @@ -2873,22 +2886,22 @@ "optional": false, "loc": { "start": { - "line": 43, + "line": 44, "column": 16 }, "end": { - "line": 43, + "line": 44, "column": 20 } } }, "loc": { "start": { - "line": 43, + "line": 44, "column": 9 }, "end": { - "line": 43, + "line": 44, "column": 21 } } @@ -2896,11 +2909,11 @@ ], "loc": { "start": { - "line": 42, + "line": 43, "column": 30 }, "end": { - "line": 44, + "line": 45, "column": 6 } } @@ -2908,11 +2921,11 @@ "alternate": null, "loc": { "start": { - "line": 42, + "line": 43, "column": 5 }, "end": { - "line": 44, + "line": 45, "column": 6 } } @@ -2928,11 +2941,11 @@ "decorators": [], "loc": { "start": { - "line": 45, + "line": 46, "column": 9 }, "end": { - "line": 45, + "line": 46, "column": 15 } } @@ -2942,22 +2955,22 @@ "value": 0, "loc": { "start": { - "line": 45, + "line": 46, "column": 18 }, "end": { - "line": 45, + "line": 46, "column": 19 } } }, "loc": { "start": { - "line": 45, + "line": 46, "column": 9 }, "end": { - "line": 45, + "line": 46, "column": 19 } } @@ -2966,11 +2979,11 @@ "kind": "let", "loc": { "start": { - "line": 45, + "line": 46, "column": 5 }, "end": { - "line": 45, + "line": 46, "column": 19 } } @@ -2988,11 +3001,11 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 47, "column": 14 }, "end": { - "line": 46, + "line": 47, "column": 15 } } @@ -3002,22 +3015,22 @@ "value": 0, "loc": { "start": { - "line": 46, + "line": 47, "column": 18 }, "end": { - "line": 46, + "line": 47, "column": 19 } } }, "loc": { "start": { - "line": 46, + "line": 47, "column": 14 }, "end": { - "line": 46, + "line": 47, "column": 19 } } @@ -3026,11 +3039,11 @@ "kind": "let", "loc": { "start": { - "line": 46, + "line": 47, "column": 10 }, "end": { - "line": 46, + "line": 47, "column": 19 } } @@ -3044,11 +3057,11 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 47, "column": 21 }, "end": { - "line": 46, + "line": 47, "column": 22 } } @@ -3059,22 +3072,22 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 47, "column": 25 }, "end": { - "line": 46, + "line": 47, "column": 30 } } }, "loc": { "start": { - "line": 46, + "line": 47, "column": 21 }, "end": { - "line": 46, + "line": 47, "column": 30 } } @@ -3089,22 +3102,22 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 47, "column": 34 }, "end": { - "line": 46, + "line": 47, "column": 35 } } }, "loc": { "start": { - "line": 46, + "line": 47, "column": 32 }, "end": { - "line": 46, + "line": 47, "column": 35 } } @@ -3123,11 +3136,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 9 }, "end": { - "line": 47, + "line": 48, "column": 15 } } @@ -3141,11 +3154,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 18 }, "end": { - "line": 47, + "line": 48, "column": 24 } } @@ -3161,11 +3174,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 27 }, "end": { - "line": 47, + "line": 48, "column": 35 } } @@ -3183,11 +3196,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 36 }, "end": { - "line": 47, + "line": 48, "column": 37 } } @@ -3197,22 +3210,22 @@ "value": 1, "loc": { "start": { - "line": 47, + "line": 48, "column": 38 }, "end": { - "line": 47, + "line": 48, "column": 39 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 36 }, "end": { - "line": 47, + "line": 48, "column": 39 } } @@ -3223,22 +3236,22 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 40 }, "end": { - "line": 47, + "line": 48, "column": 41 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 36 }, "end": { - "line": 47, + "line": 48, "column": 41 } } @@ -3247,11 +3260,11 @@ "optional": false, "loc": { "start": { - "line": 47, + "line": 48, "column": 27 }, "end": { - "line": 47, + "line": 48, "column": 42 } } @@ -3264,11 +3277,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 45 }, "end": { - "line": 47, + "line": 48, "column": 46 } } @@ -3279,11 +3292,11 @@ "decorators": [], "loc": { "start": { - "line": 47, + "line": 48, "column": 47 }, "end": { - "line": 47, + "line": 48, "column": 48 } } @@ -3292,55 +3305,55 @@ "optional": false, "loc": { "start": { - "line": 47, + "line": 48, "column": 45 }, "end": { - "line": 47, + "line": 48, "column": 49 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 27 }, "end": { - "line": 47, + "line": 48, "column": 49 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 18 }, "end": { - "line": 47, + "line": 48, "column": 49 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 9 }, "end": { - "line": 47, + "line": 48, "column": 49 } } }, "loc": { "start": { - "line": 47, + "line": 48, "column": 9 }, "end": { - "line": 47, + "line": 48, "column": 50 } } @@ -3348,22 +3361,22 @@ ], "loc": { "start": { - "line": 46, + "line": 47, "column": 37 }, "end": { - "line": 48, + "line": 49, "column": 6 } } }, "loc": { "start": { - "line": 46, + "line": 47, "column": 5 }, "end": { - "line": 48, + "line": 49, "column": 6 } } @@ -3376,22 +3389,22 @@ "decorators": [], "loc": { "start": { - "line": 49, + "line": 50, "column": 12 }, "end": { - "line": 49, + "line": 50, "column": 18 } } }, "loc": { "start": { - "line": 49, + "line": 50, "column": 5 }, "end": { - "line": 49, + "line": 50, "column": 19 } } @@ -3399,33 +3412,33 @@ ], "loc": { "start": { - "line": 41, + "line": 42, "column": 33 }, "end": { - "line": 50, + "line": 51, "column": 2 } } }, "loc": { "start": { - "line": 41, + "line": 42, "column": 18 }, "end": { - "line": 50, + "line": 51, "column": 2 } } }, "loc": { "start": { - "line": 41, + "line": 42, "column": 18 }, "end": { - "line": 50, + "line": 51, "column": 2 } } @@ -3434,11 +3447,11 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 42, "column": 1 }, "end": { - "line": 50, + "line": 51, "column": 2 } } @@ -3451,11 +3464,11 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 52, "column": 17 }, "end": { - "line": 51, + "line": 52, "column": 21 } } @@ -3475,11 +3488,11 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 52, "column": 17 }, "end": { - "line": 51, + "line": 52, "column": 21 } } @@ -3492,11 +3505,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 51, + "line": 52, "column": 25 }, "end": { - "line": 51, + "line": 52, "column": 28 } } @@ -3517,11 +3530,11 @@ "decorators": [], "loc": { "start": { - "line": 52, + "line": 53, "column": 5 }, "end": { - "line": 52, + "line": 53, "column": 6 } } @@ -3531,11 +3544,11 @@ "value": 0, "loc": { "start": { - "line": 52, + "line": 53, "column": 7 }, "end": { - "line": 52, + "line": 53, "column": 8 } } @@ -3544,11 +3557,11 @@ "optional": false, "loc": { "start": { - "line": 52, + "line": 53, "column": 5 }, "end": { - "line": 52, + "line": 53, "column": 9 } } @@ -3558,33 +3571,33 @@ "value": 2, "loc": { "start": { - "line": 52, + "line": 53, "column": 12 }, "end": { - "line": 52, + "line": 53, "column": 13 } } }, "loc": { "start": { - "line": 52, + "line": 53, "column": 5 }, "end": { - "line": 52, + "line": 53, "column": 13 } } }, "loc": { "start": { - "line": 52, + "line": 53, "column": 5 }, "end": { - "line": 52, + "line": 53, "column": 14 } } @@ -3602,11 +3615,11 @@ "decorators": [], "loc": { "start": { - "line": 53, + "line": 54, "column": 5 }, "end": { - "line": 53, + "line": 54, "column": 6 } } @@ -3616,11 +3629,11 @@ "value": 0, "loc": { "start": { - "line": 53, + "line": 54, "column": 7 }, "end": { - "line": 53, + "line": 54, "column": 8 } } @@ -3629,11 +3642,11 @@ "optional": false, "loc": { "start": { - "line": 53, + "line": 54, "column": 5 }, "end": { - "line": 53, + "line": 54, "column": 9 } } @@ -3643,33 +3656,33 @@ "value": 6, "loc": { "start": { - "line": 53, + "line": 54, "column": 12 }, "end": { - "line": 53, + "line": 54, "column": 13 } } }, "loc": { "start": { - "line": 53, + "line": 54, "column": 5 }, "end": { - "line": 53, + "line": 54, "column": 13 } } }, "loc": { "start": { - "line": 53, + "line": 54, "column": 5 }, "end": { - "line": 53, + "line": 54, "column": 14 } } @@ -3687,11 +3700,11 @@ "decorators": [], "loc": { "start": { - "line": 54, + "line": 55, "column": 5 }, "end": { - "line": 54, + "line": 55, "column": 6 } } @@ -3701,11 +3714,11 @@ "value": 1, "loc": { "start": { - "line": 54, + "line": 55, "column": 7 }, "end": { - "line": 54, + "line": 55, "column": 8 } } @@ -3714,11 +3727,11 @@ "optional": false, "loc": { "start": { - "line": 54, + "line": 55, "column": 5 }, "end": { - "line": 54, + "line": 55, "column": 9 } } @@ -3728,33 +3741,33 @@ "value": 2, "loc": { "start": { - "line": 54, + "line": 55, "column": 12 }, "end": { - "line": 54, + "line": 55, "column": 13 } } }, "loc": { "start": { - "line": 54, + "line": 55, "column": 5 }, "end": { - "line": 54, + "line": 55, "column": 13 } } }, "loc": { "start": { - "line": 54, + "line": 55, "column": 5 }, "end": { - "line": 54, + "line": 55, "column": 14 } } @@ -3772,11 +3785,11 @@ "decorators": [], "loc": { "start": { - "line": 55, + "line": 56, "column": 5 }, "end": { - "line": 55, + "line": 56, "column": 6 } } @@ -3786,11 +3799,11 @@ "value": 1, "loc": { "start": { - "line": 55, + "line": 56, "column": 7 }, "end": { - "line": 55, + "line": 56, "column": 8 } } @@ -3799,11 +3812,11 @@ "optional": false, "loc": { "start": { - "line": 55, + "line": 56, "column": 5 }, "end": { - "line": 55, + "line": 56, "column": 9 } } @@ -3813,33 +3826,33 @@ "value": 7, "loc": { "start": { - "line": 55, + "line": 56, "column": 12 }, "end": { - "line": 55, + "line": 56, "column": 13 } } }, "loc": { "start": { - "line": 55, + "line": 56, "column": 5 }, "end": { - "line": 55, + "line": 56, "column": 13 } } }, "loc": { "start": { - "line": 55, + "line": 56, "column": 5 }, "end": { - "line": 55, + "line": 56, "column": 14 } } @@ -3855,11 +3868,11 @@ "decorators": [], "loc": { "start": { - "line": 56, + "line": 57, "column": 9 }, "end": { - "line": 56, + "line": 57, "column": 19 } } @@ -3872,11 +3885,11 @@ "decorators": [], "loc": { "start": { - "line": 56, + "line": 57, "column": 22 }, "end": { - "line": 56, + "line": 57, "column": 30 } } @@ -3888,11 +3901,11 @@ "decorators": [], "loc": { "start": { - "line": 56, + "line": 57, "column": 31 }, "end": { - "line": 56, + "line": 57, "column": 32 } } @@ -3901,22 +3914,22 @@ "optional": false, "loc": { "start": { - "line": 56, + "line": 57, "column": 22 }, "end": { - "line": 56, + "line": 57, "column": 33 } } }, "loc": { "start": { - "line": 56, + "line": 57, "column": 9 }, "end": { - "line": 56, + "line": 57, "column": 33 } } @@ -3925,11 +3938,11 @@ "kind": "let", "loc": { "start": { - "line": 56, + "line": 57, "column": 5 }, "end": { - "line": 56, + "line": 57, "column": 34 } } @@ -3945,11 +3958,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 58, "column": 9 }, "end": { - "line": 57, + "line": 58, "column": 10 } } @@ -3964,11 +3977,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 58, "column": 20 }, "end": { - "line": 57, + "line": 58, "column": 24 } } @@ -3980,11 +3993,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 58, "column": 25 }, "end": { - "line": 57, + "line": 58, "column": 26 } } @@ -3993,33 +4006,33 @@ "optional": false, "loc": { "start": { - "line": 57, + "line": 58, "column": 20 }, "end": { - "line": 57, + "line": 58, "column": 27 } } }, "loc": { "start": { - "line": 57, + "line": 58, "column": 13 }, "end": { - "line": 57, + "line": 58, "column": 27 } } }, "loc": { "start": { - "line": 57, + "line": 58, "column": 9 }, "end": { - "line": 57, + "line": 58, "column": 27 } } @@ -4028,11 +4041,11 @@ "kind": "let", "loc": { "start": { - "line": 57, + "line": 58, "column": 5 }, "end": { - "line": 57, + "line": 58, "column": 28 } } @@ -4048,11 +4061,11 @@ "decorators": [], "loc": { "start": { - "line": 58, + "line": 59, "column": 9 }, "end": { - "line": 58, + "line": 59, "column": 18 } } @@ -4067,11 +4080,11 @@ "decorators": [], "loc": { "start": { - "line": 58, + "line": 59, "column": 21 }, "end": { - "line": 58, + "line": 59, "column": 22 } } @@ -4082,11 +4095,11 @@ "decorators": [], "loc": { "start": { - "line": 58, + "line": 59, "column": 23 }, "end": { - "line": 58, + "line": 59, "column": 38 } } @@ -4095,11 +4108,11 @@ "optional": false, "loc": { "start": { - "line": 58, + "line": 59, "column": 21 }, "end": { - "line": 58, + "line": 59, "column": 38 } } @@ -4108,22 +4121,22 @@ "optional": false, "loc": { "start": { - "line": 58, + "line": 59, "column": 21 }, "end": { - "line": 58, + "line": 59, "column": 40 } } }, "loc": { "start": { - "line": 58, + "line": 59, "column": 9 }, "end": { - "line": 58, + "line": 59, "column": 40 } } @@ -4132,11 +4145,11 @@ "kind": "let", "loc": { "start": { - "line": 58, + "line": 59, "column": 5 }, "end": { - "line": 58, + "line": 59, "column": 41 } } @@ -4151,11 +4164,11 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 60, "column": 5 }, "end": { - "line": 59, + "line": 60, "column": 14 } } @@ -4169,11 +4182,11 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 60, "column": 15 }, "end": { - "line": 59, + "line": 60, "column": 24 } } @@ -4182,22 +4195,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 59, + "line": 60, "column": 28 }, "end": { - "line": 59, + "line": 60, "column": 31 } } }, "loc": { "start": { - "line": 59, + "line": 60, "column": 15 }, "end": { - "line": 59, + "line": 60, "column": 24 } } @@ -4208,11 +4221,11 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 60, "column": 33 }, "end": { - "line": 59, + "line": 60, "column": 43 } } @@ -4221,22 +4234,22 @@ "optional": false, "loc": { "start": { - "line": 59, + "line": 60, "column": 5 }, "end": { - "line": 59, + "line": 60, "column": 44 } } }, "loc": { "start": { - "line": 59, + "line": 60, "column": 5 }, "end": { - "line": 59, + "line": 60, "column": 45 } } @@ -4248,22 +4261,22 @@ "value": 0, "loc": { "start": { - "line": 60, + "line": 61, "column": 12 }, "end": { - "line": 60, + "line": 61, "column": 13 } } }, "loc": { "start": { - "line": 60, + "line": 61, "column": 5 }, "end": { - "line": 60, + "line": 61, "column": 14 } } @@ -4271,33 +4284,33 @@ ], "loc": { "start": { - "line": 51, + "line": 52, "column": 29 }, "end": { - "line": 61, + "line": 62, "column": 2 } } }, "loc": { "start": { - "line": 51, + "line": 52, "column": 21 }, "end": { - "line": 61, + "line": 62, "column": 2 } } }, "loc": { "start": { - "line": 51, + "line": 52, "column": 21 }, "end": { - "line": 61, + "line": 62, "column": 2 } } @@ -4306,11 +4319,11 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 52, "column": 8 }, "end": { - "line": 61, + "line": 62, "column": 2 } } @@ -4345,7 +4358,7 @@ "column": 1 }, "end": { - "line": 62, + "line": 63, "column": 1 } } diff --git a/ets2panda/test/compiler/ets/launch_expression.ets b/ets2panda/test/compiler/ets/launch_expression.ets index 011deb2dee7ced337bf836500dd60afdef2d0804..362b63db1131de6c6281bfb347729ca6e7c963fe 100644 --- a/ets2panda/test/compiler/ets/launch_expression.ets +++ b/ets2panda/test/compiler/ets/launch_expression.ets @@ -17,6 +17,7 @@ let count = 2 let n = 9 let a: int[] = new int[count]; let v: int[] = new int[count]; +type P = Promise | null function assert_eq(value1: int, value2: int): void { if (value1 == value2) { return; @@ -28,7 +29,7 @@ function ufib(n: int) : Int { if (n >= 0 && n < count) { return v[n]; } - let p: Promise[] = new Promise[count] + let p: P[] = new P[count] for (let i = 0; i < count; ++i) { p[i] = launch ufib(n-1-i); } diff --git a/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt b/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt index a2cc17f30653f96ce760087c29e046eab9d37826..218cfffdcb33c7c392be1d8fa7840ee67f888e43 100644 --- a/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt +++ b/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt @@ -1012,4 +1012,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignGenericWithNullableTypeParamToNonNullable.ets:21:19] +TypeError: Type 'A' cannot be assigned to type 'A' [n_assignGenericWithNullableTypeParamToNonNullable.ets:21:19] diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt b/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f309c04503198af162a59c46ddc98158510b52aa --- /dev/null +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt @@ -0,0 +1,1853 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "data", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "exec", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "pointer", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 24 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "R", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "R", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Uint8Array", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "R", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 16, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "exec", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "arguments": [ + { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "Identifier", + "name": "data", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "right": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "data", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 35 + }, + "end": { + "line": 24, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 35 + }, + "end": { + "line": 24, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 35 + }, + "end": { + "line": 24, + "column": 37 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 29 + }, + "end": { + "line": 24, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 29 + }, + "end": { + "line": 24, + "column": 37 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 45 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c_class", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 18 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 18 + }, + "end": { + "line": 25, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 18 + }, + "end": { + "line": 25, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 16 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 25, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 25, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 25, + "column": 28 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 25, + "column": 22 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 30 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myvar", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 14 + } + } + }, + "init": { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "Identifier", + "name": "data", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 29 + } + } + }, + "right": { + "type": "Identifier", + "name": "c_class", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 33 + }, + "end": { + "line": 26, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 44 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "baz", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "baz", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 33 + }, + "end": { + "line": 29, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 33 + }, + "end": { + "line": 29, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 33 + }, + "end": { + "line": 29, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 29 + }, + "end": { + "line": 29, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 29 + }, + "end": { + "line": 29, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Integral", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 47 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 29, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 29, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myval", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Short", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 16 + }, + "end": { + "line": 30, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 16 + }, + "end": { + "line": 30, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 16 + }, + "end": { + "line": 30, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 14 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 25 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 26 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "Identifier", + "name": "a0", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 14 + } + } + }, + "right": { + "type": "Identifier", + "name": "myval", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 18 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 46 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 32, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 33, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1.ets b/ets2panda/test/compiler/ets/null_coalescing_generic_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..c9eced66166f670ad61cf24aafbb6a3aa9ed10db --- /dev/null +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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. + */ + +function foo( + data: C | undefined, + exec: (pointer: C | undefined) => R +): R { + return exec(data ?? undefined); +} + +class C {} +function bar(data: T): void { + let c_class: C = new C(); + let myvar: Object = data ?? c_class; +} + +function baz(a0: T): Integral { + let myval: Short = 2; + return a0 ?? myval; +} diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..ffbe88bb73ad6cc0a97b6cd8b1d7fd0cff8c602f --- /dev/null +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt @@ -0,0 +1,600 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fos", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fos", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 38 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 38 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 38 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 40 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Integral", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myval", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Short", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 25 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 26 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "LogicalExpression", + "operator": "??", + "left": { + "type": "Identifier", + "name": "a0", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "right": { + "type": "Identifier", + "name": "myval", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 44 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 1 + } + } +} +TypeError: Type 'Integral' is not compatible with the enclosing method's return type 'T' [null_coalescing_generic_1_neg.ets:18:12] diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg.ets b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..557016f5f1162ee4823c37bb37967c5a7e7e2cb7 --- /dev/null +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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. + */ + +function fos(a0: T): T { + let myval: Short = 2; + return a0 ?? myval; +} diff --git a/ets2panda/test/compiler/ets/nullableTuple-expected.txt b/ets2panda/test/compiler/ets/nullableTuple-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6cd2174f4a8d7e6d0de225745c01486ca618e50c --- /dev/null +++ b/ets2panda/test/compiler/ets/nullableTuple-expected.txt @@ -0,0 +1,797 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "TNumberStringPair", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 42 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 43 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "TTupleUnion", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TNumberStringPair", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 48 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TNumberStringPair", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 12, + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + { + "type": "StringLiteral", + "value": "Hello World", + "loc": { + "start": { + "line": 20, + "column": 38 + }, + "end": { + "line": 20, + "column": 51 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 20, + "column": 52 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 53 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TTupleUnion", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 11 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 8 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, + "init": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 8 + }, + "end": { + "line": 21, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 4 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 12 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 14 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 12, + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 23, + "column": 4 + }, + "end": { + "line": 23, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/nullableTuple.ets b/ets2panda/test/compiler/ets/nullableTuple.ets new file mode 100644 index 0000000000000000000000000000000000000000..7891b82c56a24f618c77595c4a1af0b90d654d0f --- /dev/null +++ b/ets2panda/test/compiler/ets/nullableTuple.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +type TNumberStringPair = [number, string]; +type TTupleUnion = TNumberStringPair|undefined; + +function main(): void { + let x: TNumberStringPair = [12.0, "Hello World"]; + let y: TTupleUnion = undefined; + + assert x[0] == 12.0; +} diff --git a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt index e4799e206c3975afe37d67236466909ca6fbeff2..5db12240c75b1dbec3b7d9bd61164d9bbed7bb7e 100644 --- a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt @@ -255,11 +255,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 15 + "column": 14 } } } @@ -383,7 +383,7 @@ }, "end": { "line": 18, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt index 37364fa25b8d25f5d7a19254dfe384a02a91aee4..939b83aee67c16d3bf4578907c273b5df14b8211 100644 --- a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt @@ -301,11 +301,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 3 + "column": 2 } } } @@ -428,8 +428,8 @@ "column": 5 }, "end": { - "line": 19, - "column": 11 + "line": 21, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt index 7d776f219ab4f37e9980605c8736ed316acc3b00..169a5fc0281d3782ebb68ec7591c7b883e92cf17 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt @@ -351,11 +351,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 3 + "column": 2 } } } @@ -478,8 +478,8 @@ "column": 5 }, "end": { - "line": 20, - "column": 11 + "line": 22, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt index 368098ad83f6eb7b5f35661510a5781ab22f2714..5cd0f4bddf4b50d36c14ec89c13559c22ce1cba1 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 15 + "column": 14 } } } @@ -289,7 +289,7 @@ }, "end": { "line": 18, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt index ef22164be00fe61f84da4df0bdc7c4adc381728e..1d661df1c8903a61214f9394e782d9733727402d 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 12 + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt index 365d537e22b794e553d61b68cf3d0407320c40f5..4ca426fbcd1116c9be8cbc318b863a55698c693a 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt @@ -298,11 +298,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 15 + "column": 14 } } } @@ -426,7 +426,7 @@ }, "end": { "line": 20, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt index d7eb3607ecdda660cc4a5d74dd402f5e03f19c6d..5af2594c5c6755cb3ea30fafdd89aa383432d918 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt @@ -302,11 +302,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 3 + "column": 2 } } } @@ -429,8 +429,8 @@ "column": 5 }, "end": { - "line": 19, - "column": 11 + "line": 21, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt index 15dc9ad6b1f1d483d7ac083b9f8a22f8341d1e22..6113219ccd8f8db6287845cb135fe8096785428d 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 17 + "column": 16 } } } @@ -218,7 +218,7 @@ }, "end": { "line": 16, - "column": 11 + "column": 16 } } } @@ -257,4 +257,4 @@ } } } -TypeError: target type for class composite needs to be an object type [objectLiteralPrimitiveContextType.ets:16:14] +TypeError: Target type for class composite needs to be an object type, found 'int' [objectLiteralPrimitiveContextType.ets:16:14] diff --git a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt index 65af224bc883906b76a4648d61499d8d66007624..47d07f348f76666b7e19baf5ab607894ae0d28ae 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt @@ -256,11 +256,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 15 + "column": 14 } } } @@ -384,7 +384,7 @@ }, "end": { "line": 20, - "column": 11 + "column": 14 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt index 277e55a111bd4dcedf02ac2061caecd338b5fc33..b919165f8eb8619518786458556247125a59be1e 100644 --- a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt @@ -351,11 +351,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 3 + "column": 2 } } } @@ -478,8 +478,8 @@ "column": 5 }, "end": { - "line": 20, - "column": 11 + "line": 22, + "column": 2 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt index b391dd776152656baf1fa61458c423c4940fd5ce..e741bd36d0e4dd5407e33e522c5db4f7db0fe471 100644 --- a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt @@ -351,11 +351,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 3 + "column": 2 } } } @@ -478,8 +478,8 @@ "column": 5 }, "end": { - "line": 20, - "column": 11 + "line": 22, + "column": 2 } } } @@ -518,4 +518,4 @@ } } } -TypeError: value type is not assignable to the property type [objectLiteralWrongValueType.ets:21:8] +TypeError: Type 'string' is not compatible with type 'int' at property 'f' [objectLiteralWrongValueType.ets:21:8] diff --git a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt index 9924e957d690a3113855b4d71560149411b50da3..24be78cae4b038b2e51b904cd49746f9301bb966 100644 --- a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt +++ b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt @@ -233,20 +233,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 16, @@ -385,16 +371,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -409,148 +395,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "exec", - "typeAnnotation": { - "type": "ETSFunctionType", - "params": [], - "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "void", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -561,34 +422,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 34 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 38 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -596,192 +457,8 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "exec", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { + "type": "ReturnStatement", + "argument": { "type": "CallExpression", "callee": { "type": "Identifier", @@ -790,27 +467,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "exec", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -819,22 +495,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -842,33 +518,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 606, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 606, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -881,7 +557,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt b/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt index 8ffd0b9a5d19dfe657a11d0b09cf16dcbafe7746..f893cf2cf947f21eb13ee07d5a94113356a00a8a 100644 --- a/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt +++ b/ets2panda/test/compiler/ets/switchStatementWrongBoxing-expected.txt @@ -696,4 +696,4 @@ } } } -TypeError: Switch case type byte is not comparable to discriminant type Int [switchStatementWrongBoxing.ets:21:18] +TypeError: Switch case type 'byte' is not comparable to discriminant type 'Int' [switchStatementWrongBoxing.ets:21:18] diff --git a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt index 14b1a16a4052ff3326d0faf4d09ed45a02c3c214..ec00b6e66775db291cf5967ae914d5c39549b73a 100644 --- a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt +++ b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt @@ -134,11 +134,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 28 + "column": 27 } } } diff --git a/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt index d72397b08129f0c4baff9b180854da7793e1d7b8..7f3a1736aab48579ebf17c752c738a584f5fd706 100644 --- a/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt @@ -670,4 +670,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [tuple_types_10_neg.ets:19:39] +TypeError: Type '[double, double]' cannot be assigned to type '[double, double, double]' [tuple_types_10_neg.ets:19:39] diff --git a/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt index 669daa1144697c1a660006e303b6418a12aff12f..999b175e3a065c110cd895d35d7f978a58b0c4b1 100644 --- a/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt @@ -684,4 +684,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [tuple_types_11_neg.ets:19:31] +TypeError: Type '[double, double, double]' cannot be assigned to type '[double, double]' [tuple_types_11_neg.ets:19:31] diff --git a/ets2panda/test/compiler/ets/tuple_types_16-expected.txt b/ets2panda/test/compiler/ets/tuple_types_16-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed97776aece3afabf4541668951cfbbd80036748 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_16-expected.txt @@ -0,0 +1,1523 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 17, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 17, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 17, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Func0", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "FuncTuple2", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 19, + "column": 5 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 19, + "column": 5 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "FuncTuple3", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Func0", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 40 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 9 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "t2", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "FuncTuple2", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 40 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 22, + "column": 44 + }, + "end": { + "line": 22, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 46 + } + } + }, + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 63 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 63 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 22, + "column": 67 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 69 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 70 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 70 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 70 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "t3", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "FuncTuple3", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 9 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 33 + }, + "end": { + "line": 23, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 33 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 33 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 40 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 23, + "column": 44 + }, + "end": { + "line": 23, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 46 + } + } + }, + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 56 + }, + "end": { + "line": 23, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 56 + }, + "end": { + "line": 23, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 56 + }, + "end": { + "line": 23, + "column": 63 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 49 + }, + "end": { + "line": 23, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 49 + }, + "end": { + "line": 23, + "column": 63 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 23, + "column": 67 + }, + "end": { + "line": 23, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 48 + }, + "end": { + "line": 23, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 48 + }, + "end": { + "line": 23, + "column": 69 + } + } + }, + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 23, + "column": 77 + }, + "end": { + "line": 23, + "column": 79 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 71 + }, + "end": { + "line": 23, + "column": 79 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 71 + }, + "end": { + "line": 23, + "column": 79 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 24 + }, + "end": { + "line": 23, + "column": 80 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 80 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 3 + }, + "end": { + "line": 23, + "column": 80 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_16.ets b/ets2panda/test/compiler/ets/tuple_types_16.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0069f32aa1522761c7f9e38408a26f2a388a8e3 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_16.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 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. + */ + +type Func1 = (value: String) => void +type Func0 = () => void; +type FuncTuple2 = [Func1, Func1] +type FuncTuple3 = [Func1, Func1, Func0] + +function main(): void { + let t2: FuncTuple2 = [(value: String) => {}, (value: String) => {}] + let t3: FuncTuple3 = [(value: String) => {}, (value: String) => {}, () => {}] +} diff --git a/ets2panda/test/compiler/ets/tuple_types_19-expected.txt b/ets2panda/test/compiler/ets/tuple_types_19-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c1e89ef573fc1e707aedc695c77a4224f6cd2765 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_19-expected.txt @@ -0,0 +1,2271 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "TuplePair", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "Y", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "one", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Y", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 16 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "provide", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "provide", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Y", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 29 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 43 + } + } + }, + "property": { + "type": "Identifier", + "name": "one", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 44 + }, + "end": { + "line": 18, + "column": 47 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 48 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 30 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "TupleProvider", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 20 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 17 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 23, + "column": 24 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 31 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 23, + "column": 34 + }, + "end": { + "line": 23, + "column": 38 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 39 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 34 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "right": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 46 + }, + "end": { + "line": 23, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 34 + }, + "end": { + "line": 23, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 34 + }, + "end": { + "line": 23, + "column": 52 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 32 + }, + "end": { + "line": 23, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 53 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 53 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "publish", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "publish", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 27 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 27 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 27 + }, + "end": { + "line": 24, + "column": 29 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 24, + "column": 23 + }, + "end": { + "line": 24, + "column": 31 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 43 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 44 + }, + "end": { + "line": 24, + "column": 48 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 32 + }, + "end": { + "line": 24, + "column": 49 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 30 + }, + "end": { + "line": 24, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 51 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 51 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "number_tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 29 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 30 + }, + "end": { + "line": 28, + "column": 37 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 28, + "column": 21 + }, + "end": { + "line": 28, + "column": 39 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 9 + }, + "end": { + "line": 28, + "column": 19 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 42, + "loc": { + "start": { + "line": 28, + "column": 41 + }, + "end": { + "line": 28, + "column": 45 + } + } + }, + { + "type": "NumberLiteral", + "value": 43, + "loc": { + "start": { + "line": 28, + "column": 47 + }, + "end": { + "line": 28, + "column": 51 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 40 + }, + "end": { + "line": 28, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 9 + }, + "end": { + "line": 28, + "column": 52 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 53 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tn", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TupleProvider", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 26 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 36 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TupleProvider", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 41 + }, + "end": { + "line": 29, + "column": 54 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 55 + }, + "end": { + "line": 29, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 55 + }, + "end": { + "line": 29, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 55 + }, + "end": { + "line": 29, + "column": 62 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 54 + }, + "end": { + "line": 29, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 41 + }, + "end": { + "line": 29, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 41 + }, + "end": { + "line": 29, + "column": 63 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "number_tup", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 63 + }, + "end": { + "line": 29, + "column": 73 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 75 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 75 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 75 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "result", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 26 + }, + "end": { + "line": 30, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 26 + }, + "end": { + "line": 30, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 26 + }, + "end": { + "line": 30, + "column": 33 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 15 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tn", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 36 + }, + "end": { + "line": 30, + "column": 38 + } + } + }, + "property": { + "type": "Identifier", + "name": "publish", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 46 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 30, + "column": 36 + }, + "end": { + "line": 30, + "column": 46 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 30, + "column": 36 + }, + "end": { + "line": 30, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 48 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 49 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 16 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 32, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_19.ets b/ets2panda/test/compiler/ets/tuple_types_19.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb744db81f9bb5fe65c828a53358f149b16b33c0 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_19.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 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. + */ + +class TuplePair { + one: [X, Y] + public provide(): [X, Y] { return this.one; } +} + +class TupleProvider { + memb: [X, X]; + constructor(value: [X, X]) { this.memb = value;} + public publish(): [X, X] { return this.memb; } +} + +function foo() { + let number_tup: [Double, Double] = [42.0, 43.0]; + let tn: TupleProvider = new TupleProvider(number_tup); + let result: [Number, Number] = tn.publish(); +} diff --git a/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt index b54e94654925d1e947df0a94a2a422e77fb8d7d7..01342b3043190796795c718862a79fccfe61600f 100644 --- a/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt @@ -533,4 +533,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [tuple_types_6_neg.ets:19:23] +TypeError: Type '[double]' cannot be assigned to type '[Double]' [tuple_types_6_neg.ets:19:23] diff --git a/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt index b3ff7ada9a55d8e924a21cbf03450f3a735d4d72..959d61e1011afa27a0a0ced8f375374fdc2c4a61 100644 --- a/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt @@ -737,4 +737,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [tuple_types_9_neg.ets:19:36] +TypeError: Type '[double, String, ...Int[]]' cannot be assigned to type '[double, String, Int]' [tuple_types_9_neg.ets:19:36] diff --git a/ets2panda/test/compiler/ets/typeAlias-expected.txt b/ets2panda/test/compiler/ets/typeAlias-expected.txt index 4f17d69d03438581f00eefe50e28732e1d2d4227..2f9467386e7446c3d6d02b3dd65de31ccf83d260 100644 --- a/ets2panda/test/compiler/ets/typeAlias-expected.txt +++ b/ets2panda/test/compiler/ets/typeAlias-expected.txt @@ -179,11 +179,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 29 + "column": 28 } } } diff --git a/ets2panda/test/compiler/ets/union_types_4-expected.txt b/ets2panda/test/compiler/ets/union_types_4-expected.txt index 3ae46f4f245c157c7e296e237c49a9f52d4ef420..bdf5420f3250eb689575b745872c63bd7784175b 100644 --- a/ets2panda/test/compiler/ets/union_types_4-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_4-expected.txt @@ -1555,4 +1555,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [union_types_4.ets:30:9] +TypeError: Type 'B' cannot be assigned to type 'String|Short|A' [union_types_4.ets:30:9] diff --git a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt index b50e9e486748a14f8ad68761bfe6093b6b1ee9e0..e3d9bb26996bce61295784fdbb1dc03a09b77d27 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt @@ -133,7 +133,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt index f981e5c3544c73106fa0e317c75001073cc238bc..d4d7953e1ddc1cfdb2618604ac4986693b9e892a 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt @@ -296,7 +296,7 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 18, @@ -368,7 +368,7 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, diff --git a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt index f38a7fdcfff8746312205053549a22f3cd26c14e..ad15034d8115d3f755ff12deb9605ccc76574606 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt @@ -118,7 +118,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/parser/ets/FunctionType-expected.txt b/ets2panda/test/parser/ets/FunctionType-expected.txt index 051ecf2aa9ba66bce0629e4cfa1a0f047d63f03c..dc021dada9161ad394a153deb782588c9a2b40a6 100644 --- a/ets2panda/test/parser/ets/FunctionType-expected.txt +++ b/ets2panda/test/parser/ets/FunctionType-expected.txt @@ -569,7 +569,7 @@ }, "end": { "line": 16, - "column": 32 + "column": 6 } } }, @@ -674,7 +674,7 @@ }, "end": { "line": 17, - "column": 26 + "column": 6 } } }, diff --git a/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt b/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt index e93759c2243f392338aa46f83c9ca3eca341abe8..729267764b1fa5fd473148c109b91e5f4a5c647f 100644 --- a/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt +++ b/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt @@ -168,20 +168,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 17, @@ -359,16 +345,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 8 } } }, @@ -383,134 +369,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 8 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "param", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -521,12 +396,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 26 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 27 } } }, @@ -543,258 +418,74 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 28 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 29 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 27 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "param", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -806,11 +497,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -821,11 +512,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -834,27 +525,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "param", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -863,22 +553,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -886,33 +576,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 628, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 628, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -925,7 +615,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1253,20 +943,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 23, @@ -1485,16 +1161,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 8 } } }, @@ -1509,134 +1185,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 8 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "param", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -1647,12 +1212,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 23, + "column": 26 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 27 } } }, @@ -1669,34 +1234,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 23, + "column": 28 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 29 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1710,258 +1275,74 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 23, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 31 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], "loc": { "start": { - "line": 1, - "column": 3 + "line": 23, + "column": 27 }, "end": { - "line": 1, - "column": 3 + "line": 23, + "column": 32 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "param", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -1973,11 +1354,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1988,11 +1369,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2001,27 +1382,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "param", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2030,22 +1410,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2053,33 +1433,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 704, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 704, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2092,7 +1472,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/ambiguous_call_1-expected.txt b/ets2panda/test/parser/ets/ambiguous_call_1-expected.txt index 6c87709fc0d5444e5425f038a53931f2a119957a..148428068646902e1de2336131ae20fe73c92cfb 100644 --- a/ets2panda/test/parser/ets/ambiguous_call_1-expected.txt +++ b/ets2panda/test/parser/ets/ambiguous_call_1-expected.txt @@ -621,7 +621,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -632,7 +632,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -814,7 +814,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -825,7 +825,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -1062,7 +1062,7 @@ "loc": { "start": { "line": 22, - "column": 15 + "column": 14 }, "end": { "line": 24, @@ -1073,7 +1073,7 @@ "loc": { "start": { "line": 22, - "column": 15 + "column": 14 }, "end": { "line": 24, diff --git a/ets2panda/test/parser/ets/ambiguous_call_2-expected.txt b/ets2panda/test/parser/ets/ambiguous_call_2-expected.txt index 6fb45ac9a58bb9d68457777ab0df9c2d2af6d304..d6d64da7f553380079804535db743eac6be32e22 100644 --- a/ets2panda/test/parser/ets/ambiguous_call_2-expected.txt +++ b/ets2panda/test/parser/ets/ambiguous_call_2-expected.txt @@ -1022,7 +1022,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -1033,7 +1033,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -1325,7 +1325,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -1336,7 +1336,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -1640,7 +1640,7 @@ "loc": { "start": { "line": 18, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -1651,7 +1651,7 @@ "loc": { "start": { "line": 18, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -1916,7 +1916,7 @@ "loc": { "start": { "line": 26, - "column": 15 + "column": 14 }, "end": { "line": 28, @@ -1927,7 +1927,7 @@ "loc": { "start": { "line": 26, - "column": 15 + "column": 14 }, "end": { "line": 28, diff --git a/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt b/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt index eaca9b0b5c8b670de976435123d9890766056d5c..b0372384472fab1d80e94652d49988402ff23b9e 100644 --- a/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt +++ b/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt @@ -701,7 +701,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -712,7 +712,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 16, @@ -894,7 +894,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -905,7 +905,7 @@ "loc": { "start": { "line": 17, - "column": 14 + "column": 13 }, "end": { "line": 17, @@ -1142,7 +1142,7 @@ "loc": { "start": { "line": 22, - "column": 15 + "column": 14 }, "end": { "line": 24, @@ -1153,7 +1153,7 @@ "loc": { "start": { "line": 22, - "column": 15 + "column": 14 }, "end": { "line": 24, diff --git a/ets2panda/test/parser/ets/array-expected.txt b/ets2panda/test/parser/ets/array-expected.txt index 94a5bd22f3afa1dc49d04edd32d2342628ce3c27..3a3d657a176f9baf8bb49aec3e5c4010543271ed 100644 --- a/ets2panda/test/parser/ets/array-expected.txt +++ b/ets2panda/test/parser/ets/array-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 24 + "column": 23 } } }, @@ -260,11 +260,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 35 + "column": 34 } } } @@ -373,7 +373,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 23 } } }, @@ -463,7 +463,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 34 } } }, diff --git a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt index d9ff0c65bccdf4ff3e8f29a7deff02413dc370e6..7a2d431eb4ca7b5d87725f8f8cc43ff96fa17938 100644 --- a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 28 + "column": 27 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 31 + "column": 30 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 31 + "column": 30 } } } @@ -343,7 +343,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 27 } } }, @@ -405,7 +405,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 30 } } }, @@ -495,7 +495,7 @@ }, "end": { "line": 18, - "column": 18 + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/assign-expected.txt b/ets2panda/test/parser/ets/assign-expected.txt index 89ce3dbfcaa36a1abdb33489da5ff8c2b95fcd1b..1ee8a063a2f43d6e14c10ea189d4935814e31a6f 100644 --- a/ets2panda/test/parser/ets/assign-expected.txt +++ b/ets2panda/test/parser/ets/assign-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } } diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ca5ac47b0920194410560ce064a40e53f7d4dc5 --- /dev/null +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt @@ -0,0 +1,894 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "__Observable__", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "__memo_state_observable_handler__", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 45 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Observable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 53 + }, + "end": { + "line": 17, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 53 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 53 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 47 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Observable", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "installOn", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "installOn", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "observable", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Observable", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 49 + }, + "end": { + "line": 21, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 49 + }, + "end": { + "line": 21, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 49 + }, + "end": { + "line": 21, + "column": 60 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 37 + }, + "end": { + "line": 21, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 37 + }, + "end": { + "line": 21, + "column": 60 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "TSAsExpression", + "expression": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "__Observable__", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "property": { + "type": "Identifier", + "name": "__memo_state_observable_handler__", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 68 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 68 + } + } + }, + "right": { + "type": "Identifier", + "name": "observable", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 71 + }, + "end": { + "line": 23, + "column": 81 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 81 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 81 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 27, + "column": 1 + } + } +} +TypeError: Assigning a non-functional variable "observable" to a functional type [assignment_non-functional_variable_to_functional_type.ets:23:71] diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type.ets b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..4288ab1f6b71fc00fb0c4925c8378045e2d62a4d --- /dev/null +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type.ets @@ -0,0 +1,26 @@ +/** + * Copyright (c) 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. + */ + +abstract class __Observable__ { + public __memo_state_observable_handler__: () => Observable|undefined; +} + +class Observable { + static installOn(value: Object, observable: Observable|undefined) + { + (value as __Observable__).__memo_state_observable_handler__ = observable + } + +} diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1-expected.txt b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..366185c853bd450c1640486343677eeb2bc1922b --- /dev/null +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1-expected.txt @@ -0,0 +1,449 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "right": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} +TypeError: Assigning a non-functional variable "b" to a functional type [assignment_non-functional_variable_to_functional_type_1.ets:20:9] diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1.ets b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..fec2befa80c4552c67cb95286d6b630a9a6efc24 --- /dev/null +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type_1.ets @@ -0,0 +1,21 @@ +/** + * Copyright (c) 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. + */ + +function main() +{ + let a: () => int + let b: int = 5 + a = b +} diff --git a/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt b/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt index f10a8253c6cf59df9b10891b6ea0675f9b1beb3e..1ddada092839217f70e5bde695f072d200d95e35 100644 --- a/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt +++ b/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt @@ -342,4 +342,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [async_func_return_type_bad.ets:17:12] +TypeError: Type 'string' is not compatible with the enclosing method's return type 'Promise | Int' [async_func_return_type_bad.ets:17:12] diff --git a/ets2panda/test/parser/ets/async_function_bad-expected.txt b/ets2panda/test/parser/ets/async_function_bad-expected.txt index 2e3d432ead6d64f283e0d4196d4ab650fc8cc078..a993bdde6d280ecd6326bc98219d054f6ea81755 100644 --- a/ets2panda/test/parser/ets/async_function_bad-expected.txt +++ b/ets2panda/test/parser/ets/async_function_bad-expected.txt @@ -1 +1 @@ -SyntaxError: 'async' flags must be used for functions at top-level. [async_function_bad.ets:16:7] +SyntaxError: 'async' flags must be used for functions only at top-level. [async_function_bad.ets:16:7] diff --git a/ets2panda/test/parser/ets/async_with_lambda-expected.txt b/ets2panda/test/parser/ets/async_with_lambda-expected.txt index 657afa171455554c64b5d2a5cf2dd6abbcda280e..5fa0aaafbba26540c44ed7c1f6518659a0df02a5 100644 --- a/ets2panda/test/parser/ets/async_with_lambda-expected.txt +++ b/ets2panda/test/parser/ets/async_with_lambda-expected.txt @@ -161,7 +161,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 11 } } }, diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 2159d4df660a84e8b58988960fd248006cbbf539..8eb07173bd88ec6e8117fe2ac20cd045f25726f4 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 38, - "column": 1 + "column": 5 }, "end": { "line": 38, - "column": 44 + "column": 43 } } }, @@ -188,7 +188,7 @@ "loc": { "start": { "line": 39, - "column": 1 + "column": 5 }, "end": { "line": 39, @@ -2296,7 +2296,7 @@ }, "end": { "line": 38, - "column": 31 + "column": 43 } } }, @@ -2373,7 +2373,7 @@ }, "end": { "line": 39, - "column": 18 + "column": 33 } } } diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index f491c8074d578921dbadc41b6583978df7d70555..91bcafa112fb9edfbe39c50faa899c63ec9a8544 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 11 + "column": 10 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 11 + "column": 10 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 15 + "column": 14 } } }, @@ -286,11 +286,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 16 + "column": 15 } } }, @@ -383,7 +383,7 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, @@ -439,11 +439,11 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 30 + "column": 29 } } }, @@ -525,11 +525,11 @@ "loc": { "start": { "line": 25, - "column": 1 + "column": 5 }, "end": { "line": 25, - "column": 19 + "column": 18 } } }, @@ -640,11 +640,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 25 + "column": 24 } } }, @@ -726,11 +726,11 @@ "loc": { "start": { "line": 29, - "column": 1 + "column": 5 }, "end": { "line": 29, - "column": 20 + "column": 19 } } }, @@ -812,11 +812,11 @@ "loc": { "start": { "line": 30, - "column": 1 + "column": 5 }, "end": { "line": 30, - "column": 20 + "column": 19 } } }, @@ -956,11 +956,11 @@ "loc": { "start": { "line": 31, - "column": 1 + "column": 5 }, "end": { "line": 31, - "column": 34 + "column": 33 } } }, @@ -1100,11 +1100,11 @@ "loc": { "start": { "line": 32, - "column": 1 + "column": 5 }, "end": { "line": 32, - "column": 34 + "column": 33 } } }, @@ -1244,11 +1244,11 @@ "loc": { "start": { "line": 33, - "column": 1 + "column": 5 }, "end": { "line": 33, - "column": 34 + "column": 33 } } }, @@ -1388,11 +1388,11 @@ "loc": { "start": { "line": 34, - "column": 1 + "column": 5 }, "end": { "line": 34, - "column": 34 + "column": 33 } } }, @@ -1474,11 +1474,11 @@ "loc": { "start": { "line": 37, - "column": 1 + "column": 5 }, "end": { "line": 37, - "column": 17 + "column": 16 } } }, @@ -1560,11 +1560,11 @@ "loc": { "start": { "line": 38, - "column": 1 + "column": 5 }, "end": { "line": 38, - "column": 17 + "column": 16 } } }, @@ -1646,11 +1646,11 @@ "loc": { "start": { "line": 39, - "column": 1 + "column": 5 }, "end": { "line": 39, - "column": 17 + "column": 16 } } }, @@ -1848,11 +1848,11 @@ "loc": { "start": { "line": 40, - "column": 1 + "column": 5 }, "end": { "line": 40, - "column": 33 + "column": 32 } } }, @@ -1934,11 +1934,11 @@ "loc": { "start": { "line": 43, - "column": 1 + "column": 5 }, "end": { "line": 43, - "column": 18 + "column": 17 } } }, @@ -2020,11 +2020,11 @@ "loc": { "start": { "line": 44, - "column": 1 + "column": 5 }, "end": { "line": 44, - "column": 18 + "column": 17 } } }, @@ -2106,11 +2106,11 @@ "loc": { "start": { "line": 45, - "column": 1 + "column": 5 }, "end": { "line": 45, - "column": 21 + "column": 20 } } }, @@ -2192,11 +2192,11 @@ "loc": { "start": { "line": 46, - "column": 1 + "column": 5 }, "end": { "line": 46, - "column": 21 + "column": 20 } } }, @@ -2278,11 +2278,11 @@ "loc": { "start": { "line": 49, - "column": 1 + "column": 5 }, "end": { "line": 49, - "column": 17 + "column": 16 } } }, @@ -2364,11 +2364,11 @@ "loc": { "start": { "line": 50, - "column": 1 + "column": 5 }, "end": { "line": 50, - "column": 17 + "column": 16 } } }, @@ -2450,11 +2450,11 @@ "loc": { "start": { "line": 51, - "column": 1 + "column": 5 }, "end": { "line": 51, - "column": 18 + "column": 17 } } }, @@ -2536,11 +2536,11 @@ "loc": { "start": { "line": 52, - "column": 1 + "column": 5 }, "end": { "line": 52, - "column": 18 + "column": 17 } } }, @@ -2622,11 +2622,11 @@ "loc": { "start": { "line": 53, - "column": 1 + "column": 5 }, "end": { "line": 53, - "column": 32 + "column": 31 } } }, @@ -2708,11 +2708,11 @@ "loc": { "start": { "line": 56, - "column": 1 + "column": 5 }, "end": { "line": 56, - "column": 18 + "column": 17 } } }, @@ -2794,11 +2794,11 @@ "loc": { "start": { "line": 57, - "column": 1 + "column": 5 }, "end": { "line": 57, - "column": 18 + "column": 17 } } }, @@ -2880,11 +2880,11 @@ "loc": { "start": { "line": 58, - "column": 1 + "column": 5 }, "end": { "line": 58, - "column": 19 + "column": 18 } } }, @@ -3024,11 +3024,11 @@ "loc": { "start": { "line": 59, - "column": 1 + "column": 5 }, "end": { "line": 59, - "column": 29 + "column": 28 } } }, @@ -3110,11 +3110,11 @@ "loc": { "start": { "line": 62, - "column": 1 + "column": 5 }, "end": { "line": 62, - "column": 17 + "column": 16 } } }, @@ -3196,11 +3196,11 @@ "loc": { "start": { "line": 63, - "column": 1 + "column": 5 }, "end": { "line": 63, - "column": 17 + "column": 16 } } }, @@ -3340,11 +3340,11 @@ "loc": { "start": { "line": 64, - "column": 1 + "column": 5 }, "end": { "line": 64, - "column": 25 + "column": 24 } } }, @@ -3426,11 +3426,11 @@ "loc": { "start": { "line": 67, - "column": 1 + "column": 5 }, "end": { "line": 67, - "column": 17 + "column": 16 } } }, @@ -3512,11 +3512,11 @@ "loc": { "start": { "line": 68, - "column": 1 + "column": 5 }, "end": { "line": 68, - "column": 17 + "column": 16 } } }, @@ -3598,11 +3598,11 @@ "loc": { "start": { "line": 69, - "column": 1 + "column": 5 }, "end": { "line": 69, - "column": 17 + "column": 16 } } }, @@ -3800,11 +3800,11 @@ "loc": { "start": { "line": 70, - "column": 1 + "column": 5 }, "end": { "line": 70, - "column": 33 + "column": 32 } } }, @@ -3944,11 +3944,11 @@ "loc": { "start": { "line": 73, - "column": 1 + "column": 5 }, "end": { "line": 73, - "column": 27 + "column": 26 } } }, @@ -4088,11 +4088,11 @@ "loc": { "start": { "line": 74, - "column": 1 + "column": 5 }, "end": { "line": 74, - "column": 29 + "column": 28 } } }, @@ -4435,11 +4435,11 @@ "loc": { "start": { "line": 75, - "column": 1 + "column": 5 }, "end": { "line": 75, - "column": 63 + "column": 62 } } }, @@ -4782,11 +4782,11 @@ "loc": { "start": { "line": 76, - "column": 1 + "column": 5 }, "end": { "line": 76, - "column": 64 + "column": 63 } } }, @@ -4955,11 +4955,11 @@ "loc": { "start": { "line": 77, - "column": 1 + "column": 5 }, "end": { "line": 77, - "column": 35 + "column": 34 } } } @@ -5374,7 +5374,7 @@ }, "end": { "line": 22, - "column": 17 + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/boolean-expected.txt b/ets2panda/test/parser/ets/boolean-expected.txt index ddbbcc7ffe442204fe38b00816e034e1440fa5c6..bb679ea24a2d68fff09aada663c9bcaf645a3c43 100644 --- a/ets2panda/test/parser/ets/boolean-expected.txt +++ b/ets2panda/test/parser/ets/boolean-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 23 + "column": 22 } } } @@ -218,7 +218,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/break-expected.txt b/ets2panda/test/parser/ets/break-expected.txt index c165861131c3dca33733e7b1a729bb99e726b1c6..de23f03f7fce3c61174941971647bf4eb59f0d0e 100644 --- a/ets2panda/test/parser/ets/break-expected.txt +++ b/ets2panda/test/parser/ets/break-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/cast_expressions5-expected.txt b/ets2panda/test/parser/ets/cast_expressions5-expected.txt index d8a3a2b217d8f3854979e80bd5d1110a4dd80f79..e68c5b2871da60fc0ea86b28d06422f40b4116cd 100644 --- a/ets2panda/test/parser/ets/cast_expressions5-expected.txt +++ b/ets2panda/test/parser/ets/cast_expressions5-expected.txt @@ -717,11 +717,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -817,7 +817,7 @@ }, "end": { "line": 16, - "column": 21 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/class_instance-expected.txt b/ets2panda/test/parser/ets/class_instance-expected.txt index a4e953fd73edf315b9fb8640d579eb82ca42af9e..ec3b1a26abc0f5c07063532cdcc6e88b8788a1bc 100644 --- a/ets2panda/test/parser/ets/class_instance-expected.txt +++ b/ets2panda/test/parser/ets/class_instance-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 12 + "column": 11 } } }, @@ -256,11 +256,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 21 + "column": 20 } } }, @@ -356,11 +356,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 23 + "column": 22 } } }, @@ -500,11 +500,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 30 + "column": 29 } } } diff --git a/ets2panda/test/parser/ets/const_enum-expected.txt b/ets2panda/test/parser/ets/const_enum-expected.txt index 512ed79e801a4e6f3a3a937586aac7d904238771..bfb000b7101af408f91801cce4f18a74329c6e08 100644 --- a/ets2panda/test/parser/ets/const_enum-expected.txt +++ b/ets2panda/test/parser/ets/const_enum-expected.txt @@ -1 +1 @@ -SyntaxError: Identifier expected. [const_enum.ets:16:7] +SyntaxError: Variable declaration expected. [const_enum.ets:16:7] diff --git a/ets2panda/test/parser/ets/continue-expected.txt b/ets2panda/test/parser/ets/continue-expected.txt index cd8cfe6fabf65c4e7e0b788ab216c52b559ed281..264fa690177a02a6a2cef7da2581307d074a6eae 100644 --- a/ets2panda/test/parser/ets/continue-expected.txt +++ b/ets2panda/test/parser/ets/continue-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/decl_infer-expected.txt b/ets2panda/test/parser/ets/decl_infer-expected.txt index 0455f4f8b2e9110156d6a2d656885ede6c5def4d..effb99d39e18b21b2de5b47f788631aec3ebc7ea 100644 --- a/ets2panda/test/parser/ets/decl_infer-expected.txt +++ b/ets2panda/test/parser/ets/decl_infer-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 12 + "column": 11 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 14 + "column": 13 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 15 + "column": 14 } } }, @@ -286,11 +286,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 15 + "column": 14 } } }, @@ -342,11 +342,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 16 + "column": 15 } } } diff --git a/ets2panda/test/parser/ets/default_parameter1-expected.txt b/ets2panda/test/parser/ets/default_parameter1-expected.txt index 41c4146c87dd859f8051680729b5de2477869813..2c507550ebe4adfb70277b6a6d3cb2ced975cca0 100644 --- a/ets2panda/test/parser/ets/default_parameter1-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter1-expected.txt @@ -426,20 +426,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 21, - "column": 33 - }, - "end": { - "line": 21, - "column": 35 - } - } - }, "loc": { "start": { "line": 21, @@ -564,16 +550,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -588,16 +574,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -615,116 +601,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "b", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -734,201 +638,17 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -940,11 +660,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -952,30 +672,42 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "NumberLiteral", + "value": 10, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -984,22 +716,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1007,33 +739,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 646, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 646, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1046,7 +778,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1276,4 +1008,4 @@ } } } -TypeError: Function already declared. [default_parameter1.ets:26:1] +TypeError: Function with this assembly signature already declared. [default_parameter1.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter2-expected.txt b/ets2panda/test/parser/ets/default_parameter2-expected.txt index 1bc729dc18971726d43817eb01a32178dba82144..4983c78f49b893f85a18f89e20f8517ebb8cc17d 100644 --- a/ets2panda/test/parser/ets/default_parameter2-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter2-expected.txt @@ -411,20 +411,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 21, - "column": 33 - }, - "end": { - "line": 21, - "column": 35 - } - } - }, "loc": { "start": { "line": 21, @@ -549,16 +535,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -573,16 +559,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -600,116 +586,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "b", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -719,201 +623,17 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -925,11 +645,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -937,30 +657,42 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "NumberLiteral", + "value": 10, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -969,22 +701,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -992,33 +724,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 645, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 645, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1031,7 +763,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1261,4 +993,4 @@ } } } -TypeError: Function already declared. [default_parameter2.ets:26:1] +TypeError: Function with this assembly signature already declared. [default_parameter2.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter4-expected.txt b/ets2panda/test/parser/ets/default_parameter4-expected.txt index 9ddd3595837e5d7ce3500487c46e198fe039fd33..cdb523e6a2de8bba99089279cbdb7aef91207909 100644 --- a/ets2panda/test/parser/ets/default_parameter4-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter4-expected.txt @@ -426,20 +426,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 21, - "column": 33 - }, - "end": { - "line": 21, - "column": 35 - } - } - }, "loc": { "start": { "line": 21, @@ -481,20 +467,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 15, - "loc": { - "start": { - "line": 21, - "column": 47 - }, - "end": { - "line": 21, - "column": 49 - } - } - }, "loc": { "start": { "line": 21, @@ -648,16 +620,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -672,16 +644,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -699,34 +671,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -740,116 +712,34 @@ "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "c", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 30 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -859,11 +749,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -871,373 +761,269 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "arguments": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 10, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 30 } } }, - "right": { + { "type": "NumberLiteral", - "value": 1, + "value": 15, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } } - }, + ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 15, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 646, + "column": 1 + }, + "end": { + "line": 646, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ReturnStatement", "argument": { @@ -1249,11 +1035,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1261,45 +1047,56 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "NumberLiteral", + "value": 10, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "c", - "decorators": [], + "type": "NumberLiteral", + "value": 15, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1308,22 +1105,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1331,33 +1128,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 646, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 646, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1370,7 +1167,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1449,20 +1246,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 5, - "loc": { - "start": { - "line": 26, - "column": 24 - }, - "end": { - "line": 26, - "column": 25 - } - } - }, "loc": { "start": { "line": 26, @@ -1570,16 +1353,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 26, + "column": 13 } } }, @@ -1594,306 +1377,39 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 26, + "column": 13 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "a", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 5, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -1905,27 +1421,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "a", - "decorators": [], + "type": "NumberLiteral", + "value": 5, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1934,22 +1449,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1957,33 +1472,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 729, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 729, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1996,7 +1511,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2048,4 +1563,4 @@ } } } -TypeError: Function already declared. [default_parameter4.ets:26:1] +TypeError: Function with this assembly signature already declared. [default_parameter4.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter5-expected.txt b/ets2panda/test/parser/ets/default_parameter5-expected.txt index ab0a5a6760f5398fd88173f216c0a6321beaadcd..8fac2d596690fd542cbb763bc636d90891930be3 100644 --- a/ets2panda/test/parser/ets/default_parameter5-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter5-expected.txt @@ -481,65 +481,6 @@ } } }, - "initializer": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "boo2", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 46 - }, - "end": { - "line": 21, - "column": 50 - } - } - }, - "arguments": [ - { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 21, - "column": 51 - }, - "end": { - "line": 21, - "column": 52 - } - } - }, - { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 21, - "column": 53 - }, - "end": { - "line": 21, - "column": 54 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 21, - "column": 46 - }, - "end": { - "line": 21, - "column": 55 - } - } - }, "loc": { "start": { "line": 21, @@ -693,16 +634,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "boo2_proxy", + "name": "boo2", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 } } }, @@ -717,16 +658,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "boo2_proxy", + "name": "boo2", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 } } }, @@ -744,34 +685,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 15 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -785,116 +726,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "a2", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 25 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 33 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -904,11 +763,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -916,296 +775,137 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "boo2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "right": { - "type": "NumberLiteral", - "value": 2, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + { + "type": "Identifier", + "name": "a1", + "typeAnnotation": { + "type": "ETSPrimitiveType", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 25 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 33 } } }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "boo2", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 46 + }, + "end": { + "line": 21, + "column": 50 + } } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "a2", - "decorators": [], + "arguments": [ + { + "type": "NumberLiteral", + "value": 1, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "right": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "boo2", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "arguments": [ - { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "optional": false, + { + "type": "NumberLiteral", + "value": 2, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ReturnStatement", - "argument": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "boo2", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "a0", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "Identifier", - "name": "a1", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "Identifier", - "name": "a2", - "decorators": [], + ], + "optional": false, "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 46 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 55 } } } @@ -1214,22 +914,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1237,33 +937,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 667, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 667, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1276,7 +976,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/default_parameter6-expected.txt b/ets2panda/test/parser/ets/default_parameter6-expected.txt index ad8c1be4b178b428ef903861db2327627164809c..465604404e5f9fe4cfd76d4ec2fb55d4c24c8406 100644 --- a/ets2panda/test/parser/ets/default_parameter6-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter6-expected.txt @@ -288,20 +288,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 20, - "loc": { - "start": { - "line": 16, - "column": 33 - }, - "end": { - "line": 16, - "column": 35 - } - } - }, "loc": { "start": { "line": 16, @@ -371,20 +357,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 16, - "column": 47 - }, - "end": { - "line": 16, - "column": 49 - } - } - }, "loc": { "start": { "line": 16, @@ -507,16 +479,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -531,16 +503,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -563,57 +535,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 22 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -632,167 +604,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "c", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 27 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 30 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 32 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -807,34 +669,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 53 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 56 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -842,373 +704,381 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 21 + } + } }, - "end": { - "line": 1, - "column": 3 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 22 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 30 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 20, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + { + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 606, + "column": 1 + }, + "end": { + "line": 606, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 22 } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 }, - "alternate": null, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 53 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 56 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ReturnStatement", "argument": { @@ -1220,11 +1090,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1232,45 +1102,84 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 22 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "NumberLiteral", + "value": 20, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "c", - "decorators": [], + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1279,22 +1188,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1302,33 +1211,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 606, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 606, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1341,7 +1250,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1517,20 +1426,6 @@ } } }, - "initializer": { - "type": "StringLiteral", - "value": "a", - "loc": { - "start": { - "line": 21, - "column": 36 - }, - "end": { - "line": 21, - "column": 39 - } - } - }, "loc": { "start": { "line": 21, @@ -1600,20 +1495,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 21, - "column": 51 - }, - "end": { - "line": 21, - "column": 53 - } - } - }, "loc": { "start": { "line": 21, @@ -1748,16 +1629,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -1772,158 +1653,89 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "a", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } + "line": 21, + "column": 10 }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } + "end": { + "line": 21, + "column": 13 } - }, + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ { "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "b", + "name": "a", "typeAnnotation": { "type": "ETSTypeReference", "part": { "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "string", + "name": "Int", "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1931,109 +1743,68 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "c", + "name": "b", "typeAnnotation": { "type": "ETSTypeReference", "part": { "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Int", + "name": "string", "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 27 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 33 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 35 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2048,34 +1819,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 57 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 60 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2083,373 +1854,381 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "arguments": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } } - } - }, - "right": { - "type": "StringLiteral", - "value": "a", + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ + "line": 21, + "column": 22 + } + } + }, { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 33 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 30, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 681, + "column": 1 + }, + "end": { + "line": 681, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 57 + }, + "end": { + "line": 21, + "column": 60 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ReturnStatement", "argument": { @@ -2461,11 +2240,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2473,45 +2252,84 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "StringLiteral", + "value": "a", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "c", - "decorators": [], + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2520,22 +2338,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2543,33 +2361,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 681, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 681, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -2582,7 +2400,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -2634,4 +2452,4 @@ } } } -TypeError: Function already declared. [default_parameter6.ets:21:1] +TypeError: Function with this assembly signature already declared. [default_parameter6.ets:1:1] diff --git a/ets2panda/test/parser/ets/default_parameter7-expected.txt b/ets2panda/test/parser/ets/default_parameter7-expected.txt index c6d4b58f37b4e7b7ec71d7ec93e3d29cc8df1f35..def50f4bb4ab5f728749b0a43b35620c657fbd5a 100644 --- a/ets2panda/test/parser/ets/default_parameter7-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter7-expected.txt @@ -535,20 +535,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 21, @@ -618,20 +604,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 21, - "column": 46 - }, - "end": { - "line": 21, - "column": 48 - } - } - }, "loc": { "start": { "line": 21, @@ -766,16 +738,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -790,16 +762,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 13 } } }, @@ -822,57 +794,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -891,167 +863,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "c", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 28 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 34 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 35 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1066,34 +928,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 52 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 55 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1101,373 +963,381 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } }, - "end": { - "line": 1, - "column": 3 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 28 + }, + "end": { + "line": 21, + "column": 34 + } } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 35 } } - } - ], + }, + { + "type": "NumberLiteral", + "value": 30, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 658, + "column": 1 + }, + "end": { + "line": 658, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 18 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 30, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 }, - "alternate": null, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 52 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 55 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { "type": "ReturnStatement", "argument": { @@ -1479,11 +1349,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1491,45 +1361,84 @@ { "type": "Identifier", "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 21, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 21, + "column": 22 } } }, { - "type": "Identifier", - "name": "b", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "c", - "decorators": [], + "type": "NumberLiteral", + "value": 30, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1538,22 +1447,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1561,33 +1470,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 658, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 658, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1600,7 +1509,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1652,4 +1561,4 @@ } } } -TypeError: Function already declared. [default_parameter7.ets:21:1] +TypeError: Function already declared. [default_parameter7.ets:1:1] diff --git a/ets2panda/test/parser/ets/default_parameter8-expected.txt b/ets2panda/test/parser/ets/default_parameter8-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c10f4020e5377ae0575d8fa7313e50693b3c88e --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter8-expected.txt @@ -0,0 +1,3219 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "param", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 31 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "property": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "right": { + "type": "Identifier", + "name": "param", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 33 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 101, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 638, + "column": 1 + }, + "end": { + "line": 638, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "param", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 32 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "right": { + "type": "Identifier", + "name": "param", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 34 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "SetA", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 99, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 700, + "column": 1 + }, + "end": { + "line": 700, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 7 + }, + "end": { + "line": 26, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "fs", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 12 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 102, + "loc": { + "start": { + "line": 27, + "column": 19 + }, + "end": { + "line": 27, + "column": 22 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 27, + "column": 15 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 12 + }, + "end": { + "line": 27, + "column": 22 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "fc", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 7 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 10001, + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 17 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 28, + "column": 8 + }, + "end": { + "line": 28, + "column": 11 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 17 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 6 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 29, + "column": 7 + }, + "end": { + "line": 29, + "column": 10 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 10 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "param", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 45 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 31, + "column": 15 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 15 + } + } + }, + "right": { + "type": "Identifier", + "name": "param", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 18 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 44 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 30, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "fc", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 33 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 839, + "column": 1 + }, + "end": { + "line": 839, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "getC", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 12 + }, + "end": { + "line": 33, + "column": 16 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "getC", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 12 + }, + "end": { + "line": 33, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 34, + "column": 16 + }, + "end": { + "line": 34, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 21 + }, + "end": { + "line": 34, + "column": 22 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 34, + "column": 16 + }, + "end": { + "line": 34, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 9 + }, + "end": { + "line": 34, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 25 + }, + "end": { + "line": 35, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 16 + }, + "end": { + "line": 35, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 16 + }, + "end": { + "line": 35, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 35, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 12 + }, + "end": { + "line": 36, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 12 + }, + "end": { + "line": 36, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "param", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 36, + "column": 23 + }, + "end": { + "line": 36, + "column": 26 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 16 + }, + "end": { + "line": 36, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 16 + }, + "end": { + "line": 36, + "column": 31 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 36, + "column": 35 + }, + "end": { + "line": 36, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 14 + }, + "end": { + "line": 37, + "column": 15 + } + } + }, + "property": { + "type": "Identifier", + "name": "fs", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 16 + }, + "end": { + "line": 37, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 14 + }, + "end": { + "line": 37, + "column": 18 + } + } + }, + "right": { + "type": "Identifier", + "name": "param", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 19 + }, + "end": { + "line": 37, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 14 + }, + "end": { + "line": 37, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 7 + }, + "end": { + "line": 37, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 39 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 15 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 15 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 12 + }, + "end": { + "line": 36, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 12 + }, + "end": { + "line": 36, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 27 + }, + "end": { + "line": 36, + "column": 28 + } + } + }, + "property": { + "type": "Identifier", + "name": "fs", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 29 + }, + "end": { + "line": 36, + "column": 31 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 969, + "column": 1 + }, + "end": { + "line": 969, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 2 + }, + "end": { + "line": 39, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 19 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 18 + }, + "end": { + "line": 41, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 18 + }, + "end": { + "line": 41, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 18 + }, + "end": { + "line": 41, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 15 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 10 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 20 + }, + "end": { + "line": 42, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 20 + }, + "end": { + "line": 42, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 20 + }, + "end": { + "line": 42, + "column": 22 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 42, + "column": 16 + }, + "end": { + "line": 42, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 24 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 24 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 13 + }, + "end": { + "line": 43, + "column": 14 + } + } + }, + "property": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 15 + }, + "end": { + "line": 43, + "column": 16 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 43, + "column": 13 + }, + "end": { + "line": 43, + "column": 16 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 101, + "loc": { + "start": { + "line": 43, + "column": 20 + }, + "end": { + "line": 43, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 12 + }, + "end": { + "line": 43, + "column": 24 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 24 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "setC", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 7 + }, + "end": { + "line": 44, + "column": 11 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 11 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 14 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 12 + }, + "end": { + "line": 45, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "getC", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 14 + }, + "end": { + "line": 45, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 12 + }, + "end": { + "line": 45, + "column": 18 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 12 + }, + "end": { + "line": 45, + "column": 20 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 10001, + "loc": { + "start": { + "line": 45, + "column": 24 + }, + "end": { + "line": 45, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 11 + }, + "end": { + "line": 45, + "column": 30 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 45, + "column": 5 + }, + "end": { + "line": 45, + "column": 30 + } + } + }, + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 46, + "column": 12 + }, + "end": { + "line": 46, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 46, + "column": 14 + }, + "end": { + "line": 46, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 46, + "column": 12 + }, + "end": { + "line": 46, + "column": 17 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 46, + "column": 12 + }, + "end": { + "line": 46, + "column": 19 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "*", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 46, + "column": 24 + }, + "end": { + "line": 46, + "column": 25 + } + } + }, + "property": { + "type": "Identifier", + "name": "fs", + "decorators": [], + "loc": { + "start": { + "line": 46, + "column": 26 + }, + "end": { + "line": 46, + "column": 28 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 46, + "column": 24 + }, + "end": { + "line": 46, + "column": 28 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 46, + "column": 29 + }, + "end": { + "line": 46, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 23 + }, + "end": { + "line": 46, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 11 + }, + "end": { + "line": 46, + "column": 32 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 46, + "column": 5 + }, + "end": { + "line": 46, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 41, + "column": 23 + }, + "end": { + "line": 47, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 14 + }, + "end": { + "line": 47, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 14 + }, + "end": { + "line": 47, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 47, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 48, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/default_parameter8.ets b/ets2panda/test/parser/ets/default_parameter8.ets new file mode 100644 index 0000000000000000000000000000000000000000..4dec3e67150e4cd447064d9a54e5d85f7bea495c --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter8.ets @@ -0,0 +1,47 @@ +/* + * 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. + */ + +class A { + public a:int; + constructor(param: int=101) { + this.a = param; + } + public SetA(param: int = 99) { + this.a = param; + } +} + +class C extends A { + static fs:int=102 + fc:int=10001; + c:int; + public setC (param:int=this.fc) : void { + this.c = param; + } + public getC() : int { + return this.c; + } + static foo(param: int=C.fs) : int { + return C.fs+param; + } +} + +function main(): void { + let b: C = new C(); + assert (b.a == 101) + b.setC(); + assert(b.getC() == 10001) + assert(C.foo() == (C.fs*2)) +} diff --git a/ets2panda/test/parser/ets/default_parameter9-expected.txt b/ets2panda/test/parser/ets/default_parameter9-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e13401507ac08c5c790adb6da22ef673db1a3ff3 --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter9-expected.txt @@ -0,0 +1,984 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "self", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "end", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 48 + }, + "end": { + "line": 16, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 48 + }, + "end": { + "line": 16, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 48 + }, + "end": { + "line": 16, + "column": 55 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 42 + }, + "end": { + "line": 16, + "column": 55 + } + } + } + ], + "returnType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 57 + }, + "end": { + "line": 16, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 57 + }, + "end": { + "line": 16, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 57 + }, + "end": { + "line": 16, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 61 + }, + "end": { + "line": 16, + "column": 62 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "self", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 61 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "self", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 57 + }, + "end": { + "line": 16, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "copyWithin", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "self", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 613, + "column": 1 + }, + "end": { + "line": 613, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/default_parameter9.ets b/ets2panda/test/parser/ets/default_parameter9.ets new file mode 100644 index 0000000000000000000000000000000000000000..851d4cc1ba3e9aa28dcef7c59e4c36b379f654d0 --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter9.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +export function copyWithin(self: T[], end?: Number): T[] { + return self; +} diff --git a/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt b/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt index 1e351257677d50d8e4af096df8a815f5869a7b4d..9f64e604a9917400f9fe97c96cfa1746e8769aa2 100644 --- a/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt @@ -288,20 +288,6 @@ } } }, - "initializer": { - "type": "StringLiteral", - "value": "default", - "loc": { - "start": { - "line": 16, - "column": 38 - }, - "end": { - "line": 16, - "column": 47 - } - } - }, "loc": { "start": { "line": 16, @@ -371,20 +357,6 @@ } } }, - "initializer": { - "type": "StringLiteral", - "value": "another", - "loc": { - "start": { - "line": 16, - "column": 61 - }, - "end": { - "line": 16, - "column": 70 - } - } - }, "loc": { "start": { "line": 16, @@ -438,16 +410,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -462,16 +434,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 13 } } }, @@ -494,57 +466,57 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 17 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 23 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 24 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -563,545 +535,402 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 29 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 35 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 25 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 37 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "y", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 + "arguments": [ + { + "type": "Identifier", + "name": "t", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 23 + } + } }, - "end": { - "line": 1, - "column": 3 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 24 } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 16, + "column": 35 + } } - } - }, - "right": { - "type": "StringLiteral", - "value": "default", + }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 25 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + { + "type": "StringLiteral", + "value": "another", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } ], + "optional": false, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 576, + "column": 1 + }, + "end": { + "line": 576, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "t", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 17 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 23 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "y", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "StringLiteral", - "value": "another", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, - "alternate": null, + "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 24 } } }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ { - "type": "ReturnStatement", - "argument": { + "type": "ExpressionStatement", + "expression": { "type": "CallExpression", "callee": { "type": "Identifier", @@ -1110,11 +939,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1122,45 +951,84 @@ { "type": "Identifier", "name": "t", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 3 + "line": 16, + "column": 24 } } }, { - "type": "Identifier", - "name": "x", - "decorators": [], + "type": "StringLiteral", + "value": "default", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, { - "type": "Identifier", - "name": "y", - "decorators": [], + "type": "StringLiteral", + "value": "another", "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1169,22 +1037,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1192,33 +1060,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 576, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 576, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1231,7 +1099,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt index fa2438b241b8161ab751fc2f22b9365c218d35a0..f644e4d39a8ba7c16e004f42065cc063623b8737 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_class_ctor_decl_import_bad.ets:23:19] +TypeError: Type 'string' is not compatible with type 'double' at index 1 [dynamic_class_ctor_decl_import_bad.ets:23:19] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt index 1a691d4d82cc9507b503a568bcb3ca76c361c5d4..d7211e1b8f0a3dd64046a792db39e7cf9cb2ea73 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_field_decl_import_bad_1.ets:23:12] +TypeError: Type 'int' cannot be assigned to type 'String' [dynamic_class_field_decl_import_bad_1.ets:23:12] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt index 88718c571e3511fb93e4dc18c5864a3c4bc19e6c..cd3b95281f1506394674b90e2fdf6d239a6004fc 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_field_decl_import_bad_2.ets:23:21] +TypeError: Type 'double' cannot be assigned to type 'String' [dynamic_class_field_decl_import_bad_2.ets:23:21] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt index 6eac80975caa1f8e56848f3aae0b121ba1549b4b..68bb0527cee1b4406a95ad7f2da0eebcc5852161 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_class_method_decl_import_bad_1.ets:23:11] +TypeError: Type 'string' is not compatible with type 'double' at index 1 [dynamic_class_method_decl_import_bad_1.ets:23:11] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt index 9b52cc0ef3dbec6abfa2ef8c25abf2d751e2653e..5c8704ac8c230a102a077bb0eb0b32eb469fda75 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_method_decl_import_bad_2.ets:23:21] +TypeError: Type 'double' cannot be assigned to type 'String' [dynamic_class_method_decl_import_bad_2.ets:23:21] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt index 3e84372b587dbd2db92a06f0a9a75f433b38d302..b835f137b0771ab4fbcdaf139f0e5aa1e99bdcc6 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_func_decl_import_bad.ets:23:9] +TypeError: Type 'string' is not compatible with type 'A' at index 1 [dynamic_func_decl_import_bad.ets:23:9] diff --git a/ets2panda/test/parser/ets/enum8-expected.txt b/ets2panda/test/parser/ets/enum8-expected.txt index 67d246372e6536e86ad1277fc43383ee3afbf174..150b136c75eae5fcd727ffee2806b550eff9bb2c 100644 --- a/ets2panda/test/parser/ets/enum8-expected.txt +++ b/ets2panda/test/parser/ets/enum8-expected.txt @@ -563,4 +563,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [enum8.ets:20:20] +TypeError: Type 'Color2' cannot be assigned to type 'Color' [enum8.ets:20:20] diff --git a/ets2panda/test/parser/ets/exports-expected.txt b/ets2panda/test/parser/ets/exports-expected.txt index aab03ca6223b18134f4b881ca75b3b54274a573f..aaceffc96da24f558a5e15266aaa8d5c033525b0 100644 --- a/ets2panda/test/parser/ets/exports-expected.txt +++ b/ets2panda/test/parser/ets/exports-expected.txt @@ -339,11 +339,11 @@ "loc": { "start": { "line": 16, - "column": 8 + "column": 12 }, "end": { "line": 16, - "column": 19 + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/for_of-expected.txt b/ets2panda/test/parser/ets/for_of-expected.txt index d3446be05acb4a707042ce62be9e66b71e03153c..cef1c5eec234cf47c70b01e90f95cedcf8837eac 100644 --- a/ets2panda/test/parser/ets/for_of-expected.txt +++ b/ets2panda/test/parser/ets/for_of-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 17, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/for_of_02-expected.txt b/ets2panda/test/parser/ets/for_of_02-expected.txt index f7ae611379b140d2abf221271420444eec740cd0..adcd7570162dd9a1650af2463db3e9f85a770e82 100644 --- a/ets2panda/test/parser/ets/for_of_02-expected.txt +++ b/ets2panda/test/parser/ets/for_of_02-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/functionTypeThrows-expected.txt b/ets2panda/test/parser/ets/functionTypeThrows-expected.txt index 2c3510eb6070b6e709fbb43b7891a215c1cc35ee..db780fab064523805869842981e628fd55bf481d 100644 --- a/ets2panda/test/parser/ets/functionTypeThrows-expected.txt +++ b/ets2panda/test/parser/ets/functionTypeThrows-expected.txt @@ -259,7 +259,7 @@ }, "end": { "line": 16, - "column": 32 + "column": 6 } } } diff --git a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt index 86dadbaca552b0b22c7f1cd3bcc89d9bc24254e7..b9803f021ffc4714d36a4bbeaddbe716a29f4bc7 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt @@ -316,4 +316,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type2.ets:17:27] +TypeError: Type '() => void' cannot be assigned to type '(i: int) => int' [function_implicit_return_type2.ets:17:27] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt index 41e4545d599f50668ebfd4a924992a225a4b2899..4735377d45db60992c7b814e2f10983bad6ab30b 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 33 + "column": 32 } } } @@ -465,4 +465,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type3.ets:18:27] +TypeError: Type '(i: int) => void' cannot be assigned to type '(i: int) => int' [function_implicit_return_type3.ets:18:27] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt index c942bc192dc2488e78bc4a373c507b264e0f0472..924369f75a6a5fdcf5bb5a2746a56378348a5a20 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt @@ -442,4 +442,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type6.ets:20:16] +TypeError: Type 'void' cannot be assigned to type 'int' [function_implicit_return_type6.ets:20:16] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt index 478d07c0ed0e85d640bad5451cad799687ee00d6..dd9c583fa772e519b09662d36935c9b33cd00982 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt @@ -598,4 +598,4 @@ } } } -TypeError: Return statement type is not compatible with previous method's return statement type(s). [function_implicit_return_type7.ets:21:10] +TypeError: Function cannot have different primitive return types, found 'boolean', 'int' [function_implicit_return_type7.ets:21:10] diff --git a/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt b/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt index 09b1fbae7aa48d865796e673b3f1e1a3661e4bf7..8387f49f9a5e869d2006fbcd44c5abda61bd09af 100644 --- a/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt +++ b/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt @@ -1988,7 +1988,7 @@ "loc": { "start": { "line": 31, - "column": 1 + "column": 5 }, "end": { "line": 32, @@ -2182,7 +2182,7 @@ "loc": { "start": { "line": 32, - "column": 1 + "column": 5 }, "end": { "line": 33, @@ -2417,7 +2417,7 @@ "loc": { "start": { "line": 33, - "column": 1 + "column": 5 }, "end": { "line": 34, diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt index 3b525585b96fa00ef977c4c828c982d39924a93c..8a94129e2a73312470a15c4f2d728b0585901ad2 100644 --- a/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt @@ -458,7 +458,7 @@ "loc": { "start": { "line": 17, - "column": 12 + "column": 11 }, "end": { "line": 19, @@ -469,7 +469,7 @@ "loc": { "start": { "line": 17, - "column": 12 + "column": 11 }, "end": { "line": 19, diff --git a/ets2panda/test/parser/ets/identifier-expected.txt b/ets2panda/test/parser/ets/identifier-expected.txt index 79101bcf96800d89de1a50e9199225cedaac2967..70df781844789a8e9d828acab04458243887b59f 100644 --- a/ets2panda/test/parser/ets/identifier-expected.txt +++ b/ets2panda/test/parser/ets/identifier-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 27 + "column": 26 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 32 + "column": 31 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 28 + "column": 27 } } } @@ -330,7 +330,7 @@ }, "end": { "line": 17, - "column": 22 + "column": 26 } } }, @@ -379,7 +379,7 @@ }, "end": { "line": 18, - "column": 27 + "column": 31 } } }, @@ -428,7 +428,7 @@ }, "end": { "line": 19, - "column": 23 + "column": 27 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt index 020e5e183aa1dbcfcab384d8c6d778ab10b19a39..029990a2290f196a01114b873d4d728b7b8131b0 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt @@ -191,11 +191,11 @@ "loc": { "start": { "line": 18, - "column": 8 + "column": 12 }, "end": { "line": 18, - "column": 22 + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt index 41d64f40ed99bea9ccd0c10a920cb18aa1ab0606..aa59cba3ba9796f8929283e724ec6b9547c1f3fe 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt @@ -191,11 +191,11 @@ "loc": { "start": { "line": 18, - "column": 8 + "column": 12 }, "end": { "line": 18, - "column": 22 + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt index 49fc3015d82ec7acb23970b392f82ebe012f81e4..96bbb0c8bbb147b10f1fda46f9dfa47dc9a4197f 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 8 + "column": 12 }, "end": { "line": 16, - "column": 20 + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt index 6f65df047697c0e17df741ac22d048b7e86750ad..03aa93b5c2119c8dd6e8050eeb18dfc45351bec1 100644 --- a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt @@ -580,11 +580,11 @@ "loc": { "start": { "line": 28, - "column": 1 + "column": 5 }, "end": { "line": 28, - "column": 15 + "column": 14 } } }, @@ -636,11 +636,11 @@ "loc": { "start": { "line": 30, - "column": 8 + "column": 12 }, "end": { "line": 30, - "column": 22 + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt index a05f2eaec9c5335ddc4a9a6d7c354587f81b8448..34fdeb25793387e91bc6592ad5485577b6df0f72 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt @@ -264,11 +264,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 47 + "column": 46 } } }, @@ -352,11 +352,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 46 + "column": 45 } } }, @@ -439,11 +439,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 49 + "column": 48 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt index e105d8c13c3fde8e3d43cebdb57dc782431d5609..1079f0ac8a8713cf7bb3ddeca1804168c8c7ea06 100644 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt @@ -267,11 +267,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 57 + "column": 56 } } }, @@ -415,11 +415,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 56 + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt index 18b018cd704c49b55d3b2850048acc8fb99099d5..623e169b05ef889a75de826abd53ab444d724598 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt @@ -207,11 +207,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 47 + "column": 46 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt index 20deb523cdd1d7373f54d6b94c4415469ac19e8b..46f64d4417ef8fbd41a1fd2ff30cae9bed3596f9 100644 --- a/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_type_alias-expected.txt @@ -244,7 +244,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, diff --git a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt index 77c11005f850e46bb01176d0824fede31f297e9c..40e1725683cfd4f433ef31d8cdc57c7c55fe89b4 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt @@ -308,11 +308,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 47 + "column": 46 } } }, @@ -396,7 +396,7 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, diff --git a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt index 4ce97a3c9bc8f6c6ea014f36e35c67458b7b276e..f994a5367e072d2b4e2611868a90e528ca517e3f 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt @@ -265,11 +265,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 18 + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt index 8192941368ea24f6f7720624dde7df81d27bece2..5206b8641790df52353069b95028a6cbfdd53e9d 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt @@ -308,11 +308,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 47 + "column": 46 } } }, @@ -396,11 +396,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt index 6c17455873bca42a862bb6654b85a19a7df8d4dc..d0725932432b0e7631f2ecd4e240ffa4d18f43bd 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt @@ -265,11 +265,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 18 + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt index c99810cb09868251e1b25b32ac77b981cfe998d0..69ad61a03473deef28f4cb5ee569b0de271af184 100755 --- a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt @@ -207,11 +207,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 47 + "column": 46 } } }, @@ -295,11 +295,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt index 7ceeda97255e793639dafa3e9ea26440a915fc1a..f4fc0df83c78d315630a6e2a3afd12be0d4bbf1b 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt @@ -366,11 +366,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 47 + "column": 46 } } }, @@ -454,11 +454,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt index a1118839c3ec9252ace25799812f2ba32ca32d5e..a6b92000564a98d804a61a457690d6ef0f81a501 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt @@ -264,11 +264,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 19 + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt index bb89ff35a9cc410bace3f4991833478b5450fbf3..0c310d7017adcb2bfd44639fa9c6c349dbe03297 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt @@ -279,11 +279,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 47 + "column": 46 } } }, @@ -367,11 +367,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt index 614c31accbe1145a796a297de4be41908887f17d..6ea9c81dd2acf2e77f4bc7965046e2e9a5c90e44 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt @@ -309,11 +309,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 52 + "column": 51 } } }, @@ -457,11 +457,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 56 + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt index 3d619efbbe134e3b0c9ea4606b046b17bddc6a98..eb8902b6de58993d204bb866ca4e7dcf5435dae9 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt @@ -279,11 +279,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 47 + "column": 46 } } }, @@ -367,11 +367,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt index 08763cfb560d323b79d9c3dced590c61c5054767..4f190cb5ecd462d7871dc751c465355d48225dfe 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt @@ -309,11 +309,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 52 + "column": 51 } } }, @@ -457,11 +457,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 56 + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt index a522257b8f57f2d4b3ac7d8ad4e250a471f6dde5..d4d39585263867bd92f7180547a47b6ff5638fbd 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt @@ -351,11 +351,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 47 + "column": 46 } } }, @@ -439,11 +439,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 46 + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/modules/too_many_default_exports_2-expected.txt b/ets2panda/test/parser/ets/import_tests/modules/too_many_default_exports_2-expected.txt index 286371d4e678e0daf56cc6ef689e020591ec9a97..f4b12fc8ceb618339ce31414f4661d079ce0ac48 100644 --- a/ets2panda/test/parser/ets/import_tests/modules/too_many_default_exports_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/modules/too_many_default_exports_2-expected.txt @@ -1 +1 @@ -SyntaxError: Only one default export is allowed in a module [too_many_default_exports_2.ets:16:16] +SyntaxError: Only one default export is allowed in a module [too_many_default_exports_2.ets:16:27] diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt index 78b1a6b2bbd6691406f23800e20c09cbf2293a27..0ce3e4dd8613e2d7952cb49fa0f35a7192a51927 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt @@ -349,11 +349,11 @@ "loc": { "start": { "line": 16, - "column": 8 + "column": 12 }, "end": { "line": 16, - "column": 20 + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/index_expressions-expected.txt b/ets2panda/test/parser/ets/index_expressions-expected.txt index da4f14491678ca06393920994b7ddf1ca0802ee6..39fc2ad997ddee2e89c3dcdf62e9cb95f04a6070 100644 --- a/ets2panda/test/parser/ets/index_expressions-expected.txt +++ b/ets2panda/test/parser/ets/index_expressions-expected.txt @@ -144,11 +144,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 20 + "column": 19 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 14 + "column": 13 } } }, @@ -317,11 +317,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 14 + "column": 13 } } }, @@ -434,11 +434,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 17 + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt b/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt index fce52818b71960a20d4b03225fc1764ee629b291..6e14834c9b171cd217e3a5597c7367c507b46ac6 100644 --- a/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt +++ b/ets2panda/test/parser/ets/lambda_import_alias_1-2-expected.txt @@ -303,7 +303,7 @@ "loc": { "start": { "line": 18, - "column": 8 + "column": 12 }, "end": { "line": 18, diff --git a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt index d5c78505507622de816eb29934b2c123c3b49b33..2e698140825913aa44e7fe45a90cc136f46136a7 100644 --- a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt +++ b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt @@ -408,7 +408,7 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, diff --git a/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt index d90b7f2cbad3f73a06054c2a7ad8ce30a6cdac3d..10346aee633521776c60fa9e287a6b322eaff3e8 100644 --- a/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt @@ -455,4 +455,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_arrayHoldingNullValue.ets:17:24] +TypeError: Type 'null' cannot be assigned to type 'float[]' [n_arrayHoldingNullValue.ets:17:24] diff --git a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt index cf852cc4c9f8e79ebaff9db05a99a2370c323fb4..57e9c0bfdeadebf18cd10bcaa389d9bd0c7b28f2 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt @@ -743,4 +743,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableFromFunctionToNonNullable.ets:23:22] +TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableFromFunctionToNonNullable.ets:23:22] diff --git a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt index 2f57863379270d883e3c51ef185d743e23ee990e..5698d12fe67bacf68dc54ada5347f73591a888de 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt @@ -913,4 +913,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableFromMethodToNullableParam.ets:24:22] +TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableFromMethodToNullableParam.ets:24:22] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt index c8a3c89c3654e9524ca71a4129652428bfaec1ea..ff8820fa74e1a33275c5f7950b96ca1814136a48 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt @@ -707,4 +707,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullable.ets:22:9] +TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableToNonNullable.ets:22:9] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt index 9b424caf23208fbe35f822459afa89f11846f049..c5df8b793939af578e1f314d0ab055d0db771f7f 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt @@ -803,4 +803,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullableArray.ets:22:10] +TypeError: Type 'A[]|null' cannot be assigned to type 'Object[]' [n_assignNullableToNonNullableArray.ets:22:10] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt index 2ac81c66dd171fa491b4225ef1256f366c00ad42..28ddeff4fb1ce3f0c310d9a4dc4298e59b0c7084 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt @@ -776,4 +776,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullableTypeAlias.ets:24:9] +TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableToNonNullableTypeAlias.ets:24:9] diff --git a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt index 5dffc7d900e674573395ae100ff05468f16059b6..229bee6d941c69d7ebe0c589517154c7e9ccf23e 100644 --- a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt @@ -828,4 +828,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callFunctionWithNullableParam.ets:23:9] +TypeError: Type 'A|null' is not compatible with type 'A' at index 1 [n_callFunctionWithNullableParam.ets:23:9] diff --git a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt index 1aed437dc327df8abf08b3f8e11dca184dfc7825..9e0b6dfba65ec74006a89978d032094fd9a99e23 100644 --- a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt @@ -1149,4 +1149,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callInterfaceMethodWithNullableParam.ets:27:12] +TypeError: Type 'I|null' is not compatible with type 'I' at index 1 [n_callInterfaceMethodWithNullableParam.ets:27:12] diff --git a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt index 66b6147871606ec2d4d837e67c5ab72fea6a0ba4..d671817126263aa1cff99ab62ce20a4d19d6daf2 100644 --- a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt @@ -858,4 +858,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callMethodWithNullableParam.ets:23:12] +TypeError: Type 'A|null' is not compatible with type 'A' at index 1 [n_callMethodWithNullableParam.ets:23:12] diff --git a/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt index 8d0cbdb7442d3b1d150397e933ecc5b5862d16ba..1153d45e3295033806684696475f4bfb6e68a6c0 100644 --- a/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt @@ -451,4 +451,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullFromFunction.ets:19:12] +TypeError: Type 'null' is not compatible with the enclosing method's return type 'A' [n_returnNullFromFunction.ets:19:12] diff --git a/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt index 6475dcf314bd6a18108d43742faddb1e2d281656..62e4dded196f9368f0e552dc5ac15186f6469d65 100644 --- a/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt @@ -451,4 +451,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullFromMethod.ets:18:16] +TypeError: Type 'null' is not compatible with the enclosing method's return type 'A' [n_returnNullFromMethod.ets:18:16] diff --git a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt index 7a4275b3329c44d21b6eac4df4ed0bd6933af59d..3c41b4b7afd7ff6b017bc53cb2116d9c957c532c 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt @@ -592,4 +592,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullableFromFunction.ets:21:12] +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'A' [n_returnNullableFromFunction.ets:21:12] diff --git a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt index df711d1502c49da6a4a6a678fca403d1719b8860..3c9ac3ca46d48e38cd0e19e2b911b6a4b746c820 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt @@ -592,4 +592,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullableFromMethod.ets:20:16] +TypeError: Type 'A|null' is not compatible with the enclosing method's return type 'A' [n_returnNullableFromMethod.ets:20:16] diff --git a/ets2panda/test/parser/ets/null-expected.txt b/ets2panda/test/parser/ets/null-expected.txt index f069f5a6a679ab99caee7be78a77b7c0c31c644c..6bef006c4d4c7940bdf14cd5e1e6ce6384139b09 100644 --- a/ets2panda/test/parser/ets/null-expected.txt +++ b/ets2panda/test/parser/ets/null-expected.txt @@ -255,11 +255,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 27 + "column": 26 } } }, @@ -352,7 +352,7 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, @@ -480,7 +480,7 @@ }, "end": { "line": 18, - "column": 14 + "column": 26 } } }, @@ -557,7 +557,7 @@ }, "end": { "line": 19, - "column": 14 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 1c9ab91eeeac7352aace79b9b760748ca182065d..05a4724c5f6d6baae59db1c83176afe510887a09 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 20 + "column": 19 } } } @@ -297,7 +297,7 @@ }, "end": { "line": 17, - "column": 17 + "column": 19 } } } @@ -336,4 +336,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [null_invalid.ets:17:18] +TypeError: Type 'Object|null' cannot be assigned to type 'Object' [null_invalid.ets:17:18] diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index 1891cfc564194d2f8b9d7038adff79c3ca03b7e2..cae638039c70f0722837a32e7e26bf8bb34bf8f9 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 27 + "column": 26 } } } @@ -297,7 +297,7 @@ }, "end": { "line": 17, - "column": 17 + "column": 26 } } } diff --git a/ets2panda/test/parser/ets/object-expected.txt b/ets2panda/test/parser/ets/object-expected.txt index 9f1511caa9e1a0346b5142108441c96124fe7ba3..caf59e7c601704a46a3e81e8632f106643d7d1bc 100644 --- a/ets2panda/test/parser/ets/object-expected.txt +++ b/ets2panda/test/parser/ets/object-expected.txt @@ -189,7 +189,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 6 } } } diff --git a/ets2panda/test/parser/ets/optional-chaining-array-expected.txt b/ets2panda/test/parser/ets/optional-chaining-array-expected.txt index 9fc7887951fba1bc671b1a70e962323d2562a745..9a02f3f966372bb2ef972f822f39abffa97c6cb2 100644 --- a/ets2panda/test/parser/ets/optional-chaining-array-expected.txt +++ b/ets2panda/test/parser/ets/optional-chaining-array-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 35 + "column": 34 } } }, @@ -275,11 +275,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 34 + "column": 33 } } }, @@ -389,11 +389,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 39 + "column": 38 } } } @@ -530,7 +530,7 @@ }, "end": { "line": 16, - "column": 17 + "column": 34 } } }, @@ -728,7 +728,7 @@ }, "end": { "line": 19, - "column": 21 + "column": 9 } } }, diff --git a/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt index 2c046490ecfedd22b633e419f3eb37b98677be33..c357cbf4ded228161c0cdb0835eb817aee8a741f 100644 --- a/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt @@ -456,7 +456,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 24, @@ -543,11 +543,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 30 + "column": 29 } } } @@ -670,8 +670,8 @@ "column": 5 }, "end": { - "line": 22, - "column": 15 + "line": 24, + "column": 2 } } }, diff --git a/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt index 1e67c713bc27785379b792ae9648bc38d4199bc8..120efe8f89d47fbfbf157fee6ccded238588f2eb 100644 --- a/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt @@ -533,7 +533,7 @@ "loc": { "start": { "line": 23, - "column": 1 + "column": 5 }, "end": { "line": 25, @@ -650,11 +650,11 @@ "loc": { "start": { "line": 27, - "column": 1 + "column": 5 }, "end": { "line": 27, - "column": 42 + "column": 41 } } } @@ -777,8 +777,8 @@ "column": 5 }, "end": { - "line": 23, - "column": 15 + "line": 25, + "column": 2 } } }, diff --git a/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt index 3e7ff288e94a231fe72888e0eb4ed591a370d76e..c97274831d075f813bb2affcc45700db686fe31f 100644 --- a/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt @@ -456,7 +456,7 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 24, @@ -571,11 +571,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 33 + "column": 32 } } }, @@ -686,11 +686,11 @@ "loc": { "start": { "line": 27, - "column": 1 + "column": 5 }, "end": { "line": 27, - "column": 36 + "column": 35 } } } @@ -813,8 +813,8 @@ "column": 5 }, "end": { - "line": 22, - "column": 15 + "line": 24, + "column": 2 } } }, @@ -972,7 +972,7 @@ }, "end": { "line": 27, - "column": 18 + "column": 35 } } } diff --git a/ets2panda/test/parser/ets/optional_union_paramter-expected.txt b/ets2panda/test/parser/ets/optional_union_paramter-expected.txt index a48d7291b63b3dff98f8a8e48ad7e488a70721dd..f5caec408945edfd34a2783d5fb18bf1f952d1b9 100644 --- a/ets2panda/test/parser/ets/optional_union_paramter-expected.txt +++ b/ets2panda/test/parser/ets/optional_union_paramter-expected.txt @@ -250,20 +250,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 17, @@ -414,16 +400,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "split_proxy", + "name": "split", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 17 } } }, @@ -438,16 +424,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "split_proxy", + "name": "split", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 17 } } }, @@ -473,34 +459,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 36 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 38 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 38 } } }, @@ -514,179 +500,69 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 39 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 42 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 39 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 39 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } } ], "loc": { "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "limit", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 30 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -703,235 +579,51 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 61 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 67 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "limit", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -943,11 +635,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -958,11 +650,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -971,11 +663,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -983,30 +675,126 @@ { "type": "Identifier", "name": "separator", + "typeAnnotation": { + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 43 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 43 } } }, { - "type": "Identifier", - "name": "limit", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1015,22 +803,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1038,33 +826,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1077,7 +865,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1428,7 +1216,7 @@ "loc": { "start": { "line": 21, - "column": 15 + "column": 14 }, "end": { "line": 23, @@ -1439,7 +1227,7 @@ "loc": { "start": { "line": 21, - "column": 15 + "column": 14 }, "end": { "line": 23, diff --git a/ets2panda/test/parser/ets/override-expected.txt b/ets2panda/test/parser/ets/override-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d3766e42e3ac67aad5d44c547ddf4f3ffca4f42 --- /dev/null +++ b/ets2panda/test/parser/ets/override-expected.txt @@ -0,0 +1,2007 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "op", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 20 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 26 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 6 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 621, + "column": 1 + }, + "end": { + "line": 621, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "op", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 42 + }, + "end": { + "line": 20, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 35 + }, + "end": { + "line": 20, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 685, + "column": 1 + }, + "end": { + "line": 685, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 45 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 26, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/override.ets b/ets2panda/test/parser/ets/override.ets new file mode 100644 index 0000000000000000000000000000000000000000..90460dc7007d7f4b62e0662c28bcfe228fc3804c --- /dev/null +++ b/ets2panda/test/parser/ets/override.ets @@ -0,0 +1,25 @@ +/* + * 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. + */ + +class B { + foo(a: T, op?: T): T { return a } +} +class A extends B { + override foo(a: T, op?: T): T { return a } +} +function main(){ + +} + diff --git a/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt b/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt index 32bc14b3a4b55db92bda2c320d9de403f2147a19..38eb06e701eab53350d78c911ac3561acf1fce16 100644 --- a/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt +++ b/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 11 + "column": 10 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 13 + "column": 12 } } }, @@ -230,11 +230,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 15 + "column": 14 } } }, @@ -287,11 +287,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 13 + "column": 12 } } } diff --git a/ets2panda/test/parser/ets/predefined_types-expected.txt b/ets2panda/test/parser/ets/predefined_types-expected.txt index 1917db3b8842b16629c2f9391abcdb0ffb8e33ac..630c603172c453bddbfca658ba4f28869fcf16fc 100644 --- a/ets2panda/test/parser/ets/predefined_types-expected.txt +++ b/ets2panda/test/parser/ets/predefined_types-expected.txt @@ -161,7 +161,7 @@ }, "end": { "line": 17, - "column": 12 + "column": 6 } } }, @@ -210,7 +210,7 @@ }, "end": { "line": 18, - "column": 13 + "column": 6 } } }, @@ -259,7 +259,7 @@ }, "end": { "line": 19, - "column": 11 + "column": 6 } } }, @@ -308,7 +308,7 @@ }, "end": { "line": 20, - "column": 12 + "column": 6 } } }, @@ -357,7 +357,7 @@ }, "end": { "line": 22, - "column": 13 + "column": 6 } } }, @@ -406,7 +406,7 @@ }, "end": { "line": 23, - "column": 14 + "column": 6 } } }, @@ -455,7 +455,7 @@ }, "end": { "line": 25, - "column": 12 + "column": 6 } } } diff --git a/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt b/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt index 20b3942afa9487ecff4c39d57e45c9aa7f783ef7..226e6d78ad089e6eed0fa0f697500b7e264d2a21 100644 --- a/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt +++ b/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt @@ -125,20 +125,6 @@ } } }, - "initializer": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 17, - "column": 31 - }, - "end": { - "line": 17, - "column": 35 - } - } - }, "loc": { "start": { "line": 17, @@ -233,16 +219,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "exit_proxy", + "name": "exit", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 9 } } }, @@ -257,134 +243,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "exit_proxy", + "name": "exit", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 9 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "log_", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Boolean", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -395,34 +270,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 17, + "column": 38 }, "end": { - "line": 1, - "column": 3 + "line": 17, + "column": 42 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -430,192 +305,8 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "log_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { + "type": "ReturnStatement", + "argument": { "type": "CallExpression", "callee": { "type": "MemberExpression", @@ -624,11 +315,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -639,11 +330,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -652,27 +343,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "log_", - "decorators": [], + "type": "NullLiteral", + "value": null, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -681,22 +371,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -704,33 +394,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 620, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -743,7 +433,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -863,20 +553,6 @@ } } }, - "initializer": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, "loc": { "start": { "line": 18, @@ -971,16 +647,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "exthat_proxy", + "name": "exthat", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 18, + "column": 11 } } }, @@ -995,134 +671,23 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "exthat_proxy", + "name": "exthat", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 3 + "line": 18, + "column": 11 } } }, "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "log_", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Boolean", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], + "params": [], "returnType": { "type": "ETSTypeReference", "part": { @@ -1133,34 +698,34 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 18, + "column": 29 }, "end": { - "line": 1, - "column": 3 + "line": 18, + "column": 33 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1168,192 +733,8 @@ "type": "BlockStatement", "statements": [ { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "log_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "UndefinedLiteral", - "value": undefined, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { + "type": "ReturnStatement", + "argument": { "type": "CallExpression", "callee": { "type": "MemberExpression", @@ -1362,11 +743,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1377,11 +758,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1390,27 +771,26 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "arguments": [ { - "type": "Identifier", - "name": "log_", - "decorators": [], + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1419,22 +799,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1442,33 +822,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 665, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 665, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1481,7 +861,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/proxy_method-expected.txt b/ets2panda/test/parser/ets/proxy_method-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..50bf23a4d53442de87ccf54e7b6f55e02659bca8 --- /dev/null +++ b/ets2panda/test/parser/ets/proxy_method-expected.txt @@ -0,0 +1,1172 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "s", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "q", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 31 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "arguments": [ + { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "StringLiteral", + "value": "met ", + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "right": { + "type": "Identifier", + "name": "s", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 30 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 31 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "s", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "s", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 620, + "column": 1 + }, + "end": { + "line": 620, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "met", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "S", + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 20 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/proxy_method.ets b/ets2panda/test/parser/ets/proxy_method.ets new file mode 100644 index 0000000000000000000000000000000000000000..d058f7149570e230ac1b8e13dcd50c0822993da9 --- /dev/null +++ b/ets2panda/test/parser/ets/proxy_method.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +class A { + met(s: string, q?: string){ + console.log("met " + s) + } +} + +function main() { + new A().met('S') +} diff --git a/ets2panda/test/parser/ets/re_export/folder/re_export_6-expected.txt b/ets2panda/test/parser/ets/re_export/folder/re_export_6-expected.txt index 3120da76ac6e849950f577d23b178a88d0288fec..ffe77aba606f7ebfee57ae474d781adfba86f5a0 100644 --- a/ets2panda/test/parser/ets/re_export/folder/re_export_6-expected.txt +++ b/ets2panda/test/parser/ets/re_export/folder/re_export_6-expected.txt @@ -1,6 +1,76 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/folder/re_export_7-expected.txt b/ets2panda/test/parser/ets/re_export/folder/re_export_7-expected.txt index 3120da76ac6e849950f577d23b178a88d0288fec..120c86b0aa647ef4c91199a62fb02bd995a35bc0 100644 --- a/ets2panda/test/parser/ets/re_export/folder/re_export_7-expected.txt +++ b/ets2panda/test/parser/ets/re_export/folder/re_export_7-expected.txt @@ -1,6 +1,76 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./folder2", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/folderIndex/index-expected.txt b/ets2panda/test/parser/ets/re_export/folderIndex/index-expected.txt index 3120da76ac6e849950f577d23b178a88d0288fec..1e030741403204291d65f22b45cbf3c135daac23 100644 --- a/ets2panda/test/parser/ets/re_export/folderIndex/index-expected.txt +++ b/ets2panda/test/parser/ets/re_export/folderIndex/index-expected.txt @@ -1,6 +1,91 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "ad", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "imported": { + "type": "Identifier", + "name": "ad", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export-expected.txt b/ets2panda/test/parser/ets/re_export/re_export-expected.txt index 3120da76ac6e849950f577d23b178a88d0288fec..ffe77aba606f7ebfee57ae474d781adfba86f5a0 100644 --- a/ets2panda/test/parser/ets/re_export/re_export-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export-expected.txt @@ -1,6 +1,76 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export_2-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_2-expected.txt index 3120da76ac6e849950f577d23b178a88d0288fec..99e93e232901fc0be1a70e325a2e695eb7804ff5 100644 --- a/ets2panda/test/parser/ets/re_export/re_export_2-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export_2-expected.txt @@ -1,6 +1,91 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "FOO", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export_3-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_3-expected.txt index 3120da76ac6e849950f577d23b178a88d0288fec..61ba5da592c74b189346d702a9f1ade61fa9b764 100644 --- a/ets2panda/test/parser/ets/re_export/re_export_3-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export_3-expected.txt @@ -1,6 +1,91 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export_4-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_4-expected.txt index 5d09166882a764752791df5da354f031d15c9fc3..daf3fd0b18e0b08151097e9bdfe482152d9c9a1a 100644 --- a/ets2panda/test/parser/ets/re_export/re_export_4-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export_4-expected.txt @@ -1,6 +1,176 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/re_export/re_export_5-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_5-expected.txt index 5d09166882a764752791df5da354f031d15c9fc3..94d968a1316106adccaef7c338b16653bc413529 100644 --- a/ets2panda/test/parser/ets/re_export/re_export_5-expected.txt +++ b/ets2panda/test/parser/ets/re_export/re_export_5-expected.txt @@ -1,6 +1,146 @@ { "type": "Program", "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, { "type": "ClassDeclaration", "definition": { diff --git a/ets2panda/test/parser/ets/rest_parameter_01-expected.txt b/ets2panda/test/parser/ets/rest_parameter_01-expected.txt index 19a0a0e6e6ef729e640fac4f3a0f3c69f9e80703..537df9b4b085fd0cd70aaf3ad67856f35471d5bc 100644 --- a/ets2panda/test/parser/ets/rest_parameter_01-expected.txt +++ b/ets2panda/test/parser/ets/rest_parameter_01-expected.txt @@ -302,7 +302,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -313,7 +313,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -534,7 +534,7 @@ "loc": { "start": { "line": 20, - "column": 14 + "column": 13 }, "end": { "line": 22, @@ -545,7 +545,7 @@ "loc": { "start": { "line": 20, - "column": 14 + "column": 13 }, "end": { "line": 22, diff --git a/ets2panda/test/parser/ets/rest_parameter_02-expected.txt b/ets2panda/test/parser/ets/rest_parameter_02-expected.txt index 87a53b8d5ad3652e22ff54d040f3e644ec706331..5417cf11899a760fa0a6ff1d3362fb7aa59f6733 100644 --- a/ets2panda/test/parser/ets/rest_parameter_02-expected.txt +++ b/ets2panda/test/parser/ets/rest_parameter_02-expected.txt @@ -328,7 +328,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -339,7 +339,7 @@ "loc": { "start": { "line": 16, - "column": 14 + "column": 13 }, "end": { "line": 18, @@ -505,20 +505,6 @@ } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 20, - "column": 40 - }, - "end": { - "line": 20, - "column": 41 - } - } - }, "loc": { "start": { "line": 20, @@ -589,7 +575,7 @@ "loc": { "start": { "line": 20, - "column": 14 + "column": 13 }, "end": { "line": 22, @@ -600,7 +586,7 @@ "loc": { "start": { "line": 20, - "column": 14 + "column": 13 }, "end": { "line": 22, @@ -625,16 +611,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 13 } } }, @@ -649,16 +635,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo_proxy", + "name": "foo", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 10 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 13 } } }, @@ -676,34 +662,34 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 15 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 21 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -717,116 +703,34 @@ "loc": { "start": { "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "z", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "$proxy_mask$", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 29 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -836,201 +740,17 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "body": { "type": "BlockStatement", "statements": [ - { - "type": "IfStatement", - "test": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "BinaryExpression", - "operator": "&", - "left": { - "type": "BinaryExpression", - "operator": ">>", - "left": { - "type": "Identifier", - "name": "$proxy_mask$", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "z", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "alternate": null, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, { "type": "ReturnStatement", "argument": { @@ -1042,11 +762,11 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1054,45 +774,70 @@ { "type": "Identifier", "name": "x", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 15 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 21 } } }, { "type": "Identifier", "name": "y", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 3 + "line": 20, + "column": 23 }, "end": { - "line": 1, - "column": 3 + "line": 20, + "column": 29 } } }, { - "type": "Identifier", - "name": "z", - "decorators": [], + "type": "NumberLiteral", + "value": 0, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1101,22 +846,22 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } } @@ -1124,33 +869,33 @@ "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, "loc": { "start": { - "line": 1, - "column": 3 + "line": 658, + "column": 1 }, "end": { - "line": 1, - "column": 3 + "line": 658, + "column": 1 } } }, "loc": { "start": { "line": 1, - "column": 3 + "column": 1 }, "end": { "line": 1, - "column": 3 + "column": 1 } } }, @@ -1163,7 +908,7 @@ }, "end": { "line": 1, - "column": 3 + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/rest_parameter_03-expected.txt b/ets2panda/test/parser/ets/rest_parameter_03-expected.txt index bf94e31aa126976178f8cc9a80df5d5af489d289..1799a3c9a3e5229ccc31dda47af6f842a3b77290 100644 --- a/ets2panda/test/parser/ets/rest_parameter_03-expected.txt +++ b/ets2panda/test/parser/ets/rest_parameter_03-expected.txt @@ -1 +1 @@ -SyntaxError: Both optional and rest parameters are not allowed in function's parameter list. [rest_parameter_03.ets:16:14] +SyntaxError: Both optional and rest parameters are not allowed in function's parameter list. [rest_parameter_03.ets:16:13] diff --git a/ets2panda/test/parser/ets/return-expected.txt b/ets2panda/test/parser/ets/return-expected.txt index ee83fa8590954398b414c31cfa2e74c94becba16..45f9c493e3d83c22ab4c699b690f51e1da318eae 100644 --- a/ets2panda/test/parser/ets/return-expected.txt +++ b/ets2panda/test/parser/ets/return-expected.txt @@ -161,11 +161,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 26 + "column": 25 } } } @@ -274,7 +274,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/selective_export/selective_export_bad-expected.txt b/ets2panda/test/parser/ets/selective_export/selective_export_bad-expected.txt index dc09c9ecd89c2b385430e8cc8a2e691a400cfbbf..840f7dbccf260fd6b9a361243e2748564a7dfff1 100644 --- a/ets2panda/test/parser/ets/selective_export/selective_export_bad-expected.txt +++ b/ets2panda/test/parser/ets/selective_export/selective_export_bad-expected.txt @@ -1 +1 @@ -SyntaxError: Cannot find name 'foo' to export. [selective_export_bad.ets:16:8] +SyntaxError: Cannot find name 'foo' to export. [selective_export_bad.ets:16:10] diff --git a/ets2panda/test/parser/ets/simple_types-expected.txt b/ets2panda/test/parser/ets/simple_types-expected.txt index b75839eeb2747a4359414db7de8f4f03e8be5477..ce0e4dda7fcb9c8f71bb0d367b0398923f12a704 100644 --- a/ets2panda/test/parser/ets/simple_types-expected.txt +++ b/ets2panda/test/parser/ets/simple_types-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 19 + "column": 18 } } }, @@ -189,11 +189,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 23 + "column": 22 } } }, @@ -245,11 +245,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 25 + "column": 24 } } }, @@ -316,11 +316,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 36 + "column": 35 } } }, @@ -372,11 +372,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 23 + "column": 22 } } }, @@ -428,11 +428,11 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 20 + "column": 19 } } }, @@ -484,11 +484,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 23 + "column": 22 } } }, @@ -540,11 +540,11 @@ "loc": { "start": { "line": 27, - "column": 1 + "column": 5 }, "end": { "line": 27, - "column": 24 + "column": 23 } } }, @@ -597,11 +597,11 @@ "loc": { "start": { "line": 29, - "column": 1 + "column": 5 }, "end": { "line": 29, - "column": 17 + "column": 16 } } } @@ -697,7 +697,7 @@ }, "end": { "line": 16, - "column": 12 + "column": 18 } } }, @@ -746,7 +746,7 @@ }, "end": { "line": 17, - "column": 13 + "column": 22 } } }, @@ -795,7 +795,7 @@ }, "end": { "line": 18, - "column": 11 + "column": 24 } } }, @@ -844,7 +844,7 @@ }, "end": { "line": 19, - "column": 12 + "column": 35 } } }, @@ -893,7 +893,7 @@ }, "end": { "line": 21, - "column": 15 + "column": 22 } } }, @@ -942,7 +942,7 @@ }, "end": { "line": 22, - "column": 12 + "column": 19 } } }, @@ -1019,7 +1019,7 @@ }, "end": { "line": 24, - "column": 13 + "column": 6 } } }, @@ -1068,7 +1068,7 @@ }, "end": { "line": 26, - "column": 13 + "column": 22 } } }, @@ -1117,7 +1117,7 @@ }, "end": { "line": 27, - "column": 14 + "column": 23 } } }, @@ -1166,7 +1166,7 @@ }, "end": { "line": 29, - "column": 12 + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/string-expected.txt b/ets2panda/test/parser/ets/string-expected.txt index 657641c2443d16f5e35b06a8d4469fe9ac19ce13..38083df2f96d302e93fb9e76db965178ada9257b 100644 --- a/ets2panda/test/parser/ets/string-expected.txt +++ b/ets2panda/test/parser/ets/string-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 25 + "column": 24 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 25 + "column": 24 } } } @@ -302,7 +302,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 24 } } }, @@ -379,7 +379,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 24 } } } diff --git a/ets2panda/test/parser/ets/switch_enum2-expected.txt b/ets2panda/test/parser/ets/switch_enum2-expected.txt index 18f714c8312f6140c2a527e4ab792df4c8733662..59ed0f5ca2428204a9f25a66938e7acf8ff9599f 100644 --- a/ets2panda/test/parser/ets/switch_enum2-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum2-expected.txt @@ -577,4 +577,4 @@ } } } -TypeError: Switch case type int is not comparable to discriminant type Color [switch_enum2.ets:20:14] +TypeError: Switch case type 'int' is not comparable to discriminant type 'Color' [switch_enum2.ets:20:14] diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt index f34d7e3f9246eb67d65876ae8c128e8bd56ab57c..8ce637786ed4b25f6795d7702a6ff7bbf84107ff 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt @@ -1293,4 +1293,4 @@ } } } -TypeError: Switch case type A is not comparable to discriminant type E [switch_readonly_member_different_enum.ets:35:14] +TypeError: Switch case type 'A' is not comparable to discriminant type 'E' [switch_readonly_member_different_enum.ets:35:14] diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt index 3ef004f3ec9a6b0181d78255d6c875c3b60de6b3..5891ffb6e13f852b8cc5f8a4a7e84a53ebbba50b 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt @@ -1293,4 +1293,4 @@ } } } -TypeError: Switch case type A is not comparable to discriminant type E [switch_readonly_member_different_enum_2.ets:34:14] +TypeError: Switch case type 'A' is not comparable to discriminant type 'E' [switch_readonly_member_different_enum_2.ets:34:14] diff --git a/ets2panda/test/parser/ets/ternary-expected.txt b/ets2panda/test/parser/ets/ternary-expected.txt index b80d1cd97c9239f52f71459d19eda0c19fd35b4e..f74401a8ee172e5100d56301aa892057b1461e8d 100644 --- a/ets2panda/test/parser/ets/ternary-expected.txt +++ b/ets2panda/test/parser/ets/ternary-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 11 + "column": 10 } } }, @@ -303,11 +303,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 23 + "column": 22 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue-expected.txt b/ets2panda/test/parser/ets/test_jsvalue-expected.txt index f172336108f9f1c27fa523ff53efe64d4124ef69..ee9b4367bf66ce9713691f10055e0b195af0dc4f 100644 --- a/ets2panda/test/parser/ets/test_jsvalue-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue-expected.txt @@ -189,7 +189,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 6 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt index 59de21d316643ba4412ad6bb533b38326006b41f..e95785906dbea44c7255b317ad334e97809f31b0 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt @@ -119,11 +119,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 23 + "column": 22 } } } @@ -247,7 +247,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 6 } } }, @@ -296,7 +296,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 22 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt index dfd10c05a70cb678eac98f913ed6c2dde59eb601..73bf02b6226729e84e158047d96bf03c04e42710 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt @@ -149,11 +149,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 33 + "column": 32 } } } @@ -277,7 +277,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 6 } } }, @@ -354,7 +354,7 @@ }, "end": { "line": 17, - "column": 20 + "column": 32 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt index b19aae63841f98e1262b375be17e6061f97d1eb2..69a2a714c4c45f1f0fc2dc05861e6ca62f34c78a 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt @@ -179,11 +179,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 47 + "column": 46 } } } @@ -307,7 +307,7 @@ }, "end": { "line": 16, - "column": 16 + "column": 6 } } }, @@ -384,7 +384,7 @@ }, "end": { "line": 17, - "column": 20 + "column": 46 } } } diff --git a/ets2panda/test/parser/ets/test_type_alias9-expected.txt b/ets2panda/test/parser/ets/test_type_alias9-expected.txt index 20df64b662c0a1a355500af56dffb173b65c20bf..f71a0b03d7d710c885670b8cc54535e408fb6337 100644 --- a/ets2panda/test/parser/ets/test_type_alias9-expected.txt +++ b/ets2panda/test/parser/ets/test_type_alias9-expected.txt @@ -226,11 +226,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 17 + "column": 16 } } }, @@ -397,11 +397,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 52 + "column": 51 } } } @@ -525,7 +525,7 @@ }, "end": { "line": 19, - "column": 13 + "column": 16 } } }, @@ -602,7 +602,7 @@ }, "end": { "line": 20, - "column": 16 + "column": 51 } } } diff --git a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt index 203a0147ad78122484ca1943d0a1535679d7cac4..f0c71fd7157de9a6131b00cde2bacacbca9e81c9 100644 --- a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt +++ b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 16 + "column": 15 } } }, @@ -174,11 +174,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 18 + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt index fba13eb71c47ee15f33656c8ef2708ad9bd50150..f3e0754f7fb15442145d41336b1871a5a9b6df0c 100644 --- a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt +++ b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt @@ -118,7 +118,7 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, diff --git a/ets2panda/test/parser/ets/tuple_type_1-expected.txt b/ets2panda/test/parser/ets/tuple_type_1-expected.txt index 101d5111ac1423c4ab01bfac717452d510f6307e..bca78f1e0e0c02825b24312f23069a4bf691ccb9 100644 --- a/ets2panda/test/parser/ets/tuple_type_1-expected.txt +++ b/ets2panda/test/parser/ets/tuple_type_1-expected.txt @@ -359,11 +359,11 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 34 + "column": 33 } } }, @@ -470,11 +470,11 @@ "loc": { "start": { "line": 23, - "column": 1 + "column": 5 }, "end": { "line": 23, - "column": 44 + "column": 43 } } }, @@ -569,11 +569,11 @@ "loc": { "start": { "line": 24, - "column": 1 + "column": 5 }, "end": { "line": 24, - "column": 50 + "column": 49 } } }, @@ -625,11 +625,11 @@ "loc": { "start": { "line": 25, - "column": 1 + "column": 5 }, "end": { "line": 25, - "column": 16 + "column": 15 } } }, @@ -710,11 +710,11 @@ "loc": { "start": { "line": 26, - "column": 1 + "column": 5 }, "end": { "line": 26, - "column": 42 + "column": 41 } } }, @@ -809,11 +809,11 @@ "loc": { "start": { "line": 27, - "column": 1 + "column": 5 }, "end": { "line": 27, - "column": 50 + "column": 49 } } } @@ -1342,7 +1342,7 @@ }, "end": { "line": 22, - "column": 26 + "column": 33 } } }, @@ -1476,7 +1476,7 @@ }, "end": { "line": 23, - "column": 26 + "column": 43 } } }, @@ -1663,7 +1663,7 @@ }, "end": { "line": 24, - "column": 39 + "column": 49 } } }, @@ -1713,7 +1713,7 @@ }, "end": { "line": 25, - "column": 12 + "column": 15 } } }, @@ -1847,7 +1847,7 @@ }, "end": { "line": 26, - "column": 34 + "column": 41 } } }, @@ -1994,7 +1994,7 @@ }, "end": { "line": 27, - "column": 39 + "column": 49 } } } diff --git a/ets2panda/test/parser/ets/unary_op-expected.txt b/ets2panda/test/parser/ets/unary_op-expected.txt index 9a9d965671f43a0614d6fbf981349d914768d60c..32aa0ba97dbd588e3d409a47515063803947c002 100644 --- a/ets2panda/test/parser/ets/unary_op-expected.txt +++ b/ets2panda/test/parser/ets/unary_op-expected.txt @@ -118,11 +118,11 @@ "loc": { "start": { "line": 16, - "column": 1 + "column": 5 }, "end": { "line": 16, - "column": 11 + "column": 10 } } }, @@ -190,11 +190,11 @@ "loc": { "start": { "line": 17, - "column": 1 + "column": 5 }, "end": { "line": 17, - "column": 13 + "column": 12 } } }, @@ -262,11 +262,11 @@ "loc": { "start": { "line": 18, - "column": 1 + "column": 5 }, "end": { "line": 18, - "column": 13 + "column": 12 } } }, @@ -333,11 +333,11 @@ "loc": { "start": { "line": 19, - "column": 1 + "column": 5 }, "end": { "line": 19, - "column": 12 + "column": 11 } } }, @@ -405,11 +405,11 @@ "loc": { "start": { "line": 20, - "column": 1 + "column": 5 }, "end": { "line": 20, - "column": 12 + "column": 11 } } }, @@ -477,11 +477,11 @@ "loc": { "start": { "line": 21, - "column": 1 + "column": 5 }, "end": { "line": 21, - "column": 12 + "column": 11 } } }, @@ -533,11 +533,11 @@ "loc": { "start": { "line": 22, - "column": 1 + "column": 5 }, "end": { "line": 22, - "column": 14 + "column": 13 } } }, @@ -605,11 +605,11 @@ "loc": { "start": { "line": 23, - "column": 1 + "column": 5 }, "end": { "line": 23, - "column": 12 + "column": 11 } } }, @@ -677,11 +677,11 @@ "loc": { "start": { "line": 25, - "column": 1 + "column": 5 }, "end": { "line": 25, - "column": 12 + "column": 11 } } } diff --git a/ets2panda/test/parser/ets/user_defined_22-expected.txt b/ets2panda/test/parser/ets/user_defined_22-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f61d047d2f720b35b8d719e5d8b00856a7514a01 --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_22-expected.txt @@ -0,0 +1,830 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "type", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 7 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 20, + "column": 4 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "property": { + "type": "Identifier", + "name": "type", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 7 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "right": { + "type": "StringLiteral", + "value": "", + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 11 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 23, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/user_defined_22.ets b/ets2panda/test/parser/ets/user_defined_22.ets new file mode 100644 index 0000000000000000000000000000000000000000..75ace1622ecc1c9df99dbfbfdc94c91de78b9f7a --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_22.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + +class A { + type: number = 0 +} +type B = string +let a = new A +a.type +let b: B = "" diff --git a/ets2panda/test/parser/ets/user_defined_23-expected.txt b/ets2panda/test/parser/ets/user_defined_23-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6fb05ccbb52e0df7af28ce7abb5ffc304ff03e2e --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_23-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot be used as user-defined type. [user_defined_23.ets:16:7] diff --git a/ets2panda/test/parser/ets/user_defined_23.ets b/ets2panda/test/parser/ets/user_defined_23.ets new file mode 100644 index 0000000000000000000000000000000000000000..43577e643e54b7c0212c454c7d61702e4fdd0c1d --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_23.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +class type { + type: number = 0 +} diff --git a/ets2panda/test/parser/ets/user_defined_24-expected.txt b/ets2panda/test/parser/ets/user_defined_24-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..458482bb15f2d2b7074995373a30343c4ada7b54 --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_24-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot be used as user-defined type. [user_defined_24.ets:16:8] diff --git a/ets2panda/test/parser/ets/user_defined_24.ets b/ets2panda/test/parser/ets/user_defined_24.ets new file mode 100644 index 0000000000000000000000000000000000000000..c52cb720a562c7a85660eb323bc97006a14078a7 --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_24.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +struct type { + type: number = 0 +} diff --git a/ets2panda/test/parser/ets/user_defined_25-expected.txt b/ets2panda/test/parser/ets/user_defined_25-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..105c5ae7614ee23c06e38a3a40cfcde868fa7cef --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_25-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot be used as user-defined type. [user_defined_25.ets:16:11] diff --git a/ets2panda/test/parser/ets/user_defined_25.ets b/ets2panda/test/parser/ets/user_defined_25.ets new file mode 100644 index 0000000000000000000000000000000000000000..db7c0eb73b4b3ba9d2d78af762c6cf38098a769e --- /dev/null +++ b/ets2panda/test/parser/ets/user_defined_25.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +interface type { + type: number = 0 +} diff --git a/ets2panda/test/parser/ets/user_defined_3-expected.txt b/ets2panda/test/parser/ets/user_defined_3-expected.txt index 18603423f6d99c99c01e3049fb6eba27d5e08031..4ed6dec988bd3eff6ffb1e80196af7a887214c70 100644 --- a/ets2panda/test/parser/ets/user_defined_3-expected.txt +++ b/ets2panda/test/parser/ets/user_defined_3-expected.txt @@ -161,7 +161,7 @@ }, "end": { "line": 16, - "column": 22 + "column": 14 } } }, @@ -210,7 +210,7 @@ }, "end": { "line": 17, - "column": 26 + "column": 16 } } }, @@ -259,7 +259,7 @@ }, "end": { "line": 18, - "column": 24 + "column": 15 } } }, @@ -308,7 +308,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 13 } } }, @@ -357,7 +357,7 @@ }, "end": { "line": 20, - "column": 22 + "column": 14 } } }, @@ -406,7 +406,7 @@ }, "end": { "line": 21, - "column": 18 + "column": 12 } } }, @@ -455,7 +455,7 @@ }, "end": { "line": 22, - "column": 20 + "column": 13 } } }, @@ -504,7 +504,7 @@ }, "end": { "line": 23, - "column": 20 + "column": 13 } } }, diff --git a/ets2panda/test/runtime/ets/Enum6.ets b/ets2panda/test/runtime/ets/Enum6.ets new file mode 100644 index 0000000000000000000000000000000000000000..39b8f0c5dbc6055f02556c7eafd137f1a757f249 --- /dev/null +++ b/ets2panda/test/runtime/ets/Enum6.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 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. + */ + +enum Access { + READ = 1, + WRITE = 2, + READWRITE = 3 +} + +enum TestEnum { + A = 144, + B, + C = 795 +} + +function main(): void { + test_access_enum_bitwise(Access.WRITE); + assert (Access.WRITE & Access.READWRITE) == 2; + + test_test_enum_bitwise(TestEnum.C); + assert (TestEnum.B & TestEnum.A) == 144 + +} + +function test_access_enum_bitwise(enum_val: Access): void { + assert (enum_val & Access.READ) == 0 + assert (enum_val & Access.WRITE) == 2 + assert (enum_val | Access.READ) == 3 + assert (enum_val | Access.READWRITE) == 3 + assert (enum_val & Access.READWRITE) == 2 +} + +function test_test_enum_bitwise(enum_val: TestEnum): void { + assert (enum_val & TestEnum.A) == 16 + assert (enum_val | TestEnum.A) == 923 + assert (enum_val & TestEnum.B) == 17 + assert (enum_val | TestEnum.B) == 923 +} diff --git a/ets2panda/test/runtime/ets/InferProxymethodType.ets b/ets2panda/test/runtime/ets/InferProxymethodType.ets new file mode 100644 index 0000000000000000000000000000000000000000..334bb0f6ecc188699f01216ed9dacc34ea1f0acb --- /dev/null +++ b/ets2panda/test/runtime/ets/InferProxymethodType.ets @@ -0,0 +1,37 @@ +/* + * 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. + */ + + class A { + met(s: string, q?: string){ + return true; + } + + mat2(){ + return this.met("cat","a"); + } +} + +function main() { + let newA = new A(); + let a1 = new A().met('S'); + let a2 = new A().met('S',"a"); + let a3 = newA.met('S', 'a'); + let b = new A().mat2(); + + assert a1; + assert a2; + assert a3; + assert b; +} diff --git a/ets2panda/test/runtime/ets/Override-3.ets b/ets2panda/test/runtime/ets/Override-3.ets new file mode 100644 index 0000000000000000000000000000000000000000..f3294dc06643c672f992482394ffbbd9c1b570a8 --- /dev/null +++ b/ets2panda/test/runtime/ets/Override-3.ets @@ -0,0 +1,42 @@ +/* + * 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. + */ + +class B { + foo(a: int, op?: int): int { return a } +} +class A extends B { + override foo(a: int, op?: int): int { return a } +} + +class C { + foo(a: T, op?: T): T { return a } +} +class D extends C { + override foo(a: T, op?: T): T { return a } +} + +function main(){ + let a = new A(); + let b = new B(); + let c = new C(); + let d = new D(); + + assert(b.foo(5) == a.foo(5)); + assert(b.foo(6) != a.foo(5)); + assert(b.foo(5) != a.foo(6)); + assert(c.foo("x") == d.foo("x")); + assert(c.foo("x") != d.foo("y")); + assert(c.foo("y") != d.foo("x")); +} diff --git a/ets2panda/test/runtime/ets/UpdateExpression.ets b/ets2panda/test/runtime/ets/UpdateExpression.ets index 4cb626c2c2e7cd15f7ffb4362d7319643ec2d585..ef41ddc5812407f3dfeeb248fa2c23f2ade6627c 100644 --- a/ets2panda/test/runtime/ets/UpdateExpression.ets +++ b/ets2panda/test/runtime/ets/UpdateExpression.ets @@ -92,4 +92,10 @@ function main(): void { assert ++s as int == -32768; assert --s as int == 32767; } + + { + let b: Int[] = [1, 2] + assert ++b[1] == 3 + assert --b[1] == 2 + } } diff --git a/ets2panda/test/runtime/ets/call_static_with_type_alias.ets b/ets2panda/test/runtime/ets/call_static_with_type_alias.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a86ff562a0955f9cd46cd6c3a26303c5787305d --- /dev/null +++ b/ets2panda/test/runtime/ets/call_static_with_type_alias.ets @@ -0,0 +1,52 @@ +/* + * 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. + */ + +interface I { + static inc(p: number): number { + return p + 1; + } +} + +class C1 { + static inc2(p: number): number { + return p + 2; + } +} + +class C2 implements I { +} + +type TI = I; +type TTI = TI; + +type TC1 = C1; +type TTC1 = TC1; + +type TC2 = C2; +type TTC2 = TC2; + +function main(): void { + assert I.inc(20) == 21; + assert TI.inc(20) == 21; + assert TTI.inc(20) == 21; + + assert C1.inc2(20) == 22; + assert TC1.inc2(20) == 22; + assert TTC1.inc2(20) == 22; + + assert C2.inc(20) == 21; + assert TC2.inc(20) == 21; + assert TTC2.inc(20) == 21; +} diff --git a/ets2panda/test/runtime/ets/classGetterSetter.ets b/ets2panda/test/runtime/ets/classGetterSetter.ets new file mode 100644 index 0000000000000000000000000000000000000000..29b68b3979c71a948d403e18a8a8efcf57301f13 --- /dev/null +++ b/ets2panda/test/runtime/ets/classGetterSetter.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 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. + */ + +interface inter { + get my_field (): int; + set my_field(param: int); +} + +class A implements inter { + my_field: int = 3; +} + +function main() { + let a0: A = new A(); + assert a0.my_field == 3; + + let a1: inter = new A(); + assert a1.my_field == 3; + a1.my_field = 5; + assert a1.my_field == 5; +} diff --git a/ets2panda/test/runtime/ets/stringConcatenation.ets b/ets2panda/test/runtime/ets/stringConcatenation.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff66d04edc5a5967d4e65bf5101872179d05987e --- /dev/null +++ b/ets2panda/test/runtime/ets/stringConcatenation.ets @@ -0,0 +1,44 @@ +/* + * 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. + */ + +function main() { + let src: string | undefined = undefined; + let s = "_str_"; + let udef = undefined; + let a :string = "A_"; + let n : string | undefined | null = null; + + let dst: string = "" + src; + let dst_s : string = src + ""; + let a_dst :string = a + dst; + let n_dst : string = n + a_dst; + let dst_a : string = dst + a; + + + + assert dst == "undefined"; + assert dst_s == "undefined"; + assert a_dst == "A_undefined"; + assert dst_a == "undefinedA_"; + assert n_dst == "nullA_undefined"; + assert udef + s == "undefined_str_"; + assert s + udef == "_str_undefined"; + assert a + n == "A_null"; + assert a + s == "A__str_"; + assert a + s + udef == "A__str_undefined"; + assert a + udef + a == "A_undefinedA_"; + assert udef + s + n == "undefined_str_null"; + +} diff --git a/ets2panda/test/runtime/ets/string_from_nullish.ets b/ets2panda/test/runtime/ets/string_from_nullish.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2aae3aa507ea8b5f41faa8b72f207f7d530df39 --- /dev/null +++ b/ets2panda/test/runtime/ets/string_from_nullish.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023-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. + */ + +function main(): int { + let z: NullishType = new Number(1); + let z1 = undefined; + let z2 = null; + let z3: Object = new String("0"); + let z4: Object = new Number(1); + let x = new String(z) + let x1 = new String(z1) + let x2 = new String(z2) + let x3 = new String(z3) + let x4 = new String(z4) + let x5 = new String(null) + let x6 = new String(undefined) + let actual: String[] = [new String(z), new String(z1), new String(z2), new String(z3), new String(z4), new String(null), new String(undefined)] + let expected: String[] = ["1", "undefined", "null", "0", "1", "null", "undefined"] + for (let i = 0; i < expected.length; i++) { + if (actual[i] != expected[i]) { + console.log("Failed: actual is \"" + actual[i] + "\" expected is \"" + expected[i] + "\"") + return 1; + } + } + return 0; +} diff --git a/ets2panda/test/runtime/ets/tuple_types_runtime.ets b/ets2panda/test/runtime/ets/tuple_types_runtime.ets index 5f57797cab21335e752f5e8d7956c1866ebe4774..046ad690bbe8e15bb533655b49d1bc3a03c012b1 100644 --- a/ets2panda/test/runtime/ets/tuple_types_runtime.ets +++ b/ets2panda/test/runtime/ets/tuple_types_runtime.ets @@ -28,6 +28,12 @@ class B extends A { } } +class TupleProvider { + memb: [X, X]; + constructor(value: [X, X]) { this.memb = value;} + public publish(): [X, X] { return this.memb; } +} + function main(): void { const tup_1: [string, number] = ["a", 12]; @@ -126,4 +132,9 @@ function main(): void { assert(a_b_tup[0].foo() == 1); assert(a_b_tup[1].foo() == 2); assert(a_b_tup[2].foo() == 2); + + let number_tup: [Double, Double] = [42.0, 43.0]; + let tn: TupleProvider = new TupleProvider(number_tup); + let result: [Number, Number] = tn.publish(); + assert result[0] == 42.0; } diff --git a/ets2panda/test/unit/public/es2panda_public_test.cpp b/ets2panda/test/unit/public/es2panda_public_test.cpp index fcdef1dd3635d08341cc691e4c635a4b2da4ce91..d0b8c83d6c67dee65e76f4327e04eedea064c197 100644 --- a/ets2panda/test/unit/public/es2panda_public_test.cpp +++ b/ets2panda/test/unit/public/es2panda_public_test.cpp @@ -57,7 +57,7 @@ TEST_F(Es2PandaLibTest, TypeError) impl_->ProceedToState(ctx, ES2PANDA_STATE_ASM_GENERATED); ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_ERROR); ASSERT_EQ(std::string(impl_->ContextErrorMessage(ctx)), - "TypeError: Initializers type is not assignable to the target type[type-error.ets:1,32]"); + "TypeError: Type 'string' cannot be assigned to type 'int'[type-error.ets:1,32]"); impl_->DestroyContext(ctx); } @@ -94,9 +94,8 @@ function main() { impl_->AstNodeForEach(impl_->ProgramAst(impl_->ContextProgram(ctx)), func, &arg); - std::vector expected {"C", "n", "string", "constructor", "constructor", "ETSGLOBAL", - "_$init$_", "_$init$_", "main", "main", "c", "C", - "console", "log", "c", "n", ""}; + std::vector expected {"C", "n", "string", "constructor", "constructor", "main", + "c", "C", "console", "log", "c", "n"}; ASSERT_EQ(arg.ids, expected); impl_->DestroyContext(ctx); diff --git a/ets2panda/test/unit/public/plugin_test.expected.txt b/ets2panda/test/unit/public/plugin_test.expected.txt index f578824e8435dd77777c35b1233f0e02b4ea338d..b1a9b406b06462bc1afe12d7556eb855704c3427 100644 --- a/ets2panda/test/unit/public/plugin_test.expected.txt +++ b/ets2panda/test/unit/public/plugin_test.expected.txt @@ -1,9 +1,5 @@ Hi there! After parse -ETSGLOBAL -_$init$_ -_$init$_ -main main m n @@ -11,6 +7,5 @@ console log m n - After check After lowerings diff --git a/ets2panda/test/unit/union_normalization_test.cpp b/ets2panda/test/unit/union_normalization_test.cpp index 0c680764b0ac1f60f2f4b86e11747bb81e8fea9b..f55635c05934a8e1407f70fb5a168878432dd9b4 100644 --- a/ets2panda/test/unit/union_normalization_test.cpp +++ b/ets2panda/test/unit/union_normalization_test.cpp @@ -122,10 +122,6 @@ public: publicContext_->emitter = context.GetEmitter(); parser.ParseScript(unit.input, unit.options.compilationMode == CompilationMode::GEN_STD_LIB); - if constexpr (std::is_same_v && std::is_same_v) { - reinterpret_cast(varbinder)->FillResolvedImportPathes( - parser.ResolvedParsedSourcesMap(), allocator_.get()); - } for (auto *phase : getPhases) { if (!phase->Apply(publicContext_.get(), program)) { return; diff --git a/ets2panda/util/arktsconfig.cpp b/ets2panda/util/arktsconfig.cpp index 3e84f1fd0545b7bfdfb1bc667d2f65fa65aa2d8d..2c87edc44491adb12a753dca062559dba60ce1c9 100644 --- a/ets2panda/util/arktsconfig.cpp +++ b/ets2panda/util/arktsconfig.cpp @@ -321,7 +321,7 @@ static std::string TrimPath(const std::string &path) return trimmedPath; } -std::string ArkTsConfig::ResolvePath(const std::string &path) +std::optional ArkTsConfig::ResolvePath(const std::string &path) const { for (const auto &[alias, paths] : paths_) { auto trimmedAlias = TrimPath(alias); @@ -334,7 +334,7 @@ std::string ArkTsConfig::ResolvePath(const std::string &path) return resolved; } } - return ""; + return std::nullopt; } #ifdef ARKTSCONFIG_USE_FILESYSTEM diff --git a/ets2panda/util/arktsconfig.h b/ets2panda/util/arktsconfig.h index e7c697eaa2af1d8bded418ef4ed00cfbaf3e9326..1ebb1a25278bdea845b098f038ba645a5ab8c89b 100644 --- a/ets2panda/util/arktsconfig.h +++ b/ets2panda/util/arktsconfig.h @@ -80,7 +80,7 @@ public: explicit ArkTsConfig(std::string configPath) : configPath_(std::move(configPath)) {} bool Parse(); - std::string ResolvePath(const std::string &path); + std::optional ResolvePath(const std::string &path) const; std::string ConfigPath() const { diff --git a/ets2panda/util/error_handler.cpp b/ets2panda/util/error_handler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8554ce8bf21da23321763088328d7a64bbc76ac --- /dev/null +++ b/ets2panda/util/error_handler.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#include "util/error_handler.h" + +namespace panda::es2panda::util { + +void ErrorHandler::ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const +{ + lexer::LineIndex index(program_->SourceCode()); + lexer::SourceLocation loc = index.GetLocation(pos); + + throw Error {ErrorType::SYNTAX, program_->SourceFilePath().Utf8(), errorMessage, loc.line, loc.col}; +} + +void ErrorHandler::ThrowSyntaxError(const parser::Program *program, std::string_view errorMessage, + const lexer::SourcePosition &pos) +{ + ErrorHandler(program).ThrowSyntaxError(errorMessage, pos); +} + +} // namespace panda::es2panda::util diff --git a/ets2panda/util/error_handler.h b/ets2panda/util/error_handler.h new file mode 100644 index 0000000000000000000000000000000000000000..547ee62dab155447bb358bffd23db9e995368479 --- /dev/null +++ b/ets2panda/util/error_handler.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 - 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. + */ + +#ifndef PANDA_ERRORHANDLER_H +#define PANDA_ERRORHANDLER_H + +#include +#include "parser/program/program.h" +#include "lexer/token/sourceLocation.h" + +namespace panda::es2panda::util { + +class ErrorHandler { +public: + explicit ErrorHandler(const parser::Program *program) : program_(program) {} + + [[noreturn]] void ThrowSyntaxError(std::string_view errorMessage, const lexer::SourcePosition &pos) const; + + [[noreturn]] static void ThrowSyntaxError(const parser::Program *program, std::string_view errorMessage, + const lexer::SourcePosition &pos); + +private: + const parser::Program *program_; +}; +} // namespace panda::es2panda::util + +#endif // PANDA_ERRORHANDLER_H diff --git a/ets2panda/util/helpers.cpp b/ets2panda/util/helpers.cpp index c1b73175b87979bab1279d85d8752f099fb207fa..262a2009bb7fa5b8786d6da76e5a4491661ea245 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -487,20 +487,16 @@ std::vector Helpers::CollectBindingNames(ir::AstNode *node) return bindings; } -void Helpers::CheckImportedName(ArenaVector *specifiers, const ir::ImportSpecifier *specifier, - const std::string &fileName) +void Helpers::CheckImportedName(const ArenaVector &specifiers, + const ir::ImportSpecifier *specifier, const std::string &fileName) { auto newIdentName = specifier->Imported()->Name(); auto newAliasName = specifier->Local()->Name(); std::stringstream message {}; - for (auto *it : *specifiers) { - if (!it->IsImportSpecifier()) { - continue; - } - - auto savedIdentName = it->AsImportSpecifier()->Imported()->Name(); - auto savedAliasName = it->AsImportSpecifier()->Local()->Name(); + for (auto *it : specifiers) { + auto savedIdentName = it->Imported()->Name(); + auto savedAliasName = it->Local()->Name(); if (savedIdentName == savedAliasName && savedAliasName == newIdentName) { message << "Warning: '" << newIdentName << "' has already imported "; diff --git a/ets2panda/util/helpers.h b/ets2panda/util/helpers.h index f3f0b927def1331db906a85bd257f636bced776b..447096d4a201efe571262b730d5a877cd259607b 100644 --- a/ets2panda/util/helpers.h +++ b/ets2panda/util/helpers.h @@ -63,6 +63,40 @@ enum class LogLevel : std::uint8_t { FATAL, }; +class NodeAllocator { +public: + template + static T *NoSetParent(ArenaAllocator *alloc, Args &&...args) + { + return alloc->New(std::forward(args)...); + } + + template + static T *ForceSetParent(ArenaAllocator *alloc, Args &&...args) + { + auto *ret = NoSetParent(alloc, std::forward(args)...); + if (ret == nullptr) { + return nullptr; + } + ret->Iterate([ret](ir::AstNode *child) { child->SetParent(ret); }); + return ret; + } + + template + static T *Alloc(ArenaAllocator *alloc, Args &&...args) + { + auto *ret = NoSetParent(alloc, std::forward(args)...); + if (ret == nullptr) { + return nullptr; + } + ret->Iterate([ret](ir::AstNode *child) { + ASSERT(child->Parent() == nullptr); + child->SetParent(ret); + }); + return ret; + } +}; + class Helpers { public: Helpers() = delete; @@ -122,11 +156,18 @@ public: static bool IsPattern(const ir::AstNode *node); static std::vector CollectBindingNames(ir::AstNode *node); static util::StringView FunctionName(ArenaAllocator *allocator, const ir::ScriptFunction *func); - static void CheckImportedName(ArenaVector *specifiers, const ir::ImportSpecifier *specifier, - const std::string &fileName); + static void CheckImportedName(const ArenaVector &specifiers, + const ir::ImportSpecifier *specifier, const std::string &fileName); static std::tuple ParamName(ArenaAllocator *allocator, const ir::AstNode *param, uint32_t index); + template + static ArenaVector ConvertVector(const ArenaVector &src) + { + ArenaVector dst(src.begin(), src.end(), src.get_allocator()); + return dst; + } + template static bool IsTargetFitInSourceRange(Target target) { diff --git a/ets2panda/util/importPathResolver.cpp b/ets2panda/util/importPathResolver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..156024b96f58472aa7f84ad5484474a7d74085b5 --- /dev/null +++ b/ets2panda/util/importPathResolver.cpp @@ -0,0 +1,354 @@ +/** + * Copyright (c) 2021 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 "util/importPathResolver.h" +#include "util/error_handler.h" + +#if defined PANDA_TARGET_MOBILE +#define USE_UNIX_SYSCALL +#endif + +#ifdef USE_UNIX_SYSCALL +#include +#include +#include +#else +#if __has_include() +#include +namespace fs = std::filesystem; +#elif __has_include() +#include +namespace fs = std::experimental::filesystem; +#endif +#endif + +namespace panda::es2panda::util { + +std::string ImportPathResolver::ResolveFullPathFromRelative(const std::string &path, const parser::Program *program) +{ + const auto resolvedFp = program->ResolvedFilePath().Mutf8(); + const auto sourceFp = program->SourceFileFolder().Mutf8(); + if (resolvedFp.empty()) { + auto fp = JoinPaths(sourceFp, path); + return util::Helpers::IsRealPath(fp) ? fp : path; + } + auto fp = JoinPaths(resolvedFp, path); + if (util::Helpers::IsRealPath(fp)) { + return fp; + } + if (path.find(sourceFp) == 0) { + return JoinPaths(resolvedFp, path.substr(sourceFp.size())); + } + return path; +} + +ImportPathResolver::ResultPath ImportPathResolver::GetImportPath(const PathT &path, + const parser::Program *program) const +{ + ResultPath resolvedPath; + if (util::Helpers::IsRelativePath(path)) { + resolvedPath = ResultPath::Ok(util::Helpers::GetAbsPath(ResolveFullPathFromRelative(path, program))); + } else if (path.find(PATH_DELIM) == 0) { + resolvedPath = ResultPath::Ok(config_->BaseUrl()); + resolvedPath->append(path, 0, path.length()); + } else { + auto &dynamicPaths = config_->DynamicPaths(); + auto it = dynamicPaths.find(path); + if (it != dynamicPaths.cend() && !it->second.HasDecl()) { + resolvedPath = ResultPath::Ok(path); + } else { + resolvedPath = ResolveRootPath(path); + } + } + return resolvedPath; +} + +ImportPathResolver::ResultPath ImportPathResolver::ResolveImportPath(const PathT &path, const parser::Program *program) +{ + auto importPath = GetImportPath(path, program); + if (importPath) { + AddResolved(path, *importPath); + } + return importPath; +} + +std::pair ImportPathResolver::GetSourceRegularPath( + const PathT &path, const PathT &resolvedPath) const +{ + if (!panda::os::file::File::IsRegularFile(resolvedPath)) { + for (const auto &ext : allowedExts_) { + if (panda::os::file::File::IsRegularFile(resolvedPath + ext)) { + return std::make_pair(ResultPath::Ok(path + ext), true); + } + } + return std::make_pair(ResultPath::Error(ErrorCode::INCORRECT_PATH, resolvedPath), false); + } + return std::make_pair(ResultPath::Ok(path), false); +} + +ImportPathResolver::ImportData ImportPathResolver::GetImportData(const PathT &path) const +{ + auto &dynamicPaths = config_->DynamicPaths(); + auto key = panda::os::NormalizePath(path); + + auto it = dynamicPaths.find(key); + if (it == dynamicPaths.cend()) { + key = panda::os::RemoveExtension(key); + } + + while (it == dynamicPaths.cend() && !key.empty()) { + it = dynamicPaths.find(key); + if (it != dynamicPaths.cend()) { + break; + } + key = panda::os::GetParentDir(key); + } + + if (it != dynamicPaths.cend()) { + return {it->second.GetLanguage(), key, it->second.HasDecl()}; + } + return {ToLanguage(extension_), path, true}; +} + +ImportPathResolver::ResultSources ImportPathResolver::CollectUserSources(const PathT &path, + const parser::Program *program) +{ + const auto maybeResolvedPath = ResolveImportPath(path, program); + if (!maybeResolvedPath) { + return ResultSources::Error(maybeResolvedPath); + } + const auto &resolvedPath = *maybeResolvedPath; + const auto data = GetImportData(resolvedPath); + if (!data.hasDecl) { + return ResultSources::Ok(std::vector {}, false); + } + + if (!panda::os::file::File::IsDirectory(resolvedPath)) { + auto [regular_path, is_module] = GetSourceRegularPath(path, resolvedPath); + return std::move(regular_path).Transform([module = is_module](PathT &&resPath) { + return UserSources {std::vector {resPath}, module}; + }); + } + + auto newPaths = CollectUserSourcesFromIndex(path, resolvedPath); + return std::move(newPaths).Transform([](std::vector &&paths) { + return UserSources {std::move(paths), false}; + }); +} + +ImportPathResolver::ResultT> ImportPathResolver::CollectUserSourcesFromIndex( + const std::string &path, const std::string &resolvedPath) +{ + std::vector userPaths; + + auto files = ListFiles(resolvedPath); + if (!files) { + return files.ExpectError(); + } + for (const auto &filename : files.ExpectOk()) { + std::string filePath = JoinPaths(path, filename); + + if (IsIndexFile(filename)) { + userPaths.clear(); + userPaths.emplace_back(filePath); + break; + } + if (filename == "Object.ets") { + userPaths.emplace(userPaths.begin(), filePath); + } else { + userPaths.emplace_back(filePath); + } + } + return ResultT>::Ok(userPaths); +} + +ImportPathResolver::ResultT> ImportPathResolver::CollectDefaultSources( + const std::vector &stdlib, const parser::Program *program) +{ + std::vector paths; + std::vector defaultSources; + + for (auto const &path : stdlib) { + const auto maybeResolvedPath = ResolveImportPath(path, program); + if (!maybeResolvedPath) { + return maybeResolvedPath.ExpectError(); + } + auto files = ListFiles(maybeResolvedPath.ExpectOk()); + if (!files) { + return files.ExpectError(); + } + for (const auto &filename : files.ExpectOk()) { + const PathT filePath = JoinPaths(path, filename); + if (filename == "Object.ets") { + defaultSources.emplace(defaultSources.begin(), filePath); + } else { + defaultSources.emplace_back(filePath); + } + } + } + return ResultT>::Ok(defaultSources); +} + +ImportPathResolver::ResultT> ImportPathResolver::ParseSources( + const std::vector &paths, const parser::Program *program) +{ + std::vector sources; + + for (const auto &path : paths) { + auto resolvedPath = ResolveImportPath(path, program); + if (!resolvedPath) { + return resolvedPath.ExpectError(); + } + + const auto data = GetImportData(resolvedPath.ExpectOk()); + if (!data.hasDecl) { + continue; + } + sources.emplace_back(SourceInfo {path, resolvedPath.ExpectOk(), false, data.lang}); + } + return ResultT>::Ok(sources); +} + +void ImportPathResolver::FilterParsedSources(std::vector &sources, const parser::Program *program) +{ + auto condition = [this, program](auto x) { + auto resolved = GetImportPath(x, program).ExpectOk(); + auto found = std::count_if(resolvedParsedSources_.begin(), resolvedParsedSources_.end(), + [resolved](const auto &p) { return p.second == resolved; }); + if (found != 0) { + AddResolved(x, resolved); + } + return found; + }; + + // erase_if - c++20 ext + for (auto it = sources.begin(); it != sources.end();) { + if (condition(*it) != 0) { + it = sources.erase(it); + } else { + ++it; + } + } +} + +ImportPathResolver::ResultPath ImportPathResolver::ResolveRootPath(const ImportPathResolver::PathT &path) const +{ + std::string::size_type pos = path.find(PATH_DELIM); + bool containsDelim = (pos != std::string::npos); + std::string rootPart = containsDelim ? path.substr(0, pos) : path; + + static const std::unordered_set STDLIB_PARTS = {"std", "escompat"}; + + PathT resolvedPath; + if (STDLIB_PARTS.count(rootPart) != 0 && !stdlibPath_.empty()) { + resolvedPath = JoinPaths(stdlibPath_, rootPart); + if (containsDelim) { + resolvedPath.append(1, PATH_DELIM).append(path, rootPart.length() + 1, path.length()); + } + } else { + auto resolved = config_->ResolvePath(path); + if (resolved) { + resolvedPath = *resolved; + } else { + return ResultPath::Error(ErrorCode::ARKTS_PREFIX_FAIL, path); + } + } + return ResultPath::Ok(resolvedPath); +} + +std::vector ImportPathResolver::ReExportPaths( + const ArenaVector &reExports, const std::vector &alreadyExported) +{ + std::vector result; + for (auto reExport : reExports) { + auto progPath = reExport->GetProgramPath().Mutf8(); + if (std::count(alreadyExported.begin(), alreadyExported.end(), progPath) == 0U) { + continue; + } + auto path = progPath.substr(0, progPath.find_last_of(PATH_DELIM)); + for (auto item : reExport->GetUserPaths()) { + const auto reExPath = item.Mutf8(); + result.push_back( + JoinPaths(path, reExPath.substr(reExPath.find_first_of(PATH_DELIM) + 1, reExPath.length()))); + } + } + return result; +} + +bool ImportPathResolver::IsCompatibleExtension(const std::string &extension) const +{ + return allowedExts_.count(extension) != 0U; +} + +bool ImportPathResolver::IsCompatibleFile(const std::string &fileName) const +{ + std::string::size_type pos = fileName.find_last_of('.'); + if (pos == std::string::npos) { + return false; + } + return IsCompatibleExtension(fileName.substr(pos)); +} + +bool ImportPathResolver::IsStdLib(const parser::Program *program) const +{ + const auto &stdlib = StdLib(); + return std::count(stdlib.begin(), stdlib.end(), std::string(program->SourceFileFolder())) != 0; +} + +ImportPathResolver::ResultT> ImportPathResolver::ListFiles( + const PathT &resolvedPath) const +{ + std::vector files; +#ifdef USE_UNIX_SYSCALL + DIR *dir = opendir(resolvedPath.c_str()); + + if (dir == nullptr) { + return ResultT>::Error(ErrorCode::INCORRECT_PATH, resolvedPath); + } + + struct dirent *entry; + while ((entry = readdir(dir)) != nullptr) { + if (entry->d_type != DT_REG) { + continue; + } + + std::string fileName = entry->d_name; + if (!IsCompatibleFile(fileName)) { + continue; + } + + files.emplace_back(fileName); + } + + closedir(dir); +#else + for (auto const &entry : fs::directory_iterator(resolvedPath)) { + if (!fs::is_regular_file(entry) || !IsCompatibleExtension(entry.path().extension().string())) { + continue; + } + files.emplace_back(entry.path().filename().string()); + } +#endif + std::sort(files.begin(), files.end()); + return ResultT>::Ok(files); +} + +bool ImportPathResolver::IsIndexFile(const std::string &fileName) +{ + return fileName == "index.ets" || fileName == "index.ts"; +} + +} // namespace panda::es2panda::util +#undef USE_UNIX_SYSCALL diff --git a/ets2panda/util/importPathResolver.h b/ets2panda/util/importPathResolver.h new file mode 100644 index 0000000000000000000000000000000000000000..e10d6e26f24daf962f24fff75a7ba99276c4e258 --- /dev/null +++ b/ets2panda/util/importPathResolver.h @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2021 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. + */ + +#ifndef PANDA_IMPORTPATHRESOLVER_H +#define PANDA_IMPORTPATHRESOLVER_H + +#include +#include +#include "util/helpers.h" +#include "util/arktsconfig.h" +#include "ir/ets/etsReExportDeclaration.h" +#include "parser/program/program.h" +#include "es2panda.h" +#include "os/filesystem.h" +#include "util/error_handler.h" +#include "util/result.h" + +namespace panda::es2panda::util { + +class ImportPathResolver { +public: + enum class ErrorCode { + INCORRECT_PATH, + ARKTS_PREFIX_FAIL, + }; + + template + using ResultT = Result; + +private: + using PathT = std::string; + + using ResultPath = ResultT; + + struct UserSources { + std::vector sources; + bool isModule {false}; + }; + using ResultSources = ResultT; + + const std::unordered_set allowedExts_ = {".ets", ".ts"}; + +public: + struct ImportData { + Language lang; + std::string module; + bool hasDecl; + }; + + ImportPathResolver(std::shared_ptr config, PathT stdlibPath, ScriptExtension extension) + : config_(std::move(config)), stdlibPath_(std::move(stdlibPath)), extension_(extension) + { + } + + static std::vector ReExportPaths(const ArenaVector &reExports, + const std::vector &alreadyExported); + + void AddResolved(const PathT &path, const PathT &realPath) + { + resolvedParsedSources_.emplace(path, realPath); + } + + ResultPath ResolveImportPath(const PathT &path, const parser::Program *program); + + ImportData GetImportData(const PathT &path) const; + + const std::unordered_map &ResolvedParsedSourcesMap() const + { + return resolvedParsedSources_; + } + + static std::vector &StdLib() + { + static std::vector stdlib {"std/core", "std/math", "std/containers", + "std/time", "std/interop/js", "escompat"}; + return stdlib; + } + + bool IsStdLib(const parser::Program *program) const; + + ResultSources CollectUserSources(const PathT &path, const parser::Program *program); + + ResultT> CollectDefaultSources(const std::vector &stdlib, const parser::Program *program); + + struct SourceInfo { + PathT filePath; + PathT resolvedPath; + bool isModule; + Language lang; + }; + + ResultT> ParseSources(const std::vector &paths, const parser::Program *program); + + /** + * Removes from `sources` already parsed files, and mark this paths as resolved + * @param sources + * @param resolved_fp + * @param source_fp + */ + void FilterParsedSources(std::vector &sources, const parser::Program *program); + + /** + * Resolves root path. E.g. rel_dir/file.ets -> absolute_path/rel_dir + * @param path + * @return root path + */ + ResultPath ResolveRootPath(const PathT &path) const; + +private: + ResultT> CollectUserSourcesFromIndex(const PathT &path, const PathT &resolvedPath); + + /** + * @param path + * @param resolved_path + * @return (src path, is_module) + */ + std::pair GetSourceRegularPath(const PathT &path, const PathT &resolvedPath) const; + static PathT ResolveFullPathFromRelative(const PathT &path, const parser::Program *program); + ResultPath GetImportPath(const PathT &path, const parser::Program *program) const; + + /** + * @param resolvedPath directory absolute path + * @return alphabetically ordered ts/ets files in directory + */ + ResultT> ListFiles(const PathT &resolvedPath) const; + + bool IsCompatibleExtension(const std::string &extension) const; + + bool IsCompatibleFile(const std::string &fileName) const; + + static bool IsIndexFile(const std::string &fileName); + +private: + std::shared_ptr config_; + std::unordered_map resolvedParsedSources_; + const PathT stdlibPath_; + const ScriptExtension extension_; + static constexpr char PATH_DELIM = panda::os::file::File::GetPathDelim().at(0); +}; +} // namespace panda::es2panda::util + +#endif // PANDA_IMPORTPATHRESOLVER_H diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index db863804e2a4b208d9cb1caa588fd6d34295d3fb..7961ee7c144c5dae77f599155b7ad563d25b8c36 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -181,8 +181,22 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg genStdLib("gen-stdlib", false, "Gen standard library"); panda::PandArg plugins("plugins", "", "Plugins"); panda::PandArg skipPhases("skip-phases", "", "Phases to skip"); - panda::PandArg verifierWarnings("verifier-warnings", "", "Show warnings form verifier"); - panda::PandArg verifierErrors("verifier-errors", "", "Show warnings form verifier"); + panda::PandArg verifierWarnings( + "verifier-warnings", "", + "Print errors and continue compilation if AST tree is incorrect. " + "Possible values: " + "NodeHasParentForAll,EveryChildHasValidParentForAll,VariableHasScopeForAll,NodeHasTypeForAll," + "IdentifierHasVariableForAll,ArithmeticOperationValidForAll,SequenceExpressionHasLastTypeForAll," + "ForLoopCorrectlyInitializedForAll,VariableHasEnclosingScopeForAll,ModifierAccessValidForAll," + "ImportExportAccessValid"); + panda::PandArg verifierErrors( + "verifier-errors", "ForLoopCorrectlyInitializedForAll", + "Print errors and stop compilation if AST tree is incorrect. " + "Possible values: " + "NodeHasParentForAll,EveryChildHasValidParentForAll,VariableHasScopeForAll,NodeHasTypeForAll," + "IdentifierHasVariableForAll,ArithmeticOperationValidForAll,SequenceExpressionHasLastTypeForAll," + "ForLoopCorrectlyInitializedForAll,VariableHasEnclosingScopeForAll,ModifierAccessValidForAll," + "ImportExportAccessValid"); panda::PandArg dumpBeforePhases("dump-before-phases", "", "Generate program dump before running phases in the list"); panda::PandArg dumpEtsSrcBeforePhases( diff --git a/ets2panda/util/result.h b/ets2panda/util/result.h new file mode 100644 index 0000000000000000000000000000000000000000..c73a76fe7a10b910b117aa603b69c35d894fd51f --- /dev/null +++ b/ets2panda/util/result.h @@ -0,0 +1,149 @@ +/** + * Copyright (c) 2021-2022 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. + */ + +#ifndef PANDA_RESULT_H +#define PANDA_RESULT_H + +#include +#include + +namespace panda::es2panda::util { + +/** + * Class to handle errors + * @tparam SuccessT type in case of success + * @tparam ErrorStatus error code, should be enum + * @tparam ErrorV error value to provide detail about error + * NOTE: `ErrorV = void` not allowed yet. + */ +template +class Result { + using ErrorT = std::pair; + + class Tag {}; + template + explicit Result(Tag /*tag*/, Args... args) : value_ {SuccessT {std::forward(args)...}} + { + } + +public: + Result() = default; + + template + static Result Ok(Args... args) + { + return Result(Tag {}, std::forward(args)...); + } + + static Result Error(ErrorStatus status, ErrorV value) + { + return Result(std::make_pair(status, value)); + } + + template + static Result Error(Result result) + { + return Result(result.ExpectError()); + } + + Result(ErrorStatus status, ErrorV errorVal) : value_(std::make_pair(std::move(status), std::move(errorVal))) {} + + // NOLINTNEXTLINE(google-explicit-constructor) + Result(std::pair error) : value_(std::move(error)) {} + + explicit Result(SuccessT success) : value_(success) {} + + explicit operator bool() const + { + return IsOk(); + } + + SuccessT &operator*() + { + return std::get(value_); + } + + const SuccessT &operator*() const + { + return std::get(value_); + } + + SuccessT *operator->() + { + return &std::get(value_); + } + + const SuccessT *operator->() const + { + return &std::get(value_); + } + + bool IsOk() const + { + return std::holds_alternative(value_); + } + + bool IsError() const + { + return !IsOk(); + } + + const std::pair &ExpectError() const + { + return std::get(value_); + } + + const SuccessT &ExpectOk() const & + { + return std::get(value_); + } + + SuccessT ExpectOk() && + { + return std::move(std::get(value_)); + } + + template + Result Transform(std::function cb) + { + Result result; + if (IsError()) { + result = Result::Error(this); + } else { + result = Result::Ok(cb(ExpectOk())); + } + return result; + } + + template + Result Transform(std::function cb) && + { + using ReturnT = Result; + ReturnT result; + if (IsError()) { + result = ReturnT::Error(*this); + } else { + result = ReturnT::Ok(cb(std::move(*this).ExpectOk())); + } + return result; + } + +private: + std::variant value_; +}; + +} // namespace panda::es2panda::util + +#endif // PANDA_RESULT_H diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 3df41bd5eb4f8adc0057e200074c3d104823e11f..b60c1e5f1e17c1b5ff6669589d55bc6130bf050d 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -1036,11 +1036,11 @@ void ETSBinder::BuildETSNewClassInstanceExpression(ir::ETSNewClassInstanceExpres void ETSBinder::BuildImportDeclaration(ir::ETSImportDeclaration *decl) { - if (decl->Source()->Str() == Program()->AbsoluteName()) { + if (decl->Source()->Str() == Program()->SourceFile().GetAbsolutePath()) { return; } - auto specifiers = decl->Specifiers(); + const auto &specifiers = decl->Specifiers(); for (auto specifier : specifiers) { AddSpecifiersToTopBindings(specifier, decl, decl->Source()); diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/varbinder/ETSBinder.h index edd27f9a43a6b9cd3905d994d94ac3fbaf527937..bbaaad08f618d861712b8d12097a2e71daf15e70 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/varbinder/ETSBinder.h @@ -46,7 +46,7 @@ public: lambdaObjects_(Allocator()->Adapter()), dynamicImportVars_(Allocator()->Adapter()), importSpecifiers_(Allocator()->Adapter()), - resolvedImportPathesMap_(Allocator()->Adapter()) + resolvedImportPathsMap_(Allocator()->Adapter()) { InitImplicitThisParam(); } @@ -202,23 +202,18 @@ public: defaultExport_ = defaultExport; } - const ArenaUnorderedMap &ResolvedImportPathesMap() const - { - return resolvedImportPathesMap_; - } - const util::StringView &GetResolvedImportPath(const util::StringView &path) const { - ASSERT(resolvedImportPathesMap_.find(path) != resolvedImportPathesMap_.end()); + ASSERT(resolvedImportPathsMap_.find(path) != resolvedImportPathsMap_.end()); - return resolvedImportPathesMap_.find(path)->second; + return resolvedImportPathsMap_.find(path)->second; } - void FillResolvedImportPathes(const std::unordered_map &map, ArenaAllocator *allocator) + void FillResolvedImportPaths(const std::unordered_map &map, ArenaAllocator *allocator) { for (const auto &path : map) { - resolvedImportPathesMap_.emplace(util::UString(path.first, allocator).View(), - util::UString(path.second, allocator).View()); + resolvedImportPathsMap_.emplace(util::UString(path.first, allocator).View(), + util::UString(path.second, allocator).View()); } } @@ -226,16 +221,6 @@ public: bool IsDynamicNamespaceVariable(const Variable *var) const; const DynamicImportData *DynamicImportDataForVar(const Variable *var) const; - static constexpr std::string_view DEFAULT_IMPORT_SOURCE_FILE = ".ets"; - static constexpr std::string_view DEFAULT_IMPORT_SOURCE = R"( -import * from "std/core"; -import * from "std/math"; -import * from "std/containers"; -import * from "std/time"; -import * from "std/interop/js"; -import * from "escompat"; -)"; - void ResolveReferenceForScope(ir::AstNode *node, Scope *scope); void ResolveReferencesForScope(ir::AstNode const *parent, Scope *scope); @@ -262,7 +247,7 @@ private: DynamicImportVariables dynamicImportVars_; ir::Identifier *thisParam_ {}; ArenaVector> importSpecifiers_; - ArenaUnorderedMap resolvedImportPathesMap_; + ArenaUnorderedMap resolvedImportPathsMap_; ir::AstNode *defaultExport_ {}; }; diff --git a/ets2panda/varbinder/scope.h b/ets2panda/varbinder/scope.h index b53625d68e4f2f30d39b2b7fff23c1a732d452e6..f1030ca4089df18e3dee09a9d5805b18b3bb1369 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -245,6 +245,13 @@ public: return bindings_; } + ArenaMap OrderedBindings(ArenaAllocator *allocator) const + { + ArenaMap result(allocator->Adapter()); + result.insert(bindings_.begin(), bindings_.end()); + return result; + } + virtual Variable *AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension) = 0; diff --git a/ets2panda/varbinder/varbinder.h b/ets2panda/varbinder/varbinder.h index 48aa8c71668a0751b16424578bab3ffd7f88ef4b..0d38ce15be0937b3e23d056739b5dbccc220e766 100644 --- a/ets2panda/varbinder/varbinder.h +++ b/ets2panda/varbinder/varbinder.h @@ -129,6 +129,11 @@ public: return varScope_; } + bool IsETSBinder() const + { + return Extension() == ScriptExtension::ETS; + } + ETSBinder *AsETSBinder() { ASSERT(Extension() == ScriptExtension::ETS); diff --git a/ets2panda/varbinder/variableFlags.h b/ets2panda/varbinder/variableFlags.h index 87e165e4cead92a3ea44803aeaee632009e571ca..3c9fa9813a5904e6ce1138bc13b61b835893f753 100644 --- a/ets2panda/varbinder/variableFlags.h +++ b/ets2panda/varbinder/variableFlags.h @@ -152,6 +152,7 @@ enum class VariableFlags : uint64_t { BUILTIN_TYPE = 1ULL << 32ULL, BOXED = 1ULL << 33ULL, + GETTER_SETTER = 1ULL << 34ULL, HOIST_VAR = HOIST | VAR, CLASS_OR_INTERFACE = CLASS | INTERFACE,