diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index c52f3f348262fc97c954a998da416d2b77580569..2ebfd84bc484d56d0067569d8ec1314df2d67697 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -269,20 +269,22 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ETSScript *node) const checker::Type *ETSAnalyzer::Check(ir::ETSClassLiteral *expr) const { ETSChecker *checker = GetETSChecker(); - checker->ThrowTypeError("Class literal is not yet supported.", expr->expr_->Start()); + auto *const literal = expr->Expr(); - expr->expr_->Check(checker); - auto *exprType = expr->expr_->GetType(checker); + checker->ThrowTypeError("Class literal is not yet supported.", literal->Start()); + + auto *exprType = literal->Check(checker); if (exprType->IsETSVoidType()) { - checker->ThrowTypeError("Invalid .class reference", expr->expr_->Start()); + checker->ThrowTypeError("Invalid .class reference", literal->Start()); } ArenaVector typeArgTypes(checker->Allocator()->Adapter()); typeArgTypes.push_back(exprType); // NOTE: Box it if it's a primitive type - checker::InstantiationContext ctx(checker, checker->GlobalBuiltinTypeType(), typeArgTypes, expr->range_.start); + checker::InstantiationContext ctx(checker, checker->GlobalBuiltinTypeType(), typeArgTypes, expr->Range().start); expr->SetTsType(ctx.Result()); + return expr->TsType(); } @@ -377,11 +379,15 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewArrayInstanceExpression *expr) const if (!elementType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { if (elementType->IsETSObjectType()) { auto *calleeObj = elementType->AsETSObjectType(); - if (!calleeObj->HasObjectFlag(checker::ETSObjectFlags::ABSTRACT)) { + const auto flags = checker::ETSObjectFlags::ABSTRACT | checker::ETSObjectFlags::INTERFACE; + if (!calleeObj->HasObjectFlag(flags)) { // A workaround check for new Interface[...] in test cases expr->SetSignature( checker->CollectParameterlessConstructor(calleeObj->ConstructSignatures(), expr->Start())); checker->ValidateSignatureAccessibility(calleeObj, nullptr, expr->Signature(), expr->Start()); + } else { + checker->ThrowTypeError("Cannot use array creation expression with abstract classes and interfaces.", + expr->Start()); } } } diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index c512dfb6581254cad68adecaa950753e682689b4..e7edba09bd8f97ee9f05fc5fa8249ebcfdfabf13 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -385,7 +385,8 @@ public: void CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Signature *signature, ETSObjectType *functionalInterface); ir::AstNode *CreateLambdaImplicitField(varbinder::ClassScope *scope, const lexer::SourcePosition &pos); - ir::MethodDefinition *CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool isStaticReference); + ir::MethodDefinition *CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool isStaticReference, + ETSObjectType *functionalInterface); ir::MethodDefinition *CreateLambdaImplicitCtor(ArenaVector &properties); ir::MethodDefinition *CreateProxyMethodForLambda(ir::ClassDefinition *klass, ir::ArrowFunctionExpression *lambda, ArenaVector &captured, bool isStatic); @@ -587,6 +588,9 @@ public: varbinder::ClassScope *scope, bool isSetter, ETSChecker *checker); void GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *originalProp, ETSObjectType *classType); + ir::MethodDefinition *GenerateSetterForProperty(ir::ClassProperty *originalProp, ir::ClassProperty *interfaceProp, + ir::ClassProperty *classProp, ETSObjectType *classType, + ir::MethodDefinition *getter); ETSObjectType *GetImportSpecifierObjectType(ir::ETSImportDeclaration *importDecl, ir::Identifier *ident); void ImportNamespaceObjectTypeAddReExportType(ir::ETSImportDeclaration *importDecl, checker::ETSObjectType *lastObjectType, ir::Identifier *ident); diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 6def0c73b1492cb88d19b07b64713d3ab959a63e..b0798dd1a77f453011a36621064eb7e110537d36 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -507,10 +507,8 @@ std::tuple ETSChecker::CheckBinaryOperatorInstanceOf(lexer::Sour ThrowTypeError("Bad operand type, the types of the operands must be same type.", pos); } - if (rightType->IsETSDynamicType() || leftType->IsETSDynamicType()) { - if (!(rightType->IsETSDynamicType() && leftType->IsETSDynamicType())) { - ThrowTypeError("Bad operand type, both types of the operands must be dynamic.", pos); - } + if (rightType->IsETSDynamicType() && !rightType->AsETSDynamicType()->HasDecl()) { + ThrowTypeError("Right-hand side of instanceof expression must represent a type.", pos); } tsType = GlobalETSBooleanType(); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 3f127702f536453220de2d558ecd98c4906aaef7..1dcdf7966530c852c67883d7e31ea8c62197b107 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -2438,6 +2438,7 @@ ir::Statement *ETSChecker::CreateLambdaCtorFieldInit(util::StringView name, varb auto *initializer = // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(leftHandSide, rightHandSide, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + initializer->SetTsType(var->TsType()); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return AllocNode(initializer); } @@ -2470,7 +2471,7 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Si // Create the synthetic constructor node, where we will initialize the synthetic field (if present) to the // instance object // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - auto *ctor = CreateLambdaImplicitCtor(refNode->Range(), isStaticReference); + auto *ctor = CreateLambdaImplicitCtor(refNode->Range(), isStaticReference, functionalInterface); properties.push_back(ctor); // Create the template for the synthetic invoke function which will propagate the function call to the saved @@ -2534,7 +2535,8 @@ ir::AstNode *ETSChecker::CreateLambdaImplicitField(varbinder::ClassScope *scope, return field; } -ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool isStaticReference) +ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRange &pos, bool isStaticReference, + ETSObjectType *functionalInterface) { ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); @@ -2542,6 +2544,9 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRa // Create the parameters for the synthetic constructor // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto [funcParamScope, var] = CreateLambdaCtorImplicitParam(params, pos, isStaticReference); + if (var != nullptr && var->TsType() == nullptr) { + var->SetTsType(functionalInterface); + } // Create the scopes auto paramCtx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index a5ee1b3bb6ff005731b7531befac3be4691473af..7cbc7f967255b2a0d8a983674d845cd4df961735 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -224,7 +224,7 @@ void ETSChecker::SaveCapturedVariable(varbinder::Variable *const var, ir::Identi } if ((!var->HasFlag(varbinder::VariableFlags::LOCAL) && !var->HasFlag(varbinder::VariableFlags::METHOD)) || - (var->GetScope()->Node()->IsScriptFunction() && var->GetScope()->Node()->AsScriptFunction()->IsArrow())) { + Context().ContainingLambda()->IsVarFromSubscope(var)) { return; } @@ -253,13 +253,13 @@ checker::Type *ETSChecker::ResolveIdentifier(ir::Identifier *const ident) resolved = FindVariableInGlobal(ident); } + ident->SetVariable(resolved); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) ValidateResolvedIdentifier(ident, resolved); ValidatePropertyAccess(resolved, Context().ContainingClass(), ident->Start()); SaveCapturedVariable(resolved, ident); - ident->SetVariable(resolved); return GetTypeOfVariable(resolved); } @@ -417,11 +417,8 @@ Type *ETSChecker::HandleBooleanLogicalOperatorsExtended(Type *leftType, Type *ri auto [resolveLeft, leftValue] = IsResolvedAndValue(expr->Left(), leftType); auto [resolveRight, rightValue] = IsResolvedAndValue(expr->Right(), rightType); - if (!resolveLeft && !resolveRight) { - if (IsTypeIdenticalTo(leftType, rightType)) { - return leftType; - } - return CreateETSUnionType({leftType, rightType}); + if (!resolveLeft && !resolveRight && IsTypeIdenticalTo(leftType, rightType)) { + return leftType; } switch (expr->OperatorType()) { @@ -1142,7 +1139,9 @@ void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleO for (auto [_, var] : bindings) { (void)_; auto [found, aliasedName] = FindSpecifierForModuleObject(importDecl, var->AsLocalVariable()->Name()); - if (var->AsLocalVariable()->Declaration()->Node()->IsExported() && found) { + if ((var->AsLocalVariable()->Declaration()->Node()->IsExported() || + var->AsLocalVariable()->Declaration()->Node()->IsExportedType()) && + found) { if (!aliasedName.Empty()) { moduleObjType->AddReExportAlias(var->Declaration()->Name(), aliasedName); } @@ -1196,8 +1195,7 @@ Type *ETSChecker::GetReferencedTypeFromBase([[maybe_unused]] Type *baseType, [[m Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) { if (name->IsTSQualifiedName()) { - auto *qualified = name->AsTSQualifiedName(); - return qualified->Check(this); + return name->Check(this); } ASSERT(name->IsIdentifier() && name->AsIdentifier()->Variable() != nullptr); @@ -1205,34 +1203,43 @@ Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) // NOTE: kbaladurin. forbid usage imported entities as types without declarations auto *importData = VarBinder()->AsETSBinder()->DynamicImportDataForVar(name->AsIdentifier()->Variable()); if (importData != nullptr && importData->import->IsPureDynamic()) { - return GlobalBuiltinDynamicType(importData->import->Language()); + name->SetTsType(GlobalBuiltinDynamicType(importData->import->Language())); + return name->TsType(); } auto *refVar = name->AsIdentifier()->Variable()->AsLocalVariable(); + checker::Type *tsType = nullptr; switch (refVar->Declaration()->Node()->Type()) { case ir::AstNodeType::TS_INTERFACE_DECLARATION: { - return GetTypeFromInterfaceReference(refVar); + tsType = GetTypeFromInterfaceReference(refVar); + break; } case ir::AstNodeType::CLASS_DECLARATION: case ir::AstNodeType::STRUCT_DECLARATION: case ir::AstNodeType::CLASS_DEFINITION: { - return GetTypeFromClassReference(refVar); + tsType = GetTypeFromClassReference(refVar); + break; } case ir::AstNodeType::TS_ENUM_DECLARATION: { // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - return GetTypeFromEnumReference(refVar); + tsType = GetTypeFromEnumReference(refVar); + break; } case ir::AstNodeType::TS_TYPE_PARAMETER: { - return GetTypeFromTypeParameterReference(refVar, name->Start()); + tsType = GetTypeFromTypeParameterReference(refVar, name->Start()); + break; } case ir::AstNodeType::TS_TYPE_ALIAS_DECLARATION: { - return GetTypeFromTypeAliasReference(refVar); + tsType = GetTypeFromTypeAliasReference(refVar); + break; } default: { UNREACHABLE(); } } + name->SetTsType(tsType); + return tsType; } void ETSChecker::ConcatConstantString(util::UString &target, Type *type) @@ -2096,6 +2103,7 @@ void ETSChecker::GenerateGetterSetterBody(ArenaVector &stmts, A auto *assignmentExpression = AllocNode( memberExpression, paramExpression->Clone(Allocator(), nullptr), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + assignmentExpression->SetTsType(paramVar->TsType()); assignmentExpression->SetRange({field->Start(), field->End()}); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) @@ -2163,7 +2171,11 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty paramScope->BindNode(func); functionScope->BindNode(func); - checker->VarBinder()->AsETSBinder()->ResolveMethodDefinition(method); + { + auto classCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), classScope); + checker->VarBinder()->AsETSBinder()->ResolveMethodDefinition(method); + } + functionScope->BindName(classScope->Node()->AsClassDefinition()->InternalName()); method->Check(checker); @@ -2174,7 +2186,7 @@ void ETSChecker::GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *origin { auto *const classDef = classType->GetDeclNode()->AsClassDefinition(); auto *interfaceProp = originalProp->Clone(Allocator(), originalProp->Parent()); - interfaceProp->ClearModifier(ir::ModifierFlags::GETTER_SETTER); + interfaceProp->ClearModifier(ir::ModifierFlags::GETTER_SETTER | ir::ModifierFlags::EXTERNAL); ASSERT(Scope()->IsClassScope()); auto *const scope = Scope()->AsClassScope(); @@ -2203,21 +2215,9 @@ void ETSChecker::GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *origin auto *const decl = Allocator()->New(Allocator(), name, getter); auto *var = methodScope->AddDecl(Allocator(), decl, ScriptExtension::ETS); - ir::MethodDefinition *setter = nullptr; - if (!classProp->IsConst()) { - // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - setter = GenerateDefaultGetterSetter(interfaceProp, classProp, scope, true, this); - if (((originalProp->Modifiers() & ir::ModifierFlags::SETTER) != 0U)) { - setter->Function()->AddModifier(ir::ModifierFlags::OVERRIDE); - } - setter->SetParent(classDef); - setter->TsType()->AddTypeFlag(TypeFlag::SETTER); - getter->Variable()->TsType()->AsETSFunctionType()->AddCallSignature( - setter->TsType()->AsETSFunctionType()->CallSignatures()[0]); - classType->AddProperty(setter->Variable()->AsLocalVariable()); - - getter->AddOverload(setter); - } + ir::MethodDefinition *setter = + !classProp->IsConst() ? GenerateSetterForProperty(originalProp, interfaceProp, classProp, classType, getter) + : nullptr; if (var == nullptr) { auto *const prevDecl = methodScope->FindDecl(name); @@ -2230,10 +2230,39 @@ void ETSChecker::GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *origin var = methodScope->FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS); } + if ((originalProp->Modifiers() & ir::ModifierFlags::EXTERNAL) != 0U) { + getter->Function()->AddFlag(ir::ScriptFunctionFlags::EXTERNAL); + } + var->AddFlag(varbinder::VariableFlags::METHOD); getter->Function()->Id()->SetVariable(var); } +ir::MethodDefinition *ETSChecker::GenerateSetterForProperty(ir::ClassProperty *originalProp, + ir::ClassProperty *interfaceProp, + ir::ClassProperty *classProp, ETSObjectType *classType, + ir::MethodDefinition *getter) +{ + ir::MethodDefinition *setter = + GenerateDefaultGetterSetter(interfaceProp, classProp, Scope()->AsClassScope(), true, this); + if (((originalProp->Modifiers() & ir::ModifierFlags::SETTER) != 0U)) { + setter->Function()->AddModifier(ir::ModifierFlags::OVERRIDE); + } + + if ((originalProp->Modifiers() & ir::ModifierFlags::EXTERNAL) != 0U) { + setter->Function()->AddFlag(ir::ScriptFunctionFlags::EXTERNAL); + } + + setter->SetParent(classType->GetDeclNode()->AsClassDefinition()); + setter->TsType()->AddTypeFlag(TypeFlag::SETTER); + getter->Variable()->TsType()->AsETSFunctionType()->AddCallSignature( + setter->TsType()->AsETSFunctionType()->CallSignatures()[0]); + classType->AddProperty(setter->Variable()->AsLocalVariable()); + getter->AddOverload(setter); + + return setter; +} + const Type *ETSChecker::TryGettingFunctionTypeFromInvokeFunction(const Type *type) const { if (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { diff --git a/ets2panda/checker/ets/narrowingConverter.h b/ets2panda/checker/ets/narrowingConverter.h index 8c9a6562cbc5a062ae9349e74773ddd4c257e8d9..111d84dcd600dba0f805c1111d875d34d3fa8d36 100644 --- a/ets2panda/checker/ets/narrowingConverter.h +++ b/ets2panda/checker/ets/narrowingConverter.h @@ -104,38 +104,29 @@ private: } template - int CalculateIntValue(Type *target, SType value) + int CalculateIntValue(SType value) { - switch (ETSChecker::ETSChecker::ETSType(target)) { - case TypeFlag::BYTE: - case TypeFlag::CHAR: - case TypeFlag::SHORT: { - if (std::isinf(value)) { - return std::numeric_limits::max(); - } - if (std::signbit(std::isinf(value))) { - return std::numeric_limits::min(); - } - if (std::isnan(value)) { - return 0; - } - return static_cast(value); - } - default: { - return 0; + if (std::isinf(value)) { + if (std::signbit(value)) { + return std::numeric_limits::min(); } + return std::numeric_limits::max(); } + if (std::isnan(value)) { + return 0; + } + return static_cast(value); } template To CastFloatingPointToIntOrLong(From value) { if (std::isinf(value)) { + if (std::signbit(value)) { + return std::numeric_limits::min(); + } return std::numeric_limits::max(); } - if (std::signbit(std::isinf(value))) { - return std::numeric_limits::min(); - } ASSERT(std::is_floating_point_v); ASSERT(std::is_integral_v); To minInt = std::numeric_limits::min(); @@ -162,7 +153,7 @@ private: case TypeFlag::BYTE: case TypeFlag::CHAR: case TypeFlag::SHORT: { - return CalculateIntValue(target, value); + return CalculateIntValue(value); } case TypeFlag::INT: case TypeFlag::LONG: { diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index e8b45806837da9f2cc5528104cba7297e06a02c3..384573a26975c7e07e8e4b3eff6edc71ab77430c 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -701,11 +701,13 @@ void ETSChecker::ValidateOverriding(ETSObjectType *classType, const lexer::Sourc bool functionOverridden = false; bool isGetter = false; bool isSetter = false; + bool isExternal = false; for (auto abstractSignature = (*it)->CallSignatures().begin(); abstractSignature != (*it)->CallSignatures().end();) { bool foundSignature = false; isGetter = (*abstractSignature)->HasSignatureFlag(SignatureFlags::GETTER); isSetter = (*abstractSignature)->HasSignatureFlag(SignatureFlags::SETTER); + isExternal = (*abstractSignature)->Function()->IsExternal(); for (auto *const implemented : implementedSignatures) { Signature *substImplemented = AdjustForTypeParameters(*abstractSignature, implemented); @@ -749,6 +751,10 @@ void ETSChecker::ValidateOverriding(ETSObjectType *classType, const lexer::Sourc for (auto *field : classType->Fields()) { if (field->Name() == (*it)->Name()) { + if (isExternal) { + field->Declaration()->Node()->AddModifier(ir::ModifierFlags::EXTERNAL); + } + field->Declaration()->Node()->AddModifier(isGetter && isSetter ? ir::ModifierFlags::GETTER_SETTER : isGetter ? ir::ModifierFlags::GETTER : ir::ModifierFlags::SETTER); diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index 7d03ff0b843229cce2fecc079ffae868b5011391..86780f246f22a964db0c5614b8baf3f7c33108f2 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -156,7 +156,8 @@ void InstantiationContext::InstantiateType(ETSObjectType *type, ir::TSTypeParame } while (typeArgTypes.size() < type->TypeArguments().size()) { - typeArgTypes.push_back(type->TypeArguments().at(typeArgTypes.size())); + auto *defaultType = type->TypeArguments().at(typeArgTypes.size())->AsETSTypeParameter()->GetDefaultType(); + typeArgTypes.push_back(defaultType); } InstantiateType(type, typeArgTypes, (typeArgs == nullptr) ? lexer::SourcePosition() : typeArgs->Range().start); diff --git a/ets2panda/checker/ets/validateHelpers.cpp b/ets2panda/checker/ets/validateHelpers.cpp index 93a4ed518b3d835c3def7c9822416c9d67f8c039..f78c1f608b75d81bf055ff9aa6e03ed61e847aaa 100644 --- a/ets2panda/checker/ets/validateHelpers.cpp +++ b/ets2panda/checker/ets/validateHelpers.cpp @@ -88,6 +88,11 @@ void ETSChecker::ValidateCallExpressionIdentifier(ir::Identifier *const ident, T if (ident->Parent()->AsCallExpression()->Callee() != ident) { return; } + if (ident->Variable() != nullptr && // It should always be true! + ident->Variable()->Declaration()->Node() != nullptr && + ident->Variable()->Declaration()->Node()->IsImportNamespaceSpecifier()) { + ThrowTypeError({"Namespace style identifier ", ident->Name(), " is not callable."}, ident->Start()); + } if (type->IsETSFunctionType() || type->IsETSDynamicType() || (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { return; diff --git a/ets2panda/checker/types/ets/etsUnionType.cpp b/ets2panda/checker/types/ets/etsUnionType.cpp index d8ef4ce68bb77cbf4b825b95bf4495a48612ee72..3eab8966903123f2b5e2c38fb7291d605be9d676 100644 --- a/ets2panda/checker/types/ets/etsUnionType.cpp +++ b/ets2panda/checker/types/ets/etsUnionType.cpp @@ -486,6 +486,14 @@ bool ETSUnionType::ExtractType(checker::ETSChecker *checker, checker::ETSObjectT constituentTypes_.erase(it); return true; } + // Because 'instanceof' expression does not check for type parameters, then for generic types we should + // consider that expressions like 'SomeType' and 'SomeType' are identical for smart casting. + if (objectType->HasTypeFlag(TypeFlag::GENERIC) && sourceType->HasTypeFlag(TypeFlag::GENERIC) && + checker->Relation()->IsIdenticalTo(objectType->GetOriginalBaseType(), + sourceType->GetOriginalBaseType())) { + constituentTypes_.erase(it); + return true; + } if (auto const id = ETSObjectType::GetPrecedence(objectType); id > 0U) { numericTypes.emplace(id, it); } diff --git a/ets2panda/checker/types/signature.h b/ets2panda/checker/types/signature.h index e0ea0292e5e34d712924af3b65290049b0d46ab3..6f613bbee14a116b30549d8e6bef3438769e9228 100644 --- a/ets2panda/checker/types/signature.h +++ b/ets2panda/checker/types/signature.h @@ -239,6 +239,11 @@ public: ss << compiler::Signatures::MANGLE_SEPARATOR; } + if (signatureInfo_->restVar != nullptr) { + MaybeBoxedType(context->Checker(), signatureInfo_->restVar)->ToAssemblerTypeWithRank(ss); + ss << compiler::Signatures::MANGLE_SEPARATOR; + } + returnType_->ToAssemblerTypeWithRank(ss); ss << compiler::Signatures::MANGLE_SEPARATOR; } diff --git a/ets2panda/checker/types/typeRelation.cpp b/ets2panda/checker/types/typeRelation.cpp index 95b2f59266a6a9e9b6c579477bf89157ae325a95..bba03d35edd8fadcd3ed4a9f81f29d9f0b0a2496 100644 --- a/ets2panda/checker/types/typeRelation.cpp +++ b/ets2panda/checker/types/typeRelation.cpp @@ -51,9 +51,12 @@ RelationResult TypeRelation::CacheLookup(const Type *source, const Type *target, bool TypeRelation::IsIdenticalTo(Type *source, Type *target) { + if (source == nullptr || target == nullptr) { + return Result(false); + } + if (source == target) { - Result(true); - return true; + return Result(true); } result_ = CacheLookup(source, target, checker_->IdenticalResults(), RelationType::IDENTICAL); @@ -65,7 +68,7 @@ bool TypeRelation::IsIdenticalTo(Type *source, Type *target) checker_->IdenticalResults().cached.insert({{source->Id(), target->Id()}, {result_, RelationType::IDENTICAL}}); } - return result_ == RelationResult::TRUE; + return IsTrue(); } bool TypeRelation::IsCompatibleTo(Signature *source, Signature *target) diff --git a/ets2panda/checker/types/typeRelation.h b/ets2panda/checker/types/typeRelation.h index 264512afd4e3f8d7fc847cac11206f843bb6cf96..0e1770639d038e17575b48f90b5cdc3dfa63a5f9 100644 --- a/ets2panda/checker/types/typeRelation.h +++ b/ets2panda/checker/types/typeRelation.h @@ -21,11 +21,6 @@ #include "util/ustring.h" #include "util/enumbitops.h" -#include "macros.h" - -#include -#include - namespace ark::es2panda::ir { class Expression; } // namespace ark::es2panda::ir @@ -275,6 +270,13 @@ public: instantiationRecursionMap_.erase(type); } + // NOTE: special overloading to be used mainly in ETSCompiler where types and nodes are 'const'. + // Unfortunately now we cannot have only a single method with 'const Types *' because it affects + // a lot of non-const references... :((( + bool IsIdenticalTo(Type const *source, Type const *target) + { + return IsIdenticalTo(const_cast(source), const_cast(target)); + } bool IsIdenticalTo(Type *source, Type *target); bool IsIdenticalTo(IndexInfo *source, IndexInfo *target); bool IsCompatibleTo(Signature *source, Signature *target); diff --git a/ets2panda/compiler/base/condition.cpp b/ets2panda/compiler/base/condition.cpp index 618de0ab7e3634b536bfd185db5c370c80201c4a..87a82b2d09c4132c453c033d8b9404453c6e4a20 100644 --- a/ets2panda/compiler/base/condition.cpp +++ b/ets2panda/compiler/base/condition.cpp @@ -260,10 +260,7 @@ bool Condition::CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *binE RegScope rs(etsg); VReg lhs = etsg->AllocReg(); - binExpr->Left()->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(binExpr->Left(), lhs, binExpr->OperationType()); - binExpr->Right()->Compile(etsg); - etsg->ApplyConversion(binExpr->Right(), binExpr->OperationType()); + binExpr->CompileOperands(etsg, lhs); etsg->Condition(binExpr, binExpr->OperatorType(), lhs, falseLabel); return true; } diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp index faa26247ca1db0d7552c5c5e4e68bc018d9aaaf4..5c376a434aabab2b9bc65eff472bb49d0861cd1d 100644 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ b/ets2panda/compiler/core/ASTVerifier.cpp @@ -1005,7 +1005,7 @@ private: if (node == nullptr) { return false; } - return node->IsExported(); + return node->IsExported() || node->IsExportedType(); } bool InvariantImportExportMethod(const std::unordered_set &importedVariables, diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 8b837ef3828cef376407e4077e312b0ee39f1cba..370fcd4fa8c0234fe06cce6e4e2d5fbfc17329bc 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -23,7 +23,6 @@ #include "compiler/function/functionBuilder.h" #include "checker/types/ets/etsDynamicFunctionType.h" #include "parser/ETSparser.h" -#include "programElement.h" namespace ark::es2panda::compiler { @@ -32,7 +31,6 @@ ETSGen *ETSCompiler::GetETSGen() const return static_cast(GetCodeGen()); } -// from as folder void ETSCompiler::Compile([[maybe_unused]] const ir::NamedType *node) const { UNREACHABLE(); @@ -42,7 +40,7 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::PrefixAssertionExpression * { UNREACHABLE(); } -// from base folder + void ETSCompiler::Compile(const ir::CatchClause *st) const { ETSGen *etsg = GetETSGen(); @@ -121,6 +119,7 @@ void ETSCompiler::Compile(const ir::TemplateElement *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadAccumulatorString(expr, expr->Cooked()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::TSIndexSignature *node) const @@ -142,7 +141,7 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::TSSignatureDeclaration *nod { UNREACHABLE(); } -// from ets folder + void ETSCompiler::Compile([[maybe_unused]] const ir::ETSScript *node) const { UNREACHABLE(); @@ -151,26 +150,31 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ETSScript *node) const void ETSCompiler::Compile(const ir::ETSClassLiteral *expr) const { ETSGen *etsg = GetETSGen(); - if (expr->expr_->TsType()->IsETSReferenceType()) { - expr->expr_->Compile(etsg); - etsg->GetType(expr, false); + + auto *literal = expr->Expr(); + auto *literalType = literal->TsType(); + + bool const isPrimitive = !literalType->IsETSReferenceType(); + if (!isPrimitive) { + literal->Compile(etsg); } else { - ASSERT(expr->expr_->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)); - etsg->SetAccumulatorType(expr->expr_->TsType()); - etsg->GetType(expr, true); + ASSERT(literalType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)); + etsg->SetAccumulatorType(literalType); } + + etsg->GetType(expr, isPrimitive); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::ETSFunctionType *node) const { ETSGen *etsg = GetETSGen(); - etsg->LoadAccumulatorNull(node, node->TsType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), node->TsType())); } -void ETSCompiler::Compile(const ir::ETSTuple *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSTuple *node) const { - (void)node; UNREACHABLE(); } @@ -254,6 +258,8 @@ void ETSCompiler::Compile(const ir::ETSNewArrayInstanceExpression *expr) const etsg->SetVRegType(arr, expr->TsType()); etsg->LoadAccumulator(expr, arr); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } static std::pair LoadDynamicName(compiler::ETSGen *etsg, const ir::AstNode *node, @@ -347,7 +353,14 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ETSPackageDeclaration *st) void ETSCompiler::Compile(const ir::ETSParameterExpression *expr) const { ETSGen *etsg = GetETSGen(); - expr->Ident()->Identifier::Compile(etsg); + expr->Ident()->Compile(etsg); + + if (auto *const paramType = expr->TsType(); + !etsg->Checker()->AsETSChecker()->Relation()->IsIdenticalTo(paramType, etsg->GetAccumulatorType())) { + etsg->SetAccumulatorType(paramType); + } + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::ETSPrimitiveType *node) const @@ -364,29 +377,28 @@ void ETSCompiler::Compile(const ir::ETSTypeReference *node) const { ETSGen *etsg = GetETSGen(); node->Part()->Compile(etsg); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), node->TsType())); } void ETSCompiler::Compile(const ir::ETSTypeReferencePart *node) const { ETSGen *etsg = GetETSGen(); node->Name()->Compile(etsg); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), node->TsType())); } -void ETSCompiler::Compile(const ir::ETSNullType *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSNullType *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ETSUndefinedType *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSUndefinedType *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ETSUnionType *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ETSUnionType *node) const { - (void)node; UNREACHABLE(); } @@ -395,7 +407,7 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ETSWildcardType *node) cons ETSGen *etsg = GetETSGen(); etsg->Unimplemented(); } -// compile methods for EXPRESSIONS in alphabetical order + void ETSCompiler::Compile(const ir::ArrayExpression *expr) const { ETSGen *etsg = GetETSGen(); @@ -431,6 +443,7 @@ void ETSCompiler::Compile(const ir::ArrayExpression *expr) const } etsg->LoadAccumulator(expr, arr); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::ArrowFunctionExpression *expr) const @@ -460,15 +473,18 @@ void ETSCompiler::Compile(const ir::AssignmentExpression *expr) const ETSGen *etsg = GetETSGen(); // All other operations are handled in OpAssignmentLowering ASSERT(expr->OperatorType() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto *const exprType = expr->TsType(); + compiler::RegScope rs(etsg); auto lref = compiler::ETSLReference::Create(etsg, expr->Left(), false); - auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + auto ttctx = compiler::TargetTypeContext(etsg, exprType); if (expr->Right()->IsNullLiteral()) { - etsg->LoadAccumulatorNull(expr, expr->Left()->TsType()); + etsg->LoadAccumulatorNull(expr, exprType); } else { expr->Right()->Compile(etsg); - etsg->ApplyConversion(expr->Right(), expr->TsType()); + etsg->ApplyConversion(expr->Right(), exprType); + etsg->SetAccumulatorType(exprType); } if (expr->Right()->TsType()->IsETSBigIntType()) { @@ -478,6 +494,9 @@ void ETSCompiler::Compile(const ir::AssignmentExpression *expr) const etsg->CreateBigIntObject(expr, value, Signatures::BUILTIN_BIGINT_CTOR_BIGINT); } + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), exprType) || + etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), + etsg->Checker()->GlobalBuiltinJSValueType())); lref.SetValue(); } @@ -568,6 +587,8 @@ static void CompileLogical(compiler::ETSGen *etsg, const ir::BinaryExpression *e etsg->SetLabel(expr, endLabel); etsg->SetAccumulatorType(expr->TsType()); etsg->ApplyConversion(expr, expr->OperationType()); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } static void CompileInstanceof(compiler::ETSGen *etsg, const ir::BinaryExpression *expr) @@ -580,7 +601,7 @@ static void CompileInstanceof(compiler::ETSGen *etsg, const ir::BinaryExpression expr->Left()->Compile(etsg); etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); - if (expr->Right()->TsType()->IsETSDynamicType()) { + if (expr->Left()->TsType()->IsETSDynamicType() || expr->Right()->TsType()->IsETSDynamicType()) { auto rhs = etsg->AllocReg(); expr->Right()->Compile(etsg); etsg->StoreAccumulator(expr, rhs); @@ -588,7 +609,7 @@ static void CompileInstanceof(compiler::ETSGen *etsg, const ir::BinaryExpression } else { etsg->IsInstance(expr, lhs, expr->Right()->TsType()); } - ASSERT(etsg->GetAccumulatorType() == expr->TsType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } std::map &GetBigintSignatures() @@ -657,6 +678,7 @@ static bool CompileBigInt(compiler::ETSGen *etsg, const ir::BinaryExpression *ex break; } + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); return true; } @@ -691,15 +713,13 @@ void ETSCompiler::Compile(const ir::BinaryExpression *expr) const return; } - expr->Left()->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); - expr->Right()->Compile(etsg); - etsg->ApplyConversion(expr->Right(), expr->OperationType()); + expr->CompileOperands(etsg, lhs); if (expr->OperationType()->IsIntType()) { etsg->ApplyCast(expr->Right(), expr->OperationType()); } etsg->Binary(expr, expr->OperatorType(), lhs); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::CallExpression *expr, @@ -904,18 +924,18 @@ void ETSCompiler::Compile(const ir::CallExpression *expr) const compiler::RegScope rs(etsg); compiler::VReg calleeReg = etsg->AllocReg(); - const auto isProxy = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::PROXY); - if (isProxy && expr->Callee()->IsMemberExpression()) { + checker::Signature *signature = expr->Signature(); + + if (signature->HasSignatureFlag(checker::SignatureFlags::PROXY) && expr->Callee()->IsMemberExpression()) { if (IsSucceedCompilationProxyMemberExpr(expr)) { return; } } - bool isStatic = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); - bool isReference = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE); + bool isStatic = signature->HasSignatureFlag(checker::SignatureFlags::STATIC); + bool isReference = signature->HasSignatureFlag(checker::SignatureFlags::TYPE); bool isDynamic = expr->Callee()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_DYNAMIC_FLAG); - checker::Signature *signature = expr->Signature(); if (isReference) { signature = ConvertArgumentsForFunctionReference(etsg, expr); } @@ -947,6 +967,11 @@ void ETSCompiler::Compile(const ir::CallExpression *expr) const etsg->StoreAccumulator(expr, calleeReg); EmitCall(expr, calleeReg, isStatic, signature, isReference); } + + if (expr->HasBoxingUnboxingFlags(ir::BoxingUnboxingFlags::UNBOXING_FLAG | ir::BoxingUnboxingFlags::BOXING_FLAG)) { + etsg->ApplyConversion(expr, expr->TsType()); + } + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile([[maybe_unused]] const ir::ChainExpression *expr) const @@ -1010,20 +1035,18 @@ void ETSCompiler::Compile(const ir::Identifier *expr) const ASSERT(expr->Variable() != nullptr); if (!expr->Variable()->HasFlag(varbinder::VariableFlags::TYPE_ALIAS)) { etsg->LoadVar(expr, expr->Variable()); - } else { - etsg->SetAccumulatorType(smartType); } + etsg->SetAccumulatorType(smartType); - // In case when smart cast type of identifier differs from common variable type - // set the accumulator type to the correct actual value and perform cast if required - if (!etsg->Checker()->AsETSChecker()->Relation()->IsIdenticalTo(const_cast(smartType), - expr->Variable()->TsType())) { - etsg->SetAccumulatorType(smartType); - if (smartType->IsETSReferenceType() && //! smartType->DefinitelyNotETSNullish() && - (expr->Parent() == nullptr || !expr->Parent()->IsTSAsExpression())) { + // In case when smart cast type of identifier differs from initial variable type perform cast if required + if (!etsg->Checker()->AsETSChecker()->Relation()->IsIdenticalTo(smartType, expr->Variable()->TsType())) { + if (smartType->IsETSReferenceType() && (expr->Parent() == nullptr || !expr->Parent()->IsTSAsExpression())) { etsg->CastToReftype(expr, smartType, false); + etsg->SetAccumulatorType(smartType); } } + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), smartType)); } void ETSCompiler::Compile([[maybe_unused]] const ir::ImportExpression *expr) const @@ -1044,6 +1067,8 @@ bool ETSCompiler::CompileComputed(compiler::ETSGen *etsg, const ir::MemberExpres compiler::VReg objReg = etsg->AllocReg(); etsg->StoreAccumulator(expr, objReg); + auto pttctx = compiler::TargetTypeContext(etsg, expr->Property()->TsType()); + etsg->CompileAndCheck(expr->Property()); etsg->ApplyConversion(expr->Property(), expr->Property()->TsType()); @@ -1057,6 +1082,8 @@ bool ETSCompiler::CompileComputed(compiler::ETSGen *etsg, const ir::MemberExpres etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->TsType()); etsg->ApplyConversion(expr); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); return true; } @@ -1111,6 +1138,8 @@ void ETSCompiler::Compile(const ir::MemberExpression *expr) const etsg->LoadProperty(expr, expr->TsType(), objReg, fullName); } etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->TsType()); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } bool ETSCompiler::HandleLambdaObject(const ir::MemberExpression *expr, ETSGen *etsg) const @@ -1177,6 +1206,8 @@ bool ETSCompiler::HandleStaticProperties(const ir::MemberExpression *expr, ETSGe util::StringView fullName = etsg->FormClassPropReference(expr->Object()->TsType()->AsETSObjectType(), propName); etsg->LoadStaticProperty(expr, expr->TsType(), fullName); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); return true; } return false; @@ -1231,6 +1262,7 @@ void ETSCompiler::Compile(const ir::ObjectExpression *expr) const } etsg->LoadAccumulator(expr, objReg); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::OmittedExpression *expr) const @@ -1256,6 +1288,7 @@ void ETSCompiler::Compile(const ir::SuperExpression *expr) const ETSGen *etsg = GetETSGen(); etsg->LoadThis(expr); etsg->SetAccumulatorType(etsg->GetAccumulatorType()->AsETSObjectType()->SuperType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::TaggedTemplateExpression *expr) const @@ -1267,12 +1300,14 @@ void ETSCompiler::Compile(const ir::TemplateLiteral *expr) const { ETSGen *etsg = GetETSGen(); etsg->BuildTemplateString(expr); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::ThisExpression *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadThis(expr); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::TypeofExpression *expr) const @@ -1315,17 +1350,17 @@ void ETSCompiler::Compile(const ir::UnaryExpression *expr) const { ETSGen *etsg = GetETSGen(); auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + if (!etsg->TryLoadConstantExpression(expr->Argument())) { expr->Argument()->Compile(etsg); } etsg->ApplyConversion(expr->Argument(), nullptr); - - if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_TILDE) { - etsg->ApplyCast(expr->Argument(), expr->TsType()); - } + etsg->ApplyCast(expr->Argument(), expr->TsType()); etsg->Unary(expr, expr->OperatorType()); + + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::UpdateExpression *expr) const @@ -1381,16 +1416,22 @@ void ETSCompiler::Compile(const ir::UpdateExpression *expr) const expr->Argument()->SetBoxingUnboxingFlags(argumentBoxingFlags); etsg->ApplyConversion(expr->Argument(), expr->Argument()->TsType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->Argument()->TsType())); + lref.SetValue(); etsg->LoadAccumulator(expr->Argument(), originalValueReg); + if (expr->HasBoxingUnboxingFlags(ir::BoxingUnboxingFlags::UNBOXING_FLAG | ir::BoxingUnboxingFlags::BOXING_FLAG)) { + etsg->ApplyConversion(expr, expr->TsType()); + } + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::YieldExpression *expr) const { UNREACHABLE(); } -// compile methods for LITERAL EXPRESSIONS in alphabetical order + void ETSCompiler::Compile([[maybe_unused]] const ir::BigIntLiteral *expr) const { ETSGen *etsg = GetETSGen(); @@ -1400,58 +1441,54 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::BigIntLiteral *expr) const const compiler::VReg value = etsg->AllocReg(); etsg->StoreAccumulator(expr, value); etsg->CreateBigIntObject(expr, value); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::BooleanLiteral *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadAccumulatorBoolean(expr, expr->Value()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::CharLiteral *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadAccumulatorChar(expr, expr->Char()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::NullLiteral *expr) const { ETSGen *etsg = GetETSGen(); etsg->LoadAccumulatorNull(expr, expr->TsType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile(const ir::NumberLiteral *expr) const { ETSGen *etsg = GetETSGen(); auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + if (expr->Number().IsInt()) { if (util::Helpers::IsTargetFitInSourceRange( expr->Number().GetInt())) { etsg->LoadAccumulatorByte(expr, static_cast(expr->Number().GetInt())); - return; - } - - if (util::Helpers::IsTargetFitInSourceRange( - expr->Number().GetInt())) { + } else if (util::Helpers::IsTargetFitInSourceRange( + expr->Number().GetInt())) { etsg->LoadAccumulatorShort(expr, static_cast(expr->Number().GetInt())); - return; + } else { + etsg->LoadAccumulatorInt(expr, static_cast(expr->Number().GetInt())); } - - etsg->LoadAccumulatorInt(expr, static_cast(expr->Number().GetInt())); - return; - } - - if (expr->Number().IsLong()) { + } else if (expr->Number().IsLong()) { etsg->LoadAccumulatorWideInt(expr, expr->Number().GetLong()); - return; - } - - if (expr->Number().IsFloat()) { + } else if (expr->Number().IsFloat()) { etsg->LoadAccumulatorFloat(expr, expr->Number().GetFloat()); - return; + } else { + etsg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); } - etsg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::RegExpLiteral *expr) const @@ -1466,13 +1503,11 @@ void ETSCompiler::Compile(const ir::StringLiteral *expr) const etsg->SetAccumulatorType(expr->TsType()); } -void ETSCompiler::Compile(const ir::UndefinedLiteral *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::UndefinedLiteral *expr) const { - (void)expr; UNREACHABLE(); } -// compile methods for MODULE-related nodes in alphabetical order void ETSCompiler::Compile([[maybe_unused]] const ir::ExportAllDeclaration *st) const { UNREACHABLE(); @@ -1531,7 +1566,7 @@ static void ThrowError(compiler::ETSGen *const etsg, const ir::AssertStatement * etsg->CallThisStatic1(st, assertionError, compiler::Signatures::BUILTIN_ASSERTION_ERROR_CTOR, message); etsg->EmitThrow(st, assertionError); } -// compile methods for STATEMENTS in alphabetical order + void ETSCompiler::Compile(const ir::AssertStatement *st) const { ETSGen *etsg = GetETSGen(); @@ -1973,7 +2008,7 @@ void ETSCompiler::Compile(const ir::WhileStatement *st) const ETSGen *etsg = GetETSGen(); CompileImpl(st, etsg); } -// from ts folder + void ETSCompiler::Compile([[maybe_unused]] const ir::TSAnyKeyword *node) const { UNREACHABLE(); @@ -1982,7 +2017,6 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::TSAnyKeyword *node) const void ETSCompiler::Compile(const ir::TSArrayType *node) const { ETSGen *etsg = GetETSGen(); - etsg->LoadAccumulatorNull(node, node->TsType()); } @@ -2130,6 +2164,7 @@ void ETSCompiler::Compile(const ir::TSAsExpression *expr) const } CompileCast(expr); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), targetType)); } void ETSCompiler::Compile([[maybe_unused]] const ir::TSBigintKeyword *node) const @@ -2251,27 +2286,27 @@ void ETSCompiler::Compile(const ir::TSNonNullExpression *expr) const expr->Expr()->Compile(etsg); - if (etsg->GetAccumulatorType()->DefinitelyNotETSNullish()) { - return; - } + if (!etsg->GetAccumulatorType()->DefinitelyNotETSNullish()) { + if (etsg->GetAccumulatorType()->DefinitelyETSNullish()) { + etsg->EmitNullishException(expr); + return; + } - if (etsg->GetAccumulatorType()->DefinitelyETSNullish()) { - etsg->EmitNullishException(expr); - return; - } + auto arg = etsg->AllocReg(); + etsg->StoreAccumulator(expr, arg); + etsg->LoadAccumulator(expr, arg); - auto arg = etsg->AllocReg(); - etsg->StoreAccumulator(expr, arg); - etsg->LoadAccumulator(expr, arg); + auto endLabel = etsg->AllocLabel(); - auto endLabel = etsg->AllocLabel(); + etsg->BranchIfNotNullish(expr, endLabel); + etsg->EmitNullishException(expr); - etsg->BranchIfNotNullish(expr, endLabel); - etsg->EmitNullishException(expr); + etsg->SetLabel(expr, endLabel); + etsg->LoadAccumulator(expr, arg); + etsg->AssumeNonNullish(expr, expr->OriginalType()); + } - etsg->SetLabel(expr, endLabel); - etsg->LoadAccumulator(expr, arg); - etsg->AssumeNonNullish(expr, expr->OriginalType()); + ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->OriginalType())); } void ETSCompiler::Compile([[maybe_unused]] const ir::TSNullKeyword *node) const diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index fbdfd5f110410470a9dfe675f6b5e6a87f65850f..c72da309cea0dce361edfa003220e8d1d4035e7b 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -545,7 +545,7 @@ void ETSGen::StorePropertyDynamic(const ir::AstNode *node, const checker::Type * // Set property by name Ra().Emit(node, methodName, objReg, propNameReg, propValueReg, dummyReg_); - SetAccumulatorType(nullptr); + SetAccumulatorType(Checker()->GlobalBuiltinJSValueType()); } void ETSGen::LoadPropertyDynamic(const ir::AstNode *node, const checker::Type *propType, VReg objReg, @@ -773,11 +773,75 @@ static bool IsAnyReferenceSupertype(checker::Type const *type) }); } -void ETSGen::IsInstanceDynamic(const ir::AstNode *const node, const VReg srcReg, [[maybe_unused]] const VReg tgtReg) +void ETSGen::IsInstanceDynamic(const ir::BinaryExpression *const node, const VReg srcReg, + [[maybe_unused]] const VReg tgtReg) { - ASSERT(Checker()->GetApparentType(GetVRegType(tgtReg))->IsETSDynamicType() && - GetVRegType(srcReg)->IsETSDynamicType()); - Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF, srcReg, MoveAccToReg(node)); + ASSERT(node->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF); + const checker::Type *lhsType = node->Left()->TsType(); + const checker::Type *rhsType = node->Right()->TsType(); + ASSERT(rhsType->IsETSDynamicType() || lhsType->IsETSDynamicType()); + + const RegScope rs(this); + if (rhsType->IsETSDynamicType()) { + ASSERT(node->Right()->TsType()->AsETSDynamicType()->HasDecl()); + if (lhsType->IsETSDynamicType()) { + VReg dynTypeReg = MoveAccToReg(node); + // Semantics: + // let dyn_val: JSValue = ... + // dyn_value instanceof DynamicDecl + // Bytecode: + // call runtime intrinsic_dynamic + CallStatic2(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF_DYNAMIC, srcReg, dynTypeReg); + } else if (lhsType == Checker()->GlobalETSObjectType()) { + // Semantics: + // let obj: Object = ... + // obj instanceof DynamicDecl + // Bytecode: + // if isinstance : + // checkcast + // return call runtime intrinsic_dynamic + // return false + Label *ifFalse = AllocLabel(); + Language lang = rhsType->AsETSDynamicType()->Language(); + VReg dynTypeReg = MoveAccToReg(node); + LoadAccumulator(node, srcReg); + Sa().Emit(node, Checker()->GlobalBuiltinDynamicType(lang)->AssemblerName()); + BranchIfFalse(node, ifFalse); + LoadAccumulator(node, srcReg); + Sa().Emit(node, Checker()->GlobalBuiltinDynamicType(lang)->AssemblerName()); + CallStatic2(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF_DYNAMIC, srcReg, dynTypeReg); + SetLabel(node, ifFalse); + } else { + // Semantics: + // let obj: EtsType = ... + // obj instanceof DynamicDecl + // Bytecode: + // False + Sa().Emit(node, 0); + } + } else { + if (lhsType->IsETSDynamicType()) { + if (rhsType == Checker()->GlobalETSObjectType()) { + // Semantics: + // let dyn_val: JSValue = ... + // dyn_val instanceof Object + // Bytecode: + // True + Sa().Emit(node, 1); + } else { + // Semantics: + // let dyn_val: JSValue = ... + // dyn_val instanceof EtsType + // Bytecode: + // lda.type + call runtime instrinsic_static + Sa().Emit(node, rhsType->AsETSObjectType()->AssemblerName()); + VReg typeReg = MoveAccToReg(node); + CallStatic2(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF_STATIC, srcReg, typeReg); + } + } else { + UNREACHABLE(); + } + } SetAccumulatorType(Checker()->GlobalETSBooleanType()); } @@ -978,9 +1042,8 @@ void ETSGen::GuardUncheckedType(const ir::AstNode *node, const checker::Type *un if (unchecked != nullptr) { SetAccumulatorType(unchecked); CheckedReferenceNarrowing(node, Checker()->MaybePromotedBuiltinType(target)); - } else { - SetAccumulatorType(target); } + SetAccumulatorType(target); } void ETSGen::EmitFailedTypeCastException(const ir::AstNode *node, const VReg src, checker::Type const *target) @@ -1218,6 +1281,9 @@ void ETSGen::EmitUnboxedCall(const ir::AstNode *node, std::string_view signature Ra().Emit(node, signatureFlag, dummyReg_, 0); SetAccumulatorType(targetType); + if (node->IsExpression()) { + const_cast(node->AsExpression())->SetTsType(const_cast(targetType)); + } } void ETSGen::EmitUnboxingConversion(const ir::AstNode *node) @@ -1281,51 +1347,57 @@ void ETSGen::EmitBoxingConversion(const ir::AstNode *node) RegScope rs(this); ApplyCastToBoxingFlags(node, boxingFlag); + checker::Type *boxedType; switch (boxingFlag) { case ir::BoxingUnboxingFlags::BOX_TO_BOOLEAN: { Ra().Emit(node, Signatures::BUILTIN_BOOLEAN_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalETSBooleanBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalETSBooleanBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_BYTE: { Ra().Emit(node, Signatures::BUILTIN_BYTE_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalByteBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalByteBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_CHAR: { Ra().Emit(node, Signatures::BUILTIN_CHAR_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalCharBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalCharBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_SHORT: { Ra().Emit(node, Signatures::BUILTIN_SHORT_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalShortBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalShortBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_INT: { Ra().Emit(node, Signatures::BUILTIN_INT_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalIntegerBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalIntegerBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_LONG: { Ra().Emit(node, Signatures::BUILTIN_LONG_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalLongBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalLongBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_FLOAT: { Ra().Emit(node, Signatures::BUILTIN_FLOAT_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalFloatBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalFloatBuiltinType(); break; } case ir::BoxingUnboxingFlags::BOX_TO_DOUBLE: { Ra().Emit(node, Signatures::BUILTIN_DOUBLE_VALUE_OF, dummyReg_, 0); - SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalDoubleBuiltinType()); + boxedType = Checker()->GetGlobalTypesHolder()->GlobalDoubleBuiltinType(); break; } default: UNREACHABLE(); } + + SetAccumulatorType(boxedType); + if (node->IsExpression()) { + const_cast(node->AsExpression())->SetTsType(boxedType); + } } void ETSGen::SwapBinaryOpArgs(const ir::AstNode *const node, const VReg lhs) @@ -1448,6 +1520,7 @@ void ETSGen::EmitLocalBoxSet(ir::AstNode const *node, varbinder::LocalVariable * Ra().Emit(node, Signatures::BUILTIN_BOX_SET, vreg, 1); break; } + SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalVoidType()); } @@ -1496,6 +1569,7 @@ void ETSGen::EmitPropertyBoxSet(const ir::AstNode *const node, const checker::Ty Ra().Emit(node, Signatures::BUILTIN_BOX_SET, field, 1); break; } + SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalVoidType()); } diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 42267cbd547d7c171eb5ca67754fed74adae1a3d..1f76640253074841522061a24a0182f5ff723217 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -93,7 +93,7 @@ public: void BranchIfIsInstance(const ir::AstNode *node, VReg srcReg, const checker::Type *target, Label *ifTrue); void IsInstance(const ir::AstNode *node, VReg srcReg, checker::Type const *target); - void IsInstanceDynamic(const ir::AstNode *node, VReg srcReg, VReg tgtReg); + void IsInstanceDynamic(const ir::BinaryExpression *node, VReg srcReg, VReg tgtReg); void EmitFailedTypeCastException(const ir::AstNode *node, VReg src, checker::Type const *target); void Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs); @@ -339,7 +339,7 @@ public: { Sa().Emit(node, value ? 1 : 0); SetAccumulatorType(Checker()->GlobalETSBooleanType()); - ApplyConversion(node, nullptr); + ApplyConversion(node, Checker()->GlobalETSBooleanType()); } void LoadAccumulatorString(const ir::AstNode *node, util::StringView str) @@ -374,7 +374,7 @@ public: { Sa().Emit(node, value); SetAccumulatorType(Checker()->GlobalCharType()); - ApplyConversion(node); + ApplyConversion(node, Checker()->GlobalCharType()); } void LoadAccumulatorDynamicModule(const ir::AstNode *node, const ir::ETSImportDeclaration *import); @@ -564,6 +564,16 @@ public: Ra().Emit(node, name, dummyReg_, dummyReg_); } + void CallStatic1(const ir::AstNode *const node, const util::StringView name, const VReg arg0) + { + Ra().Emit(node, name, arg0, dummyReg_); + } + + void CallStatic2(const ir::AstNode *const node, const util::StringView name, const VReg arg0, const VReg arg1) + { + Ra().Emit(node, name, arg0, arg1); + } + void CallThisStatic0(const ir::AstNode *const node, const VReg ctor, const util::StringView name) { Ra().Emit(node, name, ctor, dummyReg_); @@ -1041,6 +1051,7 @@ private: void CallImpl(const ir::AstNode *node, checker::Signature const *signature, const ArenaVector &arguments) { + ASSERT(signature != nullptr); RegScope rs(this); if (ResolveStringFromNullishBuiltin(node, signature, arguments)) { return; diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index a35a088569468e695d8e25e5b4c804df52df496b..dd4c1fae8b0d52e997dd3c1e60d08b1590757dcc 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -111,7 +111,6 @@ static pandasm::Function GenScriptFunction(CompilerContext const *context, const auto *paramScope = funcScope->ParamScope(); auto func = pandasm::Function(funcScope->InternalName().Mutf8(), EXTENSION); - func.params.reserve(paramScope->Params().size()); for (const auto *var : paramScope->Params()) { @@ -125,10 +124,15 @@ static pandasm::Function GenScriptFunction(CompilerContext const *context, const func.returnType = PandasmTypeWithRank(scriptFunc->Signature()->ReturnType()); } + uint32_t accessFlags = 0; if (!scriptFunc->IsStaticBlock()) { const auto *methodDef = util::Helpers::GetContainingClassMethodDefinition(scriptFunc); - func.metadata->SetAccessFlags(TranslateModifierFlags(methodDef->Modifiers())); + accessFlags |= TranslateModifierFlags(methodDef->Modifiers()); } + if (scriptFunc->HasRestParameter()) { + accessFlags |= ACC_VARARGS; + } + func.metadata->SetAccessFlags(accessFlags); return func; } @@ -136,6 +140,11 @@ static pandasm::Function GenScriptFunction(CompilerContext const *context, const pandasm::Function *ETSFunctionEmitter::GenFunctionSignature() { auto func = GenScriptFunction(Cg()->Context(), Cg()->RootNode()->AsScriptFunction()); + + if (Cg()->RootNode()->AsScriptFunction()->IsExternal()) { + func.metadata->SetAttribute(Signatures::EXTERNAL); + } + auto *funcElement = new pandasm::Function(func.name, func.language); *funcElement = std::move(func); GetProgramElement()->SetFunction(funcElement); diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp index e8a5d5e635c3992b2f28dfc455f78950a07f2925..506adef2d0c1d016e81c9765f58da4cfe3d6072e 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp @@ -34,6 +34,17 @@ namespace ark::es2panda::compiler { using util::NodeAllocator; +static bool MainFunctionExists(const ArenaVector &statements) +{ + for (auto stmt : statements) { + if (stmt->IsFunctionDeclaration() && + stmt->AsFunctionDeclaration()->Function()->Id()->Name().Is(compiler::Signatures::MAIN)) { + return true; + } + } + return false; +} + void GlobalClassHandler::InitGlobalClass(const ArenaVector &programs) { if (programs.empty()) { @@ -55,53 +66,57 @@ void GlobalClassHandler::InitGlobalClass(const ArenaVector &p }; ArenaVector statements(allocator_->Adapter()); + bool mainExists = false; + bool topLevelStatementsExist = false; for (auto program : programs) { program->Ast()->IterateRecursively(addCCtor); + if (program->IsEntryPoint() && !mainExists && MainFunctionExists(program->Ast()->Statements())) { + mainExists = true; + } auto stmts = MakeGlobalStatements(program->Ast(), globalClass, !program->GetPackageName().Empty()); + if (!topLevelStatementsExist && !stmts.empty()) { + topLevelStatementsExist = true; + } 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; + InitCallToCCTOR(programs.front(), statements, mainExists, topLevelStatementsExist); } -ir::MethodDefinition *GlobalClassHandler::CreateInitMethod() +static ir::MethodDefinition *CreateAndFillTopLevelMethod( + const ArenaVector &initStatements, ArenaAllocator *allocator, + const std::string_view name) { const auto functionFlags = ir::ScriptFunctionFlags::NONE; const auto functionModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; - auto *initIdent = NodeAllocator::Alloc(allocator_, INIT_NAME, allocator_); + auto *ident = NodeAllocator::Alloc(allocator, name, allocator); - ArenaVector params(allocator_->Adapter()); + ArenaVector params(allocator->Adapter()); - ArenaVector statements(allocator_->Adapter()); - auto *initBody = NodeAllocator::Alloc(allocator_, allocator_, std::move(statements)); + ArenaVector statements(allocator->Adapter()); + auto *body = NodeAllocator::Alloc(allocator, allocator, std::move(statements)); auto funcSignature = ir::FunctionSignature(nullptr, std::move(params), nullptr); - auto *initFunc = NodeAllocator::Alloc( - allocator_, allocator_, + auto *func = NodeAllocator::Alloc( + allocator, allocator, ir::ScriptFunction::ScriptFunctionData { - initBody, std::move(funcSignature), functionFlags, {}, false, Language(Language::Id::ETS)}); + body, std::move(funcSignature), functionFlags, {}, false, Language(Language::Id::ETS)}); + + func->SetIdent(ident); + func->AddModifier(functionModifiers); - initFunc->SetIdent(initIdent); - initFunc->AddModifier(functionModifiers); + auto *funcExpr = NodeAllocator::Alloc(allocator, func); + auto methodDef = NodeAllocator::Alloc(allocator, ir::MethodDefinitionKind::METHOD, + ident->Clone(allocator, nullptr)->AsExpression(), + funcExpr, functionModifiers, allocator, false); - auto *funcExpr = NodeAllocator::Alloc(allocator_, initFunc); - auto methodDef = NodeAllocator::Alloc(allocator_, ir::MethodDefinitionKind::METHOD, - initIdent->Clone(allocator_, nullptr)->AsExpression(), - funcExpr, functionModifiers, allocator_, false); + for (const auto &stmts : initStatements) { + for (auto stmt : stmts.statements) { + methodDef->Function()->Body()->AsBlockStatement()->Statements().emplace_back(stmt); + stmt->SetParent(methodDef->Function()->Body()); + } + } return methodDef; } @@ -211,7 +226,8 @@ ir::ClassDeclaration *GlobalClassHandler::CreateGlobalClass() return classDecl; } -void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements) +void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements, + bool mainExists, bool topLevelStatementsExist) { auto globalClass = program->GlobalClass(); auto globalDecl = globalClass->Parent()->AsClassDeclaration(); @@ -220,7 +236,12 @@ void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVe InitGlobalClass(globalClass, program->Kind()); auto &globalBody = globalClass->Body(); if (program->GetPackageName().Empty() && program->Kind() != parser::ScriptKind::STDLIB) { - ir::MethodDefinition *initMethod = CreateAndFillInitMethod(initStatements); + ir::MethodDefinition *initMethod = CreateAndFillTopLevelMethod(initStatements, allocator_, INIT_NAME); + ir::MethodDefinition *mainMethod = nullptr; + if (!mainExists && topLevelStatementsExist) { + const ArenaVector emptyStatements(allocator_->Adapter()); + mainMethod = CreateAndFillTopLevelMethod(emptyStatements, allocator_, compiler::Signatures::MAIN); + } if (initMethod != nullptr) { initMethod->SetParent(program->GlobalClass()); globalBody.insert(globalBody.begin(), initMethod); @@ -228,7 +249,11 @@ void GlobalClassHandler::InitCallToCCTOR(parser::Program *program, const ArenaVe AddInitCall(program->GlobalClass(), initMethod); } } + if (mainMethod != nullptr) { + mainMethod->SetParent(program->GlobalClass()); + globalBody.insert(globalBody.begin(), mainMethod); + } } } -} // namespace ark::es2panda::compiler \ No newline at end of file +} // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h index 8433d0822e4589c6b7f7c201aff6cedbb9df20c0..491838311c6d39133a1b39e6aa29efa735548806 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.h @@ -23,12 +23,11 @@ namespace ark::es2panda::compiler { class GlobalClassHandler { +public: struct GlobalStmts { parser::Program *program; ArenaVector statements; }; - -public: explicit GlobalClassHandler(ArenaAllocator *allocator) : allocator_(allocator) {}; /** @@ -44,7 +43,8 @@ private: * @param program program of module * @param init_statements statements which should be executed */ - void InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements); + void InitCallToCCTOR(parser::Program *program, const ArenaVector &initStatements, + bool mainExists = false, bool topLevelStatementsExist = false); private: void InitGlobalClass(ir::ClassDefinition *classDef, parser::ScriptKind scriptKind); @@ -62,8 +62,6 @@ private: 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); diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp index 6f463c7f7111da49441e342a5f1e46b65c96ab33..1e9029342d47ea72a812c0f3c21d40f56d6255c4 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp @@ -94,6 +94,7 @@ ir::ExpressionStatement *GlobalDeclTransformer::InitTopLevelProperty(ir::ClassPr allocator_, ident, initializer->Clone(allocator_, nullptr)->AsExpression(), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); assignmentExpression->SetRange({ident->Start(), initializer->End()}); + assignmentExpression->SetTsType(initializer->TsType()); auto expressionStatement = util::NodeAllocator::Alloc(allocator_, assignmentExpression); @@ -122,4 +123,4 @@ void GlobalDeclTransformer::HandleNode(ir::AstNode *node) } } -} // namespace ark::es2panda::compiler \ No newline at end of file +} // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp index eb13cef95e9b762feeb1d298b2b89379df44a11c..a79f97beb23d9bd1be9275a8a2704b692b7ed762 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp @@ -29,20 +29,25 @@ void ImportExportDecls::ParseDefaultSources() void ImportExportDecls::HandleGlobalStmts(const ArenaVector &programs) { VerifySingleExportDefault(programs); + VerifyTypeExports(programs); for (const auto &program : programs) { auto errorHandler = util::ErrorHandler(program); fieldMap_.clear(); exportNameMap_.clear(); + exportedTypes_.clear(); for (auto stmt : program->Ast()->Statements()) { stmt->Accept(this); } for (auto &[exportName, startLoc] : exportNameMap_) { - if (fieldMap_.count(exportName) == 0) { + const bool isType = exportedTypes_.find(exportName) != exportedTypes_.end(); + if ((fieldMap_.count(exportName) == 0 && !isType)) { auto errorStr = "Cannot find name '" + std::string(exportName.Utf8()) + "' to export."; errorHandler.ThrowSyntaxError(errorStr, startLoc); } - auto field = fieldMap_[exportName]; - field->AddModifier(ir::ModifierFlags::EXPORT); + if (!isType) { + auto field = fieldMap_[exportName]; + field->AddModifier(ir::ModifierFlags::EXPORT); + } } } } @@ -65,10 +70,90 @@ void ImportExportDecls::VisitExportNamedDeclaration(ir::ExportNamedDeclaration * { for (auto spec : exportDecl->Specifiers()) { auto local = spec->Local(); + if (exportDecl->IsExportedType()) { + exportedTypes_.insert(local->Name()); + } exportNameMap_.emplace(local->Name(), local->Start()); } } +void HandleSimpleType(std::set &exportedTypes, std::set &exportedStatements, + ir::Statement *stmt, util::StringView name, parser::Program *program, lexer::SourcePosition pos) +{ + if (stmt->IsExported()) { + exportedStatements.insert(name); + } + + if (!stmt->IsExportedType()) { + return; + } + + if (exportedStatements.find(name) != exportedStatements.end()) { + util::ErrorHandler::ThrowSyntaxError( + program, "Name '" + name.Mutf8() + "' cannot be exported and type exported at the same time.", pos); + } + + if (exportedTypes.find(name) != exportedTypes.end()) { + util::ErrorHandler::ThrowSyntaxError(program, "Cannot export the same '" + name.Mutf8() + "' type twice.", pos); + } else { + exportedTypes.insert(name); + } +} + +void ImportExportDecls::VerifyTypeExports(const ArenaVector &programs) +{ + std::set exportedTypes; + std::set exportedStatements; + std::map typesMap; + auto verifyType = [&exportedTypes, &exportedStatements, &typesMap](ir::Statement *stmt, parser::Program *program) { + if (stmt->IsClassDeclaration()) { + typesMap.insert({stmt->AsClassDeclaration()->Definition()->Ident()->Name(), stmt}); + return HandleSimpleType(exportedTypes, exportedStatements, stmt, + stmt->AsClassDeclaration()->Definition()->Ident()->Name(), program, stmt->Start()); + } + + if (stmt->IsTSInterfaceDeclaration()) { + typesMap.insert({stmt->AsTSInterfaceDeclaration()->Id()->Name(), stmt}); + return HandleSimpleType(exportedTypes, exportedStatements, stmt, + stmt->AsTSInterfaceDeclaration()->Id()->Name(), program, stmt->Start()); + } + + if (stmt->IsTSTypeAliasDeclaration()) { + typesMap.insert({stmt->AsTSTypeAliasDeclaration()->Id()->Name(), stmt}); + return HandleSimpleType(exportedTypes, exportedStatements, stmt, + stmt->AsTSTypeAliasDeclaration()->Id()->Name(), program, stmt->Start()); + } + + if (!stmt->IsExportedType()) { + return; + } + + if (!stmt->IsExportNamedDeclaration()) { + util::ErrorHandler::ThrowSyntaxError(program, "Can only type export class or interface!", stmt->Start()); + } + + for (auto spec : stmt->AsExportNamedDeclaration()->Specifiers()) { + util::StringView name = spec->Local()->Name(); + + auto element = typesMap.find(name); + if (element == typesMap.end()) { + util::ErrorHandler::ThrowSyntaxError(program, "Can only type export class or interface!", + spec->Local()->Start()); + } + if (!element->second->IsExportedType()) { + element->second->AddModifier(ir::ModifierFlags::EXPORT_TYPE); + } + HandleSimpleType(exportedTypes, exportedStatements, stmt, name, program, spec->Local()->Start()); + } + }; + + for (const auto &program : programs) { + for (auto stmt : program->Ast()->Statements()) { + verifyType(stmt, program); + } + } +} + void ImportExportDecls::VerifySingleExportDefault(const ArenaVector &programs) { bool metDefaultExport = false; diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h index 950558ea54a749ef0d3fcc0ad0ca375fa3f96851..f92c9a13e9db71f4f98145354715c1f39ddc95ac 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h @@ -56,6 +56,7 @@ public: * @param global_stmts program global statements */ void HandleGlobalStmts(const ArenaVector &programs); + void VerifyTypeExports(const ArenaVector &programs); void VerifySingleExportDefault(const ArenaVector &programs); @@ -68,6 +69,7 @@ private: varbinder::ETSBinder *varbinder_ {nullptr}; std::map fieldMap_; std::map exportNameMap_; + std::set exportedTypes_; parser::ETSParser *parser_ {nullptr}; }; } // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index e0152017b78e7649945d4b27f2e47814602e7ead..79ccb624cfb25696d8a1e60715024c794ee76ffc 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -161,8 +161,11 @@ static ir::TSAsExpression *HandleUnionCastToPrimitive(checker::ETSChecker *check } auto *const unboxableUnionType = sourceType != nullptr ? sourceType : unionType->FindUnboxableType(); auto *const unboxedUnionType = checker->ETSBuiltinTypeAsPrimitiveType(unboxableUnionType); - expr->SetExpr(UnionCastToPrimitive(checker, unboxableUnionType->AsETSObjectType(), unboxedUnionType, expr->Expr())); - return expr; + auto *const node = + UnionCastToPrimitive(checker, unboxableUnionType->AsETSObjectType(), unboxedUnionType, expr->Expr()); + node->SetParent(expr->Parent()); + + return node; } bool UnionLowering::Perform(public_lib::Context *ctx, parser::Program *program) diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index be8ee46864b0d84b8e0de04178de45fa8fd89f95..66028b32b473b58aad874394e1c15442aa9f3994 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -740,6 +740,16 @@ void InitScopesPhaseETS::VisitImportNamespaceSpecifier(ir::ImportNamespaceSpecif Iterate(importSpec); } +void InitScopesPhaseETS::VisitImportSpecifier(ir::ImportSpecifier *importSpec) +{ + if (importSpec->Parent()->AsETSImportDeclaration()->IsPureDynamic()) { + auto [decl, var] = + VarBinder()->NewVarDecl(importSpec->Start(), importSpec->Local()->Name(), importSpec); + var->AddFlag(varbinder::VariableFlags::INITIALIZED); + } + Iterate(importSpec); +} + // Auxiliary method to avoid extra nested levels and too large function size void AddOverload(ir::MethodDefinition *overload, varbinder::Variable *variable) noexcept { diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h index 29bed5afae6724cb1e939a1fa2575566cf55b792..77dc1c45d66e8e099f161a02a56ce2c059ef53d0 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.h @@ -337,7 +337,7 @@ private: void VisitClassStaticBlock(ir::ClassStaticBlock *staticBlock) override; void VisitBlockExpression(ir::BlockExpression *blockExpr) override; void VisitImportNamespaceSpecifier(ir::ImportNamespaceSpecifier *importSpec) override; - void VisitImportSpecifier([[maybe_unused]] ir::ImportSpecifier *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; diff --git a/ets2panda/compiler/scripts/signatures.yaml b/ets2panda/compiler/scripts/signatures.yaml index 20746ed7eb6d60304d1cb092cfe9ec90c74a5a1f..813c238ee0a98a02e21fed786c15877e2cb24680 100644 --- a/ets2panda/compiler/scripts/signatures.yaml +++ b/ets2panda/compiler/scripts/signatures.yaml @@ -1136,10 +1136,18 @@ signatures: ref: BUILTIN_JSRUNTIME_STRICT_EQUAL - callee: BUILTIN_JSRUNTIME - method_name: instanceOf + method_name: instanceOfDynamic params: [BUILTIN_JSVALUE, BUILTIN_JSVALUE] return_type: PRIMITIVE_BOOLEAN - ref: BUILTIN_JSRUNTIME_INSTANCE_OF + ref: BUILTIN_JSRUNTIME_INSTANCE_OF_DYNAMIC + + - callee: BUILTIN_JSRUNTIME + method_name: instanceOfStatic + # NOTE(v.cherkashin): + # Replace BUILTIN_OBJECT by BUILTIN_TYPE when issue #15273 was resolved + params: [BUILTIN_JSVALUE, BUILTIN_OBJECT] # 2nd argument is ClassClass + return_type: PRIMITIVE_BOOLEAN + ref: BUILTIN_JSRUNTIME_INSTANCE_OF_STATIC - callee: BUILTIN_JSVALUE method_name: toString diff --git a/ets2panda/compiler/templates/isa.h.erb b/ets2panda/compiler/templates/isa.h.erb index 588d7702cf7ee1822df5a2b454845891f3d99917..226519bcdf1c192a205337acb750656e5362429a 100644 --- a/ets2panda/compiler/templates/isa.h.erb +++ b/ets2panda/compiler/templates/isa.h.erb @@ -126,9 +126,17 @@ private: class <%= class_name %> : public <%= base_class %> { public: - explicit <%= class_name %>(<%= ctor_args %>) : <%= base_class %>(node)<%= ops %> {} + explicit <%= class_name %>(<%= ctor_args %>) : <%= base_class %>(node)<%= ops %> + { +% insn.operands.each do |operand| +% if operand.id? && operand.name != :string_id + ASSERT(!string_id.Empty()); +% end +% end + } - Formats GetFormats() const override { + Formats GetFormats() const override + { return Span(<%= get_format_name(insn.mnemonic) %>); } diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index d46d1c6fac542de00ccb8b79cdd8bd1b1949574c..bbea99ee9dcd1cb1123ca3e91154f7a16e0f4f7c 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -66,6 +66,8 @@ void TSDeclGen::Generate() license << " */\n\n"; Out(license.str()); Out("declare const exports: any;"); + OutEndl(); + Out("let ETSGLOBAL: any = (globalThis as any).Panda.getClass('LETSGLOBAL;');"); OutEndl(2U); for (auto *globalStatement : program_->Ast()->Statements()) { @@ -556,8 +558,7 @@ void TSDeclGen::GenMethodDeclaration(const ir::MethodDefinition *methodDef) OutEndl(); if (state_.inGlobalClass) { - Out("(", methodName, " as any) = (globalThis as any).Panda.getFunction('", state_.currentClassDescriptor, - "', '", methodName, "');"); + Out("(", methodName, " as any) = ETSGLOBAL.", methodName, ";"); OutEndl(); GenExports(methodName); if (methodName == compiler::Signatures::INIT_METHOD) { @@ -570,6 +571,7 @@ void TSDeclGen::GenMethodDeclaration(const ir::MethodDefinition *methodDef) void TSDeclGen::GenPropDeclaration(const ir::ClassProperty *classProp) { if (state_.inGlobalClass) { + GenGlobalVarDeclaration(classProp); return; } @@ -589,6 +591,28 @@ void TSDeclGen::GenPropDeclaration(const ir::ClassProperty *classProp) OutEndl(); } +void TSDeclGen::GenGlobalVarDeclaration(const ir::ClassProperty *globalVar) +{ + if (!globalVar->IsExported() && !globalVar->IsDefaultExported()) { + return; + } + + const auto varName = GetKeyName(globalVar->Key()); + DebugPrint("GenGlobalVarDeclaration: " + varName); + if (!globalVar->IsConst()) { + Warning("Not constant global variables are not supported, variable \"" + varName + "\" was skipped"); + return; + } + + Out("const ", varName, ": "); + GenType(globalVar->TsType()); + Out(" = ETSGLOBAL.", varName, ';'); + OutEndl(); + + GenExports(varName); + OutEndl(); +} + bool GenerateTsDeclarations(checker::ETSChecker *checker, const ark::es2panda::parser::Program *program, const std::string &outPath) { diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.h b/ets2panda/declgen_ets2ts/declgenEts2Ts.h index 1934c19cab9d04c64eb0d98e7c474581207658d6..984f1cd3165075f86bfde4996a556fe94bc170b0 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.h +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.h @@ -61,6 +61,7 @@ private: void GenClassDeclaration(const ir::ClassDeclaration *classDecl); void GenMethodDeclaration(const ir::MethodDefinition *methodDef); void GenPropDeclaration(const ir::ClassProperty *classProp); + void GenGlobalVarDeclaration(const ir::ClassProperty *globalVar); void GenLiteral(const ir::Literal *literal); template diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index a17cc9d0fd40cbbdff1bdccfa138e1de09b65ff8..64d2983a31160b8fec0721ab189d9424e91a10fc 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -30,6 +30,15 @@ AstNode::AstNode(AstNode const &other) // boxing_unboxing_flags_ {}; leave default value! } +[[nodiscard]] bool ir::AstNode::IsExportedType() const noexcept +{ + if (UNLIKELY(IsClassDefinition())) { + return this->parent_->IsExportedType(); + } + + return (flags_ & ModifierFlags::EXPORT_TYPE) != 0; +} + template static R GetTopStatementImpl(T *self) { @@ -112,6 +121,14 @@ AstNode *AstNode::FindChild(const NodePredicate &cb) const return found; } +varbinder::Scope *AstNode::EnclosingScope(const ir::AstNode *expr) +{ + while (expr != nullptr && !expr->IsScopeBearer()) { + expr = expr->Parent(); + } + return expr != nullptr ? expr->Scope() : nullptr; +} + std::string AstNode::DumpJSON() const { ir::AstDumper dumper {this}; diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 3f6537ca5c49ecb6590f82fd83bb9880280ee1c8..e2a69f5e99e140061baad105434cdcb7e4ea6eaa 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -381,6 +381,8 @@ public: return (flags_ & ModifierFlags::DEFAULT_EXPORT) != 0; } + [[nodiscard]] bool IsExportedType() const noexcept; + [[nodiscard]] bool IsDeclare() const noexcept { return (flags_ & ModifierFlags::DECLARE) != 0; @@ -463,6 +465,8 @@ public: return reinterpret_cast(this); } + static varbinder::Scope *EnclosingScope(const ir::AstNode *expr); + [[nodiscard]] virtual bool IsScopeBearer() const noexcept { return false; diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index 3b1d2f0a236d2a26f86aa5ca01c9b2918f5e44d8..ffd34027a957eabbb6404145013bab429c7373cb 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -52,12 +52,15 @@ enum class ModifierFlags : uint32_t { GETTER = 1U << 21U, SETTER = 1U << 22U, DEFAULT_EXPORT = 1U << 23U, + EXPORT_TYPE = 1U << 24U, + EXTERNAL = 1U << 25U, ACCESS = PUBLIC | PROTECTED | PRIVATE | INTERNAL, ALL = STATIC | ASYNC | ACCESS | DECLARE | READONLY | ABSTRACT, ALLOWED_IN_CTOR_PARAMETER = ACCESS | READONLY, INTERNAL_PROTECTED = INTERNAL | PROTECTED, ACCESSOR_MODIFIERS = ABSTRACT | FINAL, - GETTER_SETTER = GETTER | SETTER + GETTER_SETTER = GETTER | SETTER, + EXPORTED = EXPORT | DEFAULT_EXPORT | EXPORT_TYPE }; enum class PrivateFieldKind { FIELD, METHOD, GET, SET, STATIC_FIELD, STATIC_METHOD, STATIC_GET, STATIC_SET }; diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 2ca76dd1079a763757b6c1526810994145ff26ae..7511ae3a2617dace7ac512f70920441d3d8df77e 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -17,6 +17,7 @@ #define ES2PANDA_PARSER_INCLUDE_AST_SCRIPT_FUNCTION_H #include "ir/statements/returnStatement.h" +#include "checker/types/signature.h" #include "ir/astNode.h" #include "varbinder/scope.h" #include "util/enumbitops.h" @@ -214,6 +215,11 @@ public: return body_ != nullptr; } + [[nodiscard]] bool HasRestParameter() const noexcept + { + return signature_->RestVar() != nullptr; + } + [[nodiscard]] bool IsThrowing() const noexcept { return (funcFlags_ & ir::ScriptFunctionFlags::THROWS) != 0; diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index de3806314117330cd238937eab3df014da0462e8..1307f1a30541065e2e4a622fe6b9717c01f8283b 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -40,9 +40,10 @@ public: [[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; - friend class compiler::ETSCompiler; + [[nodiscard]] ir::TypeNode *Expr() const noexcept + { + return expr_; + } void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsImportDeclaration.h b/ets2panda/ir/ets/etsImportDeclaration.h index b46d39d89398cc4517ee33f5f0a4904938fd0de8..c09cdba2adb58612e55d9ea3638e42e959774fae 100644 --- a/ets2panda/ir/ets/etsImportDeclaration.h +++ b/ets2panda/ir/ets/etsImportDeclaration.h @@ -26,8 +26,9 @@ class StringLiteral; class ETSImportDeclaration : public ImportDeclaration { public: - explicit ETSImportDeclaration(ImportSource *source, const ArenaVector &specifiers) - : ImportDeclaration(source->Source(), specifiers), source_(source) + explicit ETSImportDeclaration(ImportSource *source, const ArenaVector &specifiers, + const ImportKinds importKind = ImportKinds::VALUE) + : ImportDeclaration(source->Source(), specifiers, importKind), source_(source) { SetType(AstNodeType::ETS_IMPORT_DECLARATION); } diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 44c6a4ba6b5316213624bd00b33c9814e802afb1..fbc40255c9c201c341bf4530fc748c7e91909b53 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -99,32 +99,31 @@ checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) { if (prev_ == nullptr) { if (name_->IsIdentifier()) { - if ((name_->AsIdentifier()->Variable() != nullptr) && - (name_->AsIdentifier()->Variable()->Declaration()->IsTypeAliasDecl())) { - return checker->HandleTypeAlias(name_, typeParams_); - } - if (name_->AsIdentifier()->Name() == compiler::Signatures::UNDEFINED) { - return checker->GlobalETSUndefinedType(); - } - - if (name_->AsIdentifier()->Name() == compiler::Signatures::NULL_LITERAL) { - return checker->GlobalETSNullType(); + const auto ident = name_->AsIdentifier(); + if ((ident->Variable() != nullptr) && (ident->Variable()->Declaration()->IsTypeAliasDecl())) { + SetTsType(checker->HandleTypeAlias(name_, typeParams_)); + } else if (ident->Name() == compiler::Signatures::UNDEFINED) { + SetTsType(checker->GlobalETSUndefinedType()); + } else if (ident->Name() == compiler::Signatures::NULL_LITERAL) { + SetTsType(checker->GlobalETSNullType()); } } - - checker::Type *baseType = checker->GetReferencedTypeBase(name_); - - ASSERT(baseType != nullptr); - if (baseType->IsETSObjectType()) { - checker::InstantiationContext ctx(checker, baseType->AsETSObjectType(), typeParams_, Start()); - return ctx.Result(); + if (TsType() == nullptr) { + checker::Type *baseType = checker->GetReferencedTypeBase(name_); + + ASSERT(baseType != nullptr); + if (baseType->IsETSObjectType()) { + checker::InstantiationContext ctx(checker, baseType->AsETSObjectType(), typeParams_, Start()); + SetTsType(ctx.Result()); + } else { + SetTsType(baseType); + } } - - return baseType; + } else { + checker::Type *baseType = prev_->GetType(checker); + SetTsType(checker->GetReferencedTypeFromBase(baseType, name_)); } - - checker::Type *baseType = prev_->GetType(checker); - return checker->GetReferencedTypeFromBase(baseType, name_); + return TsType(); } ETSTypeReferencePart *ETSTypeReferencePart::Clone(ArenaAllocator *const allocator, AstNode *const parent) diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 77d39416dd9051ea2de320db3bc14054924feed8..02ae52b50af1474f949d847b9a6f74226706e246 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -149,12 +149,27 @@ ir::TypeNode *ArrowFunctionExpression::CreateTypeAnnotation(checker::ETSChecker void ArrowFunctionExpression::AddCapturedVar(varbinder::Variable *var) { + if (IsVarFromSubscope(var)) { + return; + } + // Not using an ArenaSet for now, simpler to do it this way. + if (std::find(capturedVars_.begin(), capturedVars_.end(), var) != capturedVars_.end()) { + return; + } capturedVars_.push_back(var); if (parentLambda_ != nullptr) { parentLambda_->AddCapturedVar(var); } } +bool ArrowFunctionExpression::IsVarFromSubscope(const varbinder::Variable *var) const +{ + // The parameter scope's and the function scope's common ancestor lives outside the function, so we have to check + // them separetely. + return Function()->Scope()->IsSuperscopeOf(var->GetScope()) || + Function()->Scope()->ParamScope()->IsSuperscopeOf(var->GetScope()); +} + void ArrowFunctionExpression::AddChildLambda(ArrowFunctionExpression *childLambda) { childLambdas_.push_back(childLambda); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index dac4194054533d754af34b3d0ed858b697f84d37..104cdcf1d2643d0910a9cc657fb7815962b547c3 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -116,6 +116,7 @@ public: ir::TypeNode *CreateTypeAnnotation(checker::ETSChecker *checker); ir::TypeNode *CreateReturnNodeFromType(checker::ETSChecker *checker, checker::Type *returnType); void AddChildLambda(ArrowFunctionExpression *childLambda); + bool IsVarFromSubscope(const varbinder::Variable *var) const; void Accept(ASTVisitorT *v) override { diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 438e05239d35548a966f2e3a35efdcc50b10869e..7f189a7c87877578df78e9cb7714898f703e8c01 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -74,6 +74,20 @@ void BinaryExpression::Compile(compiler::ETSGen *etsg) const etsg->GetAstCompiler()->Compile(this); } +void BinaryExpression::CompileOperands(compiler::ETSGen *etsg, compiler::VReg lhs) const +{ + left_->Compile(etsg); + + if (operator_ == lexer::TokenType::KEYW_INSTANCEOF) { + etsg->StoreAccumulator(left_, lhs); + } else { + etsg->ApplyConversionAndStoreAccumulator(left_, lhs, operationType_); + } + + right_->Compile(etsg); + etsg->ApplyConversion(right_, operationType_); +} + checker::Type *BinaryExpression::Check(checker::TSChecker *checker) { return checker->GetAnalyzer()->Check(this); diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index d0ed782aa0ac6e281b66ada5b553266df08744f4..8865ac101da6588f6812af2cec0a586772048a55 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -17,6 +17,7 @@ #define ES2PANDA_IR_EXPRESSION_BINARY_EXPRESSION_H #include "checker/checkerContext.h" +#include "compiler/core/vReg.h" #include "ir/expression.h" namespace ark::es2panda::checker { @@ -157,6 +158,7 @@ public: void Dump(ir::SrcDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; + void CompileOperands(compiler::ETSGen *etsg, compiler::VReg lhs) const; checker::Type *Check(checker::TSChecker *checker) override; checker::Type *Check(checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index aa25c7a4f7633b879d07a939275e0577632f7940..f2c577a806afd22ced3c9c0d0a8caf1de3eb2e16 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -22,6 +22,7 @@ #include "ir/srcDump.h" namespace ark::es2panda::ir { + void ImportDeclaration::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) { if (auto *transformedNode = cb(source_); source_ != transformedNode) { diff --git a/ets2panda/ir/module/importDeclaration.h b/ets2panda/ir/module/importDeclaration.h index c9096366dc8e72a92948e2d4e1a48e97cf3f0dfe..9a1c5e4fa5c3e54c874b565eeada96c84f3b834f 100644 --- a/ets2panda/ir/module/importDeclaration.h +++ b/ets2panda/ir/module/importDeclaration.h @@ -21,10 +21,13 @@ namespace ark::es2panda::ir { class StringLiteral; +enum class ImportKinds { VALUE, TYPE }; + class ImportDeclaration : public Statement { public: - explicit ImportDeclaration(StringLiteral *source, ArenaVector const &specifiers) - : Statement(AstNodeType::IMPORT_DECLARATION), source_(source), specifiers_(specifiers) + explicit ImportDeclaration(StringLiteral *source, ArenaVector const &specifiers, + const ImportKinds importKind = ImportKinds::VALUE) + : Statement(AstNodeType::IMPORT_DECLARATION), source_(source), specifiers_(specifiers), importKind_(importKind) { } @@ -57,9 +60,15 @@ public: v->Accept(this); } + bool IsTypeKind() const + { + return importKind_ == ImportKinds::TYPE; + } + private: StringLiteral *source_; ArenaVector specifiers_; + ImportKinds importKind_; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/parser/ETSFormattedParser.cpp b/ets2panda/parser/ETSFormattedParser.cpp index e593df2fea32e7a430ada74bdc0c3101ca1b1802..5de9e175076713c03577a038d3d5dc17f074d77f 100644 --- a/ets2panda/parser/ETSFormattedParser.cpp +++ b/ets2panda/parser/ETSFormattedParser.cpp @@ -34,7 +34,6 @@ namespace ark::es2panda::parser { inline constexpr char const FORMAT_SIGNATURE = '@'; inline constexpr char const TYPE_FORMAT_NODE = 'T'; inline constexpr char const GENERAL_FORMAT_NODE = 'N'; -inline constexpr char const EXPRESSION_FORMAT_NODE = 'E'; inline constexpr char const IDENTIFIER_FORMAT_NODE = 'I'; static constexpr char const INVALID_NUMBER_NODE[] = "Invalid node number in format expression."; @@ -173,6 +172,28 @@ ir::Statement *ETSParser::ParseStatementFormatPlaceholder() const return insertingNode->AsStatement(); } +ir::AstNode *ETSParser::ParseTypeParametersFormatPlaceholder() const +{ + ParserImpl::NodeFormatType nodeFormat = GetFormatPlaceholderType(); + if (std::get<0>(nodeFormat) || std::get<1>(nodeFormat) != EXPRESSION_FORMAT_NODE) { + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + + auto const placeholderNumber = std::get<2>(nodeFormat); + if (placeholderNumber >= insertingNodes_.size()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + auto *const insertingNode = insertingNodes_[placeholderNumber]; + if (insertingNode != nullptr && !insertingNode->IsTSTypeParameterDeclaration() && + !insertingNode->IsTSTypeParameterInstantiation()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + Lexer()->NextToken(); + return insertingNode; +} + ArenaVector &ETSParser::ParseAstNodesArrayFormatPlaceholder() const { if (insertingNodes_.empty()) { diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 773822beff78d20a16f4d83923a69f8ba287c9de..4ee4c681c655011dab9135e73a3d4f45f786fbaf 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -295,7 +295,7 @@ ArenaVector ETSParser::ParseTopLevelStatements() ir::Statement *ETSParser::ParseTopLevelDeclStatement(StatementParsingFlags flags) { auto [memberModifiers, startLoc] = ParseMemberModifiers(); - if ((memberModifiers & (ir::ModifierFlags::EXPORT | ir::ModifierFlags::DEFAULT_EXPORT)) != 0U && + if ((memberModifiers & (ir::ModifierFlags::EXPORTED)) != 0U && (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY || Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE)) { return ParseExport(startLoc, memberModifiers); @@ -332,10 +332,14 @@ ir::Statement *ETSParser::ParseTopLevelDeclStatement(StatementParsingFlags flags break; } default: { - break; } } if (result != nullptr) { + if ((memberModifiers & ir::ModifierFlags::EXPORT_TYPE) != 0U && + !(result->IsClassDeclaration() || result->IsTSInterfaceDeclaration() || + result->IsTSTypeAliasDeclaration())) { + ThrowSyntaxError("Can only type export class or interface!"); + } result->AddModifier(memberModifiers); } return result; @@ -2333,7 +2337,7 @@ ir::Statement *ETSParser::ParseExport(lexer::SourcePosition startLoc, ir::Modifi ir::ImportSource *reExportSource = ParseSourceFromClause(true); lexer::SourcePosition endLoc = reExportSource->Source()->End(); - auto *reExportDeclaration = AllocNode(reExportSource, specifiers); + auto *reExportDeclaration = AllocNode(reExportSource, std::move(specifiers)); reExportDeclaration->SetRange({startLoc, endLoc}); ConsumeSemicolon(reExportDeclaration); @@ -2429,9 +2433,15 @@ ArenaVector ETSParser::ParseImportDeclarations() auto startLoc = Lexer()->GetToken().Start(); Lexer()->NextToken(); // eat import + ir::ImportKinds importKind = + Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_TYPE) ? ir::ImportKinds::TYPE : ir::ImportKinds::VALUE; + ArenaVector specifiers(Allocator()->Adapter()); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { + if (importKind == ir::ImportKinds::TYPE) { + ThrowSyntaxError("Type import requires selective binding to define the required imported elements."); + } ParseNameSpaceSpecifier(&specifiers); } else if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { auto specs = ParseNamedSpecifiers(); @@ -2443,7 +2453,7 @@ ArenaVector ETSParser::ParseImportDeclarations() ir::ImportSource *importSource = ParseSourceFromClause(true); lexer::SourcePosition endLoc = importSource->Source()->End(); - auto *importDeclaration = AllocNode(importSource, std::move(specifiers)); + auto *importDeclaration = AllocNode(importSource, std::move(specifiers), importKind); importDeclaration->SetRange({startLoc, endLoc}); ConsumeSemicolon(importDeclaration); @@ -4072,6 +4082,7 @@ void ETSParser::CheckDeclare() case lexer::TokenType::KEYW_ENUM: case lexer::TokenType::KEYW_TYPE: case lexer::TokenType::KEYW_ABSTRACT: + case lexer::TokenType::KEYW_FINAL: case lexer::TokenType::KEYW_INTERFACE: { return; } @@ -4136,8 +4147,14 @@ std::pair ETSParser::ParseMemberModifi auto memberModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; if (Lexer()->TryEatTokenType(lexer::TokenType::KEYW_EXPORT)) { + const auto savedPos = Lexer()->Save(); if (Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_DEFAULT)) { memberModifiers |= ir::ModifierFlags::DEFAULT_EXPORT; + } else if (Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_TYPE)) { + if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { + Lexer()->Rewind(savedPos); + } + memberModifiers |= ir::ModifierFlags::EXPORT_TYPE; } else { memberModifiers |= ir::ModifierFlags::EXPORT; } diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 756aff605f240399caf83fb79ea42c8da1a540a3..f08fdfa4d5c513ecc645d59086ddc4a920c299ac 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -193,6 +193,7 @@ private: ir::Expression *ParseExpressionFormatPlaceholder(); ir::Identifier *ParseIdentifierFormatPlaceholder(std::optional nodeFormat) const override; ir::TypeNode *ParseTypeFormatPlaceholder(std::optional nodeFormat = std::nullopt); + ir::AstNode *ParseTypeParametersFormatPlaceholder() const override; ArenaVector &ParseAstNodesArrayFormatPlaceholder() const override; ArenaVector &ParseStatementsArrayFormatPlaceholder() const override; diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index 037b2da82734721ff6b25894622a5ead734c5a74..bfabd1423f46b776b69b850c664a1936e1c570c7 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -547,6 +547,9 @@ ArenaVector TypedParser::ParseTypeLiteralOrInterfaceBody() if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COMMA && Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SEMI_COLON) { + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { + ThrowSyntaxError("Interface member initialization is prohibited"); + } if (!Lexer()->GetToken().NewLine()) { ThrowSyntaxError("',' expected"); } @@ -704,15 +707,12 @@ ir::TSTypeParameter *TypedParser::ParseTypeParameter(TypeAnnotationParsingOption return typeParam; } -ir::TSTypeParameterDeclaration *TypedParser::ParseTypeParameterDeclaration(TypeAnnotationParsingOptions *options) +// Auxiliary method to reduce the size of functions. +ir::AstNode *TypedParser::ParseTypeParameterDeclarationImpl(TypeAnnotationParsingOptions *options) { - ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); - - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); ArenaVector params(Allocator()->Adapter()); bool seenDefault = false; - size_t requiredParams = 0; - Lexer()->NextToken(); // eat '<' + size_t requiredParams = 0U; while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { auto newOptions = *options | TypeAnnotationParsingOptions::ADD_TYPE_PARAMETER_BINDING; @@ -733,31 +733,52 @@ ir::TSTypeParameterDeclaration *TypedParser::ParseTypeParameterDeclaration(TypeA params.push_back(currentParam); - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { - Lexer()->NextToken(); - continue; + if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COMMA) { + break; } - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { - if ((newOptions & TypeAnnotationParsingOptions::THROW_ERROR) == 0) { - return nullptr; - } - - ThrowSyntaxError("'>' expected"); - } + Lexer()->NextToken(); } if (params.empty()) { ThrowSyntaxError("Type parameter list cannot be empty."); } + return AllocNode(std::move(params), requiredParams); +} + +ir::TSTypeParameterDeclaration *TypedParser::ParseTypeParameterDeclaration(TypeAnnotationParsingOptions *options) +{ + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); + + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + Lexer()->NextToken(); // eat '<' + + ir::AstNode *typeParamDecl; + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT && + Lexer()->Lookahead() == static_cast(EXPRESSION_FORMAT_NODE)) { + typeParamDecl = ParseTypeParametersFormatPlaceholder(); + } else { + typeParamDecl = ParseTypeParameterDeclarationImpl(options); + } + + if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { + if ((*options & TypeAnnotationParsingOptions::THROW_ERROR) == 0) { + return nullptr; + } + ThrowSyntaxError("Expected closing '>'."); + } + lexer::SourcePosition endLoc = Lexer()->GetToken().End(); Lexer()->NextToken(); // eat '>' - auto *typeParamDecl = AllocNode(std::move(params), requiredParams); - typeParamDecl->SetRange({startLoc, endLoc}); + if (typeParamDecl != nullptr) { + typeParamDecl->SetRange({startLoc, endLoc}); + return typeParamDecl->AsTSTypeParameterDeclaration(); + } - return typeParamDecl; + return nullptr; } ir::Expression *TypedParser::ParseSuperClassReference() @@ -1207,19 +1228,14 @@ ir::Expression *TypedParser::ParseQualifiedReference(ir::Expression *typeName, E return typeName; } -ir::TSTypeParameterInstantiation *TypedParser::ParseTypeParameterInstantiation(TypeAnnotationParsingOptions *options) +// Auxiliary method to reduce the size of functions. +ir::AstNode *TypedParser::ParseTypeParameterInstantiationImpl(TypeAnnotationParsingOptions *options) { - ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); - bool throwError = ((*options) & TypeAnnotationParsingOptions::THROW_ERROR) != 0; - lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); ArenaVector params(Allocator()->Adapter()); - Lexer()->NextToken(); // eat '<' while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { - TypeAnnotationParsingOptions tmp = *options; - *options &= ~TypeAnnotationParsingOptions::IGNORE_FUNCTION_TYPE; - ir::TypeNode *currentParam = ParseTypeAnnotation(options); - *options = tmp; + TypeAnnotationParsingOptions tmpOptions = *options &= ~TypeAnnotationParsingOptions::IGNORE_FUNCTION_TYPE; + ir::TypeNode *currentParam = ParseTypeAnnotation(&tmpOptions); if (currentParam == nullptr) { return nullptr; @@ -1244,23 +1260,45 @@ ir::TSTypeParameterInstantiation *TypedParser::ParseTypeParameterInstantiation(T break; } default: { - if (throwError) { - ThrowSyntaxError("'>' expected"); - } - return nullptr; } } } - lexer::SourcePosition endLoc = Lexer()->GetToken().End(); - Lexer()->NextToken(); + return AllocNode(std::move(params)); +} + +ir::TSTypeParameterInstantiation *TypedParser::ParseTypeParameterInstantiation(TypeAnnotationParsingOptions *options) +{ + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); + + lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); + Lexer()->NextToken(); // eat '<' + + ir::AstNode *typeParamInst; + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT && + Lexer()->Lookahead() == static_cast(EXPRESSION_FORMAT_NODE)) { + typeParamInst = ParseTypeParametersFormatPlaceholder(); + } else { + typeParamInst = ParseTypeParameterInstantiationImpl(options); + } + + if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_GREATER_THAN) { + if ((*options & TypeAnnotationParsingOptions::THROW_ERROR) == 0) { + return nullptr; + } + ThrowSyntaxError("Expected closing '>'."); + } - auto *typeParamInst = AllocNode(std::move(params)); + lexer::SourcePosition endLoc = Lexer()->GetToken().End(); + Lexer()->NextToken(); // eat '>' - typeParamInst->SetRange({startLoc, endLoc}); + if (typeParamInst != nullptr) { + typeParamInst->SetRange({startLoc, endLoc}); + return typeParamInst->AsTSTypeParameterInstantiation(); + } - return typeParamInst; + return nullptr; } ir::Statement *TypedParser::ParseDeclareAndDecorators(StatementParsingFlags flags) diff --git a/ets2panda/parser/TypedParser.h b/ets2panda/parser/TypedParser.h index 69d59dbc2d439fd0b184ce43479a383c4e34586b..4ad1a1ccc41090a6f3ef02eefdf5e46df388b225 100644 --- a/ets2panda/parser/TypedParser.h +++ b/ets2panda/parser/TypedParser.h @@ -42,9 +42,13 @@ protected: ir::ArrowFunctionExpression *ParseGenericArrowFunction(); ir::TSTypeAssertion *ParseTypeAssertion(); + ir::TSTypeParameterInstantiation *ParseTypeParameterInstantiation(TypeAnnotationParsingOptions *options); + ir::AstNode *ParseTypeParameterInstantiationImpl(TypeAnnotationParsingOptions *options); ir::TSTypeParameterDeclaration *ParseTypeParameterDeclaration(TypeAnnotationParsingOptions *options); + ir::AstNode *ParseTypeParameterDeclarationImpl(TypeAnnotationParsingOptions *options); + ir::Expression *ParseQualifiedName(ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS); ir::Expression *ParseQualifiedReference(ir::Expression *typeName, ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS); diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index c9dcc97c70207204171a054b56dd4ef4f4549796..2fef7d65752f8415a4fa1545f2295f65c2ee3aaf 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -1092,12 +1092,17 @@ void ParserImpl::ThrowParameterModifierError(ir::ModifierFlags status) const ir::Identifier *ParserImpl::ParseIdentifierFormatPlaceholder( [[maybe_unused]] std::optional nodeFormat) const { - ThrowSyntaxError("Identifier expected"); + ThrowSyntaxError("Identifier expected."); } ir::Statement *ParserImpl::ParseStatementFormatPlaceholder() const { - ThrowSyntaxError("Statement expected"); + ThrowSyntaxError("Statement expected."); +} + +ir::AstNode *ParserImpl::ParseTypeParametersFormatPlaceholder() const +{ + ThrowSyntaxError("Type parameter(s) expected."); } ArenaVector &ParserImpl::ParseStatementsArrayFormatPlaceholder() const diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index d63f7ebcefdb9fcd1b325929837aac1abf812b86..9f24cbb4d42fbc1319d4b415ac4dcaec31a9fe48 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -99,6 +99,7 @@ using FunctionSignature = std::tuple; virtual ir::Identifier *ParseIdentifierFormatPlaceholder(std::optional nodeFormat) const; virtual ir::Statement *ParseStatementFormatPlaceholder() const; + virtual ir::AstNode *ParseTypeParametersFormatPlaceholder() const; virtual ArenaVector &ParseAstNodesArrayFormatPlaceholder() const; virtual ArenaVector &ParseStatementsArrayFormatPlaceholder() const; virtual ArenaVector &ParseExpressionsArrayFormatPlaceholder() const; diff --git a/ets2panda/test/CMakeLists.txt b/ets2panda/test/CMakeLists.txt index 5e81e2016ab973f81e0e6f2d9a128b7753cc5465..74efc75be0a7da03b2e5d20ee5e45e56113b5b59 100644 --- a/ets2panda/test/CMakeLists.txt +++ b/ets2panda/test/CMakeLists.txt @@ -42,16 +42,21 @@ function(ets2panda_add_gtest TARGET) ) MESSAGE(${TARGET}) + panda_add_gtest( NAME ${TARGET} - SOURCES ${ARG_CPP_SOURCES} + SOURCES + ${ARG_CPP_SOURCES} LIBRARIES - es2panda-public es2panda-lib + es2panda-public + es2panda-lib + arkassembler + arkbytecodeopt INCLUDE_DIRS - ${ES2PANDA_PATH} - ${ES2PANDA_BINARY_ROOT} + ${ES2PANDA_PATH} + ${ES2PANDA_BINARY_ROOT} SANITIZERS - ${PANDA_SANITIZERS_LIST} + ${PANDA_SANITIZERS_LIST} ) endfunction(ets2panda_add_gtest) @@ -64,105 +69,6 @@ if(PANDA_WITH_ETS) endif() endif() -if(PANDA_REGRESSION_TESTS) - panda_add_gtest( - NAME es2panda_public_test - SOURCES - unit/public/es2panda_public_test.cpp - LIBRARIES - es2panda-public es2panda-lib arkassembler arkbytecodeopt - INCLUDE_DIRS - ${ES2PANDA_ROOT} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - panda_add_library(e2p_test_plugin SHARED unit/public/e2p_test_plugin.c) - panda_target_include_directories(e2p_test_plugin PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") - panda_target_link_libraries(e2p_test_plugin es2panda-public) - - add_custom_target(es2panda-plugin-test - COMMENT "Test es2panda plugin functionality" - COMMAND ${CMAKE_COMMAND} -E env - LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${PANDA_RUN_PREFIX} $ --plugins=e2p_test_plugin - "${CMAKE_CURRENT_SOURCE_DIR}/unit/public/t.ets" > "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" - COMMAND ${CMAKE_COMMAND} -E compare_files - "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" "${CMAKE_CURRENT_SOURCE_DIR}/unit/public/plugin_test.expected.txt" - ) - add_dependencies(es2panda-plugin-test es2panda e2p_test_plugin) - add_dependencies(es2panda_tests es2panda-plugin-test) - - ets2panda_add_gtest(es2panda_dynamic_call_test - CPP_SOURCES unit/dynamic/dynamic_call_test.cpp - ) - - panda_add_gtest( - NAME es2panda_astverifier_tests - SOURCES - unit/public/ast_verifier_test.cpp - LIBRARIES - es2panda-public es2panda-lib - INCLUDE_DIRS - ${ES2PANDA_PATH} - ${ES2PANDA_BINARY_ROOT} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - if(PANDA_WITH_ETS) - panda_add_gtest( - NAME scopes_initialization_test - SOURCES - unit/lowerings/scopes_initialization.cpp - LIBRARIES - es2panda-lib es2panda-public arkassembler arkbytecodeopt - INCLUDE_DIRS - ${ES2PANDA_PATH} - ${OUTPUT_DIR} - - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - panda_add_gtest( - NAME es2panda_checker_tests - SOURCES - unit/checker_test.cpp - LIBRARIES - es2panda-public es2panda-lib - INCLUDE_DIRS - ${ES2PANDA_ROOT} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - endif() - - panda_add_gtest( - NAME es2panda_astdumper_tests - SOURCES - unit/ast_dumper_test.cpp - LIBRARIES - es2panda-public es2panda-lib arkassembler arkbytecodeopt - INCLUDE_DIRS - ${ES2PANDA_PATH} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - panda_add_gtest( - NAME es2panda_union_normalization_tests - SOURCES - unit/union_normalization_test.cpp - LIBRARIES - es2panda-public es2panda-lib arkassembler arkbytecodeopt - INCLUDE_DIRS - ${ES2PANDA_PATH} - ${ES2PANDA_BINARY_ROOT} - SANITIZERS - ${PANDA_SANITIZERS_LIST} - ) - - add_subdirectory(tsconfig) -endif() - +add_subdirectory(tsconfig) add_subdirectory(options) +add_subdirectory(unit) diff --git a/ets2panda/test/compiler/ets/FunctionType5-expected.txt b/ets2panda/test/compiler/ets/FunctionType5-expected.txt index 1a02058a93a6d40f58b84960d59413d4d8a6392f..d1fe63d93deb7de080d0548b99afd5e63edb7793 100644 --- a/ets2panda/test/compiler/ets/FunctionType5-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType5-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 fbcb2d6d444bb1a572116c537df974813e8b6b00..67feb0b46a3f39ade73584a660c3e9d5d706cd04 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 @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 8e44cb782ba8318788d6fbc98212291128a16dcc..fc7f5b71f34046b65eed14f86dbece20e91af691 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 @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 e3d9e2b92f4334f21e0a910015187130e5849b9c..64368b82a207270a53f9dc9411f80085d800a31b 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 @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 4331d93569cf65012576d99e0d54749b1f76e015..239799c8e9dbab0dd1e45d54aaa54e9cffe3ba8b 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 @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/boxingConversion10-expected.txt b/ets2panda/test/compiler/ets/boxingConversion10-expected.txt index 305e19af4765f7924dc337d62e654d1200525046..4bcb71a8f5efbfe48145a2032e153a44b8159e47 100644 --- a/ets2panda/test/compiler/ets/boxingConversion10-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion10-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/boxingConversion5-expected.txt b/ets2panda/test/compiler/ets/boxingConversion5-expected.txt index 23d54930c8abddcf5700560920ab7660faa96323..56650da869d3e0449dee589269cb2a73ce454471 100644 --- a/ets2panda/test/compiler/ets/boxingConversion5-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion5-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/boxingConversion6-expected.txt b/ets2panda/test/compiler/ets/boxingConversion6-expected.txt index 28d3661654527a87044ab6d9a91f61f2f3762c5f..ed340f5d6c69dd49853f491f35f0425a21bd7d43 100644 --- a/ets2panda/test/compiler/ets/boxingConversion6-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion6-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/boxingConversion7-expected.txt b/ets2panda/test/compiler/ets/boxingConversion7-expected.txt index 0dbd1571053672a06203f9f6493dd31c9bf5d4c7..b8192a7bf9622c7909d066097a86d51a9abaf45b 100644 --- a/ets2panda/test/compiler/ets/boxingConversion7-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion7-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/boxingConversion8-expected.txt b/ets2panda/test/compiler/ets/boxingConversion8-expected.txt index b88cf9cea5ec2b384d814386adaff6369ecb3502..494a5c5647758b246a47713457cb8aa7eb0fa944 100644 --- a/ets2panda/test/compiler/ets/boxingConversion8-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion8-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/boxingConversion9-expected.txt b/ets2panda/test/compiler/ets/boxingConversion9-expected.txt index ac8bfdfce8cb914f4642b7977b05bb154a3672e6..dd96498ac6b89f794c5432256f34ddb428140a07 100644 --- a/ets2panda/test/compiler/ets/boxingConversion9-expected.txt +++ b/ets2panda/test/compiler/ets/boxingConversion9-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/export_and_export_type_class-expected.txt b/ets2panda/test/compiler/ets/export_and_export_type_class-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1a3e6a97c604b5c45394ff10bb08fa6779be15a6 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_and_export_type_class-expected.txt @@ -0,0 +1 @@ +SyntaxError: Name 'A' cannot be exported and type exported at the same time. [export_and_export_type_class.ets:17:14] diff --git a/ets2panda/test/compiler/ets/export_and_export_type_class.ets b/ets2panda/test/compiler/ets/export_and_export_type_class.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d4f7d88458f545b42f742224d3d7684bfc4215b --- /dev/null +++ b/ets2panda/test/compiler/ets/export_and_export_type_class.ets @@ -0,0 +1,17 @@ +/* + * 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 class A {} +export type {A} diff --git a/ets2panda/test/compiler/ets/export_and_export_type_interface-expected.txt b/ets2panda/test/compiler/ets/export_and_export_type_interface-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..a40e4b221c4d90781a5fa523a3069e0b5f04e662 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_and_export_type_interface-expected.txt @@ -0,0 +1 @@ +SyntaxError: Name 'I' cannot be exported and type exported at the same time. [export_and_export_type_interface.ets:17:14] diff --git a/ets2panda/test/compiler/ets/export_and_export_type_interface.ets b/ets2panda/test/compiler/ets/export_and_export_type_interface.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c96ef79d0622830a980e9fc1d6f3adfa93c994f --- /dev/null +++ b/ets2panda/test/compiler/ets/export_and_export_type_interface.ets @@ -0,0 +1,17 @@ +/* + * 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 interface I {} +export type {I} diff --git a/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding-expected.txt b/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f1a41963b3e68160d6601a0800bab4e8cf697a09 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot export the same 'A' type twice. [export_same_type_at_decl_and_selective_binding.ets:17:14] diff --git a/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding.ets b/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding.ets new file mode 100644 index 0000000000000000000000000000000000000000..871c63ec97ee2cda4a024d130f91b4501d0ce04b --- /dev/null +++ b/ets2panda/test/compiler/ets/export_same_type_at_decl_and_selective_binding.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 type class A {} +export type {A} + diff --git a/ets2panda/test/compiler/ets/export_type-expected.txt b/ets2panda/test/compiler/ets/export_type-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..38d02fc55f5c32237199b95076e74071e7370948 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type-expected.txt @@ -0,0 +1,607 @@ +{ + "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": "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": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "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": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "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": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + { + "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": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/export_type.ets b/ets2panda/test/compiler/ets/export_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..53d5c94441d3e6764aef0694503593e913565f65 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type.ets @@ -0,0 +1,21 @@ +/* + * 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 {} +interface B {} + +export class C {} +export type {A, B} +export type class D {} diff --git a/ets2panda/test/compiler/ets/export_type_class_multiple_times-expected.txt b/ets2panda/test/compiler/ets/export_type_class_multiple_times-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..9cb362a6ef6dc21ec98809105c4269baf8402ec7 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_class_multiple_times-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot export the same 'MyA' type twice. [export_type_class_multiple_times.ets:20:14] diff --git a/ets2panda/test/compiler/ets/export_type_class_multiple_times.ets b/ets2panda/test/compiler/ets/export_type_class_multiple_times.ets new file mode 100644 index 0000000000000000000000000000000000000000..2b5afbebefeb3a6997cea9e754b68f9e985162d1 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_class_multiple_times.ets @@ -0,0 +1,20 @@ +/* + * 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 {} + +export type {A} +export type MyA = A +export type {MyA} diff --git a/ets2panda/test/compiler/ets/export_type_enum-expected.txt b/ets2panda/test/compiler/ets/export_type_enum-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c1e7b9f5b24501d356d09bf59d5409a5785f636d --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_enum-expected.txt @@ -0,0 +1 @@ +SyntaxError: Can only type export class or interface! [export_type_enum.ets:18:14] diff --git a/ets2panda/test/compiler/ets/export_type_enum.ets b/ets2panda/test/compiler/ets/export_type_enum.ets new file mode 100644 index 0000000000000000000000000000000000000000..4cdb42f4d3b4142d6221d6c5b7051eea72e3af63 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_enum.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. + */ + +enum E { A = 5, B = 5 } + +export type {E} diff --git a/ets2panda/test/compiler/ets/export_type_function-expected.txt b/ets2panda/test/compiler/ets/export_type_function-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0d3996957f91780328ae8ead07b0135eb5c1cd5 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_function-expected.txt @@ -0,0 +1 @@ +SyntaxError: Can only type export class or interface! [export_type_function.ets:20:14] diff --git a/ets2panda/test/compiler/ets/export_type_function.ets b/ets2panda/test/compiler/ets/export_type_function.ets new file mode 100644 index 0000000000000000000000000000000000000000..a2160ce0e154038a5c1b38a88342b3b8c8d21e8d --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_function.ets @@ -0,0 +1,20 @@ +/* + * 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 f(){ + return 1; +} + +export type {f} diff --git a/ets2panda/test/compiler/ets/export_type_interface_multiple_times-expected.txt b/ets2panda/test/compiler/ets/export_type_interface_multiple_times-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d9df14f0aa9ca7c51bca1b407f2a607ae3a63307 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_interface_multiple_times-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot export the same 'MyI' type twice. [export_type_interface_multiple_times.ets:20:14] diff --git a/ets2panda/test/compiler/ets/export_type_interface_multiple_times.ets b/ets2panda/test/compiler/ets/export_type_interface_multiple_times.ets new file mode 100644 index 0000000000000000000000000000000000000000..fc7d0bfeb80e49bb6ea5b976ed0b6ae82b53c853 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_interface_multiple_times.ets @@ -0,0 +1,20 @@ +/* + * 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 {} + +export type {I} +export type MyI = I +export type {MyI} diff --git a/ets2panda/test/compiler/ets/export_type_variable-expected.txt b/ets2panda/test/compiler/ets/export_type_variable-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3374cd51e4a7cfcc361d8c0a3997fe357a2fc1aa --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_variable-expected.txt @@ -0,0 +1 @@ +SyntaxError: Can only type export class or interface! [export_type_variable.ets:18:14] diff --git a/ets2panda/test/compiler/ets/export_type_variable.ets b/ets2panda/test/compiler/ets/export_type_variable.ets new file mode 100644 index 0000000000000000000000000000000000000000..58c9c2a52b19fdd585732063ae315d802ca814e0 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_variable.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. + */ + +let a = 5; + +export type {a} diff --git a/ets2panda/test/compiler/ets/export_type_variable_at_definition-expected.txt b/ets2panda/test/compiler/ets/export_type_variable_at_definition-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2e24f525fff376569535ce273fdc5a408bf0c507 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_variable_at_definition-expected.txt @@ -0,0 +1 @@ +SyntaxError: Can only type export class or interface! [export_type_variable_at_definition.ets:17:1] diff --git a/ets2panda/test/compiler/ets/export_type_variable_at_definition.ets b/ets2panda/test/compiler/ets/export_type_variable_at_definition.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7a1766318dd145b34a2016b7c6eb1dde5b42706 --- /dev/null +++ b/ets2panda/test/compiler/ets/export_type_variable_at_definition.ets @@ -0,0 +1,16 @@ +/* + * 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 type let a = 5; diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index e533c263b4ac4994709d180a5eca9639396bd51f..42b3cf05dee88d5323b65653e606d2c3a2ba1a9a 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/identifierReference3-expected.txt b/ets2panda/test/compiler/ets/identifierReference3-expected.txt index 14afe7479d7ea4f9ed991778196952c73900da86..106853cf9abfa8b06b44bb56eca4c0b7b385432d 100644 --- a/ets2panda/test/compiler/ets/identifierReference3-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference3-expected.txt @@ -323,6 +323,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/identifierReference4-expected.txt b/ets2panda/test/compiler/ets/identifierReference4-expected.txt index 8dc988a332e67f9c9acf34730dd1d8c82545d2a6..184b2438b963091192dfff9f6a99c4b1431c8aa8 100644 --- a/ets2panda/test/compiler/ets/identifierReference4-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference4-expected.txt @@ -577,6 +577,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters-expected.txt b/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c59ee7adad2962e6ae32a580e09fb768b821f401 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters-expected.txt @@ -0,0 +1,1083 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "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": 26 + }, + "end": { + "line": 16, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "node", + "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": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "node", + "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": "node", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + } + ], + "declare": true, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "node", + "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": "node", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + } + ], + "declare": true, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "ManagedScope", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 22, + "column": 7 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ScopeImpl", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "superClass": null, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ManagedScope", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 49 + } + } + } + ], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 3 + }, + "end": { + "line": 23, + "column": 7 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 35 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 3 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "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": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 24, + "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": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters.ets b/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters.ets new file mode 100644 index 0000000000000000000000000000000000000000..08f480aa138ddd45ad1d02d79b3ef733fc5021e3 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_tests/export_class_with_getters_setters.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. + */ + +export class TestClass {} + +interface ManagedScope { + node: TestClass +} + +export class ScopeImpl implements ManagedScope { + node: TestClass = new TestClass() +} diff --git a/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters-expected.txt b/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..665ead9d92fa32e03ef71a4a2b7e87e10c163be1 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters-expected.txt @@ -0,0 +1,789 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export_class_with_getters_setters", + "loc": { + "start": { + "line": 16, + "column": 38 + }, + "end": { + "line": 16, + "column": 75 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "ScopeImpl", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "imported": { + "type": "Identifier", + "name": "ScopeImpl", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 76 + } + } + }, + { + "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": 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": "main", + "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": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ScopeImpl", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 27 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TestClass", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 38 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "property": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 4 + } + } + }, + "property": { + "type": "Identifier", + "name": "node", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 9 + } + } + }, + "right": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "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/import_tests/import_class_with_getters_setters.ets b/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters.ets new file mode 100644 index 0000000000000000000000000000000000000000..72c06e675f9a54ef94e14d8cd34f3bf57e48be08 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_tests/import_class_with_getters_setters.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. + */ + +import { TestClass, ScopeImpl } from "./export_class_with_getters_setters"; + +function main(): void { + let a = new ScopeImpl(); + let b: TestClass = new TestClass(); + b = a.node; + a.node = b; +} diff --git a/ets2panda/test/compiler/ets/import_type-expected.txt b/ets2panda/test/compiler/ets/import_type-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5be8032eba8c9cc334d14a64eaa22a186ce28c55 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type-expected.txt @@ -0,0 +1,1162 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export_type.ets", + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 47 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "imported": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "imported": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "imported": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 47 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + } + ], + "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": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "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": "main", + "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": "main", + "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": "_$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": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "c", + "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": "C", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 22, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 22, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 22, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "c", + "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": "C", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "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": 4 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 22, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 22, + "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": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/import_type.ets b/ets2panda/test/compiler/ets/import_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..1170a3ddbd7478f4f9ecb0a7591b47ce5977bdaf --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import type {A, B, D} from './export_type.ets' + +let a = new A(); +class C implements B {}; +let c = new C() +let d = new D() diff --git a/ets2panda/test/compiler/ets/import_type_with_invalid_syntax-expected.txt b/ets2panda/test/compiler/ets/import_type_with_invalid_syntax-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..597df0de5a2e916dd2890288ea48bbcd7e40f16b --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type_with_invalid_syntax-expected.txt @@ -0,0 +1 @@ +SyntaxError: Type import requires selective binding to define the required imported elements. [import_type_with_invalid_syntax.ets:16:13] diff --git a/ets2panda/test/compiler/ets/import_type_with_invalid_syntax.ets b/ets2panda/test/compiler/ets/import_type_with_invalid_syntax.ets new file mode 100644 index 0000000000000000000000000000000000000000..ac8b47de374acb92f3691c97d3a395fa5c50be54 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type_with_invalid_syntax.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import type * from './export_type.ets' + +let a = new A(); +class C implements B {}; +let c = new C() diff --git a/ets2panda/test/compiler/ets/import_type_without_export-expected.txt b/ets2panda/test/compiler/ets/import_type_without_export-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3eeb537ae29697d100166dc88dba215ddb93b64d --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type_without_export-expected.txt @@ -0,0 +1,740 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export_type.ets", + "loc": { + "start": { + "line": 16, + "column": 25 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "imported": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "imported": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + { + "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": "main", + "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": "main", + "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": "_$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": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "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": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "value": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "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 + } + } +} +SyntaxError: Cannot import 'C', imported type imports only exported types. [import_type_without_export.ets:16:25] diff --git a/ets2panda/test/compiler/ets/import_type_without_export.ets b/ets2panda/test/compiler/ets/import_type_without_export.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb85867cb1aff36b9485763a3a6bae670a2f2e59 --- /dev/null +++ b/ets2panda/test/compiler/ets/import_type_without_export.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + +import type {A, C} from './export_type.ets' + +let a = new A(); +let b = new C(); diff --git a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt index bd192ee2e370499a226715d154937f4522c7d7b2..504d76b4bbd44eb7acb73f7bdddbc86d62ff0be8 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt index 7d12e35a6e07b3eb8ccb7442aa1fd4df4216fcfb..ac77ac91d9a083af5da37b815b54d64d868d4170 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt index 35a019dc887f16d3899fabce73dd16a56f4bb626..1de3b1358f6dfee017257cf66f1d3a9910f46fe5 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt index 054d89e7f5aac3fb886bf0c64d1c2694840895fc..eff5986167df3f6c94a425361c2017437bd965c4 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e781c4e7537b811274ffc6da927b01d8c680e53b --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_dyndecl_dynvalue.ets:24:12] diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe9e626df205e62a427e188cf74054a02f2005c8 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_dynvalue.ets @@ -0,0 +1,26 @@ +/* + * 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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" +import { ADeclared } from "dynamic_import_tests/modules/instanceof" + +function fn(o: ADeclared): boolean { + return o instanceof A; +} + diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b36abe05bb1690d1607ec1712ff8dcbed9a5c1f6 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_dyndecl_jsvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f9079bfe87765ba668d95d5986fa7bd3f027ec6 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dyndecl_jsvalue.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { ADeclared } from "dynamic_import_tests/modules/instanceof" + +function fn_dyn_decl(o: ADeclared): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..01d89967b959af52709dec9851afcfbce75d89d2 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_dynvalue_dynvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb22f8eaf2e799656fadaca319752d400db6f89f --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_dynvalue.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A, B } from "dynamic_js_import_tests" + +function fn(o: B): boolean { + return o instanceof A; +} diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e207a90d75b4fcaba9397369ef39974565e77469 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_dynvalue_jsvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..f2edb27aacae5b4b34645850c95bacd535604b6d --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_dynvalue_jsvalue.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" + +function fn(o: A): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..995ed14f7956b719e3036f2adabfbf005cee001b --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_etsobject_dynvalue.ets:25:12] diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..706874e5dd18a735faab4adcd9d91836499de3e2 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_dynvalue.ets @@ -0,0 +1,26 @@ +/* + * 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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" + +class B {} + +function fn(o: B): boolean { + return o instanceof A; +} diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..579f0aa5676d88631b1b0f736bd61a8652e16183 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_etsobject_jsvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..03a61006d13c82769afabd487d6749af36f2b469 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_etsobject_jsvalue.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +class A {} + +function fn(o: A): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2487a7ed86fb38113318d82aa1b25bdbea9ba30c --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_jsvalue_dynvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..0737247320a02bf345157b9f97aeff8590418e18 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_dynvalue.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" + +function fn(o: JSValue): boolean { + return o instanceof A; +} diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..04bfe221d19eb36be70cd40bee0167887ed72ddb --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_jsvalue_jsvalue.ets:21:12] diff --git a/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..6946a5e8612689fc83f68ecd1d8bbaaa64a9e72a --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_jsvalue_jsvalue.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +function fn(o: JSValue): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_object_dynvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_object_dynvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..65b0bb51f32133f5eb55c2f7bc5de13554613340 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_dynvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_object_dynvalue.ets:23:12] diff --git a/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets b/ets2panda/test/compiler/ets/instanceof_object_dynvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..d2a16a112c0957407f3ffb1ba99904fca4020f3a --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_dynvalue.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { A } from "dynamic_js_import_tests" + +function fn(o: Object): boolean { + return o instanceof A; +} diff --git a/ets2panda/test/compiler/ets/instanceof_object_jsvalue-expected.txt b/ets2panda/test/compiler/ets/instanceof_object_jsvalue-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..bad900e767ba5a5fbd6cffc6389a9ef2287bc88f --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_jsvalue-expected.txt @@ -0,0 +1 @@ +TypeError: Right-hand side of instanceof expression must represent a type. [instanceof_object_jsvalue.ets:21:12] diff --git a/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets b/ets2panda/test/compiler/ets/instanceof_object_jsvalue.ets new file mode 100644 index 0000000000000000000000000000000000000000..44985bb3ab84e9453d62a780e87447f79f633730 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_jsvalue.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +function fn(o: Object): boolean { + return o instanceof JSValue; +} diff --git a/ets2panda/test/compiler/ets/instanceof_object_long-expected.txt b/ets2panda/test/compiler/ets/instanceof_object_long-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..009b4e66947af9d7c690ce9ce95c577e34e804d2 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_long-expected.txt @@ -0,0 +1 @@ +TypeError: Bad operand type, the types of the operands must be same type. [instanceof_object_long.ets:21:12] diff --git a/ets2panda/test/compiler/ets/instanceof_object_long.ets b/ets2panda/test/compiler/ets/instanceof_object_long.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e163d7dfba0a5eebbd402f9c0aa95b7c8cd140f --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_object_long.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +function fn(o: Object): boolean { + return o instanceof long; +} diff --git a/ets2panda/test/compiler/ets/instanceof_x_dyndecl-expected.txt b/ets2panda/test/compiler/ets/instanceof_x_dyndecl-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..8e2be440f7e0634339dc17bf042d2561a1ec2da0 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_dyndecl-expected.txt @@ -0,0 +1,2189 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_js_import_tests", + "loc": { + "start": { + "line": 20, + "column": 24 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "imported": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_import_tests/modules/instanceof", + "loc": { + "start": { + "line": 21, + "column": 38 + }, + "end": { + "line": 21, + "column": 79 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "imported": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 79 + } + } + }, + { + "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": "fn_object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 30 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 25, + "column": 32 + }, + "end": { + "line": 25, + "column": 39 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 40 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_ets_object", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_ets_object", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 29, + "column": 31 + }, + "end": { + "line": 29, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 39 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_jsvalue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_jsvalue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 34 + }, + "end": { + "line": 33, + "column": 41 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 42 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 33 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 37, + "column": 35 + }, + "end": { + "line": 37, + "column": 42 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 43 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 41, + "column": 37 + }, + "end": { + "line": 41, + "column": 44 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 41, + "column": 45 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 43, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "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": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassStaticBlock", + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": true, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "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 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "JSRuntime", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "loadModule", + "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": "StringLiteral", + "value": "dynamic_js_import_tests", + "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": 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 + } + } + }, + { + "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": 44, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets b/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets new file mode 100644 index 0000000000000000000000000000000000000000..e3185fe319d5900cd5c211037244769422b25467 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_dyndecl.ets @@ -0,0 +1,43 @@ +/* + * 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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { AValue } from "dynamic_js_import_tests" +import { ADeclared, BDeclared } from "dynamic_import_tests/modules/instanceof" + +class A {} + +function fn_object(o: Object): boolean { + return o instanceof BDeclared; +} + +function fn_ets_object(o: A): boolean { + return o instanceof BDeclared; +} + +function fn_jsvalue(o: JSValue): boolean { + return o instanceof BDeclared; +} + +function fn_dyn_value(o: AValue): boolean { + return o instanceof BDeclared; +} + +function fn_dyn_decl(o: ADeclared): boolean { + return o instanceof BDeclared; +} diff --git a/ets2panda/test/compiler/ets/dynamic_instanceof-expected.txt b/ets2panda/test/compiler/ets/instanceof_x_etstype-expected.txt similarity index 58% rename from ets2panda/test/compiler/ets/dynamic_instanceof-expected.txt rename to ets2panda/test/compiler/ets/instanceof_x_etstype-expected.txt index 73cfb55aeb96771b70dc15c30c067be7519594d7..ddff810f78444d4dc8238e8a5817ac86e09ececa 100644 --- a/ets2panda/test/compiler/ets/dynamic_instanceof-expected.txt +++ b/ets2panda/test/compiler/ets/instanceof_x_etstype-expected.txt @@ -9,11 +9,11 @@ "loc": { "start": { "line": 20, - "column": 30 + "column": 24 }, "end": { "line": 20, - "column": 55 + "column": 49 } } }, @@ -22,7 +22,7 @@ "type": "ImportSpecifier", "local": { "type": "Identifier", - "name": "A", + "name": "AValue", "decorators": [], "loc": { "start": { @@ -31,13 +31,13 @@ }, "end": { "line": 20, - "column": 11 + "column": 16 } } }, "imported": { "type": "Identifier", - "name": "A", + "name": "AValue", "decorators": [], "loc": { "start": { @@ -46,7 +46,7 @@ }, "end": { "line": 20, - "column": 11 + "column": 16 } } }, @@ -57,105 +57,91 @@ }, "end": { "line": 20, - "column": 11 + "column": 16 } } + } + ], + "loc": { + "start": { + "line": 20, + "column": 1 }, - { - "type": "ImportSpecifier", - "local": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 14 - } - } - }, - "imported": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 14 - } - } + "end": { + "line": 20, + "column": 49 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_import_tests/modules/instanceof", + "loc": { + "start": { + "line": 21, + "column": 27 }, - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 14 - } + "end": { + "line": 21, + "column": 68 } - }, + } + }, + "specifiers": [ { "type": "ImportSpecifier", "local": { "type": "Identifier", - "name": "jsfunc", + "name": "ADeclared", "decorators": [], "loc": { "start": { - "line": 20, - "column": 16 + "line": 21, + "column": 10 }, "end": { - "line": 20, - "column": 22 + "line": 21, + "column": 19 } } }, "imported": { "type": "Identifier", - "name": "jsfunc", + "name": "ADeclared", "decorators": [], "loc": { "start": { - "line": 20, - "column": 16 + "line": 21, + "column": 10 }, "end": { - "line": 20, - "column": 22 + "line": 21, + "column": 19 } } }, "loc": { "start": { - "line": 20, - "column": 16 + "line": 21, + "column": 10 }, "end": { - "line": 20, - "column": 22 + "line": 21, + "column": 19 } } } ], "loc": { "start": { - "line": 20, + "line": 21, "column": 1 }, "end": { - "line": 20, - "column": 55 + "line": 21, + "column": 68 } } }, @@ -278,16 +264,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "foo", + "name": "fn_object", "decorators": [], "loc": { "start": { - "line": 22, + "line": 26, "column": 10 }, "end": { - "line": 22, - "column": 13 + "line": 26, + "column": 19 } } }, @@ -302,155 +288,126 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "foo", + "name": "fn_object", "decorators": [], "loc": { "start": { - "line": 22, + "line": 26, "column": 10 }, "end": { - "line": 22, - "column": 13 + "line": 26, + "column": 19 } } }, "generator": false, "async": false, "expression": false, - "params": [], - "returnType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 22, - "column": 17 - }, - "end": { - "line": 22, - "column": 20 - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { "type": "Identifier", - "name": "a", + "name": "Object", "decorators": [], "loc": { "start": { - "line": 23, - "column": 7 - }, - "end": { - "line": 23, - "column": 8 - } - } - }, - "init": { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 15 - }, - "end": { - "line": 23, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 15 - }, - "end": { - "line": 23, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 15 - }, - "end": { - "line": 23, - "column": 17 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 23, - "column": 11 + "line": 26, + "column": 23 }, "end": { - "line": 23, - "column": 19 + "line": 26, + "column": 29 } } }, "loc": { "start": { - "line": 23, - "column": 7 + "line": 26, + "column": 23 }, "end": { - "line": 23, - "column": 19 + "line": 26, + "column": 30 } } + }, + "loc": { + "start": { + "line": 26, + "column": 23 + }, + "end": { + "line": 26, + "column": 30 + } } - ], - "kind": "let", + }, + "decorators": [], "loc": { "start": { - "line": 23, - "column": 3 + "line": 26, + "column": 20 }, "end": { - "line": 23, - "column": 19 + "line": 26, + "column": 30 } } }, + "loc": { + "start": { + "line": 26, + "column": 20 + }, + "end": { + "line": 26, + "column": 30 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 26, + "column": 32 + }, + "end": { + "line": 26, + "column": 39 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ { - "type": "IfStatement", - "test": { + "type": "ReturnStatement", + "argument": { "type": "BinaryExpression", "operator": "instanceof", "left": { "type": "Identifier", - "name": "a", + "name": "o", "decorators": [], "loc": { "start": { - "line": 24, - "column": 7 + "line": 27, + "column": 12 }, "end": { - "line": 24, - "column": 8 + "line": 27, + "column": 13 } } }, @@ -460,450 +417,93 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "A", + "name": "B", "decorators": [], "loc": { "start": { - "line": 24, - "column": 20 + "line": 27, + "column": 25 }, "end": { - "line": 24, - "column": 21 + "line": 27, + "column": 26 } } }, "loc": { "start": { - "line": 24, - "column": 20 + "line": 27, + "column": 25 }, "end": { - "line": 24, - "column": 22 + "line": 27, + "column": 27 } } }, "loc": { "start": { - "line": 24, - "column": 20 + "line": 27, + "column": 25 }, "end": { - "line": 24, - "column": 22 + "line": 27, + "column": 27 } } }, "loc": { "start": { - "line": 24, - "column": 7 - }, - "end": { - "line": 24, - "column": 22 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 5 - }, - "end": { - "line": 25, - "column": 14 - } - } - } - ], - "loc": { - "start": { - "line": 24, - "column": 23 - }, - "end": { - "line": 26, - "column": 4 - } - } - }, - "alternate": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 10 - } - } - }, - "init": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "jsfunc", - "decorators": [], - "loc": { - "start": { - "line": 27, - "column": 13 - }, - "end": { - "line": 27, - "column": 19 - } - } - }, - "arguments": [], - "optional": false, - "loc": { - "start": { - "line": 27, - "column": 13 - }, - "end": { - "line": 27, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 27, - "column": 9 - }, - "end": { - "line": 27, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 27, - "column": 5 - }, - "end": { - "line": 27, - "column": 22 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 9 - }, - "end": { - "line": 28, - "column": 10 - } - } - }, - "init": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { - "type": "Identifier", - "name": "x", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 13 - }, - "end": { - "line": 28, - "column": 14 - } - } - }, - "right": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 26 - }, - "end": { - "line": 28, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 26 - }, - "end": { - "line": 28, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 26 - }, - "end": { - "line": 28, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 13 - }, - "end": { - "line": 28, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 28, - "column": 9 - }, - "end": { - "line": 28, - "column": 28 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 28, - "column": 5 - }, - "end": { - "line": 28, - "column": 28 - } - } - }, - { - "type": "IfStatement", - "test": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 9 - }, - "end": { - "line": 29, - "column": 10 - } - } - }, - "consequent": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 30, - "column": 14 - }, - "end": { - "line": 30, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 30, - "column": 7 - }, - "end": { - "line": 30, - "column": 16 - } - } - } - ], - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 31, - "column": 6 - } - } - }, - "alternate": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 3, - "loc": { - "start": { - "line": 32, - "column": 14 - }, - "end": { - "line": 32, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 7 - }, - "end": { - "line": 32, - "column": 16 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 12 - }, - "end": { - "line": 33, - "column": 6 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 5 - }, - "end": { - "line": 33, - "column": 6 - } - } - } - ], - "loc": { - "start": { - "line": 26, - "column": 10 + "line": 27, + "column": 12 }, "end": { - "line": 34, - "column": 4 + "line": 27, + "column": 27 } } }, "loc": { "start": { - "line": 24, - "column": 3 + "line": 27, + "column": 5 }, "end": { - "line": 34, - "column": 4 + "line": 27, + "column": 27 } } } ], "loc": { "start": { - "line": 22, - "column": 21 + "line": 26, + "column": 40 }, "end": { - "line": 35, + "line": 28, "column": 2 } } }, "loc": { "start": { - "line": 22, - "column": 13 + "line": 26, + "column": 19 }, "end": { - "line": 35, + "line": 28, "column": 2 } } }, "loc": { "start": { - "line": 22, - "column": 13 + "line": 26, + "column": 19 }, "end": { - "line": 35, + "line": 28, "column": 2 } } @@ -912,266 +512,273 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 26, "column": 1 }, "end": { - "line": 35, + "line": 28, "column": 2 } } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "$jsnew", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "superClass": null, - "implements": [], - "body": [ { - "type": "ClassProperty", + "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "qname_start_from", + "name": "fn_ets_object", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 } } }, - "accessibility": "private", + "kind": "method", + "accessibility": "public", "static": true, - "readonly": true, - "declare": false, "optional": false, "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ClassStaticBlock", "value": { "type": "FunctionExpression", "function": { "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "", + "name": "fn_ets_object", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 } } }, "generator": false, "async": false, - "expression": true, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { "type": "Identifier", - "name": "JSRuntime", + "name": "A", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 28 } } }, - "property": { - "type": "Identifier", - "name": "__initJSNewClass", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } + "loc": { + "start": { + "line": 30, + "column": 27 + }, + "end": { + "line": 30, + "column": 29 } + } + }, + "loc": { + "start": { + "line": 30, + "column": 27 }, - "computed": false, - "optional": false, + "end": { + "line": 30, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 30, + "column": 31 + }, + "end": { + "line": 30, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 13 } } }, - "arguments": [ - { - "type": "StringLiteral", - "value": "L$jsnew;", + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 25 + }, + "end": { + "line": 31, + "column": 26 + } + } + }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 25 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 27 } } + }, + "loc": { + "start": { + "line": 31, + "column": 25 + }, + "end": { + "line": 31, + "column": 27 + } } - ], - "optional": false, + }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 27 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 27 } } } ], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 39 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 2 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 2 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 2 } } }, + "overloads": [], + "decorators": [], "loc": { "start": { - "line": 1, + "line": 30, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 2 } } }, @@ -1179,16 +786,16 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "invoke", + "name": "fn_jsvalue", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 20 } } }, @@ -1203,16 +810,16 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "invoke", + "name": "fn_jsvalue", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 20 } } }, @@ -1224,158 +831,724 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "obj", + "name": "o", "typeAnnotation": { - "type": "OpaqueType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 24 + }, + "end": { + "line": 34, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 24 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 24 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 32 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 32 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 32 } } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "qname_start", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 34, + "column": 34 + }, + "end": { + "line": 34, + "column": 41 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 12 + }, + "end": { + "line": 35, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 25 + }, + "end": { + "line": 35, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 25 + }, + "end": { + "line": 35, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 25 + }, + "end": { + "line": 35, + "column": 27 + } + } + }, + "loc": { "start": { - "line": 1, - "column": 1 + "line": 35, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 35, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 34, + "column": 42 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 20 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 20 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 1 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 10 + }, + "end": { + "line": 38, + "column": 22 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 10 + }, + "end": { + "line": 38, + "column": 22 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 26 + }, + "end": { + "line": 38, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 26 + }, + "end": { + "line": 38, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 26 + }, + "end": { + "line": 38, + "column": 33 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 23 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 33 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 23 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 33 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 38, + "column": 35 + }, + "end": { + "line": 38, + "column": 42 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 12 + }, + "end": { + "line": 39, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 25 + }, + "end": { + "line": 39, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 25 + }, + "end": { + "line": 39, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 25 + }, + "end": { + "line": 39, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 12 + }, + "end": { + "line": 39, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 5 + }, + "end": { + "line": 39, + "column": 27 + } } } + ], + "loc": { + "start": { + "line": 38, + "column": 43 + }, + "end": { + "line": 40, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 22 }, + "end": { + "line": 40, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 22 + }, + "end": { + "line": 40, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 1 + }, + "end": { + "line": 40, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 10 + }, + "end": { + "line": 42, + "column": 21 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 10 + }, + "end": { + "line": 42, + "column": 21 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ { "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "qname_len", + "name": "o", "typeAnnotation": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 25 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 35 } } }, "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 35 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 35 } } } ], "returnType": { - "type": "OpaqueType", + "type": "ETSPrimitiveType", "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 37 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 44 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 12 + }, + "end": { + "line": 43, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 25 + }, + "end": { + "line": 43, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 25 + }, + "end": { + "line": 43, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 25 + }, + "end": { + "line": 43, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 12 + }, + "end": { + "line": 43, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 42, + "column": 45 + }, + "end": { + "line": 44, + "column": 2 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 2 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 2 } } }, @@ -1383,12 +1556,12 @@ "decorators": [], "loc": { "start": { - "line": 1, + "line": 42, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 2 } } } @@ -1420,16 +1593,16 @@ "definition": { "id": { "type": "Identifier", - "name": "$jscall", + "name": "A", "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 8 } } }, @@ -1437,10 +1610,10 @@ "implements": [], "body": [ { - "type": "ClassProperty", + "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "qname_start_from", + "name": "constructor", "decorators": [], "loc": { "start": { @@ -1451,49 +1624,19 @@ "line": 1, "column": 1 } - } - }, - "accessibility": "private", - "static": true, - "readonly": true, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ClassStaticBlock", + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, "value": { "type": "FunctionExpression", "function": { "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "", + "name": "constructor", "decorators": [], "loc": { "start": { @@ -1508,100 +1651,11 @@ }, "generator": false, "async": false, - "expression": true, + "expression": false, "params": [], "body": { "type": "BlockStatement", - "statements": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "JSRuntime", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "property": { - "type": "Identifier", - "name": "__initJSCallClass", - "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": "StringLiteral", - "value": "L$jscall;", - "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 - } - } - } - ], + "statements": [], "loc": { "start": { "line": 1, @@ -1635,22 +1689,68 @@ } } }, + "overloads": [], + "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "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": "B", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 7 + }, + "end": { + "line": 24, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ { "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "invoke", + "name": "constructor", "decorators": [], "loc": { "start": { @@ -1663,9 +1763,8 @@ } } }, - "kind": "method", - "accessibility": "public", - "static": true, + "kind": "constructor", + "static": false, "optional": false, "computed": false, "value": { @@ -1674,7 +1773,7 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "invoke", + "name": "constructor", "decorators": [], "loc": { "start": { @@ -1690,133 +1789,10 @@ "generator": false, "async": false, "expression": false, - "params": [ - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "obj", - "typeAnnotation": { - "type": "OpaqueType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "qname_start", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "qname_len", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - } - ], - "returnType": { - "type": "OpaqueType", + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], "loc": { "start": { "line": 1, @@ -1854,35 +1830,35 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 11 } } } ], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 9 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 24, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 11 } } }, @@ -2300,7 +2276,7 @@ "column": 1 }, "end": { - "line": 37, + "line": 45, "column": 1 } } diff --git a/ets2panda/test/compiler/ets/instanceof_x_etstype.ets b/ets2panda/test/compiler/ets/instanceof_x_etstype.ets new file mode 100644 index 0000000000000000000000000000000000000000..7579954ad33386de31136c75b6bdb6ba7ef35672 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_etstype.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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { AValue } from "dynamic_js_import_tests" +import { ADeclared } from "dynamic_import_tests/modules/instanceof" + +class A {} +class B {} + +function fn_object(o: Object): boolean { + return o instanceof B; +} + +function fn_ets_object(o: A): boolean { + return o instanceof B; +} + +function fn_jsvalue(o: JSValue): boolean { + return o instanceof B; +} + +function fn_dyn_value(o: AValue): boolean { + return o instanceof B; +} + +function fn_dyn_decl(o: ADeclared): boolean { + return o instanceof B; +} diff --git a/ets2panda/test/compiler/ets/instanceof_x_object-expected.txt b/ets2panda/test/compiler/ets/instanceof_x_object-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2b42c302e50fb567cfac8abb39ca8fb7ddcf5ae6 --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_object-expected.txt @@ -0,0 +1,2146 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_js_import_tests", + "loc": { + "start": { + "line": 20, + "column": 24 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "imported": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_import_tests/modules/instanceof", + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 68 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 68 + } + } + }, + { + "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": "fn_object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 19 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 23 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 30 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 25, + "column": 32 + }, + "end": { + "line": 25, + "column": 39 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 40 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_ets_object", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_ets_object", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 27 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 24 + }, + "end": { + "line": 29, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 29, + "column": 31 + }, + "end": { + "line": 29, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 25 + }, + "end": { + "line": 30, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 39 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_jsvalue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_jsvalue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 24 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 21 + }, + "end": { + "line": 33, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 34 + }, + "end": { + "line": 33, + "column": 41 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 25 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 42 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "AValue", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 33 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 37, + "column": 35 + }, + "end": { + "line": 37, + "column": 42 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 43 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "fn_dyn_decl", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "o", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 41, + "column": 37 + }, + "end": { + "line": 41, + "column": 44 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "o", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 13 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 25 + }, + "end": { + "line": 42, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 41, + "column": 45 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 43, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 43, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "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": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassStaticBlock", + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": true, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "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 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "JSRuntime", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "loadModule", + "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": "StringLiteral", + "value": "dynamic_js_import_tests", + "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": 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 + } + } + }, + { + "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": 44, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/instanceof_x_object.ets b/ets2panda/test/compiler/ets/instanceof_x_object.ets new file mode 100644 index 0000000000000000000000000000000000000000..e7c8aa401950b0c6a81ed7a809dd07b3e49c040e --- /dev/null +++ b/ets2panda/test/compiler/ets/instanceof_x_object.ets @@ -0,0 +1,43 @@ +/* + * 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. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +import { AValue } from "dynamic_js_import_tests" +import { ADeclared } from "dynamic_import_tests/modules/instanceof" + +class A {} + +function fn_object(o: Object): boolean { + return o instanceof Object; +} + +function fn_ets_object(o: A): boolean { + return o instanceof Object; +} + +function fn_jsvalue(o: JSValue): boolean { + return o instanceof Object; +} + +function fn_dyn_value(o: AValue): boolean { + return o instanceof Object; +} + +function fn_dyn_decl(o: ADeclared): boolean { + return o instanceof Object; +} 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 f2b0e8782a289a40039a8a57255a2f264145c58f..8649b7d47878514691ebbd7e6af457b9e2d8b5f9 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 @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt index 5db12240c75b1dbec3b7d9bd61164d9bbed7bb7e..178d96416466843700393904784ecb0386eec35b 100644 --- a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt index 939b83aee67c16d3bf4578907c273b5df14b8211..6c1f4d0fbe94ac0926e8e2a04660a295a67a2637 100644 --- a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt index 169a5fc0281d3782ebb68ec7591c7b883e92cf17..9d37e6edfa38bdfa0acc6815be2c01c30d13a5fa 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt @@ -208,6 +208,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt index 5cd0f4bddf4b50d36c14ec89c13559c22ce1cba1..40bf6669c93398bf0c5afcc23048bd9994eecb29 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt @@ -65,6 +65,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt index 1d661df1c8903a61214f9394e782d9733727402d..2322196a59d67b085a8e4db42b1645c41f5471bc 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt index 4ca426fbcd1116c9be8cbc318b863a55698c693a..81e600de0c1fa01a8e5a5b30a80c9559db26745a 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt @@ -202,6 +202,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt index 5af2594c5c6755cb3ea30fafdd89aa383432d918..0318130a1bad68bb76efb432642c7d2170585cc7 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt index 6113219ccd8f8db6287845cb135fe8096785428d..623df476931aea8a04e308c1097a25450b55829c 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt index 47d07f348f76666b7e19baf5ab607894ae0d28ae..f454f752f7697c559c9e046fb1f7c146085b4ddb 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt @@ -160,6 +160,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt index b919165f8eb8619518786458556247125a59be1e..71e5cb1cc77588c9efaf504783374950f6fcbbd0 100644 --- a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt @@ -208,6 +208,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt index e741bd36d0e4dd5407e33e522c5db4f7db0fe471..225edd789074a123d4a32883c0038e8689dd1977 100644 --- a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt @@ -208,6 +208,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt index 5909a76bf2b2d465c38d5059b6761ed5ce4593f5..a8256dfb89f101897ba89ff5d93944bf17439a09 100644 --- a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt +++ b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/compiler/ets/typeAlias-expected.txt b/ets2panda/test/compiler/ets/typeAlias-expected.txt index 2f9467386e7446c3d6d02b3dd65de31ccf83d260..d1424726b95a0ab0cd886b3a2829a3f0524849e3 100644 --- a/ets2panda/test/compiler/ets/typeAlias-expected.txt +++ b/ets2panda/test/compiler/ets/typeAlias-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt index e3d9bb26996bce61295784fdbb1dc03a09b77d27..38e65071d5dd2223d3bb13065f4045354714a1ba 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt index d4d7953e1ddc1cfdb2618604ac4986693b9e892a..9a398fbcf6d63ad7c74cde980c3a8b8214f6d12c 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt @@ -159,6 +159,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt index ad15034d8115d3f755ff12deb9605ccc76574606..33a4ba9a82dc091a3522695fb7a622b3ecb50d27 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/ambient_declaration_final_class-expected.txt b/ets2panda/test/parser/ets/ambient_declaration_final_class-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5e91432c72baeac7df9d0d61802c135a99708e02 --- /dev/null +++ b/ets2panda/test/parser/ets/ambient_declaration_final_class-expected.txt @@ -0,0 +1,290 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "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": 25 + }, + "end": { + "line": 16, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + { + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/ambient_declaration_final_class.ets b/ets2panda/test/parser/ets/ambient_declaration_final_class.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e8c53a2421fbb14a89ba76b22ec742fbf91dd17 --- /dev/null +++ b/ets2panda/test/parser/ets/ambient_declaration_final_class.ets @@ -0,0 +1,16 @@ +/* + * 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. + */ + +declare final class B {} diff --git a/ets2panda/test/parser/ets/array-expected.txt b/ets2panda/test/parser/ets/array-expected.txt index 1d9580dc4987d74873ab471cbdd74c235a7004c6..1235cfe4362f86732d234fce298b5f50cab71d2c 100644 --- a/ets2panda/test/parser/ets/array-expected.txt +++ b/ets2panda/test/parser/ets/array-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 2e37ff1d071d82df5eb70d4d8079bde13f6fe931..374ab1867c75c14aa230b04463d792dc73b2c3fc 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index 1545494a35dee9da8f516f656fff2ab6c3d20360..79d30ca925560488cec431bbdef21e7d841a5d33 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/blocks-expected.txt b/ets2panda/test/parser/ets/blocks-expected.txt index 137bd892a864f82667d901647406fa6e16113fef..34e2ae3bcd87d1dce4d31614a68a8a22550669f2 100644 --- a/ets2panda/test/parser/ets/blocks-expected.txt +++ b/ets2panda/test/parser/ets/blocks-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/blocks_scopes-expected.txt b/ets2panda/test/parser/ets/blocks_scopes-expected.txt index dcfccf797d68cac7852165b91ef77ec7ec9ca6da..4f4e726209d7d9487d95876da3ef891869bf65c4 100644 --- a/ets2panda/test/parser/ets/blocks_scopes-expected.txt +++ b/ets2panda/test/parser/ets/blocks_scopes-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/boolean-expected.txt b/ets2panda/test/parser/ets/boolean-expected.txt index bb679ea24a2d68fff09aada663c9bcaf645a3c43..8c5380ff445237523f09b68a4abccd97b85ae395 100644 --- a/ets2panda/test/parser/ets/boolean-expected.txt +++ b/ets2panda/test/parser/ets/boolean-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/cast_expressions5-expected.txt b/ets2panda/test/parser/ets/cast_expressions5-expected.txt index 4ceb6d64d91321702b68b0140f9ddf97a9057608..b06feafb3236e3f8515c48d8040d6d923a85e80c 100644 --- a/ets2panda/test/parser/ets/cast_expressions5-expected.txt +++ b/ets2panda/test/parser/ets/cast_expressions5-expected.txt @@ -593,6 +593,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/class_instance-expected.txt b/ets2panda/test/parser/ets/class_instance-expected.txt index ec3b1a26abc0f5c07063532cdcc6e88b8788a1bc..ba10da040b1d9e9406365a58ecd0e4eaacc1c112 100644 --- a/ets2panda/test/parser/ets/class_instance-expected.txt +++ b/ets2panda/test/parser/ets/class_instance-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/decl_infer-expected.txt b/ets2panda/test/parser/ets/decl_infer-expected.txt index effb99d39e18b21b2de5b47f788631aec3ebc7ea..f5a56f968beca6c86c59c3cc490baf8c0e9161fe 100644 --- a/ets2panda/test/parser/ets/decl_infer-expected.txt +++ b/ets2panda/test/parser/ets/decl_infer-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import-expected.txt index f260ab4148c7d65b859d908db69dcee3add1a4fd..9e70f26122889195c1e0da8d0d9bc2c18eff3891 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import-expected.txt @@ -1693,8 +1693,8 @@ "column": 1 }, "end": { - "line": 40, - "column": 2 + "line": 41, + "column": 1 } } } diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import.ets b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import.ets index 9a0d3a8396d3d8ca2c5b6dac1beb32f80af3ed88..589c492ad74d6b4256f858545cecf2c8602cce83 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import.ets +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_decl_import.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -37,4 +37,4 @@ function main(): void { A.f2 = f2 foo(obj) -} \ No newline at end of file +} diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..327b2145460f87b93e4bb37ec8786f8eb972f204 --- /dev/null +++ b/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof-expected.txt @@ -0,0 +1,427 @@ +{ + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ADeclared", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "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": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "BDeclared", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 22 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "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": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 32 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/dynamic_instanceof.ets b/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof.ets similarity index 71% rename from ets2panda/test/compiler/ets/dynamic_instanceof.ets rename to ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof.ets index 01b06b980ac1be7dd3b9f7f346231fc4908d8312..73f81409b244fa3d0132c2b98abd6686ae8e5c93 100644 --- a/ets2panda/test/compiler/ets/dynamic_instanceof.ets +++ b/ets2panda/test/parser/ets/dynamic_import_tests/modules/instanceof.ets @@ -17,20 +17,8 @@ flags: [dynamic-ast] ---*/ -import { A, B, jsfunc } from "dynamic_js_import_tests" - -function foo(): int { - let a = new A(); - if (a instanceof A) { - return 1; - } else { - let x = jsfunc(); - let b = x instanceof B; - if (b) { - return 2; - } else { - return 3; - } - } +export declare class ADeclared { } +export declare class BDeclared { +} diff --git a/ets2panda/test/parser/ets/exports-expected.txt b/ets2panda/test/parser/ets/exports-expected.txt index 594900d4d1022298afe92f2b40d4737241c5edf0..0c256ff7d4be84a2f577c9bfa026f7e57fddb033 100644 --- a/ets2panda/test/parser/ets/exports-expected.txt +++ b/ets2panda/test/parser/ets/exports-expected.txt @@ -243,6 +243,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 d3dab3e1561091199273e9479085e86d9bc8c10d..17becf837439dc08d5e4780aa34b46a2fa942c11 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt b/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt index 8387f49f9a5e869d2006fbcd44c5abda61bd09af..4e691dcff700019477e13b4c1fc37c1f77ba358d 100644 --- a/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt +++ b/ets2panda/test/parser/ets/genericDefaultParam_1-expected.txt @@ -1401,6 +1401,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/genericDefaultParam_3-expected.txt b/ets2panda/test/parser/ets/genericDefaultParam_3-expected.txt index 03c646f0d8dc4c1076f49c53192af1d3b5588737..68b94563bb42cdb5df31be71dfba218698bc6173 100644 --- a/ets2panda/test/parser/ets/genericDefaultParam_3-expected.txt +++ b/ets2panda/test/parser/ets/genericDefaultParam_3-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/genericDefaultParam_4-expected.txt b/ets2panda/test/parser/ets/genericDefaultParam_4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..95f5b509acb0c2c4546013b29804dd6ccd525473 --- /dev/null +++ b/ets2panda/test/parser/ets/genericDefaultParam_4-expected.txt @@ -0,0 +1,887 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 10 + } + } + }, + "default": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 11 + }, + "end": { + "line": 15, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 18 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "data", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + { + "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": "t", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 23 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "data", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "right": { + "type": "Identifier", + "name": "t", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + } + ], + "loc": { + "start": { + "line": 15, + "column": 19 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 15, + "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": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 23, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 28 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "hello", + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "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 + } + } +} +TypeError: Type 'string' is not compatible with type 'Double' at index 1 [genericDefaultParam_4.ets:23:28] diff --git a/ets2panda/test/parser/ets/genericDefaultParam_4.ets b/ets2panda/test/parser/ets/genericDefaultParam_4.ets new file mode 100644 index 0000000000000000000000000000000000000000..c65b639d8b867b504e3c744c1ed34d8ceb103ae8 --- /dev/null +++ b/ets2panda/test/parser/ets/genericDefaultParam_4.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 { + data : T + constructor(t : T) { + this.data = t; + } +} + +function main() : void { + let a1 = new A("hello") +} diff --git a/ets2panda/test/parser/ets/identifier-expected.txt b/ets2panda/test/parser/ets/identifier-expected.txt index 70df781844789a8e9d828acab04458243887b59f..1d5744de88718a7ef5351137e67c9b773a8c0799 100644 --- a/ets2panda/test/parser/ets/identifier-expected.txt +++ b/ets2panda/test/parser/ets/identifier-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/import_folder-expected.txt b/ets2panda/test/parser/ets/import_folder-expected.txt index 792732b6a39c25640176f43b7c9bcec61489be55..60694fa346ba5231c4df096892f03e74eb859561 100644 --- a/ets2panda/test/parser/ets/import_folder-expected.txt +++ b/ets2panda/test/parser/ets/import_folder-expected.txt @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 d799f95d2a419bb61222c4fee659f1f7dae2fecf..6c23ec8e935ed60fd93369bb5cca7510c989f9d9 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt @@ -94,6 +94,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 ce83883aad1b8cdf9d9dc30c0820c96e667768dc..b03a89b18a64956cda95553fa256a2565d494047 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt @@ -94,6 +94,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 96bbb0c8bbb147b10f1fda46f9dfa47dc9a4197f..9dc67756a147341f524458f38c4120c66013f8f2 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 73374c4ffc6b8f19c73ccca02068be9fee0ade4c..99bb065816220147327132c7a67ed6f211486074 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 @@ -484,6 +484,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 fff159977d81af3a1ac99d5df858d1cafece446e..e807e2aaf0026e238ea97e36933473d96b58f9bb 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt @@ -136,6 +136,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 1079f0ac8a8713cf7bb3ddeca1804168c8c7ea06..a5c4b5cc542b87562fe62f1d954ce915c3fc6a03 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 @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 623e169b05ef889a75de826abd53ab444d724598..a1cd11efceaab7bcbdaf74e39e0281239de07252 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 @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_neg-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..feb58d3f2fbfb557c1dfebd9fa2d76f4bba53046 --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_neg-expected.txt @@ -0,0 +1,349 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "import_tests/packages", + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 46 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "Test", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 47 + } + } + }, + { + "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": 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": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "Test", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "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": 18, + "column": 27 + } + } +} +TypeError: Namespace style identifier Test is not callable. [import_all_alias_neg.ets:18:19] diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_neg.ets b/ets2panda/test/parser/ets/import_tests/import_all_alias_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..d5aa69dbb2d22078d4a997a972417df6d7c4e48e --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_neg.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022-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. + */ + +import * as Test from "import_tests/packages"; + +function main() { Test() } \ No newline at end of file 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 c58e5d0af3c6f4c8064c3bcf15f9c47d2cdcb852..55f0875f8b2867c8a2ae746ff2da5ffc1f26fa96 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 @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_1-expected.txt index 1192ec0859ff2fc784b5ad232e5b0ae48c7e4b0c..5ca84eea3fedc3d151e33fc37b1b7cbfb4199b0a 100644 --- a/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_2-expected.txt index db763b9353d0dc966f633a2e6b993e63fc538880..5d57b716dea3b613fc32c6be55c03652b7fa62d4 100644 --- a/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_extension/import_extension_2-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 40e1725683cfd4f433ef31d8cdc57c7c55fe89b4..0463fe6654b27c72294f52baa1a10ab0758d3d25 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 @@ -180,6 +180,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 f994a5367e072d2b4e2611868a90e528ca517e3f..6778f92a4fb72bb7defdb5b26aeba077e68dfda7 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 @@ -137,6 +137,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 5206b8641790df52353069b95028a6cbfdd53e9d..ebba4f73447d24f500e353e095df23017f3853e0 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 @@ -180,6 +180,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 d0725932432b0e7631f2ecd4e240ffa4d18f43bd..0527544f350499ed7b611917fe5498f5820e74ed 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 @@ -137,6 +137,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 47a8976e19f104c491068a85ec88c256f14dc85a..10ffc4241f2f7d418235d28e5978a8aa9641e00f 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 @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 f4fc0df83c78d315630a6e2a3afd12be0d4bbf1b..0c48238700c43b7f16a61288368751bf13748b09 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 @@ -238,6 +238,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 a6b92000564a98d804a61a457690d6ef0f81a501..b172fc50bb06215741dcfac6af05c9844b8b7231 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 @@ -137,6 +137,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 1d8e16a3b5bcc87c07a63ffbc542ba0276adea74..f07c570b17dbf8d3912617e3a52c12234a9c708a 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 @@ -151,6 +151,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 6ea9c81dd2acf2e77f4bc7965046e2e9a5c90e44..b5de45031138a46ff9ebbb096d2e33dcf4cd3bff 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 @@ -151,6 +151,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 f96445626d82a5de0a1392e585368c891d380dc7..69fbb4be277e8d4c7fdcaa3494ffe889e3082d2d 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 @@ -151,6 +151,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 4f190cb5ecd462d7871dc751c465355d48225dfe..b6fad9300ffc1666242820d392ef43278b54c687 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 @@ -151,6 +151,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 d4d39585263867bd92f7180547a47b6ff5638fbd..72d1907d1ad31e68ad8a6d454d10a0438be1c70d 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 @@ -223,6 +223,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 37cfedf51478bc0eb3483e360be3cb58677855e2..e73141cdc240be4ea67125b3c1164283e8d63ae7 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 @@ -253,6 +253,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/index_expressions-expected.txt b/ets2panda/test/parser/ets/index_expressions-expected.txt index 39fc2ad997ddee2e89c3dcdf62e9cb95f04a6070..d55d46b69472997f198fb43d48852af3ba11a088 100644 --- a/ets2panda/test/parser/ets/index_expressions-expected.txt +++ b/ets2panda/test/parser/ets/index_expressions-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression-expected.txt b/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..469ca893fd31633aa92ab7d12242fb29fb86235a --- /dev/null +++ b/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression-expected.txt @@ -0,0 +1,480 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "cls", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "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": 22 + }, + "end": { + "line": 16, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + { + "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": 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": "main", + "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": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ETSNewArrayInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "dimension": { + "type": "NumberLiteral", + "value": 10, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "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: Cannot use array creation expression with abstract classes and interfaces. [instantied_abstract_class_with_array_creation_expression.ets:19:3] diff --git a/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression.ets b/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression.ets new file mode 100644 index 0000000000000000000000000000000000000000..90455edc5103318a43d9d24ff12cd5235965d232 --- /dev/null +++ b/ets2panda/test/parser/ets/instantied_abstract_class_with_array_creation_expression.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +abstract class cls {} + +function main(): void { + new cls[10]; +} diff --git a/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression-expected.txt b/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d3d577fa5daac21f2a00975215d399234c81f3bf --- /dev/null +++ b/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression-expected.txt @@ -0,0 +1,386 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "id": { + "type": "Identifier", + "name": "iface", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "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": 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": "main", + "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": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ETSNewArrayInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "iface", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "dimension": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "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: Cannot use array creation expression with abstract classes and interfaces. [instantied_interface_with_array_creation_expression.ets:19:3] diff --git a/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression.ets b/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression.ets new file mode 100644 index 0000000000000000000000000000000000000000..a31234d06049eba97b3e48140f367ae2ae496b74 --- /dev/null +++ b/ets2panda/test/parser/ets/instantied_interface_with_array_creation_expression.ets @@ -0,0 +1,20 @@ +/* + * 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 iface {} + +function main(): void { + new iface[5]; +} diff --git a/ets2panda/test/parser/ets/interface_member_initialization-expected.txt b/ets2panda/test/parser/ets/interface_member_initialization-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbc8b1c2e4f0be9a78cf1b52cecf89298c7f963a --- /dev/null +++ b/ets2panda/test/parser/ets/interface_member_initialization-expected.txt @@ -0,0 +1 @@ +SyntaxError: Interface member initialization is prohibited [interface_member_initialization.ets:17:14] diff --git a/ets2panda/test/parser/ets/interface_member_initialization.ets b/ets2panda/test/parser/ets/interface_member_initialization.ets new file mode 100644 index 0000000000000000000000000000000000000000..3aae74b02f8e0f192b7e2c4a1c3dcc02ebee578f --- /dev/null +++ b/ets2panda/test/parser/ets/interface_member_initialization.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. + */ + +interface Colors { + Red: int = 1; +} + +function main() +{ + +} 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 2821fed8280f7a5800e34f92ffa29484a64a1eaa..89812af2db70fdba5975edbbc3ae7372d3bddf19 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 @@ -176,6 +176,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 2e698140825913aa44e7fe45a90cc136f46136a7..543b7f57139e2bf38b8ae26a569d6e51fdf9b407 100644 --- a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt +++ b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt @@ -253,6 +253,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 991dd59ae59c3bed029ab9d6fde26cfbd894cf64..60ac4d8d33c434608e5989823aa8dfb5afd24cfe 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index b1e599b104e5f7e87d80d547c249491247ef0c14..a5cc81f6113c691331507958ed7acac7bd07303b 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/optional_field_variable_2-expected.txt b/ets2panda/test/parser/ets/optional_field_variable_2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0304436df873371e03b49e3009c6b4f422c7bba4 --- /dev/null +++ b/ets2panda/test/parser/ets/optional_field_variable_2-expected.txt @@ -0,0 +1,1146 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "once", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 9 + } + } + }, + "value": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 26 + } + } + }, + { + "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": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 17, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 15, + "column": 1 + }, + "end": { + "line": 17, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "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": 5 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "global", + "typeAnnotation": { + "type": "ETSUnionType", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 41 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "init": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 21, + "column": 44 + }, + "end": { + "line": 21, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 48 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 48 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 22, + "column": 19 + } + } + }, + "right": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 22, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 22, + "column": 32 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "global", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 34 + }, + "end": { + "line": 22, + "column": 40 + } + } + }, + "right": { + "type": "BinaryExpression", + "operator": "!=", + "left": { + "type": "BlockExpression", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 47 + } + } + }, + "property": { + "type": "Identifier", + "name": "current", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 55 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "ConditionalExpression", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "Identifier", + "name": "gensym$_2", + "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 + } + } + }, + "consequent": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 61 + } + } + }, + "property": { + "type": "Identifier", + "name": "once", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 57 + }, + "end": { + "line": 22, + "column": 61 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 61 + } + } + }, + "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": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "right": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 22, + "column": 65 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 34 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 34 + }, + "end": { + "line": 22, + "column": 69 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 69 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "current", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 12 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 28 + } + } + }, + { + "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": 25, + "column": 2 + }, + "end": { + "line": 25, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "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 + } + } + } + ], + "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/optional_field_variable_2.ets b/ets2panda/test/parser/ets/optional_field_variable_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..5359d7012dc5421b423bd8ef91a51c81f16aa786 --- /dev/null +++ b/ets2panda/test/parser/ets/optional_field_variable_2.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 C { + once : boolean = true +} + +class A { + foo() { + let global : boolean | undefined = true + if (global == undefined) global = this.current?.once != true + } + current : C | undefined +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt index 5c1d2aa74e7dd53a864e85fb6a753ae2abebc32c..bc8150abb06874914ed95051fc4aa55fb29c516e 100644 --- a/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt +++ b/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/index-expected.txt b/ets2panda/test/parser/ets/re_export/folderIndex2/index-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a9a54e4c49169889a25ce89852d5739054563c3 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/index-expected.txt @@ -0,0 +1,323 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./key", + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "imported": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "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": "./type", + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "imported": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "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": 18, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/index.ets b/ets2panda/test/parser/ets/re_export/folderIndex2/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..f982d78aae9acd8637f7666b46c1bc117a698ee7 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/index.ets @@ -0,0 +1,17 @@ +/* + * 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 {Test1} from "./key"; +export {int32} from "./type"; diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/key-expected.txt b/ets2panda/test/parser/ets/re_export/folderIndex2/key-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7b3d527b0e15a75d8bcdd353436357e6d5d544cf --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/key-expected.txt @@ -0,0 +1,581 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "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", + "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": 19 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Test2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + { + "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": 19 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "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 + } + } + } + ], + "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 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/key.ets b/ets2panda/test/parser/ets/re_export/folderIndex2/key.ets new file mode 100644 index 0000000000000000000000000000000000000000..4bcccea396cc2df271bc61a222d1c73ca78106c3 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/key.ets @@ -0,0 +1,21 @@ +/* + * 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 class Test1{ + name:String; +} +export class Test2{ + name:String; +} diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/type-expected.txt b/ets2panda/test/parser/ets/re_export/folderIndex2/type-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..ff5a6456fc8bc16cb6fc1971d841f47e4f1f9905 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/type-expected.txt @@ -0,0 +1,222 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 17, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 17, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 17, + "column": 1 + } + } + }, + { + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/folderIndex2/type.ets b/ets2panda/test/parser/ets/re_export/folderIndex2/type.ets new file mode 100644 index 0000000000000000000000000000000000000000..12ea65fec58008b3c692c911010153e54bf80a02 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/folderIndex2/type.ets @@ -0,0 +1,16 @@ +/* + * 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 type int32 = Number diff --git a/ets2panda/test/parser/ets/re_export/import_index-expected.txt b/ets2panda/test/parser/ets/re_export/import_index-expected.txt index dd67fad02a8ff457a8ff832e0e002f1497f74d8a..b56a0dd932d5c5e9e08fad711b55bd56ff67e142 100644 --- a/ets2panda/test/parser/ets/re_export/import_index-expected.txt +++ b/ets2panda/test/parser/ets/re_export/import_index-expected.txt @@ -79,6 +79,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/re_export/import_index_2-expected.txt b/ets2panda/test/parser/ets/re_export/import_index_2-expected.txt index 8d4fa72dfea52519094053aafe9298b2d9f4bbed..e24ba9c385873e46de86207a5bb889090d086b9f 100644 --- a/ets2panda/test/parser/ets/re_export/import_index_2-expected.txt +++ b/ets2panda/test/parser/ets/re_export/import_index_2-expected.txt @@ -94,6 +94,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/re_export/import_index_3-expected.txt b/ets2panda/test/parser/ets/re_export/import_index_3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..accfb2f11106b2b3bedfc72c901238ae8a83e5eb --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_index_3-expected.txt @@ -0,0 +1,268 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./folderIndex2", + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "imported": { + "type": "Identifier", + "name": "Test1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "imported": { + "type": "Identifier", + "name": "int32", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + { + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/import_index_3.ets b/ets2panda/test/parser/ets/re_export/import_index_3.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c548f2eaf3dd7469fc213e23bbf585351690b68 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_index_3.ets @@ -0,0 +1,16 @@ +/* + * 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. + */ + +import {Test1, int32} from "./folderIndex2"; diff --git a/ets2panda/test/parser/ets/simple_types-expected.txt b/ets2panda/test/parser/ets/simple_types-expected.txt index 7c49b4574444f4250c998f91b1ce6632fbbf9868..74d12bdb54ccb186a250215fe19158c97c1e8a2c 100644 --- a/ets2panda/test/parser/ets/simple_types-expected.txt +++ b/ets2panda/test/parser/ets/simple_types-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/string-expected.txt b/ets2panda/test/parser/ets/string-expected.txt index 38083df2f96d302e93fb9e76db965178ada9257b..130ae76cb6dfe201b17cfbba3c5a8d0e30b514e5 100644 --- a/ets2panda/test/parser/ets/string-expected.txt +++ b/ets2panda/test/parser/ets/string-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/ternary-expected.txt b/ets2panda/test/parser/ets/ternary-expected.txt index f74401a8ee172e5100d56301aa892057b1461e8d..920024304baa61f018adb132106dab949c29b925 100644 --- a/ets2panda/test/parser/ets/ternary-expected.txt +++ b/ets2panda/test/parser/ets/ternary-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 e95785906dbea44c7255b317ad334e97809f31b0..1c79ec21c05c03c8d31e5eeb5ff5ccd0b0af90c4 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 73bf02b6226729e84e158047d96bf03c04e42710..7f7362df7047ce7904dd29dae7666fadf01707b8 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 @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { 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 69a2a714c4c45f1f0fc2dc05861e6ca62f34c78a..6ec874fa24b75de7631a8bc428f5589ede13cf3c 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 @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/test_type_alias9-expected.txt b/ets2panda/test/parser/ets/test_type_alias9-expected.txt index f71a0b03d7d710c885670b8cc54535e408fb6337..da996e2cfd42e9e2c7a9b8f8055af4432ed112b6 100644 --- a/ets2panda/test/parser/ets/test_type_alias9-expected.txt +++ b/ets2panda/test/parser/ets/test_type_alias9-expected.txt @@ -130,6 +130,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt index d1ea49ee75e51b7c0d66f3b36a9556cfa09436cf..347c036324b7c1ae78926ef362b40afebd3624b4 100644 --- a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt +++ b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_not_transform_trailing_block_1-expected.txt b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_not_transform_trailing_block_1-expected.txt index 99138c53253803a16d822394afbfcdb1c3a3c5da..697057163a81b2e5cad924df90d675db01604f44 100644 --- a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_not_transform_trailing_block_1-expected.txt +++ b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_not_transform_trailing_block_1-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/tuple_type_1-expected.txt b/ets2panda/test/parser/ets/tuple_type_1-expected.txt index bca78f1e0e0c02825b24312f23069a4bf691ccb9..3e49a8ea53bb4ff745d9a661ca665b433d1bb824 100644 --- a/ets2panda/test/parser/ets/tuple_type_1-expected.txt +++ b/ets2panda/test/parser/ets/tuple_type_1-expected.txt @@ -234,6 +234,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/unary_op-expected.txt b/ets2panda/test/parser/ets/unary_op-expected.txt index 32aa0ba97dbd588e3d409a47515063803947c002..3bd5606906daad20785f2d22b494f73acc0ff99d 100644 --- a/ets2panda/test/parser/ets/unary_op-expected.txt +++ b/ets2panda/test/parser/ets/unary_op-expected.txt @@ -22,6 +22,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/parser/ets/user_defined_22-expected.txt b/ets2panda/test/parser/ets/user_defined_22-expected.txt index f61d047d2f720b35b8d719e5d8b00856a7514a01..2723b04939acce754d629bbc14aadeb48ba9ec3a 100644 --- a/ets2panda/test/parser/ets/user_defined_22-expected.txt +++ b/ets2panda/test/parser/ets/user_defined_22-expected.txt @@ -319,6 +319,100 @@ "superClass": null, "implements": [], "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "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": "main", + "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": { diff --git a/ets2panda/test/runtime/ets/castUnion.ets b/ets2panda/test/runtime/ets/castUnion.ets new file mode 100644 index 0000000000000000000000000000000000000000..3b32fb6a0efd3fa04a63322284be8b0d081d0c7a --- /dev/null +++ b/ets2panda/test/runtime/ets/castUnion.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 A1 { + s: Byte | Short = new Byte() + bad_field: short = this.s as Byte +} + +function main() { + let a = new A1() +} + diff --git a/ets2panda/test/runtime/ets/conversionFromInfinity.ets b/ets2panda/test/runtime/ets/conversionFromInfinity.ets index 812df0fe9e9b1d94183042ad02a60e76755c5a1b..f87376cb6afd8bd0bf1afaba49f73cab6ca0188f 100644 --- a/ets2panda/test/runtime/ets/conversionFromInfinity.ets +++ b/ets2panda/test/runtime/ets/conversionFromInfinity.ets @@ -44,42 +44,54 @@ assert(b3 == -1) let l1 = Infinity as long let l2: double = Infinity let l3 = l2 as long +let l4 = -Infinity as long assert(l1 == 9223372036854775807) assert(l3 == 9223372036854775807) +assert(l4 == -9223372036854775808) let i1 = Infinity as int let i2: double = Infinity let i3 = i2 as int +let i4 = -Infinity as int assert(i1 == 2147483647) assert(i3 == 2147483647) +assert(i4 == -2147483648) let s1 = Infinity as short let s2: double = Infinity let s3 = s2 as short +let s4 = -Infinity as short assert(s1 == -1) assert(s3 == -1) +assert(s4 == 0) let c1 = Infinity as char let c2: double = Infinity let c3 = c2 as char +let c4 = -Infinity as char assert(c1 == 65535) assert(c3 == 65535) +assert(c4 == 0) let f1 = Infinity as float let f2: double = Infinity let f3 = f2 as float +let f4 = -Infinity as float assert(f1 == Infinity) assert(f3 == Infinity) +assert(f4 == -Infinity) let d1 = Infinity as double let d2: double = Infinity let d3 = d2 as double +let d4 = -Infinity as double assert(d1 == Infinity) assert(d3 == Infinity) +assert(d4 == -Infinity) } diff --git a/ets2panda/test/runtime/ets/entrypoint-with-main-and-top-level-stmts.ets b/ets2panda/test/runtime/ets/entrypoint-with-main-and-top-level-stmts.ets new file mode 100644 index 0000000000000000000000000000000000000000..93f438ebf3be376c7f6adf87ecf3180127077b67 --- /dev/null +++ b/ets2panda/test/runtime/ets/entrypoint-with-main-and-top-level-stmts.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. + */ + +let a : int = 0; + +function main() : void { + assert(a == b); +} + +let b : int = 0; \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/entrypoint-with-main.ets b/ets2panda/test/runtime/ets/entrypoint-with-main.ets new file mode 100644 index 0000000000000000000000000000000000000000..c31e9f45999fc9012de3835d6916dee8fa0b6a25 --- /dev/null +++ b/ets2panda/test/runtime/ets/entrypoint-with-main.ets @@ -0,0 +1,19 @@ +/* + * 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() : void { // gets to result_.classProperties + let a = 0; + assert(a == 0); +} diff --git a/ets2panda/test/runtime/ets/entrypoint-wout-main.ets b/ets2panda/test/runtime/ets/entrypoint-wout-main.ets new file mode 100644 index 0000000000000000000000000000000000000000..e27a52ef64af86e4957ae59cb811ad3ac6903cd7 --- /dev/null +++ b/ets2panda/test/runtime/ets/entrypoint-wout-main.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. + */ + +let a : int = 0; + +assert(a == 0); \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/generic_default_param.ets b/ets2panda/test/runtime/ets/generic_default_param.ets new file mode 100644 index 0000000000000000000000000000000000000000..91d44f25248ccb1c44f5e2f06e816e987f9582be --- /dev/null +++ b/ets2panda/test/runtime/ets/generic_default_param.ets @@ -0,0 +1,27 @@ +/* + * 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 { + data : T + constructor(t : T) { + this.data = t; + } +} + +function main() : void { + let a = new A("hello"); + let a1 = new A("world") + assert a.data instanceof string + assert a1.data instanceof string +} diff --git a/ets2panda/test/runtime/ets/nestedLambdaInnerConst.ets b/ets2panda/test/runtime/ets/nestedLambdaInnerConst.ets new file mode 100644 index 0000000000000000000000000000000000000000..94a7bbc5cab2f15e37b24e1c0ecc06d8947377e8 --- /dev/null +++ b/ets2panda/test/runtime/ets/nestedLambdaInnerConst.ets @@ -0,0 +1,123 @@ +/* + * 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 force(thunk: ()=>void) { + thunk(); +} + +function bool2Levels(): void { + force(() => { + const a0 = true; + force(() => { + const a1 = a0; + assert a0 && a1; + }); + }); +} + +function bool4Levels(): void { + force(() => { + const a0 = true; + force(() => { + const a1 = a0; + force(()=>{ + const a2 = a1; + force(()=>{ + const a3 = a2; + assert a0 && a1 && a2 && a3; + }); + }); + }); + }); +} + +function number4Levels(): void { + force(() => { + const a0 = 1; + force(() => { + const a1 = a0; + force(()=>{ + const a2 = a1; + force(()=>{ + const a3 = a2; + assert 4==a0 + a1 + a2 + a3; + }); + }); + }); + }); +} + +function array4Levels(): void { + force(() => { + const a0 = [1,0,0,0]; + force(() => { + const a1 = a0; + a1[1]=a0[0]; + force(()=>{ + const a2 = a1; + a2[2]=a1[1]; + force(()=>{ + const a3 = a2; + a3[3]=a2[2]; + assert a0[0]+a0[1]+a0[2]+a0[3]==4; + }); + }); + }); + }); +} + +function arrayProp4Levels(): void { + force(() => { + const a0 = [1,0,0,0]; + force(() => { + const a1 = a0; + a1[1]=a0[0]; + force(()=>{ + const a2 = a1; + a2[2]=a1[1]; + force(()=>{ + const a3 = a2; + a3[3]=a2[2]; + assert a0.length == 4; + assert a0[0]+a0[1]+a0[2]+a0[3] == 4; + }); + }); + }); + }); +} + +function paramCapture(): void { + const v0 = 1 + const f0 = (p0:number)=>{ + const a0 = p0; + const f1 = (p1:number)=>{ + const a1 = a0; + const a2 = p1; + const a3 = v0; + assert a0 + a1 + a2 + a3 == 4; + } + f1(p0); + } + f0(v0); +} + + +function main():void { + bool2Levels(); + bool4Levels(); + number4Levels(); + array4Levels(); + paramCapture(); +} diff --git a/ets2panda/test/runtime/ets/nestedLambdaLet.ets b/ets2panda/test/runtime/ets/nestedLambdaLet.ets new file mode 100644 index 0000000000000000000000000000000000000000..80953fa77b097d2dba47e95f9b9b7f78ba5fcb5b --- /dev/null +++ b/ets2panda/test/runtime/ets/nestedLambdaLet.ets @@ -0,0 +1,134 @@ +/* + * 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 force(thunk: () => void) { + thunk(); +} + +function bool2Levels(): void { + force(() => { + let a0 = true; + force(() => { + let a1 = a0; + assert a0 && a1; + a0 = false; + assert !a0 && a1; + a0 = true; + a1 = false; + assert a0 && !a1; + }); + }); +} + +function bool4Levels(): void { + force(() => { + let a0 = true; + force(() => { + let a1 = a0; + force(() => { + let a2 = a1; + force(() => { + let a3 = a2; + assert a0 && a1 && a2 && a3; + a0 = false; + assert !a0 && a1 && a2 && a3; + a3 = false; + assert !a0 && a1 && a2 && !a3; + }); + }); + }); + }); +} + +function bool4LevelsBi(): void { + force(() => { + let a0 = true; + force(() => { + let a1 = a0; + force(() => { + let a2 = a1; + force(() => { + let a3 = a2; + assert a0 && a1 && a2 && a3; + a0 = false; + assert !a0 && a1 && a2 && a3; + a3 = a0; + assert !a0 && a1 && a2 && !a3; + }); + force(() => { + a2 = a0; + assert !a0 && a1 && !a2; + }); + }); + force(() => { + assert !a0 && a1; + }); + }); + force(() => { + assert !a0; + }); + }); +} + +function number4Levels(): void { + force(() => { + let a0 = 1; + force(() => { + let a1 = a0++; + force(() => { + let a2 = a1++; + force(() => { + let a3 = a2++; + a3++; + assert 8 == a0 + a1 + a2 + a3; + }); + }); + }); + }); +} + +function arrays(): void { + force(() => { + let a0 = [1, 0, 0, 0]; + force(() => { + let a1 = a0; + a1[1]=a0[0]; + force(() => { + let a2 = a1; + a2[2] = a1[1]; + force(() => { + let a3 = a2; + force(() => { + a3[3] = a2[2]; + assert a0[0] + a0[1] + a0[2] + a0[3] == 4; + a0 = new double[5]; + assert a0.length == 5; + assert a0[0] + a0[1] + a0[2] + a0[3] + a0[4] == 0; + assert a1[0] + a1[1] + a1[2] + a1[3] == 4; + assert a1 == a2 && a2 == a3; + }) + }); + }); + }); + }); +} + +function main():void { + bool2Levels(); + bool4Levels(); + bool4LevelsBi(); + number4Levels(); + arrays(); +} diff --git a/ets2panda/test/runtime/ets/optional_field_variable.ets b/ets2panda/test/runtime/ets/optional_field_variable.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ad579abb7ff879a9bf4af72e1470d2b9c49539d --- /dev/null +++ b/ets2panda/test/runtime/ets/optional_field_variable.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 C { + once : boolean = true +} + +class A { + global : boolean | undefined = undefined + current : C | undefined + + foo () { + if (this.global == undefined) this.global = this.current?.once != true + } +} + +function main(): void { + let a = new A() + a.foo() + assert(a.global == true) + + a.global = undefined + a.current = new C() + a.foo() + assert(a.global == false) +} diff --git a/ets2panda/test/runtime/ets/type-check-for-logical-operators.ets b/ets2panda/test/runtime/ets/type-check-for-logical-operators.ets new file mode 100644 index 0000000000000000000000000000000000000000..84ee6e9fef30a22b0be3c6e3dc4568e5f4c13c74 --- /dev/null +++ b/ets2panda/test/runtime/ets/type-check-for-logical-operators.ets @@ -0,0 +1,29 @@ +/* + * 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 foo(inputBytes: number, size: number, byteOffset: number): string { + let blocks: number = 1; + + if ((blocks && !(byteOffset & 4) && !(size % inputBytes)) || !(byteOffset & 1)) { + return "bar"; + } + + return "baz"; +} + +function main() { + assert(foo(1, 1, 3) === "bar"); +} + diff --git a/ets2panda/test/test-lists/parser/parser-js-ignored.txt b/ets2panda/test/test-lists/parser/parser-js-ignored.txt index d4a6eab971aac9738e8b3b40efa183885ce7aab8..8c25b6543623b48dfaab605dcea3497970a962a5 100644 --- a/ets2panda/test/test-lists/parser/parser-js-ignored.txt +++ b/ets2panda/test/test-lists/parser/parser-js-ignored.txt @@ -26,9 +26,6 @@ compiler/ets/override3.ets compiler/ets/override4.ets compiler/ets/override5.ets -# 13086 -compiler/ets/dynamic_instanceof.ets - # Requires smart casts parser/ets/null-coalesc-negative.ets diff --git a/ets2panda/test/tsconfig/CMakeLists.txt b/ets2panda/test/tsconfig/CMakeLists.txt index a4eaa7e6c2a9dde0f84fb15295d1d0fa70495d1f..9dc75256341c8f65565dcc3d2c71bd66a02d0da1 100644 --- a/ets2panda/test/tsconfig/CMakeLists.txt +++ b/ets2panda/test/tsconfig/CMakeLists.txt @@ -11,6 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +if(NOT PANDA_REGRESSION_TESTS) + return() +endif() + function(add_es2panda_tsconfig_test tsproject) set(TSPROJECT_TARGET_NAME es2panda-tsconfig-test-${tsproject}) add_custom_target(${TSPROJECT_TARGET_NAME} diff --git a/ets2panda/test/unit/CMakeLists.txt b/ets2panda/test/unit/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4516e2a1f5cb69a3f1b746a89944828804613cde --- /dev/null +++ b/ets2panda/test/unit/CMakeLists.txt @@ -0,0 +1,43 @@ +# 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. + +if(NOT PANDA_REGRESSION_TESTS) + return() +endif() + +add_subdirectory(dynamic) +add_subdirectory(lowerings) +add_subdirectory(public) + +ets2panda_add_gtest(es2panda_astdumper_tests + CPP_SOURCES ast_dumper_test.cpp +) + +ets2panda_add_gtest(es2panda_union_normalization_tests + CPP_SOURCES union_normalization_test.cpp +) + +# NOTE: es2panda_rest_parameter_flag test runs a lot of time on qemu, so let's disable it +if (NOT PANDA_QEMU_BUILD) + ets2panda_add_gtest(es2panda_rest_parameter_flag + CPP_SOURCES rest_parameter_flag_test.cpp + ) +endif() + +if(NOT PANDA_WITH_ETS) + return() +endif() + +ets2panda_add_gtest(es2panda_checker_tests + CPP_SOURCES checker_test.cpp +) diff --git a/ets2panda/test/unit/dynamic/CMakeLists.txt b/ets2panda/test/unit/dynamic/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb987ef237a3d414ab15d17770ab6af906a49e21 --- /dev/null +++ b/ets2panda/test/unit/dynamic/CMakeLists.txt @@ -0,0 +1,16 @@ +# 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. + +ets2panda_add_gtest(es2panda_dynamic_call_test + CPP_SOURCES dynamic_call_test.cpp +) diff --git a/ets2panda/test/unit/dynamic/dynamic_call_test.cpp b/ets2panda/test/unit/dynamic/dynamic_call_test.cpp index ad7a3fa7fdb0d6479ee357f6681328f799b54bce..bc293db96b3ab574ee19e6d0fe9887684cc27733 100644 --- a/ets2panda/test/unit/dynamic/dynamic_call_test.cpp +++ b/ets2panda/test/unit/dynamic/dynamic_call_test.cpp @@ -23,6 +23,8 @@ #include "ir/ets/etsTypeReferencePart.h" #include "ir/ets/etsTypeReference.h" #include "ir/ts/tsQualifiedName.h" +#include "util/helpers.h" +#include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "util/language.h" #include "parser/ETSparser.h" @@ -77,13 +79,16 @@ public: void AddDynImport(const char *specifierName, varbinder::ETSBinder *varbinder, ir::Identifier *node) { auto aIdent = Allocator()->New(specifierName, Allocator()); + ArenaVector specifiers {Allocator()->Adapter()}; auto specifier = Allocator()->New(aIdent, aIdent); - auto importSrc = Allocator()->New(Allocator()->New(), + specifiers.emplace_back(specifier); + auto importSrc = Allocator()->New(Allocator()->New("/tmp"), Allocator()->New(), - Language::FromString("ets").value(), false); + Language::FromString("js").value(), false); auto importDecl = - Allocator()->New(importSrc, ArenaVector {Allocator()->Adapter()}); - varbinder->AddDynamicSpecifiersToTopBindings(specifier, importDecl); + util::NodeAllocator::Alloc(Allocator(), importSrc, std::move(specifiers)); + compiler::InitScopesPhaseETS::RunExternalNode(importDecl, varbinder); + varbinder->BuildImportDeclaration(importDecl); auto var = varbinder->TopScope()->Find(specifierName); node->SetVariable(var.variable); } diff --git a/ets2panda/test/unit/lowerings/CMakeLists.txt b/ets2panda/test/unit/lowerings/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8ccede80dd74122f90a9409fe2b8288f8df71635 --- /dev/null +++ b/ets2panda/test/unit/lowerings/CMakeLists.txt @@ -0,0 +1,20 @@ +# 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. + +if(NOT PANDA_WITH_ETS) + return() +endif() + +ets2panda_add_gtest(scopes_initialization_test + CPP_SOURCES scopes_initialization.cpp +) diff --git a/ets2panda/test/unit/public/CMakeLists.txt b/ets2panda/test/unit/public/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d43b311349b9412a25ea956e5ab9ab3be0cc347 --- /dev/null +++ b/ets2panda/test/unit/public/CMakeLists.txt @@ -0,0 +1,60 @@ +# 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. + +ets2panda_add_gtest(es2panda_public_test + CPP_SOURCES es2panda_public_test.cpp +) + +ets2panda_add_gtest(ast_verifier_short_test + CPP_SOURCES ast_verifier_short_test.cpp +) + +ets2panda_add_gtest(ast_verifier_private_protected_public_access_correct_test + CPP_SOURCES ast_verifier_private_protected_public_access_correct_test.cpp +) + +ets2panda_add_gtest(ast_verifier_private_access_negative_test_1_4 + CPP_SOURCES ast_verifier_private_access_negative_test_1_4.cpp +) + +ets2panda_add_gtest(ast_verifier_private_access_negative_test_5_7 + CPP_SOURCES ast_verifier_private_access_negative_test_5_7.cpp +) + +ets2panda_add_gtest(ast_verifier_protected_access_correct_test + CPP_SOURCES ast_verifier_protected_access_correct_test.cpp +) + +ets2panda_add_gtest(ast_verifier_protected_access_negative_test_1_3 + CPP_SOURCES ast_verifier_protected_access_negative_test_1_3.cpp +) + +ets2panda_add_gtest(ast_verifier_protected_access_negative_test_4_6 + CPP_SOURCES ast_verifier_protected_access_negative_test_4_6.cpp +) + +panda_add_library(e2p_test_plugin SHARED e2p_test_plugin.c) +panda_target_include_directories(e2p_test_plugin PRIVATE "${ES2PANDA_PATH}") +panda_target_link_libraries(e2p_test_plugin es2panda-public) + +add_custom_target(es2panda-plugin-test + COMMENT "Test es2panda plugin functionality" + COMMAND ${CMAKE_COMMAND} -E env + LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${PANDA_RUN_PREFIX} $ --plugins=e2p_test_plugin + "${CMAKE_CURRENT_SOURCE_DIR}/t.ets" > "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" + COMMAND ${CMAKE_COMMAND} -E compare_files + "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" "${CMAKE_CURRENT_SOURCE_DIR}/plugin_test.expected.txt" +) + +add_dependencies(es2panda-plugin-test es2panda e2p_test_plugin) +add_dependencies(es2panda_tests es2panda-plugin-test) diff --git a/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9fdfdeb220bef961f46963bbdb0ea2239e3805c6 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_1_4.cpp @@ -0,0 +1,174 @@ +/** + * 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. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative1) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base { + public b: int = this.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative2) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + function main(): void { + let base: Base = new Base(); + let a = base.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative3) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base {} + function main(): void { + let derived: Derived = new Derived(); + let a = derived.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative4) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base {} + function main(): void { + let derived: Base = new Derived(); + let a = derived.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42cbab0dd5951e93d340fd1d75dcfe68d8eb2e72 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_private_access_negative_test_5_7.cpp @@ -0,0 +1,179 @@ +/** + * 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. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative5) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public privateMethod() { + this.a = 2; + } + } + function main(): void { + let base: Base = new Base(); + base.privateMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative6) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public privateMethod() { + this.a = 2; + } + } + class Derived extends Base {} + function main(): void { + let derived: Derived = new Derived(); + derived.privateMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, PrivateAccessTestNegative7) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public privateMethod() { + this.a = 2; + } + } + class Derived extends Base {} + function main(): void { + let derived: Base = new Derived(); + derived.privateMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp b/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a8684a5585e60e3a88cf4b2dbd1aad58305be3f --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_private_protected_public_access_correct_test.cpp @@ -0,0 +1,82 @@ +/** + * 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. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::AstNode; + +constexpr char const *PRIVATE_PROTECTED_PUBLIC_TEST = + R"( + class Base { + public a: int = 1; + protected b: int = 2; + private c: int = 3; + public publicMethod() { + this.a = 4; + this.protectedMethod(); + this.privateMethod(); + } + protected protectedMethod() { + this.b = 5; + this.publicMethod(); + this.privateMethod(); + } + private privateMethod() { + this.c = 6; + this.publicMethod(); + this.protectedMethod(); + } + } + class Derived extends Base { + foo () { + this.a = 7; + this.b = 8; + this.publicMethod(); + this.protectedMethod(); + } + } + function main(): void { + let base: Base = new Base(); + let a = base.a; + base.publicMethod(); + let derived1: Derived = new Derived(); + let b = derived1.a; + derived1.publicMethod(); + derived1.foo(); + let derived2: Base = new Derived(); + let c = derived2.a; + derived2.publicMethod(); + } + )"; + +TEST_F(ASTVerifierTest, PrivateProtectedPublicAccessTestCorrect) +{ + ASTVerifier verifier {Allocator()}; + + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, PRIVATE_PROTECTED_PUBLIC_TEST, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + + ASSERT_EQ(messages.size(), 0); + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dccd77f94d8630a68c732e803378d469aac5f078 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_correct_test.cpp @@ -0,0 +1,57 @@ +/** + * 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. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, ProtectedAccessTestCorrect) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class A { + public a: int = 1; + } + class B extends A { + public b: int = this.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + + ASSERT_EQ(messages.size(), 0); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65f3c23ca23842be25ea1f70a7e425363bf8e1b2 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_1_3.cpp @@ -0,0 +1,137 @@ +/** + * 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. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative1) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + function main(): void { + let base: Base = new Base(); + let a = base.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative2) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base {} + function main(): void { + let derived: Derived = new Derived(); + let a = derived.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative3) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + } + class Derived extends Base {} + function main(): void { + let derived: Base = new Derived(); + let a = derived.a; + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[1] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[0] + ->AsClassProperty() + ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c74daea0485ec91b951e0f6699db46838b1f585 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_protected_access_negative_test_4_6.cpp @@ -0,0 +1,180 @@ +/** + * 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. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" + +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::ETSScript; + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative4) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public protectedMethod() { + this.a = 2; + } + } + function main(): void { + let base: Base = new Base(); + base.protectedMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative5) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public protectedMethod() { + this.a = 2; + } + } + class Derived extends Base {} + function main(): void { + let derived: Derived = new Derived(); + derived.protectedMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} + +TEST_F(ASTVerifierTest, ProtectedAccessTestNegative6) +{ + ASTVerifier verifier {Allocator()}; + + char const *text = R"( + class Base { + public a: int = 1; + public protectedMethod() { + this.a = 2; + } + } + class Derived extends Base {} + function main(): void { + let derived: Base = new Derived(); + derived.protectedMethod(); + } + )"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); + + auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); + + ast->AsETSScript() + ->Statements()[0] + ->AsClassDeclaration() + ->Definition() + ->AsClassDefinition() + ->Body()[1] + ->AsClassElement() + ->Value() + ->AsFunctionExpression() + ->Function() + ->AsScriptFunction() + ->Body() + ->AsBlockStatement() + ->Statements()[1] + ->AsExpressionStatement() + ->GetExpression() + ->AsCallExpression() + ->Signature() + ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); + + InvariantNameSet checks; + checks.insert("ModifierAccessValidForAll"); + + const auto &messages = verifier.Verify(ast, checks); + ASSERT_EQ(messages.size(), 1); + + ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); + + impl_->DestroyContext(ctx); +} diff --git a/ets2panda/test/unit/public/ast_verifier_short_test.cpp b/ets2panda/test/unit/public/ast_verifier_short_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a8add093ba9d65ddc6c8bae9206acd01b4f0c55 --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_short_test.cpp @@ -0,0 +1,265 @@ +/** + * 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. + */ + +#include "ast_verifier_test.h" +#include "checker/ETSchecker.h" +#include "ir/expressions/literals/stringLiteral.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/literals/numberLiteral.h" +#include "ir/expressions/literals/booleanLiteral.h" +#include "macros.h" +#include "parser/ETSparser.h" +#include "varbinder/ETSBinder.h" + +#include + +using ark::es2panda::CompilerOptions; +using ark::es2panda::ScriptExtension; +using ark::es2panda::checker::ETSChecker; +using ark::es2panda::compiler::ast_verifier::ASTVerifier; +using ark::es2panda::compiler::ast_verifier::InvariantNameSet; +using ark::es2panda::ir::BinaryExpression; +using ark::es2panda::ir::BooleanLiteral; +using ark::es2panda::ir::Expression; +using ark::es2panda::ir::Identifier; +using ark::es2panda::ir::NumberLiteral; +using ark::es2panda::ir::SequenceExpression; +using ark::es2panda::ir::StringLiteral; +using ark::es2panda::lexer::Number; +using ark::es2panda::lexer::TokenType; +using ark::es2panda::parser::ETSParser; +using ark::es2panda::parser::Program; +using ark::es2panda::util::StringView; +using ark::es2panda::varbinder::ETSBinder; +using ark::es2panda::varbinder::FunctionScope; +using ark::es2panda::varbinder::LetDecl; +using ark::es2panda::varbinder::LocalScope; +using ark::es2panda::varbinder::LocalVariable; +using ark::es2panda::varbinder::VariableFlags; + +TEST_F(ASTVerifierTest, NullParent) +{ + ark::es2panda::compiler::ast_verifier::ASTVerifier verifier {Allocator()}; + StringLiteral emptyNode; + + const auto check = "NodeHasParent"; + auto checks = ark::es2panda::compiler::ast_verifier::InvariantNameSet {}; + checks.insert(check); + const auto &messages = verifier.Verify(&emptyNode, checks); + bool hasParent = messages.empty(); + ASSERT_FALSE(hasParent); + ASSERT_EQ(messages.size(), 1); + + ASSERT_EQ(messages[0].Invariant(), check); +} + +TEST_F(ASTVerifierTest, NullRange) +{ + ark::es2panda::compiler::ast_verifier::ASTVerifier verifier {Allocator()}; + StringLiteral emptyNode; + + const auto check = "NodeHasSourceRange"; + auto checks = ark::es2panda::compiler::ast_verifier::InvariantNameSet {}; + checks.insert(check); + const auto &messages = verifier.Verify(&emptyNode, checks); + bool hasSourceRange = messages.empty(); + ASSERT_FALSE(hasSourceRange); + ASSERT_EQ(messages.size(), 1); + + ASSERT_EQ(messages[0].Invariant(), check); +} + +TEST_F(ASTVerifierTest, NullType) +{ + ASTVerifier verifier {Allocator()}; + StringLiteral emptyNode; + + auto check = "NodeHasType"; + auto checks = InvariantNameSet {}; + checks.insert(check); + const auto &messages = verifier.Verify(&emptyNode, checks); + bool hasType = messages.empty(); + ASSERT_EQ(hasType, false); + ASSERT_NE(messages.size(), 0); + + ASSERT_EQ(messages[0].Invariant(), check); +} + +TEST_F(ASTVerifierTest, WithoutScope) +{ + ASTVerifier verifier {Allocator()}; + StringLiteral emptyNode; + + auto checks = InvariantNameSet {}; + checks.insert("VariableHasScope"); + const auto &messages = verifier.Verify(&emptyNode, checks); + + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ScopeTest) +{ + ASTVerifier verifier {Allocator()}; + Identifier ident(StringView("var_decl"), Allocator()); + LetDecl decl("test", &ident); + LocalVariable local(&decl, VariableFlags::LOCAL); + ident.SetVariable(&local); + + LocalScope scope(Allocator(), nullptr); + FunctionScope parentScope(Allocator(), nullptr); + scope.SetParent(&parentScope); + scope.AddDecl(Allocator(), &decl, ScriptExtension::ETS); + scope.BindNode(&ident); + + local.SetScope(&scope); + + auto checks = InvariantNameSet {}; + checks.insert("VariableHasScope"); + const auto &messages = verifier.Verify(&ident, checks); + + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ScopeNodeTest) +{ + ASTVerifier verifier {Allocator()}; + Identifier ident(StringView("var_decl"), Allocator()); + LetDecl decl("test", &ident); + LocalVariable local(&decl, VariableFlags::LOCAL); + ident.SetVariable(&local); + + LocalScope scope(Allocator(), nullptr); + FunctionScope parentScope(Allocator(), nullptr); + scope.SetParent(&parentScope); + scope.AddDecl(Allocator(), &decl, ScriptExtension::ETS); + scope.BindNode(&ident); + parentScope.BindNode(&ident); + + local.SetScope(&scope); + + auto checks = InvariantNameSet {}; + checks.insert("VariableHasEnclosingScope"); + const auto &messages = verifier.Verify(&ident, checks); + + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ArithmeticExpressionCorrect1) +{ + ETSChecker etschecker {}; + ASTVerifier verifier {Allocator()}; + auto program = Program::NewProgram(Allocator()); + auto parser = ETSParser(&program, CompilerOptions {}); + + auto left = NumberLiteral(Number {1}); + auto right = NumberLiteral(Number {6}); + auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_PLUS); + + left.SetTsType(etschecker.GlobalIntType()); + right.SetTsType(etschecker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("ArithmeticOperationValid"); + const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ArithmeticExpressionCorrect2) +{ + ETSChecker etschecker {}; + ASTVerifier verifier {Allocator()}; + auto program = Program::NewProgram(Allocator()); + auto parser = ETSParser(&program, CompilerOptions {}); + + constexpr uint32_t LEFT1_PARAM = 1; + constexpr uint32_t LEFT2_PARAM = 12; + constexpr uint32_t RIGHT2_PARAM = 6; + auto left1 = NumberLiteral(Number {LEFT1_PARAM}); + auto left2 = NumberLiteral(Number {LEFT2_PARAM}); + auto right2 = NumberLiteral(Number {RIGHT2_PARAM}); + auto right1 = BinaryExpression(&left2, &right2, TokenType::PUNCTUATOR_MULTIPLY); + auto arithmeticExpression = BinaryExpression(&left1, &right1, TokenType::PUNCTUATOR_PLUS); + + left1.SetTsType(etschecker.GlobalIntType()); + right1.SetTsType(etschecker.GlobalIntType()); + left2.SetTsType(etschecker.GlobalIntType()); + right2.SetTsType(etschecker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("ArithmeticOperationValid"); + const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); + ASSERT_EQ(messages.size(), 0); +} + +TEST_F(ASTVerifierTest, ArithmeticExpressionNegative1) +{ + ETSChecker etschecker {}; + ASTVerifier verifier {Allocator()}; + auto program = Program::NewProgram(Allocator()); + auto parser = ETSParser(&program, CompilerOptions {}); + + const StringView leftParam("1"); + constexpr uint32_t RIGHT_PARAM = 1; + auto left = StringLiteral(leftParam); + auto right = NumberLiteral(Number {RIGHT_PARAM}); + auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_DIVIDE); + + left.SetTsType(etschecker.GlobalETSStringLiteralType()); + right.SetTsType(etschecker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("ArithmeticOperationValid"); + const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); + + ASSERT_EQ(messages.size(), 1); +} + +TEST_F(ASTVerifierTest, ArithmeticExpressionNegative2) +{ + ETSChecker etschecker {}; + ASTVerifier verifier {Allocator()}; + auto program = Program::NewProgram(Allocator()); + auto parser = ETSParser(&program, CompilerOptions {}); + auto left = BooleanLiteral(true); + auto right = NumberLiteral(Number {1}); + auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_DIVIDE); + + left.SetTsType(etschecker.GlobalETSStringLiteralType()); + right.SetTsType(etschecker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("ArithmeticOperationValid"); + const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); + + ASSERT_EQ(messages.size(), 1); +} + +TEST_F(ASTVerifierTest, SequenceExpressionType) +{ + ASTVerifier verifier {Allocator()}; + auto checker = ETSChecker(); + auto *last = Tree(Node(Number {3})); + auto *sequenceExpression = Tree(Node( + Nodes(Node(Number {1}), Node(Number {2}), last))); + + last->SetTsType(checker.GlobalIntType()); + sequenceExpression->SetTsType(checker.GlobalIntType()); + + auto checks = InvariantNameSet {}; + checks.insert("SequenceExpressionHasLastType"); + const auto &messages = verifier.Verify(sequenceExpression, checks); + + ASSERT_EQ(messages.size(), 0); +} diff --git a/ets2panda/test/unit/public/ast_verifier_test.cpp b/ets2panda/test/unit/public/ast_verifier_test.cpp deleted file mode 100644 index 7c82b31884166475bacf49cec7652481c9404445..0000000000000000000000000000000000000000 --- a/ets2panda/test/unit/public/ast_verifier_test.cpp +++ /dev/null @@ -1,1004 +0,0 @@ -/** - * 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. - */ - -#include "checker/ETSchecker.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/booleanLiteral.h" -#include "macros.h" -#include "parser/ETSparser.h" -#include "varbinder/ETSBinder.h" -#include "compiler/core/ASTVerifier.h" -#include "test/utils/panda_executable_path_getter.h" - -#include - -using ark::es2panda::CompilerOptions; -using ark::es2panda::ScriptExtension; -using ark::es2panda::checker::ETSChecker; -using ark::es2panda::compiler::ast_verifier::ASTVerifier; -using ark::es2panda::compiler::ast_verifier::InvariantNameSet; -using ark::es2panda::ir::AstNode; -using ark::es2panda::ir::BinaryExpression; -using ark::es2panda::ir::BooleanLiteral; -using ark::es2panda::ir::ETSScript; -using ark::es2panda::ir::Expression; -using ark::es2panda::ir::Identifier; -using ark::es2panda::ir::NumberLiteral; -using ark::es2panda::ir::SequenceExpression; -using ark::es2panda::ir::StringLiteral; -using ark::es2panda::lexer::Number; -using ark::es2panda::lexer::TokenType; -using ark::es2panda::parser::ETSParser; -using ark::es2panda::parser::Program; -using ark::es2panda::util::StringView; -using ark::es2panda::varbinder::ETSBinder; -using ark::es2panda::varbinder::FunctionScope; -using ark::es2panda::varbinder::LetDecl; -using ark::es2panda::varbinder::LocalScope; -using ark::es2panda::varbinder::LocalVariable; -using ark::es2panda::varbinder::VariableFlags; - -class ASTVerifierTest : public testing::Test { -public: - ASTVerifierTest() - { - impl_ = es2panda_GetImpl(ES2PANDA_LIB_VERSION); - auto es2pandaPath = test::utils::PandaExecutablePathGetter {}.Get(); - // NOLINTNEXTLINE(modernize-avoid-c-arrays) - char const *argv[] = {es2pandaPath.c_str()}; - cfg_ = impl_->CreateConfig(1, argv); - allocator_ = new ark::ArenaAllocator(ark::SpaceType::SPACE_TYPE_COMPILER); - } - ~ASTVerifierTest() override - { - delete allocator_; - impl_->DestroyConfig(cfg_); - } - - ark::ArenaAllocator *Allocator() - { - return allocator_; - } - - NO_COPY_SEMANTIC(ASTVerifierTest); - NO_MOVE_SEMANTIC(ASTVerifierTest); - -protected: - template - Type *Tree(Type *node) - { - return node; - } - - template - Type *Node(Args &&...args) - { - return allocator_->New(std::forward(args)...); - } - - template - ark::ArenaVector Nodes(Args &&...args) - { - auto v = ark::ArenaVector {allocator_->Adapter()}; - v.insert(v.end(), {std::forward(args)...}); - return v; - } - - // NOLINTBEGIN(misc-non-private-member-variables-in-classes) - es2panda_Impl const *impl_; - es2panda_Config *cfg_; - ark::ArenaAllocator *allocator_; - // NOLINTEND(misc-non-private-member-variables-in-classes) -}; - -TEST_F(ASTVerifierTest, NullParent) -{ - ark::es2panda::compiler::ast_verifier::ASTVerifier verifier {Allocator()}; - StringLiteral emptyNode; - - const auto check = "NodeHasParent"; - auto checks = ark::es2panda::compiler::ast_verifier::InvariantNameSet {}; - checks.insert(check); - const auto &messages = verifier.Verify(&emptyNode, checks); - bool hasParent = messages.empty(); - ASSERT_FALSE(hasParent); - ASSERT_EQ(messages.size(), 1); - - ASSERT_EQ(messages[0].Invariant(), check); -} - -TEST_F(ASTVerifierTest, NullRange) -{ - ark::es2panda::compiler::ast_verifier::ASTVerifier verifier {Allocator()}; - StringLiteral emptyNode; - - const auto check = "NodeHasSourceRange"; - auto checks = ark::es2panda::compiler::ast_verifier::InvariantNameSet {}; - checks.insert(check); - const auto &messages = verifier.Verify(&emptyNode, checks); - bool hasSourceRange = messages.empty(); - ASSERT_FALSE(hasSourceRange); - ASSERT_EQ(messages.size(), 1); - - ASSERT_EQ(messages[0].Invariant(), check); -} - -TEST_F(ASTVerifierTest, NullType) -{ - ASTVerifier verifier {Allocator()}; - StringLiteral emptyNode; - - auto check = "NodeHasType"; - auto checks = InvariantNameSet {}; - checks.insert(check); - const auto &messages = verifier.Verify(&emptyNode, checks); - bool hasType = messages.empty(); - ASSERT_EQ(hasType, false); - ASSERT_NE(messages.size(), 0); - - ASSERT_EQ(messages[0].Invariant(), check); -} - -TEST_F(ASTVerifierTest, WithoutScope) -{ - ASTVerifier verifier {Allocator()}; - StringLiteral emptyNode; - - auto checks = InvariantNameSet {}; - checks.insert("VariableHasScope"); - const auto &messages = verifier.Verify(&emptyNode, checks); - - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ScopeTest) -{ - ASTVerifier verifier {Allocator()}; - Identifier ident(StringView("var_decl"), Allocator()); - LetDecl decl("test", &ident); - LocalVariable local(&decl, VariableFlags::LOCAL); - ident.SetVariable(&local); - - LocalScope scope(Allocator(), nullptr); - FunctionScope parentScope(Allocator(), nullptr); - scope.SetParent(&parentScope); - scope.AddDecl(Allocator(), &decl, ScriptExtension::ETS); - scope.BindNode(&ident); - - local.SetScope(&scope); - - auto checks = InvariantNameSet {}; - checks.insert("VariableHasScope"); - const auto &messages = verifier.Verify(&ident, checks); - - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ScopeNodeTest) -{ - ASTVerifier verifier {Allocator()}; - Identifier ident(StringView("var_decl"), Allocator()); - LetDecl decl("test", &ident); - LocalVariable local(&decl, VariableFlags::LOCAL); - ident.SetVariable(&local); - - LocalScope scope(Allocator(), nullptr); - FunctionScope parentScope(Allocator(), nullptr); - scope.SetParent(&parentScope); - scope.AddDecl(Allocator(), &decl, ScriptExtension::ETS); - scope.BindNode(&ident); - parentScope.BindNode(&ident); - - local.SetScope(&scope); - - auto checks = InvariantNameSet {}; - checks.insert("VariableHasEnclosingScope"); - const auto &messages = verifier.Verify(&ident, checks); - - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ArithmeticExpressionCorrect1) -{ - ETSChecker etschecker {}; - ASTVerifier verifier {Allocator()}; - auto program = Program::NewProgram(Allocator()); - auto parser = ETSParser(&program, CompilerOptions {}); - - auto left = NumberLiteral(Number {1}); - auto right = NumberLiteral(Number {6}); - auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_PLUS); - - left.SetTsType(etschecker.GlobalIntType()); - right.SetTsType(etschecker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("ArithmeticOperationValid"); - const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ArithmeticExpressionCorrect2) -{ - ETSChecker etschecker {}; - ASTVerifier verifier {Allocator()}; - auto program = Program::NewProgram(Allocator()); - auto parser = ETSParser(&program, CompilerOptions {}); - - constexpr uint32_t LEFT1_PARAM = 1; - constexpr uint32_t LEFT2_PARAM = 12; - constexpr uint32_t RIGHT2_PARAM = 6; - auto left1 = NumberLiteral(Number {LEFT1_PARAM}); - auto left2 = NumberLiteral(Number {LEFT2_PARAM}); - auto right2 = NumberLiteral(Number {RIGHT2_PARAM}); - auto right1 = BinaryExpression(&left2, &right2, TokenType::PUNCTUATOR_MULTIPLY); - auto arithmeticExpression = BinaryExpression(&left1, &right1, TokenType::PUNCTUATOR_PLUS); - - left1.SetTsType(etschecker.GlobalIntType()); - right1.SetTsType(etschecker.GlobalIntType()); - left2.SetTsType(etschecker.GlobalIntType()); - right2.SetTsType(etschecker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("ArithmeticOperationValid"); - const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); - ASSERT_EQ(messages.size(), 0); -} - -TEST_F(ASTVerifierTest, ArithmeticExpressionNegative1) -{ - ETSChecker etschecker {}; - ASTVerifier verifier {Allocator()}; - auto program = Program::NewProgram(Allocator()); - auto parser = ETSParser(&program, CompilerOptions {}); - - const StringView leftParam("1"); - constexpr uint32_t RIGHT_PARAM = 1; - auto left = StringLiteral(leftParam); - auto right = NumberLiteral(Number {RIGHT_PARAM}); - auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_DIVIDE); - - left.SetTsType(etschecker.GlobalETSStringLiteralType()); - right.SetTsType(etschecker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("ArithmeticOperationValid"); - const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); - - ASSERT_EQ(messages.size(), 1); -} - -TEST_F(ASTVerifierTest, ArithmeticExpressionNegative2) -{ - ETSChecker etschecker {}; - ASTVerifier verifier {Allocator()}; - auto program = Program::NewProgram(Allocator()); - auto parser = ETSParser(&program, CompilerOptions {}); - auto left = BooleanLiteral(true); - auto right = NumberLiteral(Number {1}); - auto arithmeticExpression = BinaryExpression(&left, &right, TokenType::PUNCTUATOR_DIVIDE); - - left.SetTsType(etschecker.GlobalETSStringLiteralType()); - right.SetTsType(etschecker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("ArithmeticOperationValid"); - const auto &messages = verifier.Verify(arithmeticExpression.AsBinaryExpression(), checks); - - ASSERT_EQ(messages.size(), 1); -} - -TEST_F(ASTVerifierTest, SequenceExpressionType) -{ - ASTVerifier verifier {Allocator()}; - auto checker = ETSChecker(); - auto *last = Tree(Node(Number {3})); - auto *sequenceExpression = Tree(Node( - Nodes(Node(Number {1}), Node(Number {2}), last))); - - last->SetTsType(checker.GlobalIntType()); - sequenceExpression->SetTsType(checker.GlobalIntType()); - - auto checks = InvariantNameSet {}; - checks.insert("SequenceExpressionHasLastType"); - const auto &messages = verifier.Verify(sequenceExpression, checks); - - ASSERT_EQ(messages.size(), 0); -} - -constexpr char const *PRIVATE_PROTECTED_PUBLIC_TEST = - R"( - class Base { - public a: int = 1; - protected b: int = 2; - private c: int = 3; - public publicMethod() { - this.a = 4; - this.protectedMethod(); - this.privateMethod(); - } - protected protectedMethod() { - this.b = 5; - this.publicMethod(); - this.privateMethod(); - } - private privateMethod() { - this.c = 6; - this.publicMethod(); - this.protectedMethod(); - } - } - class Derived extends Base { - foo () { - this.a = 7; - this.b = 8; - this.publicMethod(); - this.protectedMethod(); - } - } - function main(): void { - let base: Base = new Base(); - let a = base.a; - base.publicMethod(); - let derived1: Derived = new Derived(); - let b = derived1.a; - derived1.publicMethod(); - derived1.foo(); - let derived2: Base = new Derived(); - let c = derived2.a; - derived2.publicMethod(); - } - )"; - -TEST_F(ASTVerifierTest, PrivateProtectedPublicAccessTestCorrect) -{ - ASTVerifier verifier {Allocator()}; - - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, PRIVATE_PROTECTED_PUBLIC_TEST, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - - ASSERT_EQ(messages.size(), 0); - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative1) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base { - public b: int = this.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative2) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - function main(): void { - let base: Base = new Base(); - let a = base.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative3) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base {} - function main(): void { - let derived: Derived = new Derived(); - let a = derived.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative4) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base {} - function main(): void { - let derived: Base = new Derived(); - let a = derived.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative5) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public privateMethod() { - this.a = 2; - } - } - function main(): void { - let base: Base = new Base(); - base.privateMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative6) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public privateMethod() { - this.a = 2; - } - } - class Derived extends Base {} - function main(): void { - let derived: Derived = new Derived(); - derived.privateMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, PrivateAccessTestNegative7) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public privateMethod() { - this.a = 2; - } - } - class Derived extends Base {} - function main(): void { - let derived: Base = new Derived(); - derived.privateMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PRIVATE); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestCorrect) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class A { - public a: int = 1; - } - class B extends A { - public b: int = this.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - - ASSERT_EQ(messages.size(), 0); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative1) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - function main(): void { - let base: Base = new Base(); - let a = base.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative2) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base {} - function main(): void { - let derived: Derived = new Derived(); - let a = derived.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative3) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - } - class Derived extends Base {} - function main(): void { - let derived: Base = new Derived(); - let a = derived.a; - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[1] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[0] - ->AsClassProperty() - ->AddModifier(ark::es2panda::ir::ModifierFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative4) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public protectedMethod() { - this.a = 2; - } - } - function main(): void { - let base: Base = new Base(); - base.protectedMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative5) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public protectedMethod() { - this.a = 2; - } - } - class Derived extends Base {} - function main(): void { - let derived: Derived = new Derived(); - derived.protectedMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} - -TEST_F(ASTVerifierTest, ProtectedAccessTestNegative6) -{ - ASTVerifier verifier {Allocator()}; - - char const *text = R"( - class Base { - public a: int = 1; - public protectedMethod() { - this.a = 2; - } - } - class Derived extends Base {} - function main(): void { - let derived: Base = new Derived(); - derived.protectedMethod(); - } - )"; - es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); - ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_CHECKED); - - auto *ast = reinterpret_cast(impl_->ProgramAst(impl_->ContextProgram(ctx))); - - ast->AsETSScript() - ->Statements()[0] - ->AsClassDeclaration() - ->Definition() - ->AsClassDefinition() - ->Body()[1] - ->AsClassElement() - ->Value() - ->AsFunctionExpression() - ->Function() - ->AsScriptFunction() - ->Body() - ->AsBlockStatement() - ->Statements()[1] - ->AsExpressionStatement() - ->GetExpression() - ->AsCallExpression() - ->Signature() - ->AddSignatureFlag(ark::es2panda::checker::SignatureFlags::PROTECTED); - - InvariantNameSet checks; - checks.insert("ModifierAccessValidForAll"); - - const auto &messages = verifier.Verify(ast, checks); - ASSERT_EQ(messages.size(), 1); - - ASSERT_NE(checks.find(messages[0].Invariant()), checks.end()); - - impl_->DestroyContext(ctx); -} diff --git a/ets2panda/test/unit/public/ast_verifier_test.h b/ets2panda/test/unit/public/ast_verifier_test.h new file mode 100644 index 0000000000000000000000000000000000000000..8fe3fb3e63f792e377122806f50da2130381ca8f --- /dev/null +++ b/ets2panda/test/unit/public/ast_verifier_test.h @@ -0,0 +1,77 @@ +/** + * 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. + */ + +#ifndef TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H +#define TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H + +#include "compiler/core/ASTVerifier.h" +#include "test/utils/panda_executable_path_getter.h" + +#include + +class ASTVerifierTest : public testing::Test { +public: + ASTVerifierTest() + { + impl_ = es2panda_GetImpl(ES2PANDA_LIB_VERSION); + auto es2pandaPath = test::utils::PandaExecutablePathGetter {}.Get(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) + char const *argv[] = {es2pandaPath.c_str()}; + cfg_ = impl_->CreateConfig(1, argv); + allocator_ = new ark::ArenaAllocator(ark::SpaceType::SPACE_TYPE_COMPILER); + } + ~ASTVerifierTest() override + { + delete allocator_; + impl_->DestroyConfig(cfg_); + } + + ark::ArenaAllocator *Allocator() + { + return allocator_; + } + + NO_COPY_SEMANTIC(ASTVerifierTest); + NO_MOVE_SEMANTIC(ASTVerifierTest); + +protected: + template + Type *Tree(Type *node) + { + return node; + } + + template + Type *Node(Args &&...args) + { + return allocator_->New(std::forward(args)...); + } + + template + ark::ArenaVector Nodes(Args &&...args) + { + auto v = ark::ArenaVector {allocator_->Adapter()}; + v.insert(v.end(), {std::forward(args)...}); + return v; + } + + // NOLINTBEGIN(misc-non-private-member-variables-in-classes) + es2panda_Impl const *impl_; + es2panda_Config *cfg_; + ark::ArenaAllocator *allocator_; + // NOLINTEND(misc-non-private-member-variables-in-classes) +}; + +#endif // TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H diff --git a/ets2panda/test/unit/rest_parameter_flag_test.cpp b/ets2panda/test/unit/rest_parameter_flag_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b92cf6453a623e6a941a89865df0b44874d15ec0 --- /dev/null +++ b/ets2panda/test/unit/rest_parameter_flag_test.cpp @@ -0,0 +1,383 @@ +/** + * 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. + */ + +#include + +#include "assembler/assembly-program.h" +#include "es2panda.h" +#include "generated/signatures.h" +#include "libpandabase/mem/mem.h" +#include "macros.h" +#include "mem/pool_manager.h" +#include "util/options.h" + +namespace ark::es2panda::compiler::test { + +class RestParameterTest : public testing::Test { +public: + RestParameterTest() + { + const auto compilerSize = 268435456; + + mem::MemConfig::Initialize(0, 0, compilerSize, 0, 0, 0); + PoolManager::Initialize(PoolType::MMAP); + } + ~RestParameterTest() override + { + PoolManager::Finalize(); + mem::MemConfig::Finalize(); + } + + void SetCurrentProgram(std::string_view src) + { + int argc = 1; + const char *argv = "../../../../bin/es2panda"; // NOLINT(modernize-avoid-c-arrays) + static constexpr std::string_view FILE_NAME = "dummy.ets"; + + program_ = GetProgram(argc, &argv, FILE_NAME, src); + ASSERT_NE(program_.get(), nullptr); + } + + void CheckRestParameterFlag(std::string_view functionName) + { + pandasm::Function *fn = GetFunction(functionName); + ASSERT_TRUE(fn != nullptr) << "Function '" << functionName << "' not found"; + ASSERT_TRUE(HasRestParameterFlag(fn)) << "Function '" << fn->name << "' doesn't have ACC_VARARGS flag"; + } + + void CheckNoRestParameterFlag(std::string_view functionName) + { + pandasm::Function *fn = GetFunction(functionName); + ASSERT_TRUE(fn != nullptr) << "Function '" << functionName << "' not found"; + ASSERT_FALSE(HasRestParameterFlag(fn)) << "Function '" << fn->name << "' has ACC_VARARGS flag"; + } + +private: + bool HasRestParameterFlag(pandasm::Function *fn) + { + return (fn->metadata->GetAccessFlags() & ACC_VARARGS) != 0; + } + + NO_COPY_SEMANTIC(RestParameterTest); + NO_MOVE_SEMANTIC(RestParameterTest); + + static std::unique_ptr GetProgram(int argc, const char **argv, std::string_view fileName, + std::string_view src) + { + auto options = std::make_unique(); + if (!options->Parse(argc, argv)) { + std::cerr << options->ErrorMsg() << std::endl; + return nullptr; + } + + Logger::ComponentMask mask {}; + mask.set(Logger::Component::ES2PANDA); + Logger::InitializeStdLogging(Logger::LevelFromString(options->LogLevel()), mask); + + es2panda::Compiler compiler(options->Extension(), options->ThreadCount()); + es2panda::SourceFile input(fileName, src, options->ParseModule()); + + return std::unique_ptr(compiler.Compile(input, options->CompilerOptions())); + } + + pandasm::Function *GetFunction(std::string_view functionName) + { + auto it = program_->functionTable.find(functionName.data()); + if (it == program_->functionTable.end()) { + return nullptr; + } + return &it->second; + } + +private: + std::unique_ptr program_ {}; +}; + +// === Function === +TEST_F(RestParameterTest, function_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + function fn(): void { + } + )"); + CheckNoRestParameterFlag("ETSGLOBAL.fn:void;"); +} + +TEST_F(RestParameterTest, function_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + function fn(args: int[]): void { + } + )"); + CheckNoRestParameterFlag("ETSGLOBAL.fn:i32[];void;"); +} + +TEST_F(RestParameterTest, function_without_rest_parameters_2) +{ + SetCurrentProgram(R"( + function fn(arg0: int, args: String[]): void { + } + )"); + CheckNoRestParameterFlag("ETSGLOBAL.fn:i32;std.core.String[];void;"); +} + +TEST_F(RestParameterTest, function_with_rest_parameter_0) +{ + SetCurrentProgram(R"( + function fn(...args: String[]): void { + } + )"); + CheckRestParameterFlag("ETSGLOBAL.fn:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, function_with_rest_parameter_1) +{ + SetCurrentProgram(R"( + function fn(o: Object, ...args: int[]): void { + } + )"); + CheckRestParameterFlag("ETSGLOBAL.fn:std.core.Object;i32[];void;"); +} + +// === Method of class === +TEST_F(RestParameterTest, class_method_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + fn() {}; + } + )"); + CheckNoRestParameterFlag("A.fn:void;"); +} + +TEST_F(RestParameterTest, class_method_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + fn(arg0: int) {}; + } + )"); + CheckNoRestParameterFlag("A.fn:i32;void;"); +} + +TEST_F(RestParameterTest, class_method_with_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + fn(...args: int[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:i32[];void;"); +} + +// === Static method of class === +TEST_F(RestParameterTest, static_class_method_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + static fn() {}; + } + )"); + CheckNoRestParameterFlag("A.fn:void;"); +} + +TEST_F(RestParameterTest, static_class_method_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + static fn(arg0: int) {}; + } + )"); + CheckNoRestParameterFlag("A.fn:i32;void;"); +} + +TEST_F(RestParameterTest, static_class_method_with_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + static fn(...args: int[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:i32[];void;"); +} + +TEST_F(RestParameterTest, static_class_method_with_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + static fn(a: String[], ...args: int[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:std.core.String[];i32[];void;"); +} + +// === Constructor of class === +TEST_F(RestParameterTest, class_constructor_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + constructor() {}; + } + )"); + CheckNoRestParameterFlag("A.:void;"); +} + +TEST_F(RestParameterTest, class_constructor_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + constructor(args: String[]) {}; + } + )"); + CheckNoRestParameterFlag("A.:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, class_constructor_with_rest_parameters_0) +{ + SetCurrentProgram(R"( + class A { + constructor(...args: int[]) {}; + } + )"); + CheckRestParameterFlag("A.:i32[];void;"); +} + +TEST_F(RestParameterTest, class_constructor_with_rest_parameters_1) +{ + SetCurrentProgram(R"( + class A { + constructor(v0: long, ...args: String[]) {}; + } + )"); + CheckRestParameterFlag("A.:i64;std.core.String[];void;"); +} + +// === Method of interface === +TEST_F(RestParameterTest, interface_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + interface A { + fn() {}; + } + )"); + CheckNoRestParameterFlag("A.fn:void;"); +} + +TEST_F(RestParameterTest, interface_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + interface A { + fn(args: String[]) {}; + } + )"); + CheckNoRestParameterFlag("A.fn:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, interface_with_rest_parameters_0) +{ + SetCurrentProgram(R"( + interface A { + fn(...args: Object[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:std.core.Object[];void;"); +} + +TEST_F(RestParameterTest, interface_with_rest_parameters_1) +{ + SetCurrentProgram(R"( + interface A { + fn(o: Object, ...args: String[]) {}; + } + )"); + CheckRestParameterFlag("A.fn:std.core.Object;std.core.String[];void;"); +} + +// === Lambda method === +TEST_F(RestParameterTest, lambda_without_rest_parameters_0) +{ + SetCurrentProgram(R"( + let fn: ()=>int = (): int => { + return 1; + } + )"); + CheckNoRestParameterFlag("LambdaObject-ETSGLOBAL-lambda$invoke$0-i32-0.invoke:i32;"); +} + +TEST_F(RestParameterTest, lambda_without_rest_parameters_1) +{ + SetCurrentProgram(R"( + let fn: (args: long[])=>int = (args: long[]): int => { + return 1; + } + )"); + CheckNoRestParameterFlag("LambdaObject-ETSGLOBAL-lambda$invoke$0-i64[]-i32-0.invoke:i64[];i32;"); +} + +// === Abstract method of abstract class === +TEST_F(RestParameterTest, abstract_function_without_rest_parameter_0) +{ + SetCurrentProgram(R"( + abstract class A { + abstract fn(): void + } + )"); + CheckNoRestParameterFlag("A.fn:void;"); +} + +TEST_F(RestParameterTest, abstract_function_without_rest_parameter_1) +{ + SetCurrentProgram(R"( + abstract class A { + abstract fn(args: String[]): void + } + )"); + CheckNoRestParameterFlag("A.fn:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, abstract_function_with_rest_parameter_0) +{ + SetCurrentProgram(R"( + abstract class A { + abstract fn(...args: String[]): void + } + )"); + CheckRestParameterFlag("A.fn:std.core.String[];void;"); +} + +TEST_F(RestParameterTest, abstract_function_with_rest_parameter_1) +{ + SetCurrentProgram(R"( + abstract class A { + abstract fn(v: int, ...args: String[]): void + } + )"); + CheckRestParameterFlag("A.fn:i32;std.core.String[];void;"); +} + +// === External methods === +TEST_F(RestParameterTest, external_function_with_rest_parameter_0) +{ + SetCurrentProgram(""); + CheckRestParameterFlag("std.core.LambdaValue.invoke:std.core.Object[];std.core.Object;"); +} + +TEST_F(RestParameterTest, external_function_with_rest_parameter_1) +{ + SetCurrentProgram(""); + CheckRestParameterFlag("escompat.Math.max:f64[];f64;"); +} + +} // namespace ark::es2panda::compiler::test diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 8fcb6880885515efaff4d468c981734510167d3c..6d6172564603c8c44aeddbee7f27b07c43f6b723 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -438,13 +438,9 @@ void ETSBinder::AddDynamicSpecifiersToTopBindings(ir::AstNode *const specifier, return specifier->AsImportSpecifier()->Local()->Name(); }(); - auto *const decl = Allocator()->New(name, specifier); - auto *const var = Allocator()->New(decl, varbinder::VariableFlags::STATIC); - var->AddFlag(VariableFlags::INITIALIZED); - - dynamicImportVars_.emplace(var, DynamicImportData {import, specifier, var}); - - TopScope()->InsertDynamicBinding(name, var); + ASSERT(GetScope()->Find(name, ResolveBindingOptions::DECLARATION).variable != nullptr); + auto specDecl = GetScope()->Find(name, ResolveBindingOptions::DECLARATION); + dynamicImportVars_.emplace(specDecl.variable, DynamicImportData {import, specifier, specDecl.variable}); } void ETSBinder::InsertForeignBinding(ir::AstNode *const specifier, const ir::ETSImportDeclaration *const import, @@ -512,7 +508,7 @@ bool ETSBinder::AddImportNamespaceSpecifiersToTopBindings(ir::AstNode *const spe } for (auto it : item->GetETSImportDeclarations()->Specifiers()) { - if (it->IsImportNamespaceSpecifier() && !specifier->AsImportNamespaceSpecifier()->Local()->Name().Empty()) { + if (it->IsImportNamespaceSpecifier() && !namespaceSpecifier->Local()->Name().Empty()) { continue; } @@ -604,13 +600,6 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(ir::AstNode *const specifier, return false; } const ir::StringLiteral *const importPath = import->Source(); - auto insertForeignBinding = [this, specifier, import](const util::StringView &name, Variable *var) { - if (import->Language().IsDynamic()) { - dynamicImportVars_.emplace(var, DynamicImportData {import, specifier, var}); - } - - TopScope()->InsertForeignBinding(name, var); - }; const auto *const importSpecifier = specifier->AsImportSpecifier(); @@ -659,12 +648,16 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(ir::AstNode *const specifier, if (var->Declaration()->Node()->IsDefaultExported()) { ThrowError(importPath->Start(), "Use the default import syntax to import a default exported element"); } + if (import->IsTypeKind() && !var->Declaration()->Node()->IsExportedType()) { + ThrowError(importPath->Start(), + "Cannot import '" + imported.Mutf8() + "', imported type imports only exported types."); + } - if (!var->Declaration()->Node()->IsExported()) { + if (!var->Declaration()->Node()->IsExported() && !var->Declaration()->Node()->IsExportedType()) { ThrowError(importPath->Start(), "Imported element not exported '" + var->Declaration()->Name().Mutf8() + "'"); } - insertForeignBinding(localName, var); + InsertForeignBinding(specifier, import, localName, var); return true; } @@ -716,14 +709,6 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i const auto *const importGlobalScope = importProgram->GlobalScope(); const auto &globalBindings = importGlobalScope->Bindings(); - auto insertForeignBinding = [this, specifier, import](const util::StringView &name, Variable *var) { - if (import->Language().IsDynamic()) { - dynamicImportVars_.emplace(var, DynamicImportData {import, specifier, var}); - } - - TopScope()->InsertForeignBinding(name, var); - }; - if (AddImportNamespaceSpecifiersToTopBindings(specifier, globalBindings, importProgram, importGlobalScope, import)) { return; @@ -738,12 +723,12 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i auto item = std::find_if(globalBindings.begin(), globalBindings.end(), predicateFunc); if (item == globalBindings.end()) { - insertForeignBinding(specifier->AsImportDefaultSpecifier()->Local()->Name(), + InsertForeignBinding(specifier, import, specifier->AsImportDefaultSpecifier()->Local()->Name(), FindStaticBinding(record, importPath)); return; } - insertForeignBinding(specifier->AsImportDefaultSpecifier()->Local()->Name(), item->second); + InsertForeignBinding(specifier, import, specifier->AsImportDefaultSpecifier()->Local()->Name(), item->second); } void ETSBinder::HandleCustomNodes(ir::AstNode *childNode) diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index d6bb722e4254d40327f82bdd71517638f1504b78..f89de5345d1570e9817c62c525ab798fe6cf3fdd 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -73,6 +73,17 @@ const VariableScope *Scope::EnclosingVariableScope() const return nullptr; } +bool Scope::IsSuperscopeOf(const varbinder::Scope *subscope) const +{ + while (subscope != nullptr) { + if (subscope == this) { + return true; + } + subscope = ir::AstNode::EnclosingScope(subscope->Node()->Parent()); + } + return false; +} + // NOTE(psiket): Duplication ClassScope *Scope::EnclosingClassScope() { @@ -551,7 +562,7 @@ Scope::InsertResult GlobalScope::InsertImpl(const util::StringView &name, Variab if (!isDynamic && isForeign && !var->Declaration()->Name().Is(compiler::Signatures::ETS_GLOBAL)) { const auto *const node = var->Declaration()->Node(); - if (!(node->IsExported() || node->IsDefaultExported())) { + if (!(node->IsExported() || node->IsDefaultExported() || node->IsExportedType())) { return Scope::InsertResult {Bindings().end(), false}; } } diff --git a/ets2panda/varbinder/scope.h b/ets2panda/varbinder/scope.h index 0aa277b0b4b33d3952a5e3e4901f20cf40ffc32c..5876e9fd9ac07648785ca1de3221ee82fb02f76f 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -260,6 +260,8 @@ public: virtual Variable *FindLocal(const util::StringView &name, ResolveBindingOptions options) const; + bool IsSuperscopeOf(const varbinder::Scope *subscope) const; + ConstScopeFindResult Find(const util::StringView &name, ResolveBindingOptions options = ResolveBindingOptions::BINDINGS) const;