From fa2d65f39d19a5cd27ec394089a0d9b3dfab8d2d Mon Sep 17 00:00:00 2001 From: Anton Berezin Date: Fri, 15 Dec 2023 12:33:57 +0400 Subject: [PATCH 01/48] project-wide: put initial enum refactoring code. Signed-off-by: Anton Berezin --- ets2panda/CMakeLists.txt | 1 + ets2panda/checker/ETSAnalyzer.cpp | 3 + ets2panda/checker/ets/arithmetic.cpp | 9 + ets2panda/checker/ets/helpers.cpp | 13 + ets2panda/checker/ets/typeCreation.cpp | 19 + ets2panda/checker/types/ets/etsEnumType.cpp | 112 + ets2panda/checker/types/ets/etsEnumType.h | 36 + ets2panda/checker/types/ets/etsObjectType.h | 2 + ets2panda/checker/types/type.h | 19 + ets2panda/checker/types/typeFlag.h | 4 +- ets2panda/compiler/core/ETSCompiler.cpp | 3 +- ets2panda/compiler/core/ETSGen.cpp | 18 +- ets2panda/compiler/core/ETSGen.h | 1 + .../compiler/lowering/ets/enumLowering.cpp | 394 ++ .../compiler/lowering/ets/enumLowering.h | 31 + ets2panda/compiler/lowering/phase.cpp | 3 + .../test/compiler/ets/enums_01-expected.txt | 2583 ++++++++- .../ets/from-soft-keyword-3-expected.txt | 2353 ++++++++- .../test/compiler/ets/from-soft-keyword-3.ets | 1 + ...lambda_infer_type_retrun_enum-expected.txt | 2031 +++++++- ets2panda/test/parser/ets/enum-expected.txt | 2300 +++++++- ets2panda/test/parser/ets/enum10-expected.txt | 1773 ++++++- ets2panda/test/parser/ets/enum10.ets | 2 +- ets2panda/test/parser/ets/enum11-expected.txt | 1885 ++++++- ets2panda/test/parser/ets/enum11.ets | 2 +- ets2panda/test/parser/ets/enum12-expected.txt | 1774 ++++++- ets2panda/test/parser/ets/enum13-expected.txt | 1774 ++++++- ets2panda/test/parser/ets/enum14-expected.txt | 2300 +++++++- ets2panda/test/parser/ets/enum19-expected.txt | 2300 +++++++- ets2panda/test/parser/ets/enum20-expected.txt | 2585 ++++++++- ets2panda/test/parser/ets/enum21-expected.txt | 2039 +++++++- ets2panda/test/parser/ets/enum22-expected.txt | 2 +- ets2panda/test/parser/ets/enum23-expected.txt | 2 +- ets2panda/test/parser/ets/enum4-expected.txt | 1768 ++++++- ets2panda/test/parser/ets/enum6-expected.txt | 2301 +++++++- ets2panda/test/parser/ets/enum6.ets | 2 +- ets2panda/test/parser/ets/enum7-expected.txt | 3592 ++++++++++++- ets2panda/test/parser/ets/enum8-expected.txt | 3592 ++++++++++++- ets2panda/test/parser/ets/enum9-expected.txt | 1774 ++++++- ...n_function_not_for_class_type-expected.txt | 1781 ++++++- .../test/parser/ets/switch_enum-expected.txt | 2302 +++++++- .../test/parser/ets/switch_enum2-expected.txt | 2300 +++++++- .../parser/ets/switch_enum_3-expected.txt | 2300 +++++++- .../switch_enum_case_duplicate-expected.txt | 2302 +++++++- ...eadonly_member_different_enum-expected.txt | 4630 +++++++++++++++- ...donly_member_different_enum_2-expected.txt | 4630 +++++++++++++++- .../switch_readonly_member_enum-expected.txt | 4630 +++++++++++++++- ...eadonly_member_enum_duplicate-expected.txt | 4632 ++++++++++++++++- 48 files changed, 65999 insertions(+), 2911 deletions(-) create mode 100644 ets2panda/compiler/lowering/ets/enumLowering.cpp create mode 100644 ets2panda/compiler/lowering/ets/enumLowering.h diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 386212ba63..b3311884b8 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -150,6 +150,7 @@ set(ES2PANDA_LIB_SRC compiler/lowering/phase.cpp compiler/lowering/plugin_phase.cpp compiler/lowering/util.cpp + compiler/lowering/ets/enumLowering.cpp compiler/lowering/ets/lambdaLowering.cpp compiler/lowering/ets/generateDeclarations.cpp compiler/lowering/ets/objectIndexAccess.cpp diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 7917598b0e..05c55de407 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2451,6 +2451,9 @@ checker::Type *ETSAnalyzer::Check(ir::SwitchStatement *st) const } else if (caseType->IsETSStringEnumType() && st->Discriminant()->TsType()->IsETSStringEnumType()) { validCaseType = st->Discriminant()->TsType()->AsETSStringEnumType()->IsSameEnumType( caseType->AsETSStringEnumType()); + } else if (caseType->IsETSEnum2Type() && st->Discriminant()->TsType()->IsETSEnum2Type()) { + validCaseType = + st->Discriminant()->TsType()->AsETSEnum2Type()->IsSameEnumType(caseType->AsETSEnum2Type()); } else { checker::AssignmentContext( checker->Relation(), st->discriminant_, caseType, unboxedDiscType, it->Test()->Start(), diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index ee308f3424..f387cac137 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -394,6 +394,15 @@ std::tuple ETSChecker::CheckBinaryOperatorEqual( return {tsType, leftType}; } + if (leftType->IsETSEnum2Type() && rightType->IsETSEnum2Type()) { + if (!leftType->AsETSEnum2Type()->IsSameEnumType(rightType->AsETSEnum2Type())) { + ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); + } + + tsType = GlobalETSBooleanType(); + return {tsType, leftType}; + } + if (leftType->IsETSStringEnumType() && rightType->IsETSStringEnumType()) { if (!leftType->AsETSStringEnumType()->IsSameEnumType(rightType->AsETSStringEnumType())) { ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index a4e7677631..acd4f211f9 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1699,6 +1699,11 @@ void ETSChecker::CheckSwitchDiscriminant(ir::Expression *discriminant) return; } + if (discriminantType->IsETSObjectType() && + discriminantType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::ENUM2)) { + return; + } + if (discriminantType->IsETSObjectType() && discriminantType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::VALID_SWITCH_TYPE)) { if (discriminantType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE)) { @@ -1993,6 +1998,14 @@ void ETSChecker::CheckForSameSwitchCases(ArenaVector continue; } + if (caseTest->TsType()->IsETSEnum2Type()) { + ASSERT(compareCaseTest->TsType()->IsETSEnum2Type()); + if (caseTest->TsType()->AsETSEnum2Type()->IsSameEnumLiteralType( + compareCaseTest->TsType()->AsETSEnum2Type())) { + ThrowTypeError("Case enum duplicate", caseTest->Start()); + } + continue; + } if (caseTest->IsIdentifier() || caseTest->IsMemberExpression()) { CheckIdentifierSwitchCase(caseTest, compareCaseTest, cases->at(caseNum)->Start()); continue; diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index b02188e7a1..5e30c2f6d1 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -492,6 +492,20 @@ ETSStringEnumType *ETSChecker::CreateETSStringEnumType(ir::TSEnumDeclaration con return enumType; } +bool isEnumClass(ir::AstNode *declNode) +{ + if (declNode->IsClassDefinition() && (declNode->AsClassDefinition()->Super() != nullptr) && + declNode->AsClassDefinition()->Super()->IsETSTypeReference()) { + auto superType = declNode->AsClassDefinition()->Super()->AsETSTypeReference(); + auto typeName = superType->BaseName()->Name(); + + if (typeName == "EnumIntType" || typeName == "EnumStrType") { + return true; + } + } + return false; +} + ETSObjectType *ETSChecker::CreateNewETSObjectType(util::StringView name, ir::AstNode *declNode, ETSObjectFlags flags) { util::StringView assemblerName = name; @@ -544,6 +558,11 @@ ETSObjectType *ETSChecker::CreateNewETSObjectType(util::StringView name, ir::Ast ; } + if (isEnumClass(declNode)) { + auto ret = Allocator()->New(this, name, assemblerName, declNode, flags); + return ret; + } + return Allocator()->New(Allocator(), name, assemblerName, declNode, flags, Relation()); } diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index 762dafb27f..bcfeb079fc 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -328,4 +328,116 @@ ETSFunctionType *ETSEnumInterface::LookupTypeMethod(ETSChecker *const checker, c checker->ThrowTypeError({"No enum type method called '", prop->Name(), "'"}, prop->Start()); } +std::string EnumDescription(util::StringView name) +{ + return "#Enum#" + static_cast(name); +} + +ETSEnum2Type::ETSEnum2Type(ETSChecker *checker, util::StringView name, util::StringView assembler_name, + ir::AstNode *decl_node, ETSObjectFlags flags) + : ETSObjectType(checker->Allocator(), name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2) +{ + AddTypeFlag(TypeFlag::ETS_ENUM2); + CreateLiteralTypes(checker, name, assembler_name, decl_node, flags); +} + +ETSEnum2Type::ETSEnum2Type(ArenaAllocator *allocator, util::StringView name, util::StringView assembler_name, + ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value) + : ETSObjectType(allocator, name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2), value_(value) +{ + AddTypeFlag(TypeFlag::ETS_ENUM2); + ASSERT(value); +} + +bool ETSEnum2Type::IsSameEnumType(const ETSEnum2Type *const other) const noexcept +{ + return GetDeclNode() != nullptr && other->GetDeclNode() == GetDeclNode(); +} + +bool ETSEnum2Type::IsLiteralType() const noexcept +{ + return value_ != nullptr; +} + +bool ETSEnum2Type::IsSameEnumLiteralType(const ETSEnum2Type *other) const noexcept +{ + ASSERT(IsLiteralType() && IsSameEnumType(other)); + return value_ == other->value_; +} + +bool ETSEnum2Type::AssignmentSource(TypeRelation *const relation, Type *const target) +{ + bool result = target->IsETSEnum2Type() && IsSameEnumType(target->AsETSEnum2Type()); + relation->Result(result); + return relation->IsTrue(); +} + +void ETSEnum2Type::AssignmentTarget(TypeRelation *const relation, Type *const source) +{ + bool result = source->IsETSEnum2Type() && IsSameEnumType(source->AsETSEnum2Type()); + relation->Result(result); +} + +void ETSEnum2Type::Identical(TypeRelation *const relation, Type *const other) +{ + bool result = + other->IsETSEnum2Type() && IsSameEnumType(other->AsETSEnum2Type()) && value_ == other->AsETSEnum2Type()->value_; + relation->Result(result); +} + +void ETSEnum2Type::Cast(TypeRelation *relation, Type *target) +{ + if (target->IsIntType()) { + relation->Result(true); + return; + } + + conversion::Forbidden(relation); +} + +void ETSEnum2Type::CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assembler_name, + ir::AstNode *decl_node, ETSObjectFlags flags) +{ + ASSERT(decl_node->IsClassDefinition()); + + for (auto &it : decl_node->AsClassDefinition()->Body()) { + if (!it->IsClassProperty() || !it->AsClassProperty()->Value()->IsCallExpression()) { + // @@arr property + auto *arr_ident = it->AsClassProperty()->Id(); + auto *arr_var = arr_ident->Variable(); + ASSERT(arr_ident->Name() == "@@arr" && arr_var != nullptr); + + auto *array_type = checker->CreateETSArrayType(this); + array_type->SetVariable(arr_var); + arr_var->SetTsType(array_type); + + break; + } + + // if (decl_node->IsClassDefinition()) continue; + + auto *ident = it->AsClassProperty()->Id(); + auto *var = ident->Variable(); + auto &create_args = it->AsClassProperty()->Value()->AsCallExpression()->Arguments(); + ASSERT(create_args.size() == 4); + auto *value = create_args[2]; + + ir::Literal *literal = nullptr; + if (value->IsNumberLiteral()) { + literal = value->AsNumberLiteral(); + } else if (value->IsStringLiteral()) { + literal = value->AsStringLiteral(); + } else { + UNREACHABLE(); + } + + auto *enum_literal_type = + Allocator()->New(checker->Allocator(), name, assembler_name, decl_node, flags, literal); + + enum_literal_type->SetVariable(var); + var->SetTsType(enum_literal_type); + + checker->GetSuperType(enum_literal_type); + } +} } // namespace ark::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index 2125b1ad76..a03966d24d 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -19,6 +19,7 @@ #include "checker/types/type.h" #include "ir/base/property.h" #include "ir/ts/tsEnumDeclaration.h" +#include "checker/types/ets/etsObjectType.h" template // NOLINTNEXTLINE(readability-identifier-naming) @@ -214,6 +215,41 @@ public: ETSStringEnumType() = delete; ~ETSStringEnumType() override = default; }; + +std::string EnumDescription(util::StringView name); + +// TODO(aber) rename ETSEnum2Type after removal old code +class ETSEnum2Type : public ETSObjectType { +public: + ETSEnum2Type(ETSChecker *checker, util::StringView name, util::StringView assembler_name, ir::AstNode *decl_node, + ETSObjectFlags flags); + + ETSEnum2Type(ArenaAllocator *allocator, util::StringView name, util::StringView assembler_name, + ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value); + + bool IsSameEnumType(const ETSEnum2Type *other) const noexcept; + + bool IsLiteralType() const noexcept; + + bool IsSameEnumLiteralType(const ETSEnum2Type *other) const noexcept; + + bool AssignmentSource(TypeRelation *relation, Type *target) override; + void AssignmentTarget(TypeRelation *relation, Type *source) override; + void Identical(TypeRelation *relation, Type *other) override; + + void Cast(TypeRelation *relation, Type *target) override; + + static constexpr std::string_view GetIndexMethodName() + { + return "std.core.EnumConst.getIndex:i32;"; // TODO(aber) signatures.yaml + } + +private: + void CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assembler_name, + ir::AstNode *decl_node, ETSObjectFlags flags); + + ir::Literal *value_ = nullptr; +}; } // namespace ark::es2panda::checker #endif diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 24d5b1b019..ca9235e4ce 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -56,6 +56,8 @@ enum class ETSObjectFlags : uint32_t { BUILTIN_FLOAT = 1U << 30U, BUILTIN_DOUBLE = 1U << 31U, + ENUM2 = 1U << 21U, // TODO(aber) rename after removal code with ENUM (is it needed at all?!) + UNBOXABLE_TYPE = BUILTIN_BOOLEAN | BUILTIN_BYTE | BUILTIN_CHAR | BUILTIN_SHORT | BUILTIN_INT | BUILTIN_LONG | BUILTIN_FLOAT | BUILTIN_DOUBLE, BUILTIN_TYPE = BUILTIN_STRING | BUILTIN_BIGINT | UNBOXABLE_TYPE, diff --git a/ets2panda/checker/types/type.h b/ets2panda/checker/types/type.h index e66d11f301..ae910c525a 100644 --- a/ets2panda/checker/types/type.h +++ b/ets2panda/checker/types/type.h @@ -37,6 +37,7 @@ class ETSAsyncFuncReturnType; class ETSChecker; class ETSDynamicFunctionType; class ETSTypeParameter; +class ETSEnum2Type; // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DECLARE_TYPENAMES(typeFlag, typeName) class typeName; @@ -133,6 +134,24 @@ public: return reinterpret_cast(this); } + // TODO(aber) rename after + bool IsETSEnum2Type() const + { + return IsETSObjectType() && HasTypeFlag(TypeFlag::ETS_ENUM2); + } + + ETSEnum2Type *AsETSEnum2Type() + { + ASSERT(IsETSEnum2Type()); + return reinterpret_cast(this); + } + + const ETSEnum2Type *AsETSEnum2Type() const + { + ASSERT(IsETSEnum2Type()); + return reinterpret_cast(this); + } + ETSAsyncFuncReturnType *AsETSAsyncFuncReturnType() { ASSERT(IsETSAsyncFuncReturnType()); diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index ef3a9323e2..fe3e7cfa8b 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -84,11 +84,13 @@ enum class TypeFlag : uint64_t { ETS_NULL = 1ULL << 59ULL, // ETS null ETS_UNDEFINED = 1ULL << 60ULL, // ETS undefined ETS_NONNULLISH = 1ULL << 61ULL, // ETS nonnullish type parameter + ETS_ENUM2 = 1ULL << 62ULL, // ETS Enum TODO(aber) rename after removal old ETS_DYNAMIC_TYPE = ETS_OBJECT | ETS_DYNAMIC_FLAG, + ETS_ENUM2_TYPE = ETS_OBJECT | ETS_ENUM2, // ETS Enum TODO(aber) rename ETS_DYNAMIC_FUNCTION_TYPE = FUNCTION | ETS_DYNAMIC_FLAG, ETS_TYPE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID | ETS_OBJECT | ETS_ARRAY | WILDCARD | ETS_TYPE_PARAMETER | ETS_ENUM | ETS_STRING_ENUM | ETS_DYNAMIC_TYPE | ETS_UNION | ETS_NULL | - ETS_UNDEFINED | ETS_NONNULLISH, + ETS_UNDEFINED | ETS_NONNULLISH | ETS_ENUM2_TYPE, ETS_PRIMITIVE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID, ETS_PRIMITIVE_RETURN = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_ENUM, ETS_ARRAY_INDEX = BYTE | SHORT | INT, diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index e7c26b723e..75069c7119 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -2048,7 +2048,8 @@ void ETSCompiler::CompileCast(const ir::TSAsExpression *expr) const case checker::TypeFlag::ETS_NONNULLISH: case checker::TypeFlag::ETS_UNION: case checker::TypeFlag::ETS_NULL: - case checker::TypeFlag::ETS_UNDEFINED: { + case checker::TypeFlag::ETS_UNDEFINED: + case checker::TypeFlag::ETS_ENUM2_TYPE: { etsg->CastToReftype(expr, targetType, expr->isUncheckedCast_); break; } diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 1d6a51b9ab..dc92370b8c 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -41,6 +41,7 @@ #include "checker/ETSchecker.h" #include "checker/ets/boxingConverter.h" #include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsEnumType.h" #include "checker/types/ets/types.h" #include "parser/program/program.h" @@ -649,10 +650,10 @@ void ETSGen::CreateLambdaObjectFromMemberReference(const ir::AstNode *node, ir:: } // NOLINTBEGIN(cppcoreguidelines-macro-usage, readability-container-size-empty) -#define CONV_LAMBDA_CTOR_ARG(idx) \ - ASSERT((idx) < arguments.size()); \ - auto *paramType##idx = signature->Params()[(idx)]->TsType(); \ - auto ttctx##idx = TargetTypeContext(this, paramType##idx); \ +#define CONV_LAMBDA_CTOR_ARG(idx) \ + ASSERT((idx) < arguments.size()); \ + auto *paramType##idx = signature->Params()[(idx)] -> TsType(); \ + auto ttctx##idx = TargetTypeContext(this, paramType##idx); \ ApplyConversion(node, paramType##idx) void ETSGen::InitLambdaObject(const ir::AstNode *node, checker::Signature *signature, std::vector &arguments) @@ -1724,6 +1725,14 @@ void ETSGen::CastToInt(const ir::AstNode *node) Sa().Emit(node); break; } + case checker::TypeFlag::ETS_ENUM2_TYPE: { + RegScope rs(this); + VReg obj_reg = AllocReg(); + StoreAccumulator(node, obj_reg); + Ra().Emit(node, checker::ETSEnum2Type::GetIndexMethodName(), obj_reg, dummy_reg_); + + break; + } default: { UNREACHABLE(); } @@ -2635,6 +2644,7 @@ void ETSGen::StoreArrayElement(const ir::AstNode *node, VReg objectReg, VReg ind case checker::TypeFlag::ETS_OBJECT: case checker::TypeFlag::ETS_TYPE_PARAMETER: case checker::TypeFlag::ETS_UNION: + case checker::TypeFlag::ETS_ENUM2_TYPE: case checker::TypeFlag::ETS_DYNAMIC_TYPE: { Ra().Emit(node, objectReg, index); break; diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 1daa3360f7..8605cd7fb7 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -745,6 +745,7 @@ private: } case checker::TypeFlag::ETS_ENUM: case checker::TypeFlag::ETS_STRING_ENUM: + case checker::TypeFlag::ETS_ENUM2_TYPE: case checker::TypeFlag::ETS_BOOLEAN: case checker::TypeFlag::BYTE: case checker::TypeFlag::CHAR: diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp new file mode 100644 index 0000000000..484330f838 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -0,0 +1,394 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "enumLowering.h" +#include "compiler/lowering/scopesInit/scopesInitPhase.h" + +#include "varbinder/variableFlags.h" +#include "varbinder/ETSBinder.h" +#include "checker/ETSchecker.h" +#include "compiler/core/compilerContext.h" +#include "compiler/lowering/util.h" +#include "ir/statements/classDeclaration.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/astNode.h" +#include "ir/expression.h" +#include "util/ustring.h" + +#include "ir/ts/tsEnumDeclaration.h" + +namespace panda::es2panda::compiler { + +// const char* EnumConstantClassName = "EnumConst"; +const char *ENUM_INT_BASE_CLASS_NAME = "EnumIntType"; +const char *ENUM_STR_BASE_CLASS_NAME = "EnumStrType"; +const char *ENUM_CONSTANT_CREATE_METHOD_NAME = "create"; +const char *ENUM_VALUE_OF_LIB_FUNCTION_NAME = "enumValueOf"; +const char *ENUM_CONSTANT_ARRAY_NAME = "@@arr"; + +auto CreateIdentifierRef(util::StringView const name, checker::ETSChecker *checker) +{ + auto *ret = checker->Allocator()->New(name, checker->Allocator()); + ret->SetReference(); + return ret; +} + +auto CreateETSTypeReference(util::StringView const name, checker::ETSChecker *checker) +{ + auto *name_ident = CreateIdentifierRef(name, checker); + auto *reference_part = checker->Allocator()->New(name_ident); + return checker->Allocator()->New(reference_part); +} + +auto CreateETSParameterExpression(util::StringView const par_name, util::StringView const type_name, + checker::ETSChecker *checker) +{ + auto *type_annot = CreateETSTypeReference(type_name, checker); + auto *name = checker->Allocator()->New(par_name, type_annot, checker->Allocator()); + return checker->Allocator()->New(name, nullptr); +} + +ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enum_name, + ir::TSTypeParameterInstantiation *tp_par_inst, checker::ETSChecker *checker) +{ + auto *key = checker->AllocNode("valueOf", checker->Allocator()); + + ArenaVector params(checker->Allocator()->Adapter()); + params.push_back(CreateETSParameterExpression("name", "string", checker)); + + auto *ret_type = CreateETSTypeReference(enum_name, checker); + + ArenaVector statements(checker->Allocator()->Adapter()); + auto *callee = CreateIdentifierRef(ENUM_VALUE_OF_LIB_FUNCTION_NAME, checker); + ArenaVector args(checker->Allocator()->Adapter()); + auto *arg0_obj = CreateIdentifierRef(enum_name, checker); + auto *arg0_prop = CreateIdentifierRef(ENUM_CONSTANT_ARRAY_NAME, checker); + args.push_back(checker->AllocNode(arg0_obj, arg0_prop, + ir::MemberExpressionKind::PROPERTY_ACCESS, false, false)); + auto *arg1 = CreateIdentifierRef("name", checker); + args.push_back(arg1); + auto *express = checker->AllocNode(callee, std::move(args), tp_par_inst, false); + auto *argument = checker->AllocNode(express, ret_type, false); + statements.push_back(checker->AllocNode(argument)); + auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); + + auto *func = checker->AllocNode( + ir::FunctionSignature(nullptr, std::move(params), ret_type), body, + ir::ScriptFunctionFlags::HAS_RETURN | ir::ScriptFunctionFlags::THROWS, + ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC, false, Language(Language::Id::ETS)); + + func->SetIdent(key); + + auto *value = checker->AllocNode(func); + + auto flags = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; + + auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, key, value, flags, + checker->Allocator(), false); + + return method; +} + +ir::MethodDefinition *CreateMethodCreate(const util::StringView &enum_name, bool is_int_enum, + checker::ETSChecker *checker) +{ + auto *key = checker->AllocNode("create", checker->Allocator()); + + ArenaVector params(checker->Allocator()->Adapter()); + params.push_back(CreateETSParameterExpression("typ", "string", checker)); + params.push_back(CreateETSParameterExpression("name", "string", checker)); + params.push_back(CreateETSParameterExpression("val", is_int_enum ? "Int" : "string", checker)); + params.push_back(CreateETSParameterExpression("idx", "Int", checker)); + + auto id = checker->AllocNode("ret", checker->Allocator()); + auto init = checker->AllocNode( + CreateETSTypeReference(enum_name, checker), ArenaVector(checker->Allocator()->Adapter()), + nullptr); + auto declarator = checker->AllocNode(ir::VariableDeclaratorFlag::LET, id, init); + ArenaVector declarators(checker->Allocator()->Adapter()); + declarators.push_back(declarator); + + auto var_kind = ir::VariableDeclaration::VariableDeclarationKind::LET; + auto *var_decl = + checker->AllocNode(var_kind, checker->Allocator(), std::move(declarators), false); + + ArenaVector statements(checker->Allocator()->Adapter()); + statements.push_back(var_decl); + + auto *callee_obj = CreateIdentifierRef("ret", checker); + auto *callee_prop = CreateIdentifierRef("init", checker); + auto *callee = checker->AllocNode(callee_obj, callee_prop, + ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + ArenaVector args(checker->Allocator()->Adapter()); + args.push_back(CreateIdentifierRef("typ", checker)); + args.push_back(CreateIdentifierRef("name", checker)); + args.push_back(CreateIdentifierRef("val", checker)); + args.push_back(CreateIdentifierRef("idx", checker)); + auto *expression = checker->AllocNode(callee, std::move(args), nullptr, false); + statements.push_back(checker->AllocNode(expression)); + + statements.push_back(checker->AllocNode(callee_obj)); + + auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); + + auto *func = checker->AllocNode( + ir::FunctionSignature(nullptr, std::move(params), CreateETSTypeReference(enum_name, checker)), body, + ir::ScriptFunctionFlags::HAS_RETURN, ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE, false, + Language(Language::Id::ETS)); + + func->SetIdent(key); + auto *value = checker->AllocNode(func); + + auto flags = ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE; + + auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, key, value, flags, + checker->Allocator(), false); + + return method; +} + +ir::MethodDefinition *CreateMethodValues(const util::StringView &enum_name, checker::ETSChecker *checker) +{ + auto *key = checker->AllocNode("values", checker->Allocator()); + + ArenaVector params(checker->Allocator()->Adapter()); + + ArenaVector statements(checker->Allocator()->Adapter()); + auto *arg_obj = CreateIdentifierRef(enum_name, checker); + auto *arg_prop = CreateIdentifierRef(ENUM_CONSTANT_ARRAY_NAME, checker); + auto *argument = checker->AllocNode(arg_obj, arg_prop, + ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + statements.push_back(checker->AllocNode(argument)); + auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); + + auto *func = checker->AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunctionFlags::HAS_RETURN, + ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC, false, Language(Language::Id::ETS)); + + func->SetIdent(key); + auto *value = checker->AllocNode(func); + + auto flags = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; + + auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, key, value, flags, + checker->Allocator(), false); + + return method; +} + +ir::MethodDefinition *CreateConstructor(checker::ETSChecker *checker) +{ + auto *key = checker->AllocNode("constructor", checker->Allocator()); + + ArenaVector params(checker->Allocator()->Adapter()); + + ArenaVector statements(checker->Allocator()->Adapter()); + auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); + + auto *func = checker->AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunctionFlags::CONSTRUCTOR | ir::ScriptFunctionFlags::IMPLICIT_SUPER_CALL_NEEDED, false, + Language(Language::Id::ETS)); + + func->SetIdent(key); + auto *value = checker->AllocNode(func); + + auto *method = checker->AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, key, value, + ir::ModifierFlags::NONE, checker->Allocator(), false); + + return method; +} + +ir::MemberExpression *CreateEnumConstantArrayElement(const util::StringView &enum_name, const ir::TSEnumMember *member, + checker::ETSChecker *checker) +{ + auto *object = CreateIdentifierRef(enum_name, checker); + auto *prop = CreateIdentifierRef(member->Name(), checker); + auto *elem = + checker->AllocNode(object, prop, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + + return elem; +} + +ir::ClassProperty *CreateEnumConstantArray(const util::StringView &enum_name, ArenaVector &&elements, + checker::ETSChecker *checker) +{ + auto *key = checker->AllocNode(ENUM_CONSTANT_ARRAY_NAME, checker->Allocator()); + auto *value = checker->AllocNode(std::move(elements), checker->Allocator()); + + auto prop_modif = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; + + auto *el_type = CreateETSTypeReference(enum_name, checker); + auto *type_annotation = checker->AllocNode(el_type); + + auto *class_prop = + checker->AllocNode(key, value, type_annotation, prop_modif, checker->Allocator(), false); + + return class_prop; +} + +ir::ClassProperty *CreateEnumConstantClassProperty(const util::StringView &enum_name, const ir::TSEnumMember *member, + int idx, checker::ETSChecker *checker) +{ + auto *key = checker->AllocNode(member->Name(), checker->Allocator()); + + auto *callee_obj = CreateIdentifierRef(enum_name, checker); + auto *callee_prop = CreateIdentifierRef(ENUM_CONSTANT_CREATE_METHOD_NAME, checker); + auto *callee = checker->AllocNode(callee_obj, callee_prop, + ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + + ArenaVector args(checker->Allocator()->Adapter()); + util::UString enum_desc(checker::EnumDescription(enum_name), checker->Allocator()); + args.push_back(checker->AllocNode(enum_desc.View())); + util::UString enum_const_name(member->Name(), checker->Allocator()); + args.push_back(checker->AllocNode(enum_const_name.View())); + if (member->Init()->IsNumberLiteral()) { + args.push_back(checker->AllocNode(member->Init()->AsNumberLiteral()->Number())); + } else if (member->Init()->IsStringLiteral()) { + args.push_back(checker->AllocNode(member->Init()->AsStringLiteral()->Str())); + } else { + UNREACHABLE(); + } + args.push_back(checker->AllocNode(lexer::Number(idx))); + + auto *value = checker->AllocNode(callee, std::move(args), nullptr, false); + + auto prop_modif = + ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC | ir::ModifierFlags::READONLY | ir::ModifierFlags::CONST; + auto *type_annot = CreateETSTypeReference(enum_name, checker); + + auto *class_prop = + checker->AllocNode(key, value, type_annot, prop_modif, checker->Allocator(), false); + + return class_prop; +} + +void CreateCCtor(ArenaVector &properties, const lexer::SourcePosition &loc, checker::ETSChecker *checker) +{ + ArenaVector params(checker->Allocator()->Adapter()); + + auto *id = checker->AllocNode(compiler::Signatures::CCTOR, checker->Allocator()); + + ArenaVector statements(checker->Allocator()->Adapter()); + + auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); + auto *func = + checker->AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, + ir::ModifierFlags::STATIC, false, Language(Language::Id::ETS)); + func->SetIdent(id); + + auto *func_expr = checker->AllocNode(func); + auto *static_block = checker->AllocNode(func_expr, checker->Allocator()); + static_block->AddModifier(ir::ModifierFlags::STATIC); + static_block->SetRange({loc, loc}); + properties.push_back(static_block); +} + +ir::TSTypeParameterInstantiation *CreateTypeParameterInstantiation(bool is_int_enum, checker::ETSChecker *checker) +{ + ArenaVector params(checker->Allocator()->Adapter()); + auto *par_part_name = CreateIdentifierRef("", checker); + if (is_int_enum) { + par_part_name->SetName("Int"); + } else { + par_part_name->SetName("string"); + } + auto *par_part = checker->AllocNode(par_part_name); + params.push_back(checker->AllocNode(par_part)); + + return checker->AllocNode(std::move(params)); +} + +ir::AstNode *CreateEnumClassFromEnumDeclaration(ir::TSEnumDeclaration *enum_decl, checker::ETSChecker *checker, + varbinder::ETSBinder * /*varbinder*/, parser::Program * /*program*/) +{ + auto &enum_name = enum_decl->Key()->Name(); + auto *ident = checker->AllocNode(enum_name, checker->Allocator()); + + ArenaVector body(checker->Allocator()->Adapter()); + ArenaVector array_elements(checker->Allocator()->Adapter()); + int idx = 0; + for (auto &member : enum_decl->Members()) { + body.push_back(CreateEnumConstantClassProperty(enum_name, member->AsTSEnumMember(), idx++, checker)); + array_elements.push_back(CreateEnumConstantArrayElement(enum_name, member->AsTSEnumMember(), checker)); + } + + bool is_int_enum = false; + auto member0 = enum_decl->Members()[0]->AsTSEnumMember(); + if (member0->Init()->IsNumberLiteral()) { + is_int_enum = true; + } else if (!member0->Init()->IsStringLiteral()) { + UNREACHABLE(); + } + auto *tp_par_inst = CreateTypeParameterInstantiation(is_int_enum, checker); + + body.push_back(CreateEnumConstantArray(enum_name, std::move(array_elements), checker)); + + body.push_back(CreateMethodCreate(enum_name, is_int_enum, checker)); + body.push_back(CreateMethodValues(enum_name, checker)); + body.push_back(CreateMethodValueOf(enum_name, tp_par_inst, checker)); + body.push_back(CreateConstructor(checker)); + + CreateCCtor(body, enum_decl->Start(), checker); + + auto def_modif = ir::ClassDefinitionModifiers::ID_REQUIRED | ir::ClassDefinitionModifiers::HAS_SUPER | + ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::DECLARATION; + auto *class_def = checker->AllocNode(checker->Allocator(), ident, std::move(body), def_modif, + Language(Language::Id::ETS)); + if (is_int_enum) { + class_def->SetSuper(CreateETSTypeReference(ENUM_INT_BASE_CLASS_NAME, checker)); + } else { + class_def->SetSuper(CreateETSTypeReference(ENUM_STR_BASE_CLASS_NAME, checker)); + } + + auto *class_decl = checker->AllocNode(class_def, checker->Allocator()); + class_decl->SetRange({enum_decl->Start(), enum_decl->End()}); + + class_decl->SetParent(enum_decl->Parent()); + + return class_decl; +} + +std::string_view EnumLowering::Name() +{ + static std::string const NAME = "enum-property-access"; + return NAME; +} + +bool EnumLowering::Perform(public_lib::Context *ctx, parser::Program *program) +{ + checker::ETSChecker *checker = ctx->checker->AsETSChecker(); + + for (auto &[_, ext_programs] : program->ExternalSources()) { + (void)_; + for (auto *ext_prog : ext_programs) { + Perform(ctx, ext_prog); + } + } + + program->Ast()->TransformChildrenRecursively([checker, ctx, program](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsTSEnumDeclaration()) { + return CreateEnumClassFromEnumDeclaration(ast->AsTSEnumDeclaration(), checker, + ctx->compiler_context->VarBinder()->AsETSBinder(), program); + } + return ast; + }); + + return true; +} + +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/enumLowering.h b/ets2panda/compiler/lowering/ets/enumLowering.h new file mode 100644 index 0000000000..52a1af7b36 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/enumLowering.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_H +#define ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_H + +#include "compiler/lowering/phase.h" + +namespace panda::es2panda::compiler { + +class EnumLowering : public Phase { +public: + std::string_view Name() override; + bool Perform(public_lib::Context *ctx, parser::Program *program) override; +}; + +} // namespace panda::es2panda::compiler + +#endif \ No newline at end of file diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index e42c608c4d..828dd90236 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -20,6 +20,7 @@ #include "compiler/lowering/ets/defaultParameterLowering.h" #include "compiler/lowering/ets/expandBrackets.h" #include "compiler/lowering/ets/recordLowering.h" +#include "compiler/lowering/ets/enumLowering.h" #include "compiler/lowering/ets/generateDeclarations.h" #include "compiler/lowering/ets/lambdaLowering.h" #include "compiler/lowering/ets/interfacePropertyDeclarations.h" @@ -65,6 +66,7 @@ static PromiseVoidInferencePhase g_promiseVoidInferencePhase; static RecordLowering g_recordLowering; static StructLowering g_structLowering; static DefaultParameterLowering g_defaultParameterLowering; +static EnumLowering g_enumLowering; static PluginPhase g_pluginsAfterParse {"plugins-after-parse", ES2PANDA_STATE_PARSED, &util::Plugin::AfterParse}; static PluginPhase g_pluginsAfterCheck {"plugins-after-check", ES2PANDA_STATE_CHECKED, &util::Plugin::AfterCheck}; static PluginPhase g_pluginsAfterLowerings {"plugins-after-lowering", ES2PANDA_STATE_LOWERED, @@ -81,6 +83,7 @@ std::vector GetETSPhaseList() return { &g_defaultParameterLowering, &g_bigintLowering, + &g_enumLowering, &g_pluginsAfterParse, &g_initScopesPhaseEts, &g_optionalLowering, diff --git a/ets2panda/test/compiler/ets/enums_01-expected.txt b/ets2panda/test/compiler/ets/enums_01-expected.txt index 153aa1ba35..efcb0375f5 100644 --- a/ets2panda/test/compiler/ets/enums_01-expected.txt +++ b/ets2panda/test/compiler/ets/enums_01-expected.txt @@ -2,43 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "E1", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 8 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "e1_item1", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 3 - }, - "end": { - "line": 17, - "column": 11 + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, "loc": { "start": { "line": 1, @@ -52,77 +51,200 @@ }, "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 11 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "e1_item2", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 3 - }, - "end": { - "line": 18, - "column": 11 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "e1_item1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 7, - "loc": { - "start": { - "line": 18, - "column": 14 + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 18, - "column": 15 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#E1", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "e1_item1", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "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": 18, - "column": 3 }, - "end": { - "line": 18, - "column": 15 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "e1_item3", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 3 + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 19, - "column": 11 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 8, + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,61 +256,2226 @@ } } }, - "loc": { - "start": { - "line": 19, - "column": 3 - }, - "end": { - "line": 19, - "column": 11 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "e1_item4", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 3 - }, - "end": { - "line": 20, - "column": 11 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 15 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "e1_item2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "loc": { - "start": { - "line": 20, - "column": 3 }, - "end": { - "line": 20, - "column": 15 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E1", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "e1_item2", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 7, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "e1_item3", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E1", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "e1_item3", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 8, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "e1_item4", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E1", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "e1_item4", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "e1_item1", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "e1_item2", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "e1_item3", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "e1_item4", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt b/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt index 5e31d54078..58a107bb75 100644 --- a/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt +++ b/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt @@ -59,85 +59,2125 @@ } }, { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "from", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 18, - "column": 10 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "from", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#from", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "from", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "from", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "from1", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#from", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "from1", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "from", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "from2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#from", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "from2", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "from", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "from", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "from1", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "from2", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "from", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "from", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], "decorators": [], "loc": { "start": { - "line": 18, - "column": 13 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 17 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, "column": 1 }, - "end": { - "line": 1, - "column": 1 + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "from", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": 18, - "column": 13 }, - "end": { - "line": 18, - "column": 17 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "from1", + "overloads": [], "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 19 - }, - "end": { - "line": 18, - "column": 24 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, "loc": { "start": { "line": 1, @@ -149,37 +2189,88 @@ } } }, - "loc": { - "start": { - "line": 18, - "column": 19 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 18, - "column": 24 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "from2", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 26 + "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 + } + } }, - "end": { - "line": 18, - "column": 31 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -190,27 +2281,26 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 18, - "column": 26 - }, - "end": { - "line": 18, - "column": 31 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { - "line": 18, + "line": 19, "column": 1 }, "end": { - "line": 18, + "line": 19, "column": 33 } } @@ -338,11 +2428,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 10 }, "end": { - "line": 20, + "line": 21, "column": 14 } } @@ -362,11 +2452,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 10 }, "end": { - "line": 20, + "line": 21, "column": 14 } } @@ -385,33 +2475,33 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 18 }, "end": { - "line": 20, + "line": 21, "column": 22 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 18 }, "end": { - "line": 20, + "line": 21, "column": 24 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 18 }, "end": { - "line": 20, + "line": 21, "column": 24 } } @@ -431,11 +2521,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 21, + "line": 22, "column": 15 }, "end": { - "line": 21, + "line": 22, "column": 18 } } @@ -443,11 +2533,11 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 22, "column": 9 }, "end": { - "line": 21, + "line": 22, "column": 13 } } @@ -457,22 +2547,22 @@ "value": 84, "loc": { "start": { - "line": 21, + "line": 22, "column": 21 }, "end": { - "line": 21, + "line": 22, "column": 23 } } }, "loc": { "start": { - "line": 21, + "line": 22, "column": 9 }, "end": { - "line": 21, + "line": 22, "column": 23 } } @@ -481,11 +2571,11 @@ "kind": "let", "loc": { "start": { - "line": 21, + "line": 22, "column": 5 }, "end": { - "line": 21, + "line": 22, "column": 24 } } @@ -493,33 +2583,33 @@ ], "loc": { "start": { - "line": 20, + "line": 21, "column": 23 }, "end": { - "line": 22, + "line": 23, "column": 2 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 14 }, "end": { - "line": 22, + "line": 23, "column": 2 } } }, "loc": { "start": { - "line": 20, + "line": 21, "column": 14 }, "end": { - "line": 22, + "line": 23, "column": 2 } } @@ -528,11 +2618,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 1 }, "end": { - "line": 22, + "line": 23, "column": 2 } } @@ -567,8 +2657,9 @@ "column": 1 }, "end": { - "line": 23, + "line": 24, "column": 1 } } } +SyntaxError: Variable 'from' is accessed before it's initialization. [from-soft-keyword-3.ets:1:1] diff --git a/ets2panda/test/compiler/ets/from-soft-keyword-3.ets b/ets2panda/test/compiler/ets/from-soft-keyword-3.ets index 96f7ae314e..e1561bf064 100644 --- a/ets2panda/test/compiler/ets/from-soft-keyword-3.ets +++ b/ets2panda/test/compiler/ets/from-soft-keyword-3.ets @@ -15,6 +15,7 @@ import * from "std/math"; +// TODO(aber) enum from { from, from1, from2 }; function main(): void { diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt index ae8e7882a3..52fbbb282c 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt @@ -2,43 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, "loc": { "start": { "line": 1, @@ -52,35 +51,200 @@ }, "loc": { "start": { - "line": 16, - "column": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Blue", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 20 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 16, - "column": 24 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -92,19 +256,1748 @@ } } }, - "loc": { - "start": { - "line": 16, - "column": 20 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 24 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Blue", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/parser/ets/enum-expected.txt b/ets2panda/test/parser/ets/enum-expected.txt index edcd158548..88da04304d 100644 --- a/ets2panda/test/parser/ets/enum-expected.txt +++ b/ets2panda/test/parser/ets/enum-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], "loc": { "start": { - "line": 16, - "column": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Green", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 24 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,35 +51,200 @@ }, "loc": { "start": { - "line": 16, - "column": 19 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 24 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Blue", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 26 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 16, - "column": 30 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,19 +256,1987 @@ } } }, - "loc": { - "start": { - "line": 16, - "column": 26 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 30 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Green", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Blue", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/parser/ets/enum10-expected.txt b/ets2panda/test/parser/ets/enum10-expected.txt index 1f526c797d..b139de95ce 100644 --- a/ets2panda/test/parser/ets/enum10-expected.txt +++ b/ets2panda/test/parser/ets/enum10-expected.txt @@ -2,43 +2,1740 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 11 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + { + "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": 1, @@ -49,20 +1746,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, @@ -705,4 +2401,3 @@ } } } -TypeError: No enum item method called 'values' [enum10.ets:20:39] diff --git a/ets2panda/test/parser/ets/enum10.ets b/ets2panda/test/parser/ets/enum10.ets index 4a0f93fe52..aa337a03bf 100644 --- a/ets2panda/test/parser/ets/enum10.ets +++ b/ets2panda/test/parser/ets/enum10.ets @@ -17,5 +17,5 @@ enum Color { Red } function main(): void { let values: Color[] = Color.values(); - let valuesFail: Color[] = values[0].values(); + let valuesFail: Color[] = values[0].values(); // TODO(aber) } diff --git a/ets2panda/test/parser/ets/enum11-expected.txt b/ets2panda/test/parser/ets/enum11-expected.txt index 325edc48c2..a7cf728a59 100644 --- a/ets2panda/test/parser/ets/enum11-expected.txt +++ b/ets2panda/test/parser/ets/enum11-expected.txt @@ -2,43 +2,1740 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 11 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + { + "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": 1, @@ -49,20 +1746,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, @@ -563,119 +2259,6 @@ } } }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "red", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 7 - }, - "end": { - "line": 22, - "column": 10 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "ordinal", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 13 - }, - "end": { - "line": 22, - "column": 20 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 24 - }, - "end": { - "line": 22, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 24 - }, - "end": { - "line": 22, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 24 - }, - "end": { - "line": 22, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 13 - }, - "end": { - "line": 22, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 7 - }, - "end": { - "line": 22, - "column": 20 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 22, - "column": 3 - }, - "end": { - "line": 22, - "column": 30 - } - } - }, { "type": "VariableDeclaration", "declarations": [ diff --git a/ets2panda/test/parser/ets/enum11.ets b/ets2panda/test/parser/ets/enum11.ets index 1b4df59799..74637d7245 100644 --- a/ets2panda/test/parser/ets/enum11.ets +++ b/ets2panda/test/parser/ets/enum11.ets @@ -19,6 +19,6 @@ function main(): void { let arr: Color[] = [Color.Red]; let ordinal: int = arr[0] as int; - let red = ordinal as Color; + //let red = ordinal as Color; let ordinalFail: int = Color as int; } diff --git a/ets2panda/test/parser/ets/enum12-expected.txt b/ets2panda/test/parser/ets/enum12-expected.txt index a3cb3a471a..d8f278a998 100644 --- a/ets2panda/test/parser/ets/enum12-expected.txt +++ b/ets2panda/test/parser/ets/enum12-expected.txt @@ -2,43 +2,1740 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 11 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + { + "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": 1, @@ -49,20 +1746,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, @@ -917,4 +2613,4 @@ } } } -TypeError: No enum type method called 'toString' [enum12.ets:20:29] +TypeError: 'toString' is an instance property of 'Color' [enum12.ets:20:29] diff --git a/ets2panda/test/parser/ets/enum13-expected.txt b/ets2panda/test/parser/ets/enum13-expected.txt index e9357392f7..6790c4eab4 100644 --- a/ets2panda/test/parser/ets/enum13-expected.txt +++ b/ets2panda/test/parser/ets/enum13-expected.txt @@ -2,43 +2,1740 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 11 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + { + "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": 1, @@ -49,20 +1746,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, @@ -976,4 +2672,4 @@ } } } -TypeError: No enum item method called 'valueOf' [enum13.ets:20:26] +TypeError: This statement can cause an exception, therefore it must be enclosed in a try statement with a default catch clause [enum13.ets:24:3] diff --git a/ets2panda/test/parser/ets/enum14-expected.txt b/ets2panda/test/parser/ets/enum14-expected.txt index 44f44c38ca..7a36976eef 100644 --- a/ets2panda/test/parser/ets/enum14-expected.txt +++ b/ets2panda/test/parser/ets/enum14-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], "loc": { "start": { - "line": 16, - "column": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Green", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 24 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,35 +51,200 @@ }, "loc": { "start": { - "line": 16, - "column": 19 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 24 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Blue", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 26 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 16, - "column": 30 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,19 +256,1987 @@ } } }, - "loc": { - "start": { - "line": 16, - "column": 26 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 30 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Green", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Blue", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/parser/ets/enum19-expected.txt b/ets2panda/test/parser/ets/enum19-expected.txt index df747461ca..61ddddb922 100644 --- a/ets2panda/test/parser/ets/enum19-expected.txt +++ b/ets2panda/test/parser/ets/enum19-expected.txt @@ -2,43 +2,1704 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "InvalidInitTypeEnum", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 25 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#InvalidInitTypeEnum", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "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 + } + } + }, + "definite": false, "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#InvalidInitTypeEnum", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Green", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": -1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#InvalidInitTypeEnum", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Blue", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": -1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } }, - "end": { - "line": 17, - "column": 6 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -50,103 +1711,532 @@ } } }, - "loc": { - "start": { - "line": 17, - "column": 3 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 17, - "column": 6 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Green", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 3 + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 18, - "column": 8 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": -1, + }, + "overloads": [], + "decorators": [], "loc": { "start": { - "line": 18, - "column": 12 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 13 + "line": 1, + "column": 1 } } }, - "loc": { - "start": { - "line": 18, - "column": 3 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 18, - "column": 13 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Blue", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 3 + "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 + } + } }, - "end": { - "line": 19, - "column": 7 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": -1, + }, + "overloads": [], + "decorators": [], "loc": { "start": { - "line": 19, - "column": 10 + "line": 1, + "column": 1 }, "end": { - "line": 19, - "column": 20 + "line": 1, + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 19, - "column": 3 - }, - "end": { - "line": 19, - "column": 20 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/parser/ets/enum20-expected.txt b/ets2panda/test/parser/ets/enum20-expected.txt index ddbf6ffb3d..3922b63528 100644 --- a/ets2panda/test/parser/ets/enum20-expected.txt +++ b/ets2panda/test/parser/ets/enum20-expected.txt @@ -2,43 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, "loc": { "start": { "line": 1, @@ -52,77 +51,200 @@ }, "loc": { "start": { - "line": 16, - "column": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Green", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 24 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": -100, - "loc": { - "start": { - "line": 16, - "column": 28 + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 16, - "column": 31 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "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": 16, - "column": 19 }, - "end": { - "line": 16, - "column": 31 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Blue", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 33 + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 37 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": -99, + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,61 +256,2226 @@ } } }, - "loc": { - "start": { - "line": 16, - "column": 33 - }, - "end": { - "line": 16, - "column": 37 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "White", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 39 - }, - "end": { - "line": 16, - "column": 44 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 16, - "column": 47 - }, - "end": { - "line": 16, - "column": 51 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "loc": { - "start": { - "line": 16, - "column": 39 }, - "end": { - "line": 16, - "column": 51 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Green", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": -100, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Blue", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": -99, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "White", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "White", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "White", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, @@ -1022,4 +3309,4 @@ } } } -TypeError: No enum item method called 'ordinal' [enum20.ets:19:23] +TypeError: Property 'ordinal' does not exist on type 'Color' [enum20.ets:19:23] diff --git a/ets2panda/test/parser/ets/enum21-expected.txt b/ets2panda/test/parser/ets/enum21-expected.txt index cdccfed003..16707525ca 100644 --- a/ets2panda/test/parser/ets/enum21-expected.txt +++ b/ets2panda/test/parser/ets/enum21-expected.txt @@ -2,109 +2,2002 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "ArkColor", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumStrType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 14 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Gray", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Gray", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#ArkColor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Gray", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "#ff808080", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArkColor", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Grey", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#ArkColor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Grey", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "#ff808080", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArkColor", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Gray", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Grey", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArkColor", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArkColor", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 7 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "StringLiteral", - "value": "#ff808080", - "loc": { - "start": { - "line": 17, - "column": 10 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArkColor", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 17, - "column": 21 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "loc": { - "start": { - "line": 17, - "column": 3 }, - "end": { - "line": 17, - "column": 21 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Grey", + "overloads": [], "decorators": [], "loc": { "start": { - "line": 18, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 7 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "StringLiteral", - "value": "#ff808080", + { + "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": 10 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 21 + "line": 1, + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 18, - "column": 3 - }, - "end": { - "line": 18, - "column": 21 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/parser/ets/enum22-expected.txt b/ets2panda/test/parser/ets/enum22-expected.txt index 7c19b3b0f3..50da86a3d7 100644 --- a/ets2panda/test/parser/ets/enum22-expected.txt +++ b/ets2panda/test/parser/ets/enum22-expected.txt @@ -1 +1 @@ -SyntaxError: Variable 'Gray' has already been declared. [enum22.ets:18:5] +SyntaxError: Variable 'Gray' has already been declared. [enum22.ets:1:1] diff --git a/ets2panda/test/parser/ets/enum23-expected.txt b/ets2panda/test/parser/ets/enum23-expected.txt index 1186992952..223c2e7b77 100644 --- a/ets2panda/test/parser/ets/enum23-expected.txt +++ b/ets2panda/test/parser/ets/enum23-expected.txt @@ -1 +1 @@ -SyntaxError: Variable 'Red' has already been declared. [enum23.ets:18:5] +SyntaxError: Variable 'Red' has already been declared. [enum23.ets:1:1] diff --git a/ets2panda/test/parser/ets/enum4-expected.txt b/ets2panda/test/parser/ets/enum4-expected.txt index 8bdb72529a..0a4c274e4b 100644 --- a/ets2panda/test/parser/ets/enum4-expected.txt +++ b/ets2panda/test/parser/ets/enum4-expected.txt @@ -2,43 +2,1647 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "TrailingCommaEnum", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 23 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#TrailingCommaEnum", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 6 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TrailingCommaEnum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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, @@ -50,19 +1654,111 @@ } } }, - "loc": { - "start": { - "line": 17, - "column": 3 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 17, - "column": 6 + "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - ], - "const": false, + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/parser/ets/enum6-expected.txt b/ets2panda/test/parser/ets/enum6-expected.txt index 7c44fc1e79..af08c1aeab 100644 --- a/ets2panda/test/parser/ets/enum6-expected.txt +++ b/ets2panda/test/parser/ets/enum6-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 3 - }, - "end": { - "line": 17, - "column": 6 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], "loc": { "start": { - "line": 17, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 6 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Green", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 3 - }, - "end": { - "line": 18, - "column": 8 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,35 +51,200 @@ }, "loc": { "start": { - "line": 18, - "column": 3 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 8 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Blue", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 3 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 19, - "column": 7 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,19 +256,1987 @@ } } }, - "loc": { - "start": { - "line": 19, - "column": 3 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 19, - "column": 7 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Green", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Blue", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, @@ -748,4 +2838,3 @@ } } } -TypeError: Enum constant does not have property 'Blue'. [enum6.ets:25:9] diff --git a/ets2panda/test/parser/ets/enum6.ets b/ets2panda/test/parser/ets/enum6.ets index 90853b1e4f..3e23bd77bc 100644 --- a/ets2panda/test/parser/ets/enum6.ets +++ b/ets2panda/test/parser/ets/enum6.ets @@ -22,5 +22,5 @@ enum Color { function main(): void { let i: Color = Color.Red; i = Color.Green; - i = i.Blue; + i = i.Blue; // TODO(aber) } diff --git a/ets2panda/test/parser/ets/enum7-expected.txt b/ets2panda/test/parser/ets/enum7-expected.txt index 1d1053bc24..533ad1b4d2 100644 --- a/ets2panda/test/parser/ets/enum7-expected.txt +++ b/ets2panda/test/parser/ets/enum7-expected.txt @@ -2,43 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, "loc": { "start": { "line": 1, @@ -52,66 +51,200 @@ }, "loc": { "start": { - "line": 16, - "column": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } - } - ], - "const": false, - "loc": { - "start": { - "line": 16, - "column": 1 }, - "end": { - "line": 16, - "column": 19 - } - } - }, - { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color2", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 6 - }, - "end": { - "line": 17, - "column": 12 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 15 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 17, - "column": 18 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -123,19 +256,3278 @@ } } }, - "loc": { - "start": { - "line": 17, - "column": 15 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 17, - "column": 18 - } - } - } - ], - "const": false, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "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 + } + } + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color2", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 17, diff --git a/ets2panda/test/parser/ets/enum8-expected.txt b/ets2panda/test/parser/ets/enum8-expected.txt index 150b136c75..a66cccaf21 100644 --- a/ets2panda/test/parser/ets/enum8-expected.txt +++ b/ets2panda/test/parser/ets/enum8-expected.txt @@ -2,43 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, "loc": { "start": { "line": 1, @@ -52,66 +51,200 @@ }, "loc": { "start": { - "line": 16, - "column": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } - } - ], - "const": false, - "loc": { - "start": { - "line": 16, - "column": 1 }, - "end": { - "line": 16, - "column": 19 - } - } - }, - { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color2", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 6 - }, - "end": { - "line": 17, - "column": 12 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 15 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 17, - "column": 18 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -123,19 +256,3278 @@ } } }, - "loc": { - "start": { - "line": 17, - "column": 15 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 17, - "column": 18 - } - } - } - ], - "const": false, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "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 + } + } + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color2", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 17, diff --git a/ets2panda/test/parser/ets/enum9-expected.txt b/ets2panda/test/parser/ets/enum9-expected.txt index 425b1e8380..cf042bdcfd 100644 --- a/ets2panda/test/parser/ets/enum9-expected.txt +++ b/ets2panda/test/parser/ets/enum9-expected.txt @@ -2,43 +2,1740 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 11 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + { + "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": 1, @@ -49,20 +1746,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, @@ -520,4 +2216,4 @@ } } } -TypeError: Cannot refer to enum members through variable. [enum9.ets:19:30] +TypeError: Property 'Red' does not exist on type 'Color' [enum9.ets:19:30] diff --git a/ets2panda/test/parser/ets/extension_function_tests/extension_function_not_for_class_type-expected.txt b/ets2panda/test/parser/ets/extension_function_tests/extension_function_not_for_class_type-expected.txt index e75faafbf4..c9f5f2e843 100644 --- a/ets2panda/test/parser/ets/extension_function_tests/extension_function_not_for_class_type-expected.txt +++ b/ets2panda/test/parser/ets/extension_function_tests/extension_function_not_for_class_type-expected.txt @@ -2,67 +2,1763 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Fruit", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Fruit", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 11 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "size", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "size", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Fruit", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Fruit", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "size", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fruit", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Fruit", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "size", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fruit", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fruit", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fruit", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Fruit", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fruit", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Fruit", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fruit", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 18 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 4, + { + "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": 21 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 22 + "line": 1, + "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 22 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, @@ -429,4 +2125,3 @@ } } } -TypeError: Extension function can only defined for class and interface type. [extension_function_not_for_class_type.ets:18:1] diff --git a/ets2panda/test/parser/ets/switch_enum-expected.txt b/ets2panda/test/parser/ets/switch_enum-expected.txt index f4d9debe2d..86c28edd58 100644 --- a/ets2panda/test/parser/ets/switch_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], "loc": { "start": { - "line": 16, - "column": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Green", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 24 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,35 +51,200 @@ }, "loc": { "start": { - "line": 16, - "column": 19 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 24 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Blue", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 26 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 16, - "column": 30 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,19 +256,1987 @@ } } }, - "loc": { - "start": { - "line": 16, - "column": 26 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 30 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Green", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Blue", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, @@ -682,4 +2772,4 @@ } } } -TypeError: Case duplicate [switch_enum.ets:20:14] +TypeError: Case enum duplicate [switch_enum.ets:20:14] diff --git a/ets2panda/test/parser/ets/switch_enum2-expected.txt b/ets2panda/test/parser/ets/switch_enum2-expected.txt index 59ed0f5ca2..eccd7e60cb 100644 --- a/ets2panda/test/parser/ets/switch_enum2-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum2-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Color", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 11 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Red", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 17 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], "loc": { "start": { - "line": 16, - "column": 14 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 17 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Green", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 24 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,35 +51,200 @@ }, "loc": { "start": { - "line": 16, - "column": 19 + "line": 1, + "column": 1 }, "end": { - "line": 16, - "column": 24 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "Blue", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 26 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 16, - "column": 30 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Red", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,19 +256,1987 @@ } } }, - "loc": { - "start": { - "line": 16, - "column": 26 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 30 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Green", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Color", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "Blue", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/parser/ets/switch_enum_3-expected.txt b/ets2panda/test/parser/ets/switch_enum_3-expected.txt index fc33dc07d5..9c4f228b99 100644 --- a/ets2panda/test/parser/ets/switch_enum_3-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum_3-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 6 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { - "line": 17, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 6 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 8 - }, - "end": { - "line": 17, - "column": 9 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,35 +51,200 @@ }, "loc": { "start": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 9 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "D", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 11 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 17, - "column": 12 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,19 +256,1987 @@ } } }, - "loc": { - "start": { - "line": 17, - "column": 11 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 17, - "column": 12 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "C", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "D", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, diff --git a/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt index 7a8067085b..09735ed4df 100644 --- a/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 6 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], "loc": { "start": { - "line": 17, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 6 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "D", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 8 - }, - "end": { - "line": 17, - "column": 9 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,35 +51,200 @@ }, "loc": { "start": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 9 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "E", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 11 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 17, - "column": 12 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#B", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -134,19 +256,1987 @@ } } }, - "loc": { - "start": { - "line": 17, - "column": 11 + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 17, - "column": 12 - } - } - } - ], - "const": false, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#B", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#B", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "C", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "D", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "E", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, "loc": { "start": { "line": 16, @@ -785,4 +2875,4 @@ } } } -TypeError: Case duplicate [switch_enum_case_duplicate.ets:25:14] +TypeError: Case enum duplicate [switch_enum_case_duplicate.ets:25:14] diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt index 8ce637786e..438834c381 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 6 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { - "line": 17, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 6 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 8 - }, - "end": { - "line": 17, - "column": 9 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,108 +51,200 @@ }, "loc": { "start": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 9 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "D", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 11 - }, - "end": { - "line": 17, - "column": 12 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 1 + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 1, - "column": 1 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "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": 17, - "column": 11 }, - "end": { - "line": 17, - "column": 12 - } - } - } - ], - "const": false, - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 18, - "column": 2 - } - } - }, - { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "E", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 6 - }, - "end": { - "line": 20, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "F", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 5 + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 21, - "column": 6 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -207,37 +256,4118 @@ } } }, - "loc": { - "start": { - "line": 21, - "column": 5 - }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "C", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "D", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "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": 21, - "column": 6 + "line": 1, + "column": 1 + } + } + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "F", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "F", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "G", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "G", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "H", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "H", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "F", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "G", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "H", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "G", + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], "decorators": [], "loc": { "start": { - "line": 21, - "column": 8 + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 21, - "column": 9 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -249,37 +4379,88 @@ } } }, - "loc": { - "start": { - "line": 21, - "column": 8 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 21, - "column": 9 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "H", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 11 + "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 + } + } }, - "end": { - "line": 21, - "column": 12 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -290,20 +4471,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 21, - "column": 11 - }, - "end": { - "line": 21, - "column": 12 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 20, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt index 5891ffb6e1..7db1b791a7 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 6 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { - "line": 17, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 6 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 8 - }, - "end": { - "line": 17, - "column": 9 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,108 +51,200 @@ }, "loc": { "start": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 9 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "D", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 11 - }, - "end": { - "line": 17, - "column": 12 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 1 + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 1, - "column": 1 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "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": 17, - "column": 11 }, - "end": { - "line": 17, - "column": 12 - } - } - } - ], - "const": false, - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 18, - "column": 2 - } - } - }, - { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "E", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 6 - }, - "end": { - "line": 20, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "F", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 5 + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 21, - "column": 6 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -207,37 +256,4118 @@ } } }, - "loc": { - "start": { - "line": 21, - "column": 5 - }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "C", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "D", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "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": 21, - "column": 6 + "line": 1, + "column": 1 + } + } + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "F", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "F", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "G", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "G", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "H", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "H", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "F", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "G", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "H", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "G", + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], "decorators": [], "loc": { "start": { - "line": 21, - "column": 8 + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 21, - "column": 9 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -249,37 +4379,88 @@ } } }, - "loc": { - "start": { - "line": 21, - "column": 8 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 21, - "column": 9 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "H", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 11 + "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 + } + } }, - "end": { - "line": 21, - "column": 12 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -290,20 +4471,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 21, - "column": 11 - }, - "end": { - "line": 21, - "column": 12 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 20, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt index cc9db9fc4a..712a92b4b5 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 6 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { - "line": 17, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 6 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 8 - }, - "end": { - "line": 17, - "column": 9 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,108 +51,200 @@ }, "loc": { "start": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 9 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "D", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 11 - }, - "end": { - "line": 17, - "column": 12 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 1 + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 1, - "column": 1 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "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": 17, - "column": 11 }, - "end": { - "line": 17, - "column": 12 - } - } - } - ], - "const": false, - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 18, - "column": 2 - } - } - }, - { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "E", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 6 - }, - "end": { - "line": 21, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "F", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 5 + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 22, - "column": 6 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -207,37 +256,4118 @@ } } }, - "loc": { - "start": { - "line": 22, - "column": 5 - }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "C", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "D", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "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": 22, - "column": 6 + "line": 1, + "column": 1 + } + } + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "F", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "F", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "G", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "G", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "H", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "H", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "F", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "G", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "H", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "G", + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], "decorators": [], "loc": { "start": { - "line": 22, - "column": 8 + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 22, - "column": 9 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -249,37 +4379,88 @@ } } }, - "loc": { - "start": { - "line": 22, - "column": 8 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 22, - "column": 9 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "H", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 11 + "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 + } + } }, - "end": { - "line": 22, - "column": 12 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -290,20 +4471,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 22, - "column": 11 - }, - "end": { - "line": 22, - "column": 12 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt index c37cacffeb..d7f0052731 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt @@ -2,85 +2,42 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 6 - }, - "end": { - "line": 16, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 5 - }, - "end": { - "line": 17, - "column": 6 - } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { - "line": 17, - "column": 5 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 6 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 8 - }, - "end": { - "line": 17, - "column": 9 + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, "loc": { "start": { "line": 1, @@ -94,108 +51,200 @@ }, "loc": { "start": { - "line": 17, - "column": 8 + "line": 1, + "column": 1 }, "end": { - "line": 17, - "column": 9 + "line": 1, + "column": 1 } } }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "D", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 11 - }, - "end": { - "line": 17, - "column": 12 + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 1, - "column": 1 + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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 + } + } }, - "end": { - "line": 1, - "column": 1 + "arguments": [ + { + "type": "StringLiteral", + "value": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "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": 17, - "column": 11 }, - "end": { - "line": 17, - "column": 12 - } - } - } - ], - "const": false, - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 18, - "column": 2 - } - } - }, - { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "E", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 6 - }, - "end": { - "line": 21, - "column": 7 - } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "F", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 5 + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 22, - "column": 6 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, + "definite": false, + "decorators": [], "loc": { "start": { "line": 1, @@ -207,37 +256,4118 @@ } } }, - "loc": { - "start": { - "line": 22, - "column": 5 - }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#A", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "B", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "C", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "D", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": "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": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "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": 22, - "column": 6 + "line": 1, + "column": 1 + } + } + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "F", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "F", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "G", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "G", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "H", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#E", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "H", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "F", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "G", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "H", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "G", + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } + }, + "overloads": [], "decorators": [], "loc": { "start": { - "line": 22, - "column": 8 + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "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": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "E", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 22, - "column": 9 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -249,37 +4379,88 @@ } } }, - "loc": { - "start": { - "line": 22, - "column": 8 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 22, - "column": 9 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "H", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 11 + "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 + } + } }, - "end": { - "line": 22, - "column": 12 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 2, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -290,20 +4471,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 22, - "column": 11 - }, - "end": { - "line": 22, - "column": 12 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 21, @@ -1293,4 +5473,4 @@ } } } -TypeError: Case duplicate [switch_readonly_member_enum_duplicate.ets:35:14] +TypeError: Case enum duplicate [switch_readonly_member_enum_duplicate.ets:35:14] -- Gitee From 3b85d71abcd8569f5cff4b7ba5be8d3d2f3c8881 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Fri, 2 Feb 2024 15:02:46 +0300 Subject: [PATCH 02/48] fix build issues Signed-off-by: Vadim Lomovtsev --- ets2panda/compiler/core/ETSGen.cpp | 6 +++--- ets2panda/compiler/lowering/ets/enumLowering.cpp | 8 +------- ets2panda/compiler/lowering/ets/enumLowering.h | 7 +++++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index dc92370b8c..8074b0700b 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -1727,9 +1727,9 @@ void ETSGen::CastToInt(const ir::AstNode *node) } case checker::TypeFlag::ETS_ENUM2_TYPE: { RegScope rs(this); - VReg obj_reg = AllocReg(); - StoreAccumulator(node, obj_reg); - Ra().Emit(node, checker::ETSEnum2Type::GetIndexMethodName(), obj_reg, dummy_reg_); + VReg objReg = AllocReg(); + StoreAccumulator(node, objReg); + Ra().Emit(node, checker::ETSEnum2Type::GetIndexMethodName(), objReg, dummyReg_); break; } diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index 484330f838..27f66c429c 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -363,12 +363,6 @@ ir::AstNode *CreateEnumClassFromEnumDeclaration(ir::TSEnumDeclaration *enum_decl return class_decl; } -std::string_view EnumLowering::Name() -{ - static std::string const NAME = "enum-property-access"; - return NAME; -} - bool EnumLowering::Perform(public_lib::Context *ctx, parser::Program *program) { checker::ETSChecker *checker = ctx->checker->AsETSChecker(); @@ -383,7 +377,7 @@ bool EnumLowering::Perform(public_lib::Context *ctx, parser::Program *program) program->Ast()->TransformChildrenRecursively([checker, ctx, program](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsTSEnumDeclaration()) { return CreateEnumClassFromEnumDeclaration(ast->AsTSEnumDeclaration(), checker, - ctx->compiler_context->VarBinder()->AsETSBinder(), program); + ctx->compilerContext->VarBinder()->AsETSBinder(), program); } return ast; }); diff --git a/ets2panda/compiler/lowering/ets/enumLowering.h b/ets2panda/compiler/lowering/ets/enumLowering.h index 52a1af7b36..20815a4c9c 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.h +++ b/ets2panda/compiler/lowering/ets/enumLowering.h @@ -22,10 +22,13 @@ namespace panda::es2panda::compiler { class EnumLowering : public Phase { public: - std::string_view Name() override; + std::string_view Name() override + { + return "EnumLowering"; + } bool Perform(public_lib::Context *ctx, parser::Program *program) override; }; } // namespace panda::es2panda::compiler -#endif \ No newline at end of file +#endif -- Gitee From 9aee1c485a8ef7580b44473102b98c8c8bccefd3 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Fri, 2 Feb 2024 17:59:15 +0300 Subject: [PATCH 03/48] process enum only for ETS Signed-off-by: Vadim Lomovtsev --- ets2panda/compiler/lowering/ets/enumLowering.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index 27f66c429c..9d628f746b 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -365,6 +365,10 @@ ir::AstNode *CreateEnumClassFromEnumDeclaration(ir::TSEnumDeclaration *enum_decl bool EnumLowering::Perform(public_lib::Context *ctx, parser::Program *program) { + if (program->Extension() != ScriptExtension::ETS) { + return true; + } + checker::ETSChecker *checker = ctx->checker->AsETSChecker(); for (auto &[_, ext_programs] : program->ExternalSources()) { -- Gitee From 85914c7cb1ca0092e78e84d80481e88bb51d0216 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 5 Feb 2024 14:32:06 +0300 Subject: [PATCH 04/48] update expected; need to rework? Signed-off-by: Vadim Lomovtsev --- .../ets/from-soft-keyword-3-expected.txt | 63 +- .../test/compiler/ets/from-soft-keyword-3.ets | 1 - .../test/parser/ets/declare_enum-expected.txt | 2019 ++++++++++++++++- 3 files changed, 1987 insertions(+), 96 deletions(-) diff --git a/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt b/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt index 58a107bb75..3a77f851a5 100644 --- a/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt +++ b/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt @@ -2296,11 +2296,11 @@ }, "loc": { "start": { - "line": 19, + "line": 18, "column": 1 }, "end": { - "line": 19, + "line": 18, "column": 33 } } @@ -2428,11 +2428,11 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 20, "column": 10 }, "end": { - "line": 21, + "line": 20, "column": 14 } } @@ -2452,11 +2452,11 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 20, "column": 10 }, "end": { - "line": 21, + "line": 20, "column": 14 } } @@ -2475,33 +2475,33 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 20, "column": 18 }, "end": { - "line": 21, + "line": 20, "column": 22 } } }, "loc": { "start": { - "line": 21, + "line": 20, "column": 18 }, "end": { - "line": 21, + "line": 20, "column": 24 } } }, "loc": { "start": { - "line": 21, + "line": 20, "column": 18 }, "end": { - "line": 21, + "line": 20, "column": 24 } } @@ -2521,11 +2521,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 22, + "line": 21, "column": 15 }, "end": { - "line": 22, + "line": 21, "column": 18 } } @@ -2533,11 +2533,11 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 21, "column": 9 }, "end": { - "line": 22, + "line": 21, "column": 13 } } @@ -2547,22 +2547,22 @@ "value": 84, "loc": { "start": { - "line": 22, + "line": 21, "column": 21 }, "end": { - "line": 22, + "line": 21, "column": 23 } } }, "loc": { "start": { - "line": 22, + "line": 21, "column": 9 }, "end": { - "line": 22, + "line": 21, "column": 23 } } @@ -2571,11 +2571,11 @@ "kind": "let", "loc": { "start": { - "line": 22, + "line": 21, "column": 5 }, "end": { - "line": 22, + "line": 21, "column": 24 } } @@ -2583,33 +2583,33 @@ ], "loc": { "start": { - "line": 21, + "line": 20, "column": 23 }, "end": { - "line": 23, + "line": 22, "column": 2 } } }, "loc": { "start": { - "line": 21, + "line": 20, "column": 14 }, "end": { - "line": 23, + "line": 22, "column": 2 } } }, "loc": { "start": { - "line": 21, + "line": 20, "column": 14 }, "end": { - "line": 23, + "line": 22, "column": 2 } } @@ -2618,11 +2618,11 @@ "decorators": [], "loc": { "start": { - "line": 21, + "line": 20, "column": 1 }, "end": { - "line": 23, + "line": 22, "column": 2 } } @@ -2657,9 +2657,8 @@ "column": 1 }, "end": { - "line": 24, + "line": 23, "column": 1 } } } -SyntaxError: Variable 'from' is accessed before it's initialization. [from-soft-keyword-3.ets:1:1] diff --git a/ets2panda/test/compiler/ets/from-soft-keyword-3.ets b/ets2panda/test/compiler/ets/from-soft-keyword-3.ets index e1561bf064..96f7ae314e 100644 --- a/ets2panda/test/compiler/ets/from-soft-keyword-3.ets +++ b/ets2panda/test/compiler/ets/from-soft-keyword-3.ets @@ -15,7 +15,6 @@ import * from "std/math"; -// TODO(aber) enum from { from, from1, from2 }; function main(): void { diff --git a/ets2panda/test/parser/ets/declare_enum-expected.txt b/ets2panda/test/parser/ets/declare_enum-expected.txt index 99104b7475..3379dcdd36 100644 --- a/ets2panda/test/parser/ets/declare_enum-expected.txt +++ b/ets2panda/test/parser/ets/declare_enum-expected.txt @@ -2,43 +2,1465 @@ "type": "Program", "statements": [ { - "type": "TSEnumDeclaration", - "id": { - "type": "Identifier", - "name": "Enum", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 14 + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "EnumIntType", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 16, - "column": 18 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "members": [ - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "AAA", + }, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "AAA", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Enum", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "AAA", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Enum", + "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 + } + } + }, + "definite": false, "decorators": [], "loc": { "start": { - "line": 17, - "column": 5 + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "BBB", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "create", + "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": "#Enum#Enum", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "StringLiteral", + "value": "BBB", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Enum", + "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 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "@@arr", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "AAA", + "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 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "BBB", + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "create", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "private", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "create", + "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": "typ", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "val", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "idx", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Enum", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Enum", + "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 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "typ", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "val", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "name": "idx", + "decorators": [], + "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 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "ret", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "values", + "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": "values", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + "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 + } + } }, - "end": { - "line": 17, - "column": 8 + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } } - } - }, - "initializer": { - "type": "NumberLiteral", - "value": 0, + }, + "overloads": [], + "decorators": [], "loc": { "start": { "line": 1, @@ -50,37 +1472,509 @@ } } }, - "loc": { - "start": { - "line": 17, - "column": 5 + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "valueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } }, - "end": { - "line": 17, - "column": 8 - } - } - }, - { - "type": "TSEnumMember", - "id": { - "type": "Identifier", - "name": "BBB", + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "valueOf", + "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": "name", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "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 + } + } + }, + "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": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Enum", + "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 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "TSAsExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "enumValueOf", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "@@arr", + "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 + } + } + }, + { + "type": "Identifier", + "name": "name", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + "throwMarker": "throws", + "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": 5 + "line": 1, + "column": 1 }, "end": { - "line": 18, - "column": 8 + "line": 1, + "column": 1 } } }, - "initializer": { - "type": "NumberLiteral", - "value": 1, + { + "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": 1, @@ -91,20 +1985,19 @@ "column": 1 } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - "loc": { - "start": { - "line": 18, - "column": 5 - }, - "end": { - "line": 18, - "column": 8 - } + "end": { + "line": 1, + "column": 1 } } - ], - "const": false, + }, "loc": { "start": { "line": 16, -- Gitee From b663a409223e025dc6ebc0cdcc60207ef8bab998 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 6 Feb 2024 14:17:55 +0300 Subject: [PATCH 05/48] update enum20-expected.txt with respect to runtime changes Signed-off-by: Vadim Lomovtsev --- ets2panda/test/parser/ets/enum20-expected.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/ets2panda/test/parser/ets/enum20-expected.txt b/ets2panda/test/parser/ets/enum20-expected.txt index 3922b63528..3f623561d6 100644 --- a/ets2panda/test/parser/ets/enum20-expected.txt +++ b/ets2panda/test/parser/ets/enum20-expected.txt @@ -3309,4 +3309,3 @@ } } } -TypeError: Property 'ordinal' does not exist on type 'Color' [enum20.ets:19:23] -- Gitee From 1c8978a53014f0239473120c83cf6e7eba6919f6 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 6 Feb 2024 15:11:57 +0300 Subject: [PATCH 06/48] enumLowering: rename '@@arr' to 'arr', fix lib1.ts issue Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/types/ets/etsEnumType.cpp | 4 ++-- ets2panda/compiler/lowering/ets/enumLowering.cpp | 2 +- ets2panda/test/compiler/ets/enums_01-expected.txt | 6 +++--- .../compiler/ets/from-soft-keyword-3-expected.txt | 6 +++--- .../lambda_infer_type_retrun_enum-expected.txt | 6 +++--- ets2panda/test/parser/ets/declare_enum-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum10-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum11-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum12-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum13-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum14-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum19-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum20-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum21-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum4-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum6-expected.txt | 6 +++--- ets2panda/test/parser/ets/enum6.ets | 2 +- ets2panda/test/parser/ets/enum7-expected.txt | 12 ++++++------ ets2panda/test/parser/ets/enum8-expected.txt | 12 ++++++------ ets2panda/test/parser/ets/enum9-expected.txt | 6 +++--- ...xtension_function_not_for_class_type-expected.txt | 6 +++--- ets2panda/test/parser/ets/switch_enum-expected.txt | 6 +++--- ets2panda/test/parser/ets/switch_enum2-expected.txt | 6 +++--- ets2panda/test/parser/ets/switch_enum_3-expected.txt | 6 +++--- .../ets/switch_enum_case_duplicate-expected.txt | 6 +++--- ...witch_readonly_member_different_enum-expected.txt | 12 ++++++------ ...tch_readonly_member_different_enum_2-expected.txt | 12 ++++++------ .../ets/switch_readonly_member_enum-expected.txt | 12 ++++++------ ...witch_readonly_member_enum_duplicate-expected.txt | 12 ++++++------ 30 files changed, 103 insertions(+), 103 deletions(-) diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index bcfeb079fc..a30e125e6f 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -402,10 +402,10 @@ void ETSEnum2Type::CreateLiteralTypes(ETSChecker *checker, util::StringView name for (auto &it : decl_node->AsClassDefinition()->Body()) { if (!it->IsClassProperty() || !it->AsClassProperty()->Value()->IsCallExpression()) { - // @@arr property + // arr property auto *arr_ident = it->AsClassProperty()->Id(); auto *arr_var = arr_ident->Variable(); - ASSERT(arr_ident->Name() == "@@arr" && arr_var != nullptr); + ASSERT(arr_ident->Name() == "arr" && arr_var != nullptr); auto *array_type = checker->CreateETSArrayType(this); array_type->SetVariable(arr_var); diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index 9d628f746b..349b46f677 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -37,7 +37,7 @@ const char *ENUM_INT_BASE_CLASS_NAME = "EnumIntType"; const char *ENUM_STR_BASE_CLASS_NAME = "EnumStrType"; const char *ENUM_CONSTANT_CREATE_METHOD_NAME = "create"; const char *ENUM_VALUE_OF_LIB_FUNCTION_NAME = "enumValueOf"; -const char *ENUM_CONSTANT_ARRAY_NAME = "@@arr"; +const char *ENUM_CONSTANT_ARRAY_NAME = "arr"; auto CreateIdentifierRef(util::StringView const name, checker::ETSChecker *checker) { diff --git a/ets2panda/test/compiler/ets/enums_01-expected.txt b/ets2panda/test/compiler/ets/enums_01-expected.txt index efcb0375f5..056649ba55 100644 --- a/ets2panda/test/compiler/ets/enums_01-expected.txt +++ b/ets2panda/test/compiler/ets/enums_01-expected.txt @@ -842,7 +842,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1866,7 +1866,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2150,7 +2150,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt b/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt index 3a77f851a5..918f9efdf1 100644 --- a/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt +++ b/ets2panda/test/compiler/ets/from-soft-keyword-3-expected.txt @@ -705,7 +705,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1684,7 +1684,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1968,7 +1968,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt index 52fbbb282c..7d5614c559 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt @@ -454,7 +454,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1388,7 +1388,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1672,7 +1672,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/declare_enum-expected.txt b/ets2panda/test/parser/ets/declare_enum-expected.txt index 3379dcdd36..b1d5f47bd5 100644 --- a/ets2panda/test/parser/ets/declare_enum-expected.txt +++ b/ets2panda/test/parser/ets/declare_enum-expected.txt @@ -454,7 +454,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1388,7 +1388,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1672,7 +1672,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum-expected.txt b/ets2panda/test/parser/ets/enum-expected.txt index 88da04304d..e2e006a986 100644 --- a/ets2panda/test/parser/ets/enum-expected.txt +++ b/ets2panda/test/parser/ets/enum-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum10-expected.txt b/ets2panda/test/parser/ets/enum10-expected.txt index b139de95ce..f07570df0d 100644 --- a/ets2panda/test/parser/ets/enum10-expected.txt +++ b/ets2panda/test/parser/ets/enum10-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum11-expected.txt b/ets2panda/test/parser/ets/enum11-expected.txt index a7cf728a59..19c254981c 100644 --- a/ets2panda/test/parser/ets/enum11-expected.txt +++ b/ets2panda/test/parser/ets/enum11-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum12-expected.txt b/ets2panda/test/parser/ets/enum12-expected.txt index d8f278a998..805c64780a 100644 --- a/ets2panda/test/parser/ets/enum12-expected.txt +++ b/ets2panda/test/parser/ets/enum12-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum13-expected.txt b/ets2panda/test/parser/ets/enum13-expected.txt index 6790c4eab4..8e3e5ca4d4 100644 --- a/ets2panda/test/parser/ets/enum13-expected.txt +++ b/ets2panda/test/parser/ets/enum13-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum14-expected.txt b/ets2panda/test/parser/ets/enum14-expected.txt index 7a36976eef..f501a46f17 100644 --- a/ets2panda/test/parser/ets/enum14-expected.txt +++ b/ets2panda/test/parser/ets/enum14-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum19-expected.txt b/ets2panda/test/parser/ets/enum19-expected.txt index 61ddddb922..a63279338e 100644 --- a/ets2panda/test/parser/ets/enum19-expected.txt +++ b/ets2panda/test/parser/ets/enum19-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum20-expected.txt b/ets2panda/test/parser/ets/enum20-expected.txt index 3f623561d6..279efaf4c7 100644 --- a/ets2panda/test/parser/ets/enum20-expected.txt +++ b/ets2panda/test/parser/ets/enum20-expected.txt @@ -842,7 +842,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1866,7 +1866,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2150,7 +2150,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum21-expected.txt b/ets2panda/test/parser/ets/enum21-expected.txt index 16707525ca..f412982eb7 100644 --- a/ets2panda/test/parser/ets/enum21-expected.txt +++ b/ets2panda/test/parser/ets/enum21-expected.txt @@ -454,7 +454,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1388,7 +1388,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1672,7 +1672,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum4-expected.txt b/ets2panda/test/parser/ets/enum4-expected.txt index 0a4c274e4b..b6b7ec755b 100644 --- a/ets2panda/test/parser/ets/enum4-expected.txt +++ b/ets2panda/test/parser/ets/enum4-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum6-expected.txt b/ets2panda/test/parser/ets/enum6-expected.txt index af08c1aeab..495f8d0cbf 100644 --- a/ets2panda/test/parser/ets/enum6-expected.txt +++ b/ets2panda/test/parser/ets/enum6-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum6.ets b/ets2panda/test/parser/ets/enum6.ets index 3e23bd77bc..90853b1e4f 100644 --- a/ets2panda/test/parser/ets/enum6.ets +++ b/ets2panda/test/parser/ets/enum6.ets @@ -22,5 +22,5 @@ enum Color { function main(): void { let i: Color = Color.Red; i = Color.Green; - i = i.Blue; // TODO(aber) + i = i.Blue; } diff --git a/ets2panda/test/parser/ets/enum7-expected.txt b/ets2panda/test/parser/ets/enum7-expected.txt index 533ad1b4d2..24964032c9 100644 --- a/ets2panda/test/parser/ets/enum7-expected.txt +++ b/ets2panda/test/parser/ets/enum7-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2029,7 +2029,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2918,7 +2918,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -3202,7 +3202,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum8-expected.txt b/ets2panda/test/parser/ets/enum8-expected.txt index a66cccaf21..68aad2d813 100644 --- a/ets2panda/test/parser/ets/enum8-expected.txt +++ b/ets2panda/test/parser/ets/enum8-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2029,7 +2029,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2918,7 +2918,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -3202,7 +3202,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/enum9-expected.txt b/ets2panda/test/parser/ets/enum9-expected.txt index cf042bdcfd..59a4185076 100644 --- a/ets2panda/test/parser/ets/enum9-expected.txt +++ b/ets2panda/test/parser/ets/enum9-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/extension_function_tests/extension_function_not_for_class_type-expected.txt b/ets2panda/test/parser/ets/extension_function_tests/extension_function_not_for_class_type-expected.txt index c9f5f2e843..1b84684ff5 100644 --- a/ets2panda/test/parser/ets/extension_function_tests/extension_function_not_for_class_type-expected.txt +++ b/ets2panda/test/parser/ets/extension_function_tests/extension_function_not_for_class_type-expected.txt @@ -260,7 +260,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1149,7 +1149,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1433,7 +1433,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/switch_enum-expected.txt b/ets2panda/test/parser/ets/switch_enum-expected.txt index 86c28edd58..690f778090 100644 --- a/ets2panda/test/parser/ets/switch_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/switch_enum2-expected.txt b/ets2panda/test/parser/ets/switch_enum2-expected.txt index eccd7e60cb..ef66b72e2a 100644 --- a/ets2panda/test/parser/ets/switch_enum2-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum2-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/switch_enum_3-expected.txt b/ets2panda/test/parser/ets/switch_enum_3-expected.txt index 9c4f228b99..e90730be3f 100644 --- a/ets2panda/test/parser/ets/switch_enum_3-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum_3-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt index 09735ed4df..bab2550fcf 100644 --- a/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum_case_duplicate-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt index 438834c381..67d744d461 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2895,7 +2895,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -3874,7 +3874,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -4158,7 +4158,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt index 7db1b791a7..0500129c6b 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2895,7 +2895,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -3874,7 +3874,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -4158,7 +4158,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt index 712a92b4b5..d7efd33f24 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2895,7 +2895,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -3874,7 +3874,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -4158,7 +4158,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt index d7f0052731..6e82de7efb 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt @@ -648,7 +648,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1627,7 +1627,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -1911,7 +1911,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -2895,7 +2895,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -3874,7 +3874,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { @@ -4158,7 +4158,7 @@ }, "property": { "type": "Identifier", - "name": "@@arr", + "name": "arr", "decorators": [], "loc": { "start": { -- Gitee From 2e70a2c7c92d83b044551e9ce680d17b4ddf6f75 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 12 Feb 2024 13:23:43 +0300 Subject: [PATCH 07/48] rebase fixes Signed-off-by: Vadim Lomovtsev --- ets2panda/compiler/lowering/ets/enumLowering.cpp | 4 ++-- ets2panda/compiler/lowering/ets/enumLowering.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index 349b46f677..3066a8e333 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -30,7 +30,7 @@ #include "ir/ts/tsEnumDeclaration.h" -namespace panda::es2panda::compiler { +namespace ark::es2panda::compiler { // const char* EnumConstantClassName = "EnumConst"; const char *ENUM_INT_BASE_CLASS_NAME = "EnumIntType"; @@ -389,4 +389,4 @@ bool EnumLowering::Perform(public_lib::Context *ctx, parser::Program *program) return true; } -} // namespace panda::es2panda::compiler +} // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/enumLowering.h b/ets2panda/compiler/lowering/ets/enumLowering.h index 20815a4c9c..82acf1a493 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.h +++ b/ets2panda/compiler/lowering/ets/enumLowering.h @@ -18,7 +18,7 @@ #include "compiler/lowering/phase.h" -namespace panda::es2panda::compiler { +namespace ark::es2panda::compiler { class EnumLowering : public Phase { public: @@ -29,6 +29,6 @@ public: bool Perform(public_lib::Context *ctx, parser::Program *program) override; }; -} // namespace panda::es2panda::compiler +} // namespace ark::es2panda::compiler #endif -- Gitee From 77ab490d4f9195a35fd6f8bcf338e5060296dbe9 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 13 Feb 2024 11:45:04 +0300 Subject: [PATCH 08/48] put potential fix for CI tests Fixed follwoign tests: ets-runtime: - Enum2.ets ets-cts: - 03.types/08.reference_types/06.array_types/object_8.ets - 03.types/08.reference_types/06.array_types/types_8.ets - 11.enumerations/02.enumeration_operations/enum_type_methods_valueof.ets Signed-off-by: Vadim Lomovtsev --- ets2panda/compiler/core/ETSGen.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 8074b0700b..96d8853d54 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -2599,6 +2599,11 @@ void ETSGen::LoadArrayElement(const ir::AstNode *node, VReg objectReg) Ra().Emit(node, objectReg); break; } + // WARNING: this seems to fix assert bu cause later run-time verifier failures + case checker::TypeFlag::ETS_ENUM2_TYPE: { + Ra().Emit(node, objectReg); + break; + } default: { UNREACHABLE(); -- Gitee From 4f46ebc3709812754a19f91668ce4cebb3e36e08 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Thu, 15 Feb 2024 12:01:52 +0300 Subject: [PATCH 09/48] rename enumLowering to enumLoweringPrePhase Signed-off-by: Vadim Lomovtsev --- ets2panda/BUILD.gn | 1 + ets2panda/CMakeLists.txt | 2 +- .../ets/{enumLowering.cpp => enumLoweringPrePhase.cpp} | 4 ++-- .../ets/{enumLowering.h => enumLoweringPrePhase.h} | 10 +++++----- ets2panda/compiler/lowering/phase.cpp | 6 +++--- 5 files changed, 12 insertions(+), 11 deletions(-) rename ets2panda/compiler/lowering/ets/{enumLowering.cpp => enumLoweringPrePhase.cpp} (99%) rename ets2panda/compiler/lowering/ets/{enumLowering.h => enumLoweringPrePhase.h} (76%) diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index f80821e40e..0f9f47c733 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -160,6 +160,7 @@ libes2panda_sources = [ "compiler/lowering/checkerPhase.cpp", "compiler/lowering/ets/bigintLowering.cpp", "compiler/lowering/ets/defaultParameterLowering.cpp", + "compiler/lowering/ets/enumLoweringPrePhase.cpp", "compiler/lowering/ets/expandBrackets.cpp", "compiler/lowering/ets/generateDeclarations.cpp", "compiler/lowering/ets/interfacePropertyDeclarations.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index b3311884b8..e0fa04ab7e 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -150,7 +150,7 @@ set(ES2PANDA_LIB_SRC compiler/lowering/phase.cpp compiler/lowering/plugin_phase.cpp compiler/lowering/util.cpp - compiler/lowering/ets/enumLowering.cpp + compiler/lowering/ets/enumLoweringPrePhase.cpp compiler/lowering/ets/lambdaLowering.cpp compiler/lowering/ets/generateDeclarations.cpp compiler/lowering/ets/objectIndexAccess.cpp diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp similarity index 99% rename from ets2panda/compiler/lowering/ets/enumLowering.cpp rename to ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index 3066a8e333..8a3a5ad54e 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "enumLowering.h" +#include "enumLoweringPrePhase.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "varbinder/variableFlags.h" @@ -363,7 +363,7 @@ ir::AstNode *CreateEnumClassFromEnumDeclaration(ir::TSEnumDeclaration *enum_decl return class_decl; } -bool EnumLowering::Perform(public_lib::Context *ctx, parser::Program *program) +bool EnumLoweringPrePhase::Perform(public_lib::Context *ctx, parser::Program *program) { if (program->Extension() != ScriptExtension::ETS) { return true; diff --git a/ets2panda/compiler/lowering/ets/enumLowering.h b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h similarity index 76% rename from ets2panda/compiler/lowering/ets/enumLowering.h rename to ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h index 82acf1a493..d8d8a41990 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.h +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h @@ -13,22 +13,22 @@ * limitations under the License. */ -#ifndef ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_H -#define ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_H +#ifndef ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_PREPHASE_H +#define ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_PREPHASE_H #include "compiler/lowering/phase.h" namespace ark::es2panda::compiler { -class EnumLowering : public Phase { +class EnumLoweringPrePhase : public Phase { public: std::string_view Name() override { - return "EnumLowering"; + return "EnumLoweringPrePhase"; } bool Perform(public_lib::Context *ctx, parser::Program *program) override; }; } // namespace ark::es2panda::compiler -#endif +#endif // ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_PREPHASE_H diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index 828dd90236..980b717267 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -20,7 +20,7 @@ #include "compiler/lowering/ets/defaultParameterLowering.h" #include "compiler/lowering/ets/expandBrackets.h" #include "compiler/lowering/ets/recordLowering.h" -#include "compiler/lowering/ets/enumLowering.h" +#include "compiler/lowering/ets/enumLoweringPrePhase.h" #include "compiler/lowering/ets/generateDeclarations.h" #include "compiler/lowering/ets/lambdaLowering.h" #include "compiler/lowering/ets/interfacePropertyDeclarations.h" @@ -66,7 +66,7 @@ static PromiseVoidInferencePhase g_promiseVoidInferencePhase; static RecordLowering g_recordLowering; static StructLowering g_structLowering; static DefaultParameterLowering g_defaultParameterLowering; -static EnumLowering g_enumLowering; +static EnumLoweringPrePhase g_enumLoweringPrePhase; static PluginPhase g_pluginsAfterParse {"plugins-after-parse", ES2PANDA_STATE_PARSED, &util::Plugin::AfterParse}; static PluginPhase g_pluginsAfterCheck {"plugins-after-check", ES2PANDA_STATE_CHECKED, &util::Plugin::AfterCheck}; static PluginPhase g_pluginsAfterLowerings {"plugins-after-lowering", ES2PANDA_STATE_LOWERED, @@ -83,7 +83,7 @@ std::vector GetETSPhaseList() return { &g_defaultParameterLowering, &g_bigintLowering, - &g_enumLowering, + &g_enumLoweringPrePhase, &g_pluginsAfterParse, &g_initScopesPhaseEts, &g_optionalLowering, -- Gitee From 4567594c5eeb6a06a1d09baf6c355dc1ae7db466 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Thu, 15 Feb 2024 12:25:15 +0300 Subject: [PATCH 10/48] add post phase for Lowering Signed-off-by: Vadim Lomovtsev --- ets2panda/BUILD.gn | 1 + ets2panda/CMakeLists.txt | 1 + .../lowering/ets/enumLoweringPostPhase.cpp | 81 +++++++++++++++++++ .../lowering/ets/enumLoweringPostPhase.h | 34 ++++++++ ets2panda/compiler/lowering/phase.cpp | 3 + 5 files changed, 120 insertions(+) create mode 100644 ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp create mode 100644 ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 0f9f47c733..89b245599b 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -160,6 +160,7 @@ libes2panda_sources = [ "compiler/lowering/checkerPhase.cpp", "compiler/lowering/ets/bigintLowering.cpp", "compiler/lowering/ets/defaultParameterLowering.cpp", + "compiler/lowering/ets/enumLoweringPostPhase.cpp", "compiler/lowering/ets/enumLoweringPrePhase.cpp", "compiler/lowering/ets/expandBrackets.cpp", "compiler/lowering/ets/generateDeclarations.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index e0fa04ab7e..e5cf81c679 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -150,6 +150,7 @@ set(ES2PANDA_LIB_SRC compiler/lowering/phase.cpp compiler/lowering/plugin_phase.cpp compiler/lowering/util.cpp + compiler/lowering/ets/enumLoweringPostPhase.cpp compiler/lowering/ets/enumLoweringPrePhase.cpp compiler/lowering/ets/lambdaLowering.cpp compiler/lowering/ets/generateDeclarations.cpp diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp new file mode 100644 index 0000000000..d66c65b951 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "enumLoweringPostPhase.h" +#include "compiler/lowering/scopesInit/scopesInitPhase.h" + +#include "varbinder/variableFlags.h" +#include "varbinder/ETSBinder.h" +#include "checker/ETSchecker.h" +#include "compiler/core/compilerContext.h" +#include "compiler/lowering/util.h" +#include "ir/statements/classDeclaration.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" +#include "ir/astNode.h" +#include "ir/expression.h" +#include "util/ustring.h" + +#include "ir/ts/tsEnumDeclaration.h" + +namespace ark::es2panda::compiler { + +bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *program) +{ + if (program->Extension() != ScriptExtension::ETS) { + return true; + } + + [[maybe_unused]] checker::ETSChecker *checker = ctx->checker->AsETSChecker(); + + for (auto &[_, ext_programs] : program->ExternalSources()) { + (void)_; + for (auto *ext_prog : ext_programs) { + Perform(ctx, ext_prog); + } + } + + program->Ast()->TransformChildrenRecursively([program](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsCallExpression()) { + // check & update call expression with explicit cast to new type + // e.g. for the following + // + // enum Color {Red, Blue, Green, Yellow}; + // function foo(a:Color) {..} + // function main():void { + // foo(1); + // } + // + // so the foo(1) should be translated to foo(Color.Blue) + } else if (ast->IsIfStatement()) { + // check & update conditional expression with explicit cast to new type + // e.g. for the following + // + // enum Color {Red, Blue, Green, Yellow}; + // function main():void { + // let v: Color = Color.Blue; + // if (v) {...} + // } + // + // so the if (v) should be translated to the if (v.getValue() == true) ?? + } + + return ast; + }); + + return true; +} + +} // namespace ark::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h new file mode 100644 index 0000000000..430e5a4823 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_POSTPHASE_H +#define ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_POSTPHASE_H + +#include "compiler/lowering/phase.h" + +namespace ark::es2panda::compiler { + +class EnumLoweringPostPhase : public Phase { +public: + std::string_view Name() override + { + return "EnumLoweringPostPhase"; + } + bool Perform(public_lib::Context *ctx, parser::Program *program) override; +}; + +} // namespace ark::es2panda::compiler + +#endif // ES2PANDA_COMPILER_LOWERING_ENUM_LOWERING_POSTPHASE_H diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index 980b717267..3fa29d7490 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -21,6 +21,7 @@ #include "compiler/lowering/ets/expandBrackets.h" #include "compiler/lowering/ets/recordLowering.h" #include "compiler/lowering/ets/enumLoweringPrePhase.h" +#include "compiler/lowering/ets/enumLoweringPostPhase.h" #include "compiler/lowering/ets/generateDeclarations.h" #include "compiler/lowering/ets/lambdaLowering.h" #include "compiler/lowering/ets/interfacePropertyDeclarations.h" @@ -67,6 +68,7 @@ static RecordLowering g_recordLowering; static StructLowering g_structLowering; static DefaultParameterLowering g_defaultParameterLowering; static EnumLoweringPrePhase g_enumLoweringPrePhase; +static EnumLoweringPostPhase g_enumLoweringPostPhase; static PluginPhase g_pluginsAfterParse {"plugins-after-parse", ES2PANDA_STATE_PARSED, &util::Plugin::AfterParse}; static PluginPhase g_pluginsAfterCheck {"plugins-after-check", ES2PANDA_STATE_CHECKED, &util::Plugin::AfterCheck}; static PluginPhase g_pluginsAfterLowerings {"plugins-after-lowering", ES2PANDA_STATE_LOWERED, @@ -101,6 +103,7 @@ std::vector GetETSPhaseList() &g_tupleLowering, &g_unionLowering, &g_expandBracketsPhase, + &g_enumLoweringPostPhase, &g_pluginsAfterLowerings, }; } -- Gitee From ea410db995e28a2ac383307b3600fde739e80311 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Fri, 16 Feb 2024 09:59:14 +0300 Subject: [PATCH 11/48] fix for if(v) for enum TODO: remove debug code, squash or rework peaces into separate functions Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.cpp | 114 +++++++++++++++--- ets2panda/compiler/lowering/phase.cpp | 2 +- ets2panda/ir/statements/ifStatement.h | 4 + 3 files changed, 103 insertions(+), 17 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index d66c65b951..b25c0b849a 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -16,22 +16,56 @@ #include "enumLoweringPostPhase.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" -#include "varbinder/variableFlags.h" -#include "varbinder/ETSBinder.h" +#include "utils/arena_containers.h" #include "checker/ETSchecker.h" #include "compiler/core/compilerContext.h" -#include "compiler/lowering/util.h" -#include "ir/statements/classDeclaration.h" #include "ir/base/classDefinition.h" #include "ir/base/classProperty.h" #include "ir/astNode.h" #include "ir/expression.h" #include "util/ustring.h" +#include "compiler/lowering/util.h" #include "ir/ts/tsEnumDeclaration.h" namespace ark::es2panda::compiler { +ir::AstNode *CreateCallExpression(ir::AstNode *ast, CompilerContext *ctx) +{ + // only identifiers allowed here! + ASSERT(ast->IsIfStatement() && ast->AsIfStatement()->Test()->IsIdentifier()); + + auto *checker = ctx->Checker()->AsETSChecker(); + [[maybe_unused]] auto *id = + checker->AllocNode(ast->AsIfStatement()->Test()->AsIdentifier()->Name(), + checker->Allocator()); // ast->AsIfStatement()->Test()->AsIdentifier(); + id->SetReference(); + auto *const callee = checker->AllocNode(util::StringView("getValue"), checker->Allocator()); + callee->SetReference(); + + ir::Expression *const accessor = + checker->AllocNode(id, // ast->AsIfStatement()->Test()->AsIdentifier(), + callee, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + id->SetParent(accessor); + callee->SetParent(accessor); + + ir::CallExpression *callExpression = checker->AllocNode( + accessor, ArenaVector(checker->Allocator()->Adapter()), nullptr, false); + accessor->SetParent(callExpression); + + auto *right = checker->AllocNode(util::StringView("0")); + ir::Expression *testExpr = + checker->AllocNode(callExpression, right, lexer::TokenType::PUNCTUATOR_NOT_EQUAL); + // testExpr->SetTsType(testExpr->Check(checker)); + callExpression->SetParent(testExpr); + right->SetParent(testExpr); + + auto *test = checker->AllocNode(testExpr, ast->AsIfStatement()->Consequent(), + ast->AsIfStatement()->Alternate()); + testExpr->SetParent(test); + return test; +} + bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *program) { if (program->Extension() != ScriptExtension::ETS) { @@ -47,7 +81,7 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } } - program->Ast()->TransformChildrenRecursively([program](ir::AstNode *ast) -> ir::AstNode * { + program->Ast()->TransformChildrenRecursively([checker, ctx, program](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsCallExpression()) { // check & update call expression with explicit cast to new type // e.g. for the following @@ -60,18 +94,66 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p // // so the foo(1) should be translated to foo(Color.Blue) } else if (ast->IsIfStatement()) { - // check & update conditional expression with explicit cast to new type - // e.g. for the following - // - // enum Color {Red, Blue, Green, Yellow}; - // function main():void { - // let v: Color = Color.Blue; - // if (v) {...} - // } - // - // so the if (v) should be translated to the if (v.getValue() == true) ?? - } + // so far let's put this only for test script + if (program->SourceFile().GetFileName() == util::StringView("40.01")) { + std::cout << "File: " << program->SourceFile().GetFileName() + << ": test statement: " << ast->AsIfStatement()->Test()->DumpJSON() << std::endl; + auto *test = ast->AsIfStatement()->Test(); + if (test->IsIdentifier()) { + std::cout << "Found Identifier: " << test->AsIdentifier()->Name() << std::endl; + // we got simple variable test expression, test against non-zero value + ASSERT(test->AsIdentifier()->Variable() != nullptr); + auto *type = checker->GetTypeOfVariable(test->AsIdentifier()->Variable()); + ASSERT(type != nullptr); + if (type->IsETSEnum2Type()) { + std::cout << "Found type: ETSEnum2Type: " << type << std::endl; + // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' + // NOTE: what about string as enum constant? + auto *parent = ast->Parent(); + auto *const scope = NearestScope(test); + auto expressionCtx = + varbinder::LexicalScope::Enter(checker->VarBinder(), scope); + auto *node = CreateCallExpression(ast, ctx->compilerContext); + node->SetParent(parent); + std::cout << "Updated node: " << node->DumpJSON() << std::endl; + + InitScopesPhaseETS::RunExternalNode(node, ctx->compilerContext->VarBinder()); + checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(node, scope); + node->Check(checker); + return node; + } else { + // .. + } + } else if (test->IsCallExpression()) { + // simple callexpression with default non-zero test + // need to checkif we'recalling to getValue() fo enum constant + } + + // check & update conditional expression with explicit cast to new type + // e.g. for the following + // + // enum Color {Red, Blue, Green, Yellow}; + // function main():void { + // let v: Color = Color.Blue; + // if (v) {...} + // } + // + // so the if (v) should be translated to the if (v.getValue() == true) ?? + // + [[maybe_unused]] auto *consequent = ast->AsIfStatement()->Consequent(); + [[maybe_unused]] auto *alternate = ast->AsIfStatement()->Alternate(); + // std::cout << "File name: " << program->SourceFile().GetFileName() << std::endl; + if (0 && program->SourceFile().GetFileName().Compare(util::StringView("40.01")) == 0) { + std::cout << program->SourceFile().GetFileName() + << ": conditional expression: " << ast->AsIfStatement()->DumpJSON() << std::endl; + if (0 && consequent != nullptr) + std::cout << "consequent: " << consequent->DumpJSON() << std::endl; + if (0 && alternate != nullptr) + std::cout << "alternate: " << alternate->DumpJSON() << std::endl; + } + } + } return ast; }); diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index 3fa29d7490..c0dfac62c9 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -85,8 +85,8 @@ std::vector GetETSPhaseList() return { &g_defaultParameterLowering, &g_bigintLowering, - &g_enumLoweringPrePhase, &g_pluginsAfterParse, + &g_enumLoweringPrePhase, &g_initScopesPhaseEts, &g_optionalLowering, &g_promiseVoidInferencePhase, diff --git a/ets2panda/ir/statements/ifStatement.h b/ets2panda/ir/statements/ifStatement.h index 3541f32ee2..d932dd8455 100644 --- a/ets2panda/ir/statements/ifStatement.h +++ b/ets2panda/ir/statements/ifStatement.h @@ -42,6 +42,10 @@ public: return test_; } + Statement *Consequent() + { + return consequent_; + } const Statement *Consequent() const { return consequent_; -- Gitee From eb8c492b3dea2f73a549cc8ba3b5d1c86bb9630b Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Fri, 16 Feb 2024 12:18:05 +0300 Subject: [PATCH 12/48] put simple fixes for loop test expression (for IsIdentifier only) Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.cpp | 178 +++++++++++------- 1 file changed, 110 insertions(+), 68 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index b25c0b849a..6581001e86 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -30,35 +30,43 @@ namespace ark::es2panda::compiler { -ir::AstNode *CreateCallExpression(ir::AstNode *ast, CompilerContext *ctx) +ir::CallExpression *CreateCallExpression(ir::Identifier *id, checker::ETSChecker *checker) { - // only identifiers allowed here! - ASSERT(ast->IsIfStatement() && ast->AsIfStatement()->Test()->IsIdentifier()); - - auto *checker = ctx->Checker()->AsETSChecker(); - [[maybe_unused]] auto *id = - checker->AllocNode(ast->AsIfStatement()->Test()->AsIdentifier()->Name(), - checker->Allocator()); // ast->AsIfStatement()->Test()->AsIdentifier(); - id->SetReference(); auto *const callee = checker->AllocNode(util::StringView("getValue"), checker->Allocator()); callee->SetReference(); - ir::Expression *const accessor = - checker->AllocNode(id, // ast->AsIfStatement()->Test()->AsIdentifier(), - callee, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + checker->AllocNode(id, callee, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); id->SetParent(accessor); callee->SetParent(accessor); ir::CallExpression *callExpression = checker->AllocNode( accessor, ArenaVector(checker->Allocator()->Adapter()), nullptr, false); accessor->SetParent(callExpression); + return callExpression; +} +ir::Expression *CreateTestExpre(ir::Identifier *id, checker::ETSChecker *checker) +{ + auto *callExpression = CreateCallExpression(id, checker); auto *right = checker->AllocNode(util::StringView("0")); ir::Expression *testExpr = checker->AllocNode(callExpression, right, lexer::TokenType::PUNCTUATOR_NOT_EQUAL); - // testExpr->SetTsType(testExpr->Check(checker)); callExpression->SetParent(testExpr); right->SetParent(testExpr); + return testExpr; +} + +ir::AstNode *CreateCallExpression_if(ir::AstNode *ast, CompilerContext *ctx) +{ + // only identifiers allowed here! + ASSERT(ast->IsIfStatement() && ast->AsIfStatement()->Test()->IsIdentifier()); + + auto *checker = ctx->Checker()->AsETSChecker(); + [[maybe_unused]] auto *id = + checker->AllocNode(ast->AsIfStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); + id->SetReference(); + + auto *testExpr = CreateTestExpre(id, checker); auto *test = checker->AllocNode(testExpr, ast->AsIfStatement()->Consequent(), ast->AsIfStatement()->Alternate()); @@ -66,6 +74,40 @@ ir::AstNode *CreateCallExpression(ir::AstNode *ast, CompilerContext *ctx) return test; } +ir::AstNode *CreateCallExpression_while(ir::AstNode *ast, CompilerContext *ctx) +{ + // only identifiers allowed here! + ASSERT(ast->IsWhileStatement() && ast->AsWhileStatement()->Test()->IsIdentifier()); + + auto *checker = ctx->Checker()->AsETSChecker(); + [[maybe_unused]] auto *id = checker->AllocNode( + ast->AsWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); + id->SetReference(); + + auto *testExpr = CreateTestExpre(id, checker); + + auto *expr = checker->AllocNode(testExpr, ast->AsWhileStatement()->Body()); + testExpr->SetParent(expr); + return expr; +} + +ir::AstNode *CreateCallExpression_do_while(ir::AstNode *ast, CompilerContext *ctx) +{ + // only identifiers allowed here! + ASSERT(ast->IsDoWhileStatement() && ast->AsDoWhileStatement()->Test()->IsIdentifier()); + + auto *checker = ctx->Checker()->AsETSChecker(); + [[maybe_unused]] auto *id = checker->AllocNode( + ast->AsDoWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); + id->SetReference(); + + auto *testExpr = CreateTestExpre(id, checker); + + auto *expr = checker->AllocNode(ast->AsDoWhileStatement()->Body(), testExpr); + testExpr->SetParent(expr); + return expr; +} + bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *program) { if (program->Extension() != ScriptExtension::ETS) { @@ -93,65 +135,65 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p // } // // so the foo(1) should be translated to foo(Color.Blue) - } else if (ast->IsIfStatement()) { + } else if (ast->IsBinaryExpression()) { + // auto *rightExpr = AllocNode(left, rightExpr, operatorType); + [[maybe_unused]] auto *left = ast->AsBinaryExpression()->Left(); + [[maybe_unused]] auto *right = ast->AsBinaryExpression()->Right(); + + } else if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement()) { // so far let's put this only for test script - if (program->SourceFile().GetFileName() == util::StringView("40.01")) { - std::cout << "File: " << program->SourceFile().GetFileName() - << ": test statement: " << ast->AsIfStatement()->Test()->DumpJSON() << std::endl; - auto *test = ast->AsIfStatement()->Test(); - if (test->IsIdentifier()) { - std::cout << "Found Identifier: " << test->AsIdentifier()->Name() << std::endl; - // we got simple variable test expression, test against non-zero value - ASSERT(test->AsIdentifier()->Variable() != nullptr); - auto *type = checker->GetTypeOfVariable(test->AsIdentifier()->Variable()); - ASSERT(type != nullptr); - if (type->IsETSEnum2Type()) { - std::cout << "Found type: ETSEnum2Type: " << type << std::endl; - // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' - // NOTE: what about string as enum constant? - auto *parent = ast->Parent(); - auto *const scope = NearestScope(test); - auto expressionCtx = - varbinder::LexicalScope::Enter(checker->VarBinder(), scope); - auto *node = CreateCallExpression(ast, ctx->compilerContext); - node->SetParent(parent); - std::cout << "Updated node: " << node->DumpJSON() << std::endl; - - InitScopesPhaseETS::RunExternalNode(node, ctx->compilerContext->VarBinder()); - - checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(node, scope); - node->Check(checker); - return node; - } else { - // .. - } - } else if (test->IsCallExpression()) { - // simple callexpression with default non-zero test - // need to checkif we'recalling to getValue() fo enum constant + const ir::Expression *test = nullptr; + if (ast->IsIfStatement()) + test = ast->AsIfStatement()->Test(); + if (ast->IsWhileStatement()) + test = ast->AsWhileStatement()->Test(); + if (ast->IsDoWhileStatement()) + test = ast->AsDoWhileStatement()->Test(); + + std::cout << "File: " << program->SourceFile().GetFileName() << ": test statement: " << test->DumpJSON() + << std::endl; + if (test->IsIdentifier()) { + std::cout << "Found Identifier: " << test->AsIdentifier()->Name() << std::endl; + // we got simple variable test expression, test against non-zero value + // ASSERT(test->AsIdentifier()->Variable() != nullptr); + if (test->AsIdentifier()->Variable() == nullptr) { + return ast; } + auto *type = checker->GetTypeOfVariable(test->AsIdentifier()->Variable()); + ASSERT(type != nullptr); + if (type->IsETSEnum2Type()) { + std::cout << "Found type: ETSEnum2Type: " << type << std::endl; + // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' + // NOTE: what about string as enum constant? + auto *parent = ast->Parent(); + auto *const scope = NearestScope(test); + auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); + ir::AstNode *node = nullptr; + if (ast->IsIfStatement()) + node = CreateCallExpression_if(ast, ctx->compilerContext); + if (ast->IsWhileStatement()) + node = CreateCallExpression_while(ast, ctx->compilerContext); + if (ast->IsDoWhileStatement()) + node = CreateCallExpression_do_while(ast, ctx->compilerContext); + + if (node == nullptr) { + std::cout << "ERRPR: can't create proper substitution!" << std::endl; + return ast; + } + node->SetParent(parent); + std::cout << "Updated node: " << node->DumpJSON() << std::endl; + + InitScopesPhaseETS::RunExternalNode(node, ctx->compilerContext->VarBinder()); - // check & update conditional expression with explicit cast to new type - // e.g. for the following - // - // enum Color {Red, Blue, Green, Yellow}; - // function main():void { - // let v: Color = Color.Blue; - // if (v) {...} - // } - // - // so the if (v) should be translated to the if (v.getValue() == true) ?? - // - [[maybe_unused]] auto *consequent = ast->AsIfStatement()->Consequent(); - [[maybe_unused]] auto *alternate = ast->AsIfStatement()->Alternate(); - // std::cout << "File name: " << program->SourceFile().GetFileName() << std::endl; - if (0 && program->SourceFile().GetFileName().Compare(util::StringView("40.01")) == 0) { - std::cout << program->SourceFile().GetFileName() - << ": conditional expression: " << ast->AsIfStatement()->DumpJSON() << std::endl; - if (0 && consequent != nullptr) - std::cout << "consequent: " << consequent->DumpJSON() << std::endl; - if (0 && alternate != nullptr) - std::cout << "alternate: " << alternate->DumpJSON() << std::endl; + checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(node, scope); + node->Check(checker); + return node; + } else { + // .. } + } else if (test->IsCallExpression()) { + // simple callexpression with default non-zero test + // need to checkif we'recalling to getValue() fo enum constant } } return ast; -- Gitee From 4e0e682184c453bea900ae6c91a2e5f70b578503 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Fri, 16 Feb 2024 16:25:22 +0300 Subject: [PATCH 13/48] put while/do..while/for processing Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.cpp | 108 ++++++++++++------ ets2panda/ir/statements/doWhileStatement.h | 5 + ets2panda/ir/statements/forUpdateStatement.h | 5 + ets2panda/ir/statements/ifStatement.h | 10 ++ ets2panda/ir/statements/whileStatement.h | 5 + ets2panda/varbinder/varbinder.cpp | 1 + 6 files changed, 101 insertions(+), 33 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index 6581001e86..995c4f8bea 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -45,7 +45,7 @@ ir::CallExpression *CreateCallExpression(ir::Identifier *id, checker::ETSChecker return callExpression; } -ir::Expression *CreateTestExpre(ir::Identifier *id, checker::ETSChecker *checker) +ir::Expression *CreateTestExpression(ir::Identifier *id, checker::ETSChecker *checker) { auto *callExpression = CreateCallExpression(id, checker); auto *right = checker->AllocNode(util::StringView("0")); @@ -62,16 +62,19 @@ ir::AstNode *CreateCallExpression_if(ir::AstNode *ast, CompilerContext *ctx) ASSERT(ast->IsIfStatement() && ast->AsIfStatement()->Test()->IsIdentifier()); auto *checker = ctx->Checker()->AsETSChecker(); - [[maybe_unused]] auto *id = - checker->AllocNode(ast->AsIfStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); - id->SetReference(); - - auto *testExpr = CreateTestExpre(id, checker); - - auto *test = checker->AllocNode(testExpr, ast->AsIfStatement()->Consequent(), - ast->AsIfStatement()->Alternate()); - testExpr->SetParent(test); - return test; + auto *id = ast->AsIfStatement()->Test()->AsIdentifier(); + // auto *id = + // checker->AllocNode(ast->AsIfStatement()->Test()->AsIdentifier()->Name(), + // checker->Allocator()); + // id->SetReference(); + + auto *testExpr = CreateTestExpression(id, checker); + + // auto *test = checker->AllocNode(testExpr, ast->AsIfStatement()->Consequent(), + // ast->AsIfStatement()->Alternate()); + ast->AsIfStatement()->SetTest(testExpr); + testExpr->SetParent(ast); + return ast; } ir::AstNode *CreateCallExpression_while(ir::AstNode *ast, CompilerContext *ctx) @@ -80,15 +83,17 @@ ir::AstNode *CreateCallExpression_while(ir::AstNode *ast, CompilerContext *ctx) ASSERT(ast->IsWhileStatement() && ast->AsWhileStatement()->Test()->IsIdentifier()); auto *checker = ctx->Checker()->AsETSChecker(); - [[maybe_unused]] auto *id = checker->AllocNode( - ast->AsWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); - id->SetReference(); + auto *id = ast->AsWhileStatement()->Test()->AsIdentifier(); + // auto *id = checker->AllocNode( + // ast->AsWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); + // id->SetReference(); - auto *testExpr = CreateTestExpre(id, checker); + auto *testExpr = CreateTestExpression(id, checker); - auto *expr = checker->AllocNode(testExpr, ast->AsWhileStatement()->Body()); - testExpr->SetParent(expr); - return expr; + // auto *expr = checker->AllocNode(testExpr, ast->AsWhileStatement()->Body()); + ast->AsWhileStatement()->SetTest(testExpr); + testExpr->SetParent(ast); + return ast; } ir::AstNode *CreateCallExpression_do_while(ir::AstNode *ast, CompilerContext *ctx) @@ -97,15 +102,39 @@ ir::AstNode *CreateCallExpression_do_while(ir::AstNode *ast, CompilerContext *ct ASSERT(ast->IsDoWhileStatement() && ast->AsDoWhileStatement()->Test()->IsIdentifier()); auto *checker = ctx->Checker()->AsETSChecker(); - [[maybe_unused]] auto *id = checker->AllocNode( - ast->AsDoWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); - id->SetReference(); + auto *id = ast->AsDoWhileStatement()->Test()->AsIdentifier(); + // auto *id = checker->AllocNode( + // ast->AsDoWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); + // id->SetReference(); + + auto *testExpr = CreateTestExpression(id, checker); - auto *testExpr = CreateTestExpre(id, checker); + // auto *expr = checker->AllocNode(ast->AsDoWhileStatement()->Body(), testExpr); + ast->AsDoWhileStatement()->SetTest(testExpr); + testExpr->SetParent(ast); + return ast; +} + +ir::AstNode *CreateCallExpression_for_update(ir::AstNode *ast, CompilerContext *ctx) +{ + // only identifiers allowed here! + ASSERT(ast->IsForUpdateStatement() && ast->AsForUpdateStatement()->Test()->IsIdentifier()); - auto *expr = checker->AllocNode(ast->AsDoWhileStatement()->Body(), testExpr); - testExpr->SetParent(expr); - return expr; + auto *checker = ctx->Checker()->AsETSChecker(); + auto *id = ast->AsForUpdateStatement()->Test()->AsIdentifier(); + // auto *id = checker->AllocNode(ast->AsForUpdateStatement()->Test()->AsIdentifier()->Name(), + // checker->Allocator()); + // id->SetReference(); + + auto *testExpr = CreateTestExpression(id, checker); + + // auto *expr = checker->AllocNode(ast->AsForUpdateStatement()->Init(), testExpr, + // ast->AsForUpdateStatement()->Update(), + // ast->AsForUpdateStatement()->Body()); + // testExpr->SetParent(expr); + ast->AsForUpdateStatement()->SetTest(testExpr); + testExpr->SetParent(ast); + return ast; } bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *program) @@ -140,7 +169,8 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p [[maybe_unused]] auto *left = ast->AsBinaryExpression()->Left(); [[maybe_unused]] auto *right = ast->AsBinaryExpression()->Right(); - } else if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement()) { + } else if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || + ast->IsForUpdateStatement()) { // so far let's put this only for test script const ir::Expression *test = nullptr; if (ast->IsIfStatement()) @@ -149,11 +179,17 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p test = ast->AsWhileStatement()->Test(); if (ast->IsDoWhileStatement()) test = ast->AsDoWhileStatement()->Test(); + if (ast->IsForUpdateStatement()) + test = ast->AsForUpdateStatement()->Test(); - std::cout << "File: " << program->SourceFile().GetFileName() << ": test statement: " << test->DumpJSON() - << std::endl; + if (0) { + std::cout << "File: " << program->SourceFile().GetFileName() << ": test statement: " << test->DumpJSON() + << std::endl; + } if (test->IsIdentifier()) { - std::cout << "Found Identifier: " << test->AsIdentifier()->Name() << std::endl; + if (0) { + std::cout << "Found Identifier: " << test->AsIdentifier()->Name() << std::endl; + } // we got simple variable test expression, test against non-zero value // ASSERT(test->AsIdentifier()->Variable() != nullptr); if (test->AsIdentifier()->Variable() == nullptr) { @@ -167,25 +203,31 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p // NOTE: what about string as enum constant? auto *parent = ast->Parent(); auto *const scope = NearestScope(test); + ASSERT(scope != nullptr); auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); ir::AstNode *node = nullptr; - if (ast->IsIfStatement()) + if (ast->IsIfStatement()) { node = CreateCallExpression_if(ast, ctx->compilerContext); - if (ast->IsWhileStatement()) + } else if (ast->IsWhileStatement()) { node = CreateCallExpression_while(ast, ctx->compilerContext); - if (ast->IsDoWhileStatement()) + } else if (ast->IsDoWhileStatement()) { node = CreateCallExpression_do_while(ast, ctx->compilerContext); + } else if (ast->IsForUpdateStatement()) { + node = CreateCallExpression_for_update(ast, ctx->compilerContext); + } if (node == nullptr) { std::cout << "ERRPR: can't create proper substitution!" << std::endl; return ast; } node->SetParent(parent); - std::cout << "Updated node: " << node->DumpJSON() << std::endl; + if (0) + std::cout << "Updated node: " << node->DumpJSON() << std::endl; InitScopesPhaseETS::RunExternalNode(node, ctx->compilerContext->VarBinder()); checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(node, scope); + node->Check(checker); return node; } else { diff --git a/ets2panda/ir/statements/doWhileStatement.h b/ets2panda/ir/statements/doWhileStatement.h index 2a63bb2731..798cdf81fe 100644 --- a/ets2panda/ir/statements/doWhileStatement.h +++ b/ets2panda/ir/statements/doWhileStatement.h @@ -52,6 +52,11 @@ public: return test_; } + void SetTest(Expression *test) + { + test_ = test; + } + void TransformChildren(const NodeTransformer &cb) override; void SetReturnType(checker::ETSChecker *checker, checker::Type *type) override { diff --git a/ets2panda/ir/statements/forUpdateStatement.h b/ets2panda/ir/statements/forUpdateStatement.h index 5a172f4faf..b126409fa2 100644 --- a/ets2panda/ir/statements/forUpdateStatement.h +++ b/ets2panda/ir/statements/forUpdateStatement.h @@ -52,6 +52,11 @@ public: return test_; } + void SetTest(Expression *test) + { + test_ = test; + } + Expression *Update() { return update_; diff --git a/ets2panda/ir/statements/ifStatement.h b/ets2panda/ir/statements/ifStatement.h index d932dd8455..f7b3667463 100644 --- a/ets2panda/ir/statements/ifStatement.h +++ b/ets2panda/ir/statements/ifStatement.h @@ -42,6 +42,16 @@ public: return test_; } + Expression *Test() + { + return test_; + } + + void SetTest(Expression *test) + { + test_ = test; + } + Statement *Consequent() { return consequent_; diff --git a/ets2panda/ir/statements/whileStatement.h b/ets2panda/ir/statements/whileStatement.h index f9b00bb98f..8ad0367df4 100644 --- a/ets2panda/ir/statements/whileStatement.h +++ b/ets2panda/ir/statements/whileStatement.h @@ -42,6 +42,11 @@ public: return test_; } + void SetTest(Expression *test) + { + test_ = test; + } + const Statement *Body() const { return body_; diff --git a/ets2panda/varbinder/varbinder.cpp b/ets2panda/varbinder/varbinder.cpp index 43809bd4f5..b956023eaa 100644 --- a/ets2panda/varbinder/varbinder.cpp +++ b/ets2panda/varbinder/varbinder.cpp @@ -308,6 +308,7 @@ void VarBinder::BuildVarDeclaratorId(ir::AstNode *childNode) } auto *variable = scope_->FindLocal(name, varbinder::ResolveBindingOptions::BINDINGS); + ASSERT(variable != nullptr); ident->SetVariable(variable); BuildSignatureDeclarationBaseParams(ident->TypeAnnotation()); variable->AddFlag(VariableFlags::INITIALIZED); -- Gitee From e0fe2dc85dc368a0b1ba60eb8ce191ed6021ba76 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Fri, 16 Feb 2024 16:40:47 +0300 Subject: [PATCH 14/48] move scope control to the test expression create func Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.cpp | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index 995c4f8bea..a542f77ab8 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -45,14 +45,22 @@ ir::CallExpression *CreateCallExpression(ir::Identifier *id, checker::ETSChecker return callExpression; } -ir::Expression *CreateTestExpression(ir::Identifier *id, checker::ETSChecker *checker) +ir::Expression *CreateTestExpression(ir::Identifier *id, checker::ETSChecker *checker, CompilerContext *ctx) { + auto *const scope = NearestScope(id); + ASSERT(scope != nullptr); + auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); auto *callExpression = CreateCallExpression(id, checker); auto *right = checker->AllocNode(util::StringView("0")); ir::Expression *testExpr = checker->AllocNode(callExpression, right, lexer::TokenType::PUNCTUATOR_NOT_EQUAL); callExpression->SetParent(testExpr); right->SetParent(testExpr); + + InitScopesPhaseETS::RunExternalNode(testExpr, ctx->VarBinder()); + checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(testExpr, scope); + testExpr->Check(checker); + return testExpr; } @@ -68,7 +76,7 @@ ir::AstNode *CreateCallExpression_if(ir::AstNode *ast, CompilerContext *ctx) // checker->Allocator()); // id->SetReference(); - auto *testExpr = CreateTestExpression(id, checker); + auto *testExpr = CreateTestExpression(id, checker, ctx); // auto *test = checker->AllocNode(testExpr, ast->AsIfStatement()->Consequent(), // ast->AsIfStatement()->Alternate()); @@ -88,7 +96,7 @@ ir::AstNode *CreateCallExpression_while(ir::AstNode *ast, CompilerContext *ctx) // ast->AsWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); // id->SetReference(); - auto *testExpr = CreateTestExpression(id, checker); + auto *testExpr = CreateTestExpression(id, checker, ctx); // auto *expr = checker->AllocNode(testExpr, ast->AsWhileStatement()->Body()); ast->AsWhileStatement()->SetTest(testExpr); @@ -107,7 +115,7 @@ ir::AstNode *CreateCallExpression_do_while(ir::AstNode *ast, CompilerContext *ct // ast->AsDoWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); // id->SetReference(); - auto *testExpr = CreateTestExpression(id, checker); + auto *testExpr = CreateTestExpression(id, checker, ctx); // auto *expr = checker->AllocNode(ast->AsDoWhileStatement()->Body(), testExpr); ast->AsDoWhileStatement()->SetTest(testExpr); @@ -126,7 +134,7 @@ ir::AstNode *CreateCallExpression_for_update(ir::AstNode *ast, CompilerContext * // checker->Allocator()); // id->SetReference(); - auto *testExpr = CreateTestExpression(id, checker); + auto *testExpr = CreateTestExpression(id, checker, ctx); // auto *expr = checker->AllocNode(ast->AsForUpdateStatement()->Init(), testExpr, // ast->AsForUpdateStatement()->Update(), @@ -198,13 +206,12 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p auto *type = checker->GetTypeOfVariable(test->AsIdentifier()->Variable()); ASSERT(type != nullptr); if (type->IsETSEnum2Type()) { - std::cout << "Found type: ETSEnum2Type: " << type << std::endl; + if (0) { + std::cout << "Found type: ETSEnum2Type: " << type << std::endl; + } // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' // NOTE: what about string as enum constant? auto *parent = ast->Parent(); - auto *const scope = NearestScope(test); - ASSERT(scope != nullptr); - auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); ir::AstNode *node = nullptr; if (ast->IsIfStatement()) { node = CreateCallExpression_if(ast, ctx->compilerContext); @@ -224,11 +231,6 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p if (0) std::cout << "Updated node: " << node->DumpJSON() << std::endl; - InitScopesPhaseETS::RunExternalNode(node, ctx->compilerContext->VarBinder()); - - checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(node, scope); - - node->Check(checker); return node; } else { // .. -- Gitee From 899b654c19451978df9bc79d841fe1206376e5bc Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Fri, 16 Feb 2024 17:12:27 +0300 Subject: [PATCH 15/48] minor fixes: comments and surplus code Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index a542f77ab8..dacd2526f3 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -211,7 +211,6 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' // NOTE: what about string as enum constant? - auto *parent = ast->Parent(); ir::AstNode *node = nullptr; if (ast->IsIfStatement()) { node = CreateCallExpression_if(ast, ctx->compilerContext); @@ -227,7 +226,6 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p std::cout << "ERRPR: can't create proper substitution!" << std::endl; return ast; } - node->SetParent(parent); if (0) std::cout << "Updated node: " << node->DumpJSON() << std::endl; @@ -236,8 +234,17 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p // .. } } else if (test->IsCallExpression()) { - // simple callexpression with default non-zero test - // need to checkif we'recalling to getValue() fo enum constant + // simple call expression with default non-zero test, i.e. + // + // if (v.getValue()) + // + // this iwll always be treated as 'true' sine getValue() returns the EnumConst + // object,but not the enum value + // + // need to checkif we're calling to getValue() for enum constant + // and convert it intobinary expression with '!= 0' test, i.e. + // + // if (v.getValue() != 0) } } return ast; -- Gitee From 000239b213db306c3d3518d50c73a536e79e533c Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 19 Feb 2024 11:13:53 +0300 Subject: [PATCH 16/48] put check for test with call expression only if there is no explciit test of function result against 0. Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.cpp | 118 ++++++++++++------ 1 file changed, 79 insertions(+), 39 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index dacd2526f3..a9a9384c15 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -30,9 +30,11 @@ namespace ark::es2panda::compiler { +const char *ENUM_GETVALUE_METHOD_NAME = "getValue"; + ir::CallExpression *CreateCallExpression(ir::Identifier *id, checker::ETSChecker *checker) { - auto *const callee = checker->AllocNode(util::StringView("getValue"), checker->Allocator()); + auto *const callee = checker->AllocNode(ENUM_GETVALUE_METHOD_NAME, checker->Allocator()); callee->SetReference(); ir::Expression *const accessor = checker->AllocNode(id, callee, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -45,12 +47,16 @@ ir::CallExpression *CreateCallExpression(ir::Identifier *id, checker::ETSChecker return callExpression; } -ir::Expression *CreateTestExpression(ir::Identifier *id, checker::ETSChecker *checker, CompilerContext *ctx) +ir::Expression *CreateTestExpression(ir::Identifier *id, CompilerContext *ctx, ir::CallExpression *callExpression) { auto *const scope = NearestScope(id); + auto *checker = ctx->Checker()->AsETSChecker(); ASSERT(scope != nullptr); auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); - auto *callExpression = CreateCallExpression(id, checker); + if (callExpression == nullptr) { + callExpression = CreateCallExpression(id, checker); + } + auto *right = checker->AllocNode(util::StringView("0")); ir::Expression *testExpr = checker->AllocNode(callExpression, right, lexer::TokenType::PUNCTUATOR_NOT_EQUAL); @@ -69,14 +75,13 @@ ir::AstNode *CreateCallExpression_if(ir::AstNode *ast, CompilerContext *ctx) // only identifiers allowed here! ASSERT(ast->IsIfStatement() && ast->AsIfStatement()->Test()->IsIdentifier()); - auto *checker = ctx->Checker()->AsETSChecker(); auto *id = ast->AsIfStatement()->Test()->AsIdentifier(); // auto *id = // checker->AllocNode(ast->AsIfStatement()->Test()->AsIdentifier()->Name(), // checker->Allocator()); // id->SetReference(); - auto *testExpr = CreateTestExpression(id, checker, ctx); + auto *testExpr = CreateTestExpression(id, ctx, nullptr); // auto *test = checker->AllocNode(testExpr, ast->AsIfStatement()->Consequent(), // ast->AsIfStatement()->Alternate()); @@ -90,13 +95,12 @@ ir::AstNode *CreateCallExpression_while(ir::AstNode *ast, CompilerContext *ctx) // only identifiers allowed here! ASSERT(ast->IsWhileStatement() && ast->AsWhileStatement()->Test()->IsIdentifier()); - auto *checker = ctx->Checker()->AsETSChecker(); auto *id = ast->AsWhileStatement()->Test()->AsIdentifier(); // auto *id = checker->AllocNode( // ast->AsWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); // id->SetReference(); - auto *testExpr = CreateTestExpression(id, checker, ctx); + auto *testExpr = CreateTestExpression(id, ctx, nullptr); // auto *expr = checker->AllocNode(testExpr, ast->AsWhileStatement()->Body()); ast->AsWhileStatement()->SetTest(testExpr); @@ -109,13 +113,12 @@ ir::AstNode *CreateCallExpression_do_while(ir::AstNode *ast, CompilerContext *ct // only identifiers allowed here! ASSERT(ast->IsDoWhileStatement() && ast->AsDoWhileStatement()->Test()->IsIdentifier()); - auto *checker = ctx->Checker()->AsETSChecker(); auto *id = ast->AsDoWhileStatement()->Test()->AsIdentifier(); // auto *id = checker->AllocNode( // ast->AsDoWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); // id->SetReference(); - auto *testExpr = CreateTestExpression(id, checker, ctx); + auto *testExpr = CreateTestExpression(id, ctx, nullptr); // auto *expr = checker->AllocNode(ast->AsDoWhileStatement()->Body(), testExpr); ast->AsDoWhileStatement()->SetTest(testExpr); @@ -128,13 +131,12 @@ ir::AstNode *CreateCallExpression_for_update(ir::AstNode *ast, CompilerContext * // only identifiers allowed here! ASSERT(ast->IsForUpdateStatement() && ast->AsForUpdateStatement()->Test()->IsIdentifier()); - auto *checker = ctx->Checker()->AsETSChecker(); auto *id = ast->AsForUpdateStatement()->Test()->AsIdentifier(); // auto *id = checker->AllocNode(ast->AsForUpdateStatement()->Test()->AsIdentifier()->Name(), // checker->Allocator()); // id->SetReference(); - auto *testExpr = CreateTestExpression(id, checker, ctx); + auto *testExpr = CreateTestExpression(id, ctx, nullptr); // auto *expr = checker->AllocNode(ast->AsForUpdateStatement()->Init(), testExpr, // ast->AsForUpdateStatement()->Update(), @@ -180,7 +182,7 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } else if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || ast->IsForUpdateStatement()) { // so far let's put this only for test script - const ir::Expression *test = nullptr; + ir::Expression *test = nullptr; if (ast->IsIfStatement()) test = ast->AsIfStatement()->Test(); if (ast->IsWhileStatement()) @@ -205,46 +207,84 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } auto *type = checker->GetTypeOfVariable(test->AsIdentifier()->Variable()); ASSERT(type != nullptr); - if (type->IsETSEnum2Type()) { - if (0) { - std::cout << "Found type: ETSEnum2Type: " << type << std::endl; - } - // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' - // NOTE: what about string as enum constant? - ir::AstNode *node = nullptr; - if (ast->IsIfStatement()) { - node = CreateCallExpression_if(ast, ctx->compilerContext); - } else if (ast->IsWhileStatement()) { - node = CreateCallExpression_while(ast, ctx->compilerContext); - } else if (ast->IsDoWhileStatement()) { - node = CreateCallExpression_do_while(ast, ctx->compilerContext); - } else if (ast->IsForUpdateStatement()) { - node = CreateCallExpression_for_update(ast, ctx->compilerContext); - } - if (node == nullptr) { - std::cout << "ERRPR: can't create proper substitution!" << std::endl; - return ast; - } - if (0) - std::cout << "Updated node: " << node->DumpJSON() << std::endl; + if (!type->IsETSEnum2Type()) { + return ast; + } + if (0) { + std::cout << "Found type: ETSEnum2Type: " << type << std::endl; + } + // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' + // NOTE: what about string as enum constant? + ir::AstNode *node = nullptr; + if (ast->IsIfStatement()) { + node = CreateCallExpression_if(ast, ctx->compilerContext); + } else if (ast->IsWhileStatement()) { + node = CreateCallExpression_while(ast, ctx->compilerContext); + } else if (ast->IsDoWhileStatement()) { + node = CreateCallExpression_do_while(ast, ctx->compilerContext); + } else if (ast->IsForUpdateStatement()) { + node = CreateCallExpression_for_update(ast, ctx->compilerContext); + } - return node; - } else { - // .. + if (node == nullptr) { + std::cout << "ERROR: can't create proper substitution!" << std::endl; + return ast; } + + if (0) + std::cout << "Updated node: " << node->DumpJSON() << std::endl; + + return node; } else if (test->IsCallExpression()) { // simple call expression with default non-zero test, i.e. // // if (v.getValue()) // - // this iwll always be treated as 'true' sine getValue() returns the EnumConst + // this wll always be treated as 'true' since getValue() returns the EnumConst // object,but not the enum value // // need to checkif we're calling to getValue() for enum constant - // and convert it intobinary expression with '!= 0' test, i.e. + // and convert it into binary expression with '!= 0' test, i.e. // // if (v.getValue() != 0) + // + // same for loop expressions. + // + if (ir::Expression *callee = test->AsCallExpression()->Callee(); + (callee != nullptr) && (callee->IsMemberExpression())) { + if ((callee->AsMemberExpression()->Object() != nullptr) && + callee->AsMemberExpression()->Object()->IsIdentifier()) { + auto *id = callee->AsMemberExpression()->Object()->AsIdentifier(); + if (id->Variable() == nullptr) { + return ast; + } + auto *type = checker->GetTypeOfVariable(id->Variable()); + ASSERT(type != nullptr); + if (!type->IsETSEnum2Type()) { + return ast; // do not modify it, it is not ETSEnum2Type + } + + if (ir::Expression *prop = callee->AsMemberExpression()->Property(); prop != nullptr) { + if (prop->IsIdentifier() && (prop->AsIdentifier()->Name() == ENUM_GETVALUE_METHOD_NAME)) { + // now we need tow rap it to the binary expression .. != 0 + auto *testExpr = CreateTestExpression(prop->AsIdentifier(), ctx->compilerContext, + test->AsCallExpression()); + if (ast->IsIfStatement()) { + ast->AsIfStatement()->SetTest(testExpr); + } else if (ast->IsWhileStatement()) { + ast->AsWhileStatement()->SetTest(testExpr); + } else if (ast->IsDoWhileStatement()) { + ast->AsDoWhileStatement()->SetTest(testExpr); + } else if (ast->IsForUpdateStatement()) { + ast->AsForUpdateStatement()->SetTest(testExpr); + } + testExpr->SetParent(ast); + return ast; + } + } + } + } } } return ast; -- Gitee From fe83411c99011048a6b246fbc30b9d7f924d3340 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 19 Feb 2024 13:01:23 +0300 Subject: [PATCH 17/48] reduce code complexity Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.cpp | 141 +++--------------- 1 file changed, 20 insertions(+), 121 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index a9a9384c15..e9099ffe1a 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -70,83 +70,6 @@ ir::Expression *CreateTestExpression(ir::Identifier *id, CompilerContext *ctx, i return testExpr; } -ir::AstNode *CreateCallExpression_if(ir::AstNode *ast, CompilerContext *ctx) -{ - // only identifiers allowed here! - ASSERT(ast->IsIfStatement() && ast->AsIfStatement()->Test()->IsIdentifier()); - - auto *id = ast->AsIfStatement()->Test()->AsIdentifier(); - // auto *id = - // checker->AllocNode(ast->AsIfStatement()->Test()->AsIdentifier()->Name(), - // checker->Allocator()); - // id->SetReference(); - - auto *testExpr = CreateTestExpression(id, ctx, nullptr); - - // auto *test = checker->AllocNode(testExpr, ast->AsIfStatement()->Consequent(), - // ast->AsIfStatement()->Alternate()); - ast->AsIfStatement()->SetTest(testExpr); - testExpr->SetParent(ast); - return ast; -} - -ir::AstNode *CreateCallExpression_while(ir::AstNode *ast, CompilerContext *ctx) -{ - // only identifiers allowed here! - ASSERT(ast->IsWhileStatement() && ast->AsWhileStatement()->Test()->IsIdentifier()); - - auto *id = ast->AsWhileStatement()->Test()->AsIdentifier(); - // auto *id = checker->AllocNode( - // ast->AsWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); - // id->SetReference(); - - auto *testExpr = CreateTestExpression(id, ctx, nullptr); - - // auto *expr = checker->AllocNode(testExpr, ast->AsWhileStatement()->Body()); - ast->AsWhileStatement()->SetTest(testExpr); - testExpr->SetParent(ast); - return ast; -} - -ir::AstNode *CreateCallExpression_do_while(ir::AstNode *ast, CompilerContext *ctx) -{ - // only identifiers allowed here! - ASSERT(ast->IsDoWhileStatement() && ast->AsDoWhileStatement()->Test()->IsIdentifier()); - - auto *id = ast->AsDoWhileStatement()->Test()->AsIdentifier(); - // auto *id = checker->AllocNode( - // ast->AsDoWhileStatement()->Test()->AsIdentifier()->Name(), checker->Allocator()); - // id->SetReference(); - - auto *testExpr = CreateTestExpression(id, ctx, nullptr); - - // auto *expr = checker->AllocNode(ast->AsDoWhileStatement()->Body(), testExpr); - ast->AsDoWhileStatement()->SetTest(testExpr); - testExpr->SetParent(ast); - return ast; -} - -ir::AstNode *CreateCallExpression_for_update(ir::AstNode *ast, CompilerContext *ctx) -{ - // only identifiers allowed here! - ASSERT(ast->IsForUpdateStatement() && ast->AsForUpdateStatement()->Test()->IsIdentifier()); - - auto *id = ast->AsForUpdateStatement()->Test()->AsIdentifier(); - // auto *id = checker->AllocNode(ast->AsForUpdateStatement()->Test()->AsIdentifier()->Name(), - // checker->Allocator()); - // id->SetReference(); - - auto *testExpr = CreateTestExpression(id, ctx, nullptr); - - // auto *expr = checker->AllocNode(ast->AsForUpdateStatement()->Init(), testExpr, - // ast->AsForUpdateStatement()->Update(), - // ast->AsForUpdateStatement()->Body()); - // testExpr->SetParent(expr); - ast->AsForUpdateStatement()->SetTest(testExpr); - testExpr->SetParent(ast); - return ast; -} - bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *program) { if (program->Extension() != ScriptExtension::ETS) { @@ -162,7 +85,7 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } } - program->Ast()->TransformChildrenRecursively([checker, ctx, program](ir::AstNode *ast) -> ir::AstNode * { + program->Ast()->TransformChildrenRecursively([checker, ctx](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsCallExpression()) { // check & update call expression with explicit cast to new type // e.g. for the following @@ -183,6 +106,8 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p ast->IsForUpdateStatement()) { // so far let's put this only for test script ir::Expression *test = nullptr; + ir::Expression *testExpr = nullptr; + if (ast->IsIfStatement()) test = ast->AsIfStatement()->Test(); if (ast->IsWhileStatement()) @@ -192,16 +117,8 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p if (ast->IsForUpdateStatement()) test = ast->AsForUpdateStatement()->Test(); - if (0) { - std::cout << "File: " << program->SourceFile().GetFileName() << ": test statement: " << test->DumpJSON() - << std::endl; - } if (test->IsIdentifier()) { - if (0) { - std::cout << "Found Identifier: " << test->AsIdentifier()->Name() << std::endl; - } // we got simple variable test expression, test against non-zero value - // ASSERT(test->AsIdentifier()->Variable() != nullptr); if (test->AsIdentifier()->Variable() == nullptr) { return ast; } @@ -211,31 +128,10 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p if (!type->IsETSEnum2Type()) { return ast; } - if (0) { - std::cout << "Found type: ETSEnum2Type: " << type << std::endl; - } // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' // NOTE: what about string as enum constant? - ir::AstNode *node = nullptr; - if (ast->IsIfStatement()) { - node = CreateCallExpression_if(ast, ctx->compilerContext); - } else if (ast->IsWhileStatement()) { - node = CreateCallExpression_while(ast, ctx->compilerContext); - } else if (ast->IsDoWhileStatement()) { - node = CreateCallExpression_do_while(ast, ctx->compilerContext); - } else if (ast->IsForUpdateStatement()) { - node = CreateCallExpression_for_update(ast, ctx->compilerContext); - } - - if (node == nullptr) { - std::cout << "ERROR: can't create proper substitution!" << std::endl; - return ast; - } - - if (0) - std::cout << "Updated node: " << node->DumpJSON() << std::endl; + testExpr = CreateTestExpression(test->AsIdentifier(), ctx->compilerContext, nullptr); - return node; } else if (test->IsCallExpression()) { // simple call expression with default non-zero test, i.e. // @@ -268,24 +164,27 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p if (ir::Expression *prop = callee->AsMemberExpression()->Property(); prop != nullptr) { if (prop->IsIdentifier() && (prop->AsIdentifier()->Name() == ENUM_GETVALUE_METHOD_NAME)) { // now we need tow rap it to the binary expression .. != 0 - auto *testExpr = CreateTestExpression(prop->AsIdentifier(), ctx->compilerContext, - test->AsCallExpression()); - if (ast->IsIfStatement()) { - ast->AsIfStatement()->SetTest(testExpr); - } else if (ast->IsWhileStatement()) { - ast->AsWhileStatement()->SetTest(testExpr); - } else if (ast->IsDoWhileStatement()) { - ast->AsDoWhileStatement()->SetTest(testExpr); - } else if (ast->IsForUpdateStatement()) { - ast->AsForUpdateStatement()->SetTest(testExpr); - } - testExpr->SetParent(ast); - return ast; + testExpr = CreateTestExpression(prop->AsIdentifier(), ctx->compilerContext, + test->AsCallExpression()); } } } } } + if (testExpr == nullptr) { + return ast; + } + if (ast->IsIfStatement()) { + ast->AsIfStatement()->SetTest(testExpr); + } else if (ast->IsWhileStatement()) { + ast->AsWhileStatement()->SetTest(testExpr); + } else if (ast->IsDoWhileStatement()) { + ast->AsDoWhileStatement()->SetTest(testExpr); + } else if (ast->IsForUpdateStatement()) { + ast->AsForUpdateStatement()->SetTest(testExpr); + } + testExpr->SetParent(ast); + return ast; } return ast; }); -- Gitee From 82670ca93fe2b25590229c6546da3c3f98803cbd Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 19 Feb 2024 14:26:42 +0300 Subject: [PATCH 18/48] enumLowering: rebase build fixes Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.h | 2 +- .../lowering/ets/enumLoweringPrePhase.cpp | 25 +++++++++---------- .../lowering/ets/enumLoweringPrePhase.h | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h index 430e5a4823..2543c4690e 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h @@ -22,7 +22,7 @@ namespace ark::es2panda::compiler { class EnumLoweringPostPhase : public Phase { public: - std::string_view Name() override + std::string_view Name() const override { return "EnumLoweringPostPhase"; } diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index 8a3a5ad54e..0b313aeb79 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -87,9 +87,8 @@ ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enum_name, auto *func = checker->AllocNode( ir::FunctionSignature(nullptr, std::move(params), ret_type), body, - ir::ScriptFunctionFlags::HAS_RETURN | ir::ScriptFunctionFlags::THROWS, - ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC, false, Language(Language::Id::ETS)); - + ir::ScriptFunctionFlags::HAS_RETURN | ir::ScriptFunctionFlags::THROWS, false, Language(Language::Id::ETS)); + func->AddModifier(ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC); func->SetIdent(key); auto *value = checker->AllocNode(func); @@ -146,9 +145,8 @@ ir::MethodDefinition *CreateMethodCreate(const util::StringView &enum_name, bool auto *func = checker->AllocNode( ir::FunctionSignature(nullptr, std::move(params), CreateETSTypeReference(enum_name, checker)), body, - ir::ScriptFunctionFlags::HAS_RETURN, ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE, false, - Language(Language::Id::ETS)); - + ir::ScriptFunctionFlags::HAS_RETURN, false, Language(Language::Id::ETS)); + func->AddModifier(ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE); func->SetIdent(key); auto *value = checker->AllocNode(func); @@ -174,10 +172,11 @@ ir::MethodDefinition *CreateMethodValues(const util::StringView &enum_name, chec statements.push_back(checker->AllocNode(argument)); auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); - auto *func = checker->AllocNode( - ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunctionFlags::HAS_RETURN, - ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC, false, Language(Language::Id::ETS)); + auto *func = + checker->AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunctionFlags::HAS_RETURN, false, Language(Language::Id::ETS)); + func->AddModifier(ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC); func->SetIdent(key); auto *value = checker->AllocNode(func); @@ -285,10 +284,10 @@ void CreateCCtor(ArenaVector &properties, const lexer::SourcePosi ArenaVector statements(checker->Allocator()->Adapter()); auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); - auto *func = - checker->AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, - ir::ModifierFlags::STATIC, false, Language(Language::Id::ETS)); + auto *func = checker->AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, false, Language(Language::Id::ETS)); + func->AddModifier(ir::ModifierFlags::STATIC); func->SetIdent(id); auto *func_expr = checker->AllocNode(func); diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h index d8d8a41990..846c3cab93 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h @@ -22,7 +22,7 @@ namespace ark::es2panda::compiler { class EnumLoweringPrePhase : public Phase { public: - std::string_view Name() override + std::string_view Name() const override { return "EnumLoweringPrePhase"; } -- Gitee From de1aa636623994de8f3700982852becfdaf6d3f1 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 19 Feb 2024 15:17:30 +0300 Subject: [PATCH 19/48] run-time fixes after rebase Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/typeCreation.cpp | 2 +- ets2panda/checker/types/ets/etsEnumType.cpp | 4 ++-- ets2panda/checker/types/ets/etsEnumType.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 5e30c2f6d1..8af3bdab5d 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -559,7 +559,7 @@ ETSObjectType *ETSChecker::CreateNewETSObjectType(util::StringView name, ir::Ast } if (isEnumClass(declNode)) { - auto ret = Allocator()->New(this, name, assemblerName, declNode, flags); + auto ret = Allocator()->New(this, name, assemblerName, declNode, flags, Relation()); return ret; } diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index a30e125e6f..cdc1756cd6 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -334,8 +334,8 @@ std::string EnumDescription(util::StringView name) } ETSEnum2Type::ETSEnum2Type(ETSChecker *checker, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags) - : ETSObjectType(checker->Allocator(), name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2) + ir::AstNode *decl_node, ETSObjectFlags flags, TypeRelation *relation) + : ETSObjectType(checker->Allocator(), name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2, relation) { AddTypeFlag(TypeFlag::ETS_ENUM2); CreateLiteralTypes(checker, name, assembler_name, decl_node, flags); diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index a03966d24d..391faa7ca5 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -222,7 +222,7 @@ std::string EnumDescription(util::StringView name); class ETSEnum2Type : public ETSObjectType { public: ETSEnum2Type(ETSChecker *checker, util::StringView name, util::StringView assembler_name, ir::AstNode *decl_node, - ETSObjectFlags flags); + ETSObjectFlags flags, TypeRelation *relation); ETSEnum2Type(ArenaAllocator *allocator, util::StringView name, util::StringView assembler_name, ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value); -- Gitee From f6f803b659f787d40e3eb323d64f2660df4a4967 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 19 Feb 2024 17:20:53 +0300 Subject: [PATCH 20/48] replace New() with AllocNode() Signed-off-by: Vadim Lomovtsev --- .../compiler/lowering/ets/enumLoweringPrePhase.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index 0b313aeb79..8855661098 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -39,9 +39,9 @@ const char *ENUM_CONSTANT_CREATE_METHOD_NAME = "create"; const char *ENUM_VALUE_OF_LIB_FUNCTION_NAME = "enumValueOf"; const char *ENUM_CONSTANT_ARRAY_NAME = "arr"; -auto CreateIdentifierRef(util::StringView const name, checker::ETSChecker *checker) +ir::Identifier *CreateIdentifierRef(util::StringView const name, checker::ETSChecker *checker) { - auto *ret = checker->Allocator()->New(name, checker->Allocator()); + auto *ret = checker->AllocNode(name, checker->Allocator()); ret->SetReference(); return ret; } @@ -49,16 +49,16 @@ auto CreateIdentifierRef(util::StringView const name, checker::ETSChecker *check auto CreateETSTypeReference(util::StringView const name, checker::ETSChecker *checker) { auto *name_ident = CreateIdentifierRef(name, checker); - auto *reference_part = checker->Allocator()->New(name_ident); - return checker->Allocator()->New(reference_part); + auto *reference_part = checker->AllocNode(name_ident); + return checker->AllocNode(reference_part); } auto CreateETSParameterExpression(util::StringView const par_name, util::StringView const type_name, checker::ETSChecker *checker) { auto *type_annot = CreateETSTypeReference(type_name, checker); - auto *name = checker->Allocator()->New(par_name, type_annot, checker->Allocator()); - return checker->Allocator()->New(name, nullptr); + auto *name = checker->AllocNode(par_name, type_annot, checker->Allocator()); + return checker->AllocNode(name, nullptr); } ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enum_name, -- Gitee From 64d1f6ad0f98d739bc38f40ca4657cd82899cd9e Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 19 Feb 2024 20:06:35 +0300 Subject: [PATCH 21/48] enumLowering: fix ASTVerifier issues Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPrePhase.cpp | 75 ++++++++++--------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index 8855661098..d49b6d4952 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -64,15 +64,12 @@ auto CreateETSParameterExpression(util::StringView const par_name, util::StringV ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enum_name, ir::TSTypeParameterInstantiation *tp_par_inst, checker::ETSChecker *checker) { - auto *key = checker->AllocNode("valueOf", checker->Allocator()); - ArenaVector params(checker->Allocator()->Adapter()); params.push_back(CreateETSParameterExpression("name", "string", checker)); auto *ret_type = CreateETSTypeReference(enum_name, checker); ArenaVector statements(checker->Allocator()->Adapter()); - auto *callee = CreateIdentifierRef(ENUM_VALUE_OF_LIB_FUNCTION_NAME, checker); ArenaVector args(checker->Allocator()->Adapter()); auto *arg0_obj = CreateIdentifierRef(enum_name, checker); auto *arg0_prop = CreateIdentifierRef(ENUM_CONSTANT_ARRAY_NAME, checker); @@ -80,22 +77,26 @@ ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enum_name, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false)); auto *arg1 = CreateIdentifierRef("name", checker); args.push_back(arg1); - auto *express = checker->AllocNode(callee, std::move(args), tp_par_inst, false); - auto *argument = checker->AllocNode(express, ret_type, false); - statements.push_back(checker->AllocNode(argument)); + + auto *callee = CreateIdentifierRef(ENUM_VALUE_OF_LIB_FUNCTION_NAME, checker); + auto *express = checker->AllocNode(std::move(callee), std::move(args), tp_par_inst, false); + auto *argument = checker->AllocNode(std::move(express), ret_type, false); + statements.push_back(checker->AllocNode(std::move(argument))); auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); auto *func = checker->AllocNode( - ir::FunctionSignature(nullptr, std::move(params), ret_type), body, + ir::FunctionSignature(nullptr, std::move(params), ret_type->Clone(checker->Allocator(), nullptr)), body, ir::ScriptFunctionFlags::HAS_RETURN | ir::ScriptFunctionFlags::THROWS, false, Language(Language::Id::ETS)); func->AddModifier(ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC); + auto *key = checker->AllocNode("valueOf", checker->Allocator()); func->SetIdent(key); auto *value = checker->AllocNode(func); auto flags = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; - auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, key, value, flags, + auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, + key->Clone(checker->Allocator(), nullptr), value, flags, checker->Allocator(), false); return method; @@ -104,64 +105,63 @@ ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enum_name, ir::MethodDefinition *CreateMethodCreate(const util::StringView &enum_name, bool is_int_enum, checker::ETSChecker *checker) { - auto *key = checker->AllocNode("create", checker->Allocator()); - - ArenaVector params(checker->Allocator()->Adapter()); - params.push_back(CreateETSParameterExpression("typ", "string", checker)); - params.push_back(CreateETSParameterExpression("name", "string", checker)); - params.push_back(CreateETSParameterExpression("val", is_int_enum ? "Int" : "string", checker)); - params.push_back(CreateETSParameterExpression("idx", "Int", checker)); - auto id = checker->AllocNode("ret", checker->Allocator()); auto init = checker->AllocNode( CreateETSTypeReference(enum_name, checker), ArenaVector(checker->Allocator()->Adapter()), nullptr); auto declarator = checker->AllocNode(ir::VariableDeclaratorFlag::LET, id, init); ArenaVector declarators(checker->Allocator()->Adapter()); - declarators.push_back(declarator); + declarators.push_back(std::move(declarator)); auto var_kind = ir::VariableDeclaration::VariableDeclarationKind::LET; auto *var_decl = checker->AllocNode(var_kind, checker->Allocator(), std::move(declarators), false); ArenaVector statements(checker->Allocator()->Adapter()); - statements.push_back(var_decl); + statements.push_back(std::move(var_decl)); auto *callee_obj = CreateIdentifierRef("ret", checker); auto *callee_prop = CreateIdentifierRef("init", checker); - auto *callee = checker->AllocNode(callee_obj, callee_prop, + auto *callee = checker->AllocNode(std::move(callee_obj), std::move(callee_prop), ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); ArenaVector args(checker->Allocator()->Adapter()); args.push_back(CreateIdentifierRef("typ", checker)); args.push_back(CreateIdentifierRef("name", checker)); args.push_back(CreateIdentifierRef("val", checker)); args.push_back(CreateIdentifierRef("idx", checker)); - auto *expression = checker->AllocNode(callee, std::move(args), nullptr, false); + auto *expression = checker->AllocNode(std::move(callee), std::move(args), nullptr, false); statements.push_back(checker->AllocNode(expression)); - statements.push_back(checker->AllocNode(callee_obj)); + statements.push_back(checker->AllocNode(CreateIdentifierRef("ret", checker))); auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); + ArenaVector params(checker->Allocator()->Adapter()); + params.push_back(CreateETSParameterExpression("typ", "string", checker)); + params.push_back(CreateETSParameterExpression("name", "string", checker)); + params.push_back(CreateETSParameterExpression("val", is_int_enum ? "Int" : "string", checker)); + params.push_back(CreateETSParameterExpression("idx", "Int", checker)); + auto *func = checker->AllocNode( ir::FunctionSignature(nullptr, std::move(params), CreateETSTypeReference(enum_name, checker)), body, ir::ScriptFunctionFlags::HAS_RETURN, false, Language(Language::Id::ETS)); func->AddModifier(ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE); + + auto *key = CreateIdentifierRef(ENUM_CONSTANT_CREATE_METHOD_NAME, checker); func->SetIdent(key); auto *value = checker->AllocNode(func); auto flags = ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE; - auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, key, value, flags, - checker->Allocator(), false); + auto *method = checker->AllocNode( + ir::MethodDefinitionKind::METHOD, std::move(key->Clone(checker->Allocator(), nullptr)->AsIdentifier()), + std::move(value), flags, checker->Allocator(), false); return method; } ir::MethodDefinition *CreateMethodValues(const util::StringView &enum_name, checker::ETSChecker *checker) { - auto *key = checker->AllocNode("values", checker->Allocator()); - ArenaVector params(checker->Allocator()->Adapter()); ArenaVector statements(checker->Allocator()->Adapter()); @@ -177,14 +177,15 @@ ir::MethodDefinition *CreateMethodValues(const util::StringView &enum_name, chec ir::ScriptFunctionFlags::HAS_RETURN, false, Language(Language::Id::ETS)); func->AddModifier(ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC); + auto *key = checker->AllocNode("values", checker->Allocator()); func->SetIdent(key); auto *value = checker->AllocNode(func); auto flags = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; - auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, key, value, flags, + auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, + key->Clone(checker->Allocator(), nullptr), value, flags, checker->Allocator(), false); - return method; } @@ -205,7 +206,8 @@ ir::MethodDefinition *CreateConstructor(checker::ETSChecker *checker) func->SetIdent(key); auto *value = checker->AllocNode(func); - auto *method = checker->AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, key, value, + auto *method = checker->AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, + key->Clone(checker->Allocator(), nullptr), value, ir::ModifierFlags::NONE, checker->Allocator(), false); return method; @@ -242,18 +244,14 @@ ir::ClassProperty *CreateEnumConstantArray(const util::StringView &enum_name, Ar ir::ClassProperty *CreateEnumConstantClassProperty(const util::StringView &enum_name, const ir::TSEnumMember *member, int idx, checker::ETSChecker *checker) { - auto *key = checker->AllocNode(member->Name(), checker->Allocator()); - - auto *callee_obj = CreateIdentifierRef(enum_name, checker); - auto *callee_prop = CreateIdentifierRef(ENUM_CONSTANT_CREATE_METHOD_NAME, checker); - auto *callee = checker->AllocNode(callee_obj, callee_prop, - ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - ArenaVector args(checker->Allocator()->Adapter()); + util::UString enum_desc(checker::EnumDescription(enum_name), checker->Allocator()); args.push_back(checker->AllocNode(enum_desc.View())); + util::UString enum_const_name(member->Name(), checker->Allocator()); args.push_back(checker->AllocNode(enum_const_name.View())); + if (member->Init()->IsNumberLiteral()) { args.push_back(checker->AllocNode(member->Init()->AsNumberLiteral()->Number())); } else if (member->Init()->IsStringLiteral()) { @@ -263,12 +261,17 @@ ir::ClassProperty *CreateEnumConstantClassProperty(const util::StringView &enum_ } args.push_back(checker->AllocNode(lexer::Number(idx))); - auto *value = checker->AllocNode(callee, std::move(args), nullptr, false); + auto *callee_obj = CreateIdentifierRef(enum_name, checker); + auto *callee_prop = CreateIdentifierRef(ENUM_CONSTANT_CREATE_METHOD_NAME, checker); + auto *callee = checker->AllocNode(std::move(callee_obj), std::move(callee_prop), + ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + auto *value = checker->AllocNode(std::move(callee), std::move(args), nullptr, false); auto prop_modif = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC | ir::ModifierFlags::READONLY | ir::ModifierFlags::CONST; auto *type_annot = CreateETSTypeReference(enum_name, checker); + auto *key = checker->AllocNode(member->Name(), checker->Allocator()); auto *class_prop = checker->AllocNode(key, value, type_annot, prop_modif, checker->Allocator(), false); -- Gitee From a7465b6147e9dbd8c609dcb18508117e23fb507a Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 19 Feb 2024 21:19:12 +0300 Subject: [PATCH 22/48] put fix for ConditionalExpression Signed-off-by: Vadim Lomovtsev --- .../compiler/lowering/ets/enumLoweringPostPhase.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index e9099ffe1a..ad07193f7a 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -103,7 +103,7 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p [[maybe_unused]] auto *right = ast->AsBinaryExpression()->Right(); } else if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || - ast->IsForUpdateStatement()) { + ast->IsForUpdateStatement() || ast->IsConditionalExpression()) { // so far let's put this only for test script ir::Expression *test = nullptr; ir::Expression *testExpr = nullptr; @@ -116,7 +116,12 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p test = ast->AsDoWhileStatement()->Test(); if (ast->IsForUpdateStatement()) test = ast->AsForUpdateStatement()->Test(); + if (ast->IsConditionalExpression()) + test = ast->AsConditionalExpression()->Test(); + if (test == nullptr) { + return ast; + } if (test->IsIdentifier()) { // we got simple variable test expression, test against non-zero value if (test->AsIdentifier()->Variable() == nullptr) { @@ -182,6 +187,8 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p ast->AsDoWhileStatement()->SetTest(testExpr); } else if (ast->IsForUpdateStatement()) { ast->AsForUpdateStatement()->SetTest(testExpr); + } else if (ast->IsConditionalExpression()) { + ast->AsConditionalExpression()->SetTest(testExpr); } testExpr->SetParent(ast); return ast; -- Gitee From c3329b252572e8b35bb3e3c730d63fc4f3a57e9d Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 20 Feb 2024 10:08:26 +0300 Subject: [PATCH 23/48] put TypeRelation* to constructor Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/types/ets/etsEnumType.cpp | 12 ++++++------ ets2panda/checker/types/ets/etsEnumType.h | 4 ++-- .../compiler/lowering/ets/enumLoweringPrePhase.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index cdc1756cd6..10ffb0c18f 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -338,12 +338,12 @@ ETSEnum2Type::ETSEnum2Type(ETSChecker *checker, util::StringView name, util::Str : ETSObjectType(checker->Allocator(), name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2, relation) { AddTypeFlag(TypeFlag::ETS_ENUM2); - CreateLiteralTypes(checker, name, assembler_name, decl_node, flags); + CreateLiteralTypes(checker, name, assembler_name, decl_node, flags, relation); } ETSEnum2Type::ETSEnum2Type(ArenaAllocator *allocator, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value) - : ETSObjectType(allocator, name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2), value_(value) + ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value, TypeRelation *relation) + : ETSObjectType(allocator, name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2, relation), value_(value) { AddTypeFlag(TypeFlag::ETS_ENUM2); ASSERT(value); @@ -396,7 +396,7 @@ void ETSEnum2Type::Cast(TypeRelation *relation, Type *target) } void ETSEnum2Type::CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags) + ir::AstNode *decl_node, ETSObjectFlags flags, TypeRelation *relation) { ASSERT(decl_node->IsClassDefinition()); @@ -431,8 +431,8 @@ void ETSEnum2Type::CreateLiteralTypes(ETSChecker *checker, util::StringView name UNREACHABLE(); } - auto *enum_literal_type = - Allocator()->New(checker->Allocator(), name, assembler_name, decl_node, flags, literal); + auto *enum_literal_type = Allocator()->New(checker->Allocator(), name, assembler_name, decl_node, + flags, literal, relation); enum_literal_type->SetVariable(var); var->SetTsType(enum_literal_type); diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index 391faa7ca5..1e67220dee 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -225,7 +225,7 @@ public: ETSObjectFlags flags, TypeRelation *relation); ETSEnum2Type(ArenaAllocator *allocator, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value); + ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value, TypeRelation *relation); bool IsSameEnumType(const ETSEnum2Type *other) const noexcept; @@ -246,7 +246,7 @@ public: private: void CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags); + ir::AstNode *decl_node, ETSObjectFlags flags, TypeRelation *relation); ir::Literal *value_ = nullptr; }; diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index d49b6d4952..0a94c65bb5 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -139,7 +139,7 @@ ir::MethodDefinition *CreateMethodCreate(const util::StringView &enum_name, bool ArenaVector params(checker->Allocator()->Adapter()); params.push_back(CreateETSParameterExpression("typ", "string", checker)); params.push_back(CreateETSParameterExpression("name", "string", checker)); - params.push_back(CreateETSParameterExpression("val", is_int_enum ? "Int" : "string", checker)); + params.push_back(CreateETSParameterExpression("val", is_int_enum ? "Int" : "String", checker)); params.push_back(CreateETSParameterExpression("idx", "Int", checker)); auto *func = checker->AllocNode( -- Gitee From fded620bb0c4556e53d25c5674ac298186082847 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 20 Feb 2024 16:03:34 +0300 Subject: [PATCH 24/48] save debug code Signed-off-by: Vadim Lomovtsev --- ets2panda/compiler/core/ASTVerifier.cpp | 8 +++++++- .../lowering/ets/enumLoweringPrePhase.cpp | 3 +++ ets2panda/ir/astNode.h | 19 ++++++++++++++++++- ets2panda/ir/expressions/memberExpression.h | 4 ++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp index 5af36a6f47..1f2f16fa08 100644 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ b/ets2panda/compiler/core/ASTVerifier.cpp @@ -690,7 +690,13 @@ public: if (ast->IsClassDeclaration() && parent != nullptr && parent->IsETSNewClassInstanceExpression()) { return; } - + if (0) { + std::cout << "Ast: " << ast->DumpJSON() << std::endl + << "Node: " << node->DumpJSON() << std::endl + << "Node->Parent: " << parent->DumpJSON() << std::endl + << "has incorrect parent! " << parent << std::endl; + ASSERT(false); + } ctx.AddCheckMessage("INCORRECT_PARENT_REF", *node, node->Start()); result = {CheckDecision::INCORRECT, CheckAction::CONTINUE}; } diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index 0a94c65bb5..8fd0834bdb 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -16,6 +16,7 @@ #include "enumLoweringPrePhase.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" +#include "utils/arena_containers.h" #include "varbinder/variableFlags.h" #include "varbinder/ETSBinder.h" #include "checker/ETSchecker.h" @@ -292,6 +293,7 @@ void CreateCCtor(ArenaVector &properties, const lexer::SourcePosi ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, false, Language(Language::Id::ETS)); func->AddModifier(ir::ModifierFlags::STATIC); func->SetIdent(id); + ASSERT(body->Parent() == func); auto *func_expr = checker->AllocNode(func); auto *static_block = checker->AllocNode(func_expr, checker->Allocator()); @@ -351,6 +353,7 @@ ir::AstNode *CreateEnumClassFromEnumDeclaration(ir::TSEnumDeclaration *enum_decl ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::DECLARATION; auto *class_def = checker->AllocNode(checker->Allocator(), ident, std::move(body), def_modif, Language(Language::Id::ETS)); + ASSERT(ident->Parent() == class_def); if (is_int_enum) { class_def->SetSuper(CreateETSTypeReference(ENUM_INT_BASE_CLASS_NAME, checker)); } else { diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index de669111d0..d115da0c76 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -252,9 +252,24 @@ public: void SetParent(AstNode *const parent) noexcept { + if (mark_ & 0x01) { + ASSERT(parent_ == nullptr); + if (parent_ != nullptr) + ASSERT(parent_ == parent); + } parent_ = parent; } + void SetMark(size_t bit) + { + mark_ |= bit; + } + + size_t GetMark() + { + return mark_; + } + [[nodiscard]] varbinder::Variable *Variable() const noexcept { return variable_; @@ -438,7 +453,7 @@ public: \ bool Has##flag_type(flag_type flag) const noexcept \ { \ - return ((member_name)&flag) != 0U; \ + return ((member_name) & flag) != 0U; \ } \ void Remove##flag_type(flag_type flag) const noexcept \ { \ @@ -524,6 +539,8 @@ protected: mutable AstNodeFlags astNodeFlags_ {}; mutable BoxingUnboxingFlags boxingUnboxingFlags_ {}; // NOLINTEND(misc-non-private-member-variables-in-classes) + + size_t mark_; }; template diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 9d5da48de7..f626a75ab3 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -66,6 +66,10 @@ public: kind_(kind), computed_(computed) { + // if (object_ != nullptr) + // object_->SetParent(this); + // if (property_ != nullptr) + // property_->SetParent(this); } explicit MemberExpression(Tag tag, MemberExpression const &other, ArenaAllocator *allocator); -- Gitee From 1afcf547f2975f8bbef540eea149a5c0267a81f2 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 20 Feb 2024 16:03:37 +0300 Subject: [PATCH 25/48] Revert "[DEBUG] save debug code" This reverts commit b021622ba620a32cdb2cb42ef0249474d91f92c5. Signed-off-by: Vadim Lomovtsev --- ets2panda/compiler/core/ASTVerifier.cpp | 8 +------- .../lowering/ets/enumLoweringPrePhase.cpp | 3 --- ets2panda/ir/astNode.h | 19 +------------------ ets2panda/ir/expressions/memberExpression.h | 4 ---- 4 files changed, 2 insertions(+), 32 deletions(-) diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp index 1f2f16fa08..5af36a6f47 100644 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ b/ets2panda/compiler/core/ASTVerifier.cpp @@ -690,13 +690,7 @@ public: if (ast->IsClassDeclaration() && parent != nullptr && parent->IsETSNewClassInstanceExpression()) { return; } - if (0) { - std::cout << "Ast: " << ast->DumpJSON() << std::endl - << "Node: " << node->DumpJSON() << std::endl - << "Node->Parent: " << parent->DumpJSON() << std::endl - << "has incorrect parent! " << parent << std::endl; - ASSERT(false); - } + ctx.AddCheckMessage("INCORRECT_PARENT_REF", *node, node->Start()); result = {CheckDecision::INCORRECT, CheckAction::CONTINUE}; } diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index 8fd0834bdb..0a94c65bb5 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -16,7 +16,6 @@ #include "enumLoweringPrePhase.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" -#include "utils/arena_containers.h" #include "varbinder/variableFlags.h" #include "varbinder/ETSBinder.h" #include "checker/ETSchecker.h" @@ -293,7 +292,6 @@ void CreateCCtor(ArenaVector &properties, const lexer::SourcePosi ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, false, Language(Language::Id::ETS)); func->AddModifier(ir::ModifierFlags::STATIC); func->SetIdent(id); - ASSERT(body->Parent() == func); auto *func_expr = checker->AllocNode(func); auto *static_block = checker->AllocNode(func_expr, checker->Allocator()); @@ -353,7 +351,6 @@ ir::AstNode *CreateEnumClassFromEnumDeclaration(ir::TSEnumDeclaration *enum_decl ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::DECLARATION; auto *class_def = checker->AllocNode(checker->Allocator(), ident, std::move(body), def_modif, Language(Language::Id::ETS)); - ASSERT(ident->Parent() == class_def); if (is_int_enum) { class_def->SetSuper(CreateETSTypeReference(ENUM_INT_BASE_CLASS_NAME, checker)); } else { diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index d115da0c76..de669111d0 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -252,24 +252,9 @@ public: void SetParent(AstNode *const parent) noexcept { - if (mark_ & 0x01) { - ASSERT(parent_ == nullptr); - if (parent_ != nullptr) - ASSERT(parent_ == parent); - } parent_ = parent; } - void SetMark(size_t bit) - { - mark_ |= bit; - } - - size_t GetMark() - { - return mark_; - } - [[nodiscard]] varbinder::Variable *Variable() const noexcept { return variable_; @@ -453,7 +438,7 @@ public: \ bool Has##flag_type(flag_type flag) const noexcept \ { \ - return ((member_name) & flag) != 0U; \ + return ((member_name)&flag) != 0U; \ } \ void Remove##flag_type(flag_type flag) const noexcept \ { \ @@ -539,8 +524,6 @@ protected: mutable AstNodeFlags astNodeFlags_ {}; mutable BoxingUnboxingFlags boxingUnboxingFlags_ {}; // NOLINTEND(misc-non-private-member-variables-in-classes) - - size_t mark_; }; template diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index f626a75ab3..9d5da48de7 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -66,10 +66,6 @@ public: kind_(kind), computed_(computed) { - // if (object_ != nullptr) - // object_->SetParent(this); - // if (property_ != nullptr) - // property_->SetParent(this); } explicit MemberExpression(Tag tag, MemberExpression const &other, ArenaAllocator *allocator); -- Gitee From 06928e380bd547041f5a3d4fe593de220b11bdfa Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Wed, 21 Feb 2024 19:54:59 +0300 Subject: [PATCH 26/48] fix bitwise test for enum constants Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/arithmetic.cpp | 28 ++++++- ets2panda/checker/ets/helpers.cpp | 14 +++- .../lowering/ets/enumLoweringPostPhase.cpp | 84 +++++++++++++++++-- ets2panda/ir/astNode.h | 25 ++++++ ets2panda/ir/astNodeFlags.h | 6 ++ 5 files changed, 149 insertions(+), 8 deletions(-) diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index f387cac137..bdad86addd 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -322,10 +322,20 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: FlagExpressionWithUnboxing(rightType, unboxedR, right); if (promotedType == nullptr && !bothConst) { + if ((left->Parent() == right->Parent()) && + (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && + (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; + left->Parent()->SetPostBit(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED); + return nullptr; + } + + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 5" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } if (bothConst) { + // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 53" << std::endl; return HandleBitwiseOperationOnTypes(leftType, rightType, operationType); } @@ -637,6 +647,15 @@ static std::tuple CheckBinaryOperatorHelper(ETSChecker *checker, return {tsType, tsType}; } +static bool checkIfBitSet(ir::Expression *expr) +{ + if (expr->IsBinaryExpression() && + expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) { + return true; + } + return false; +} + std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, ir::Expression *right, ir::Expression *expr, lexer::TokenType op, lexer::SourcePosition pos, bool forcePromotion) @@ -644,7 +663,14 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, checker::Type *const leftType = left->Check(this); checker::Type *const rightType = right->Check(this); if ((leftType == nullptr) || (rightType == nullptr)) { - ThrowTypeError("Unexpected type error in binary expression", pos); + if (checkIfBitSet(left) || checkIfBitSet(right)) { + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; + expr->SetPostBit(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED); + return {nullptr, nullptr}; + } else { + std::cout << "Erroneos expression:" << expr->DumpJSON() << std::endl; + ThrowTypeError("Unexpected type error in binary expression", pos); + } } const bool isLogicalExtendedOperator = diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index acd4f211f9..5086082318 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -78,7 +78,12 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) auto *unboxedType = ETSBuiltinTypeAsConditionalType(type); if (unboxedType == nullptr) { - ThrowTypeError("Condition must be of possible condition type", expr->Start()); + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 1" << std::endl; + if (expr->IsBinaryExpression() && + (!expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED))) { + ThrowTypeError("Condition must be of possible condition type", expr->Start()); + } + return; } if (unboxedType == GlobalBuiltinVoidType() || unboxedType->IsETSVoidType()) { @@ -86,7 +91,11 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) } if (!unboxedType->IsConditionalExprType()) { - ThrowTypeError("Condition must be of possible condition type", expr->Start()); + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 2" << std::endl; + if (expr->IsBinaryExpression() && + (!expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED))) { + ThrowTypeError("Condition must be of possible condition type", expr->Start()); + } } if (unboxedType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { @@ -865,6 +874,7 @@ Type *ETSChecker::ApplyUnaryOperatorPromotion(Type *type, const bool createConst bool ETSChecker::IsNullLikeOrVoidExpression(const ir::Expression *expr) const { + ASSERT((expr != nullptr) && (expr->TsType() != nullptr)); return expr->TsType()->DefinitelyETSNullish() || expr->TsType()->IsETSVoidType(); } diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index ad07193f7a..8c74771bb7 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -32,7 +32,7 @@ namespace ark::es2panda::compiler { const char *ENUM_GETVALUE_METHOD_NAME = "getValue"; -ir::CallExpression *CreateCallExpression(ir::Identifier *id, checker::ETSChecker *checker) +ir::CallExpression *CreateCallExpression(ir::Expression *id, checker::ETSChecker *checker) { auto *const callee = checker->AllocNode(ENUM_GETVALUE_METHOD_NAME, checker->Allocator()); callee->SetReference(); @@ -70,6 +70,76 @@ ir::Expression *CreateTestExpression(ir::Identifier *id, CompilerContext *ctx, i return testExpr; } +ir::Expression *checkBinaryBranch(ir::Expression *ast, CompilerContext *ctx) +{ + // auto updateExpression = [ctx](ir::Expression *id) -> ir::Expression * { + // + // }; + if (ast->IsMemberExpression()) { + // i.e. we have following: + // enum Color {Red, Blue, Green, Yellow}; + // + // so for such 'imcomplete' accessors like + // Color.Red + // + // we'd need to replace it with + // color.Red.getValue() + if (auto *object = ast->AsMemberExpression()->Object(); object != nullptr) { + // .. + if (object->IsIdentifier() && object->AsIdentifier()->Variable() != nullptr) { + // .. + auto *checker = ctx->Checker()->AsETSChecker(); + auto *type = checker->GetTypeOfVariable(object->AsIdentifier()->Variable()); + ASSERT(type != nullptr); + + if (!type->IsETSEnum2Type()) { + std::cout << "[DEBUG] Not a ETSEnum2Type object!" << std::endl; + return ast; + } + std::cout << "[DEBUG] Found ETSEnum2Type identifier!" << std::endl; + + // auto *const scope = NearestScope(ast); + // ASSERT(scope != nullptr); + // auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); + + // auto *parent = ast->Parent(); + auto *callExpr = + CreateCallExpression(ast->AsMemberExpression()->Clone(checker->Allocator(), nullptr), checker); + // callExpr->SetParent(parent); + // + // InitScopesPhaseETS::RunExternalNode(callExpr, ctx->VarBinder()); + // checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(callExpr, scope); + // callExpr->Check(checker); + // ASSERT(callExpr->Variable() != nullptr); + + return callExpr; + } + } + } else if (ast->IsIdentifier()) { + } else { + std::cout << "[DEBUG] Neither MemberExpression nor identifier!" << std::endl; + } + return ast; +} + +ir::AstNode *UpdateMemberExpression(ir::AstNode *ast, CompilerContext *ctx) +{ + [[maybe_unused]] auto *checker = ctx->Checker()->AsETSChecker(); + auto *const scope = NearestScope(ast); + ASSERT(scope != nullptr); + auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); + + ast->AsBinaryExpression()->SetLeft(checkBinaryBranch( + ast->AsBinaryExpression()->Left()->Clone(checker->Allocator(), nullptr)->AsExpression(), ctx)); + ast->AsBinaryExpression()->SetRight(checkBinaryBranch( + ast->AsBinaryExpression()->Right()->Clone(checker->Allocator(), nullptr)->AsExpression(), ctx)); + + InitScopesPhaseETS::RunExternalNode(ast, ctx->VarBinder()); + checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(ast, scope); + ast->Check(checker); + return ast; +} + bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *program) { if (program->Extension() != ScriptExtension::ETS) { @@ -98,10 +168,14 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p // // so the foo(1) should be translated to foo(Color.Blue) } else if (ast->IsBinaryExpression()) { - // auto *rightExpr = AllocNode(left, rightExpr, operatorType); - [[maybe_unused]] auto *left = ast->AsBinaryExpression()->Left(); - [[maybe_unused]] auto *right = ast->AsBinaryExpression()->Right(); - + if (ast->AsBinaryExpression()->IsPostBitSet( + ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) { + return UpdateMemberExpression(ast, ctx->compilerContext); + } else { + // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] Skip this one, no need to update!" << + // std::endl; + return ast; + } } else if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || ast->IsForUpdateStatement() || ast->IsConditionalExpression()) { // so far let's put this only for test script diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index de669111d0..17dd047ff8 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -507,6 +507,28 @@ public: * ASTVisitorT::accept(this, v); * } */ + + // for some cases we mgt need to postpone potentially erroneous node processing at the checker + // but only set types for its' identifiers, thus making lowering knows what type of objects + // are reffered at the node. based on that the loewring could do some additional transformations + // and the must re-start checker again. in order to track that we would use bit register per each + // affected lowering. + void SetPostBit(PostProcessingBits bit) + { + post_ |= bit; + // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] bit " << bit << std::endl; + } + void ClearPostBit(PostProcessingBits bit) + { + // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] bit " << bit << std::endl; + post_ &= bit; + } + bool IsPostBitSet(PostProcessingBits bit) + { + // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] bit " << bit << std::endl; + return (bit & post_) != 0; + } + protected: AstNode(AstNode const &other); @@ -524,6 +546,9 @@ protected: mutable AstNodeFlags astNodeFlags_ {}; mutable BoxingUnboxingFlags boxingUnboxingFlags_ {}; // NOLINTEND(misc-non-private-member-variables-in-classes) + + // post processing bits per lowerings + uint64_t post_; }; template diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index 171c8a5591..2a8d6d9264 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -109,6 +109,12 @@ enum class BoxingUnboxingFlags : uint32_t { UNBOXING_FLAG = UNBOX_TO_BOOLEAN | UNBOX_TO_BYTE | UNBOX_TO_SHORT | UNBOX_TO_CHAR | UNBOX_TO_INT | UNBOX_TO_LONG | UNBOX_TO_FLOAT | UNBOX_TO_DOUBLE, }; + +enum PostProcessingBits : uint64_t { +#define BIT(x) ((uint64_t)1 << x) + ENUM_LOWERING_POST_PROCESSING_REQUIRED = BIT(0), +}; + } // namespace ark::es2panda::ir #endif -- Gitee From 8da2bffb1287a5732e98dfe8042bd0dc770a8540 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Wed, 21 Feb 2024 20:06:57 +0300 Subject: [PATCH 27/48] use labmda, not copy-paste code Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/enumLoweringPostPhase.cpp | 58 +++++++++---------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index 8c74771bb7..2e8687d537 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -72,9 +72,28 @@ ir::Expression *CreateTestExpression(ir::Identifier *id, CompilerContext *ctx, i ir::Expression *checkBinaryBranch(ir::Expression *ast, CompilerContext *ctx) { - // auto updateExpression = [ctx](ir::Expression *id) -> ir::Expression * { - // - // }; + auto updateExpression = [ctx](ir::Expression *object, ir::Expression *ast) -> ir::Expression * { + if (object->IsIdentifier() && object->AsIdentifier()->Variable() != nullptr) { + // .. + auto *checker = ctx->Checker()->AsETSChecker(); + auto *type = checker->GetTypeOfVariable(object->AsIdentifier()->Variable()); + ASSERT(type != nullptr); + + if (!type->IsETSEnum2Type()) { + if (0) + std::cout << "[DEBUG] Not a ETSEnum2Type object!" << std::endl; + return ast; + } + if (0) + std::cout << "[DEBUG] Found ETSEnum2Type identifier!" << std::endl; + + auto *callExpr = + CreateCallExpression(ast /*->AsMemberExpression()->Clone(checker->Allocator(), nullptr)*/, checker); + + return callExpr; + } + return ast; + }; if (ast->IsMemberExpression()) { // i.e. we have following: // enum Color {Red, Blue, Green, Yellow}; @@ -86,38 +105,13 @@ ir::Expression *checkBinaryBranch(ir::Expression *ast, CompilerContext *ctx) // color.Red.getValue() if (auto *object = ast->AsMemberExpression()->Object(); object != nullptr) { // .. - if (object->IsIdentifier() && object->AsIdentifier()->Variable() != nullptr) { - // .. - auto *checker = ctx->Checker()->AsETSChecker(); - auto *type = checker->GetTypeOfVariable(object->AsIdentifier()->Variable()); - ASSERT(type != nullptr); - - if (!type->IsETSEnum2Type()) { - std::cout << "[DEBUG] Not a ETSEnum2Type object!" << std::endl; - return ast; - } - std::cout << "[DEBUG] Found ETSEnum2Type identifier!" << std::endl; - - // auto *const scope = NearestScope(ast); - // ASSERT(scope != nullptr); - // auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); - - // auto *parent = ast->Parent(); - auto *callExpr = - CreateCallExpression(ast->AsMemberExpression()->Clone(checker->Allocator(), nullptr), checker); - // callExpr->SetParent(parent); - // - // InitScopesPhaseETS::RunExternalNode(callExpr, ctx->VarBinder()); - // checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(callExpr, scope); - // callExpr->Check(checker); - // ASSERT(callExpr->Variable() != nullptr); - - return callExpr; - } + return updateExpression(object, ast); } } else if (ast->IsIdentifier()) { + return updateExpression(ast->AsIdentifier(), ast); } else { - std::cout << "[DEBUG] Neither MemberExpression nor identifier!" << std::endl; + if (0) + std::cout << "[DEBUG] Neither MemberExpression nor identifier!" << std::endl; } return ast; } -- Gitee From 74b0ce7e5ce67897a8cc985a2cf0077dad42a0b3 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Wed, 21 Feb 2024 20:08:35 +0300 Subject: [PATCH 28/48] savedebug traces Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/arithmetic.cpp | 30 +++++++++++++++++++++++----- ets2panda/checker/ets/helpers.cpp | 6 ++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index bdad86addd..c5f39fad23 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -191,6 +191,8 @@ checker::Type *ETSChecker::CheckBinaryOperatorMulDivMod(ir::Expression *left, ir } if (promotedType == nullptr && !bothConst) { + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 1" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -210,6 +212,8 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp if (leftType->IsETSStringType() || rightType->IsETSStringType()) { if (operationType == lexer::TokenType::PUNCTUATOR_MINUS || operationType == lexer::TokenType::PUNCTUATOR_MINUS_EQUAL) { + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 2" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -227,6 +231,8 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp FlagExpressionWithUnboxing(rightType, unboxedR, right); if (promotedType == nullptr && !bothConst) { + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 3" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type or String.", pos); } @@ -254,6 +260,8 @@ checker::Type *ETSChecker::CheckBinaryOperatorShift(ir::Expression *left, ir::Ex if (promotedLeftType == nullptr || !promotedLeftType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) || promotedRightType == nullptr || !promotedRightType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 4" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -295,11 +303,15 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: // to apply this conversion if (leftType->IsETSEnumType()) { + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 50" << std::endl; left->AddAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); unboxedL = GlobalIntType(); } if (rightType->IsETSEnumType()) { + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 51" << std::endl; right->AddAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); unboxedR = GlobalIntType(); } @@ -310,6 +322,8 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: if (unboxedL != nullptr && unboxedL->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && unboxedR != nullptr && unboxedR->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 52" << std::endl; FlagExpressionWithUnboxing(leftType, unboxedL, left); FlagExpressionWithUnboxing(rightType, unboxedR, right); return HandleBooleanLogicalOperators(unboxedL, unboxedR, operationType); @@ -325,17 +339,19 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: if ((left->Parent() == right->Parent()) && (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; left->Parent()->SetPostBit(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return nullptr; } - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 5" << std::endl; + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 5" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } if (bothConst) { - // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 53" << std::endl; + // if(0) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 53" << std::endl; return HandleBitwiseOperationOnTypes(leftType, rightType, operationType); } @@ -493,6 +509,8 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater( } if (promotedType == nullptr && !bothConst) { + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 6" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -664,11 +682,13 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, checker::Type *const rightType = right->Check(this); if ((leftType == nullptr) || (rightType == nullptr)) { if (checkIfBitSet(left) || checkIfBitSet(right)) { - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; expr->SetPostBit(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return {nullptr, nullptr}; } else { - std::cout << "Erroneos expression:" << expr->DumpJSON() << std::endl; + if (0) + std::cout << "Erroneos expression:" << expr->DumpJSON() << std::endl; ThrowTypeError("Unexpected type error in binary expression", pos); } } diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 5086082318..7de842b0c9 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -78,7 +78,8 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) auto *unboxedType = ETSBuiltinTypeAsConditionalType(type); if (unboxedType == nullptr) { - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 1" << std::endl; + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 1" << std::endl; if (expr->IsBinaryExpression() && (!expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED))) { ThrowTypeError("Condition must be of possible condition type", expr->Start()); @@ -91,7 +92,8 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) } if (!unboxedType->IsConditionalExprType()) { - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 2" << std::endl; + if (0) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 2" << std::endl; if (expr->IsBinaryExpression() && (!expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED))) { ThrowTypeError("Condition must be of possible condition type", expr->Start()); -- Gitee From f576ce930b11b77c331294dcbfe9d77620570350 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Sat, 24 Feb 2024 09:11:20 +0300 Subject: [PATCH 29/48] project-wide: remove former enums implementation Signed-off-by: Vadim Lomovtsev --- ets2panda/BUILD.gn | 1 - ets2panda/CMakeLists.txt | 1 - ets2panda/checker/ETSAnalyzer.cpp | 36 +- ets2panda/checker/ETSchecker.h | 22 - ets2panda/checker/ets/arithmetic.cpp | 31 - ets2panda/checker/ets/enum.cpp | 656 ------------------ ets2panda/checker/ets/function.cpp | 2 +- ets2panda/checker/ets/helpers.cpp | 47 +- ets2panda/checker/ets/typeCreation.cpp | 127 ---- ets2panda/checker/ets/typeRelationContext.cpp | 1 - ets2panda/checker/types/ets/etsEnumType.cpp | 2 +- ets2panda/checker/types/ets/intType.cpp | 5 - ets2panda/checker/types/typeFlag.h | 20 +- ets2panda/checker/types/typeMapping.h | 2 - ets2panda/compiler/core/ETSCompiler.cpp | 50 +- ets2panda/compiler/core/ETSGen.cpp | 28 +- ets2panda/compiler/core/ETSGen.h | 18 +- ets2panda/compiler/lowering/phase.cpp | 2 +- ets2panda/ir/expressions/memberExpression.cpp | 35 +- 19 files changed, 77 insertions(+), 1009 deletions(-) delete mode 100644 ets2panda/checker/ets/enum.cpp diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 89b245599b..730008bdc9 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -40,7 +40,6 @@ libes2panda_sources = [ "checker/ets/castingContext.cpp", "checker/ets/conversion.cpp", "checker/ets/dynamic.cpp", - "checker/ets/enum.cpp", "checker/ets/function.cpp", "checker/ets/helpers.cpp", "checker/ets/narrowingConverter.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index e5cf81c679..31adc191c9 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -367,7 +367,6 @@ set(ES2PANDA_LIB_SRC checker/ets/conversion.cpp checker/ets/dynamic.cpp checker/ets/function.cpp - checker/ets/enum.cpp checker/ets/helpers.cpp checker/ets/narrowingConverter.cpp checker/ets/narrowingWideningConverter.cpp diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 05c55de407..5db7b03151 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1320,12 +1320,6 @@ checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const return SetAndAdjustType(checker, expr, baseType->AsETSObjectType()); } - if (baseType->IsETSEnumType() || baseType->IsETSStringEnumType()) { - auto [memberType, memberVar] = expr->ResolveEnumMember(checker, baseType); - expr->SetPropVar(memberVar); - return expr->AdjustType(checker, memberType); - } - if (baseType->IsETSUnionType()) { return expr->AdjustType(checker, expr->CheckUnionMember(checker, baseType)); } @@ -2445,12 +2439,6 @@ checker::Type *ETSAnalyzer::Check(ir::SwitchStatement *st) const validCaseType = true; if (caseType->HasTypeFlag(checker::TypeFlag::CHAR)) { validCaseType = comparedExprType->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL); - } else if (caseType->IsETSEnumType() && st->Discriminant()->TsType()->IsETSEnumType()) { - validCaseType = - st->Discriminant()->TsType()->AsETSEnumType()->IsSameEnumType(caseType->AsETSEnumType()); - } else if (caseType->IsETSStringEnumType() && st->Discriminant()->TsType()->IsETSStringEnumType()) { - validCaseType = st->Discriminant()->TsType()->AsETSStringEnumType()->IsSameEnumType( - caseType->AsETSStringEnumType()); } else if (caseType->IsETSEnum2Type() && st->Discriminant()->TsType()->IsETSEnum2Type()) { validCaseType = st->Discriminant()->TsType()->AsETSEnum2Type()->IsSameEnumType(caseType->AsETSEnum2Type()); @@ -2655,29 +2643,9 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSConstructorType *node) UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSEnumDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSEnumDeclaration *st) const { - ETSChecker *checker = GetETSChecker(); - varbinder::Variable *enumVar = st->Key()->Variable(); - ASSERT(enumVar != nullptr); - - if (enumVar->TsType() == nullptr) { - checker::Type *etsEnumType; - if (auto *const itemInit = st->Members().front()->AsTSEnumMember()->Init(); itemInit->IsNumberLiteral()) { - etsEnumType = checker->CreateETSEnumType(st); - } else if (itemInit->IsStringLiteral()) { - etsEnumType = checker->CreateETSStringEnumType(st); - } else { - checker->ThrowTypeError("Invalid enumeration value type.", st->Start()); - } - st->SetTsType(etsEnumType); - etsEnumType->SetVariable(enumVar); - enumVar->SetTsType(etsEnumType); - } else if (st->TsType() == nullptr) { - st->SetTsType(enumVar->TsType()); - } - - return st->TsType(); + UNREACHABLE(); } checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSEnumMember *st) const diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 8c0b13990c..5878a5d14e 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -220,8 +220,6 @@ public: ETSFunctionType *extensionFunctionType); ETSTypeParameter *CreateTypeParameter(); ETSObjectType *CreateETSObjectType(util::StringView name, ir::AstNode *declNode, ETSObjectFlags flags); - ETSEnumType *CreateETSEnumType(ir::TSEnumDeclaration const *enumDecl); - ETSStringEnumType *CreateETSStringEnumType(ir::TSEnumDeclaration const *enumDecl); std::tuple CreateBuiltinArraySignatureInfo(ETSArrayType *arrayType, size_t dim); Signature *CreateBuiltinArraySignature(ETSArrayType *arrayType, size_t dim); IntType *CreateIntTypeFromType(Type *type); @@ -439,7 +437,6 @@ public: void ValidateGenericTypeAliasForClonedNode(ir::TSTypeAliasDeclaration *typeAliasNode, const ir::TSTypeParameterInstantiation *exactTypeParams); Type *HandleTypeAlias(ir::Expression *name, const ir::TSTypeParameterInstantiation *typeParams); - Type *GetTypeFromEnumReference(varbinder::Variable *var); Type *GetTypeFromTypeParameterReference(varbinder::LocalVariable *var, const lexer::SourcePosition &pos); Type *GetNonConstantTypeFromPrimitiveType(Type *type) const; bool IsNullLikeOrVoidExpression(const ir::Expression *expr) const; @@ -517,7 +514,6 @@ public: void CheckUnboxedTypesAssignable(TypeRelation *relation, Type *source, Type *target); void CheckBoxedSourceTypeAssignable(TypeRelation *relation, Type *source, Type *target); void CheckUnboxedSourceTypeWithWideningAssignable(TypeRelation *relation, Type *source, Type *target); - void CheckValidGenericTypeParameter(Type *argType, const lexer::SourcePosition &pos); void ValidateResolvedProperty(const varbinder::LocalVariable *property, const ETSObjectType *target, const ir::Identifier *ident, PropertySearchFlags flags); bool IsValidSetterLeftSide(const ir::MemberExpression *member); @@ -552,24 +548,6 @@ public: static Type *TryToInstantiate(Type *type, ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes); - // Enum - [[nodiscard]] ir::Identifier *CreateEnumNamesArray(ETSEnumInterface const *enumType); - [[nodiscard]] ir::Identifier *CreateEnumValuesArray(ETSEnumType *enumType); - [[nodiscard]] ir::Identifier *CreateEnumStringValuesArray(ETSEnumInterface *enumType); - [[nodiscard]] ir::Identifier *CreateEnumItemsArray(ETSEnumInterface *enumType); - [[nodiscard]] ETSEnumType::Method CreateEnumFromIntMethod(ir::Identifier *namesArrayIdent, - ETSEnumInterface *enumType); - [[nodiscard]] ETSEnumType::Method CreateEnumGetValueMethod(ir::Identifier *valuesArrayIdent, ETSEnumType *enumType); - [[nodiscard]] ETSEnumType::Method CreateEnumToStringMethod(ir::Identifier *stringValuesArrayIdent, - ETSEnumInterface *enumType); - [[nodiscard]] ETSEnumType::Method CreateEnumGetNameMethod(ir::Identifier *namesArrayIdent, - ETSEnumInterface *enumType); - [[nodiscard]] ETSEnumType::Method CreateEnumValueOfMethod(ir::Identifier *namesArrayIdent, - ETSEnumInterface *enumType); - [[nodiscard]] ETSEnumType::Method CreateEnumValuesMethod(ir::Identifier *itemsArrayIdent, - ETSEnumInterface *enumType); - [[nodiscard]] ir::StringLiteral *CreateEnumStringLiteral(ETSEnumInterface *const enumType, - const ir::TSEnumMember *const member); // Dynamic interop template diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index c5f39fad23..d16132dd78 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -302,20 +302,6 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: // NOTE (mmartin): These need to be done for other binary expressions, but currently it's not defined precisely when // to apply this conversion - if (leftType->IsETSEnumType()) { - if (0) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 50" << std::endl; - left->AddAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); - unboxedL = GlobalIntType(); - } - - if (rightType->IsETSEnumType()) { - if (0) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 51" << std::endl; - right->AddAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); - unboxedR = GlobalIntType(); - } - if (leftType->IsETSUnionType() || rightType->IsETSUnionType()) { ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); } @@ -411,14 +397,6 @@ std::tuple ETSChecker::CheckBinaryOperatorEqual( checker::Type *const leftType, checker::Type *const rightType, Type *unboxedL, Type *unboxedR) { checker::Type *tsType {}; - if (leftType->IsETSEnumType() && rightType->IsETSEnumType()) { - if (!leftType->AsETSEnumType()->IsSameEnumType(rightType->AsETSEnumType())) { - ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); - } - - tsType = GlobalETSBooleanType(); - return {tsType, leftType}; - } if (leftType->IsETSEnum2Type() && rightType->IsETSEnum2Type()) { if (!leftType->AsETSEnum2Type()->IsSameEnumType(rightType->AsETSEnum2Type())) { @@ -429,15 +407,6 @@ std::tuple ETSChecker::CheckBinaryOperatorEqual( return {tsType, leftType}; } - if (leftType->IsETSStringEnumType() && rightType->IsETSStringEnumType()) { - if (!leftType->AsETSStringEnumType()->IsSameEnumType(rightType->AsETSStringEnumType())) { - ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); - } - - tsType = GlobalETSBooleanType(); - return {tsType, leftType}; - } - if (leftType->IsETSDynamicType() || rightType->IsETSDynamicType()) { return CheckBinaryOperatorEqualDynamic(left, right, pos); } diff --git a/ets2panda/checker/ets/enum.cpp b/ets2panda/checker/ets/enum.cpp deleted file mode 100644 index 8c8e230845..0000000000 --- a/ets2panda/checker/ets/enum.cpp +++ /dev/null @@ -1,656 +0,0 @@ -/* - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "util/ustring.h" -#include "varbinder/ETSBinder.h" -#include "varbinder/variable.h" -#include "checker/ETSchecker.h" -#include "ir/base/classProperty.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/property.h" -#include "ir/base/scriptFunction.h" -#include "ir/ets/etsNewClassInstanceExpression.h" -#include "ir/ets/etsPrimitiveType.h" -#include "ir/ets/etsTypeReference.h" -#include "ir/ets/etsTypeReferencePart.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/binaryExpression.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/updateExpression.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/forUpdateStatement.h" -#include "ir/statements/ifStatement.h" -#include "ir/statements/returnStatement.h" -#include "ir/statements/throwStatement.h" -#include "ir/statements/variableDeclaration.h" -#include "ir/statements/variableDeclarator.h" -#include "ir/ts/tsArrayType.h" -#include "ir/ts/tsAsExpression.h" -#include "ir/ts/tsEnumMember.h" -#include "ir/ts/tsInterfaceBody.h" -#include "parser/program/program.h" -#include "ir/ets/etsParameterExpression.h" - -namespace ark::es2panda::checker { - -namespace { -void AppendParentNames(util::UString &qualifiedName, const ir::AstNode *const node) -{ - if (node != nullptr && !node->IsProgram()) { - AppendParentNames(qualifiedName, node->Parent()); - if (node->IsTSInterfaceDeclaration()) { - qualifiedName.Append(node->AsTSInterfaceDeclaration()->Id()->Name()); - } else if (node->IsClassDefinition()) { - qualifiedName.Append(node->AsClassDefinition()->Ident()->Name()); - } else { - ASSERT(node->IsClassDeclaration() || node->IsTSInterfaceBody()); - return; - } - qualifiedName.Append('#'); - } -} - -[[nodiscard]] ir::Identifier *MakeQualifiedIdentifier(ETSChecker *const checker, - const ir::TSEnumDeclaration *const enumDecl, - const util::StringView &name) -{ - util::UString qualifiedName(util::StringView("#"), checker->Allocator()); - AppendParentNames(qualifiedName, enumDecl->Parent()); - qualifiedName.Append(enumDecl->Key()->Name()); - qualifiedName.Append('#'); - qualifiedName.Append(name); - return checker->AllocNode(qualifiedName.View(), checker->Allocator()); -} - -template -[[nodiscard]] ir::Identifier *MakeArray(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, - const ETSEnumInterface *const enumType, const util::StringView &name, - Type *const elementType, ElementMaker &&elementMaker) -{ - ArenaVector elements(checker->Allocator()->Adapter()); - elements.reserve(enumType->GetMembers().size()); - for (const auto *const member : enumType->GetMembers()) { - elements.push_back(elementMaker(member->AsTSEnumMember())); - } - - auto *const arrayExpr = checker->AllocNode(std::move(elements), checker->Allocator()); - arrayExpr->SetPreferredType(elementType); - arrayExpr->SetTsType(checker->CreateETSArrayType(elementType)); - - auto *const arrayIdent = MakeQualifiedIdentifier(checker, enumType->GetDecl(), name); - - auto *const arrayClassProp = checker->AllocNode( - arrayIdent, arrayExpr, nullptr, - ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC | ir::ModifierFlags::CONST, checker->Allocator(), false); - arrayClassProp->SetTsType(arrayExpr->TsType()); - arrayClassProp->SetParent(varbinder->Program()->GlobalClass()); - arrayIdent->SetTsType(arrayClassProp->TsType()); - varbinder->Program()->GlobalClass()->Body().push_back(arrayClassProp); - - auto [array_decl, array_var] = - varbinder->NewVarDecl(arrayIdent->Start(), arrayIdent->Name(), arrayClassProp); - arrayIdent->SetVariable(array_var); - array_var->SetTsType(arrayClassProp->TsType()); - array_var->AddFlag(varbinder::VariableFlags::PUBLIC | varbinder::VariableFlags::STATIC | - varbinder::VariableFlags::PROPERTY); - array_decl->Node()->SetParent(varbinder->Program()->GlobalClass()); - return arrayIdent; -} - -[[nodiscard]] ir::ETSParameterExpression *MakeFunctionParam(ETSChecker *const checker, - varbinder::ETSBinder *const varbinder, - varbinder::FunctionParamScope *const scope, - const util::StringView &name, Type *const type) -{ - const auto paramCtx = varbinder::LexicalScope::Enter(varbinder, scope, false); - auto *const paramIdent = checker->AllocNode(name, checker->Allocator()); - auto *const param = checker->AllocNode(paramIdent, nullptr); - auto *const paramVar = std::get<1>(varbinder->AddParamDecl(param)); - paramVar->SetTsType(type); - param->Ident()->SetVariable(paramVar); - param->Ident()->SetTsType(type); - param->SetTsType(type); - return param; -} - -[[nodiscard]] ir::ETSTypeReference *MakeTypeReference(ETSChecker *const checker, const util::StringView &name) -{ - auto *const ident = checker->AllocNode(name, checker->Allocator()); - ident->SetReference(); - auto *const referencePart = checker->AllocNode(ident); - - return checker->AllocNode(referencePart); -} - -[[nodiscard]] ir::ScriptFunction *MakeFunction(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, - varbinder::FunctionParamScope *const paramScope, - ArenaVector &¶ms, - ArenaVector &&body, - ir::TypeNode *const returnTypeAnnotation, bool isDeclare) -{ - auto *const functionScope = varbinder->Allocator()->New(checker->Allocator(), paramScope); - functionScope->BindParamScope(paramScope); - paramScope->BindFunctionScope(functionScope); - - auto *const bodyBlock = checker->AllocNode(checker->Allocator(), std::move(body)); - bodyBlock->SetScope(functionScope); - - auto flags = ir::ModifierFlags::PUBLIC; - - if (isDeclare) { - flags |= ir::ModifierFlags::DECLARE; - } - - auto *const function = checker->AllocNode( - ir::FunctionSignature(nullptr, std::move(params), returnTypeAnnotation), bodyBlock, - ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, flags, isDeclare}); - function->SetScope(functionScope); - - varbinder->AsETSBinder()->BuildInternalName(function); - varbinder->AsETSBinder()->AddCompilableFunction(function); - paramScope->BindNode(function); - functionScope->BindNode(function); - - return function; -} - -void MakeMethodDef(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, ir::Identifier *const ident, - ir::ScriptFunction *const function) -{ - auto *const functionExpr = checker->AllocNode(function); - auto *const identClone = ident->Clone(checker->Allocator(), nullptr); - identClone->SetTsType(ident->TsType()); - - auto *const methodDef = - checker->AllocNode(ir::MethodDefinitionKind::METHOD, identClone, functionExpr, - ir::ModifierFlags::PUBLIC, checker->Allocator(), false); - methodDef->SetParent(varbinder->Program()->GlobalClass()); - - auto *const methodVar = std::get<1>(varbinder->NewVarDecl( - methodDef->Start(), checker->Allocator(), methodDef->Id()->Name(), methodDef)); - methodVar->AddFlag(varbinder::VariableFlags::STATIC | varbinder::VariableFlags::SYNTHETIC | - varbinder::VariableFlags::METHOD); - methodDef->Function()->Id()->SetVariable(methodVar); - methodDef->Id()->SetVariable(methodVar); -} - -[[nodiscard]] ETSFunctionType *MakeProxyFunctionType(ETSChecker *const checker, const util::StringView &name, - const std::initializer_list ¶ms, - ir::ScriptFunction *const globalFunction, Type *const returnType) -{ - auto *const signatureInfo = checker->CreateSignatureInfo(); - signatureInfo->params.insert(signatureInfo->params.end(), params); - signatureInfo->minArgCount = signatureInfo->params.size(); - - auto *const signature = checker->CreateSignature(signatureInfo, returnType, name); - signature->SetFunction(globalFunction); - signature->AddSignatureFlag(SignatureFlags::PROXY); - - return checker->CreateETSFunctionType(signature, name); -} - -[[nodiscard]] Signature *MakeGlobalSignature(ETSChecker *const checker, ir::ScriptFunction *const function, - Type *const returnType) -{ - auto *const signatureInfo = checker->CreateSignatureInfo(); - signatureInfo->params.reserve(function->Params().size()); - for (const auto *const param : function->Params()) { - signatureInfo->params.push_back(param->AsETSParameterExpression()->Variable()->AsLocalVariable()); - } - signatureInfo->minArgCount = signatureInfo->params.size(); - - auto *const signature = checker->CreateSignature(signatureInfo, returnType, function); - signature->AddSignatureFlag(SignatureFlags::PUBLIC | SignatureFlags::STATIC); - function->SetSignature(signature); - - return signature; -} -} // namespace - -ir::Identifier *ETSChecker::CreateEnumNamesArray(ETSEnumInterface const *const enumType) -{ - // clang-format off - return MakeArray(this, VarBinder()->AsETSBinder(), enumType, "NamesArray", GlobalBuiltinETSStringType(), - [this](const ir::TSEnumMember *const member) { - auto *const enumNameStringLiteral = - AllocNode(member->Key()->AsIdentifier()->Name()); - enumNameStringLiteral->SetTsType(GlobalBuiltinETSStringType()); - return enumNameStringLiteral; - }); - // clang-format on -} - -ir::Identifier *ETSChecker::CreateEnumValuesArray(ETSEnumType *const enumType) -{ - return MakeArray( - this, VarBinder()->AsETSBinder(), enumType, "ValuesArray", GlobalIntType(), - [this](const ir::TSEnumMember *const member) { - auto *const enumValueLiteral = AllocNode(lexer::Number( - member->AsTSEnumMember()->Init()->AsNumberLiteral()->Number().GetValue())); - enumValueLiteral->SetTsType(GlobalIntType()); - return enumValueLiteral; - }); -} - -ir::Identifier *ETSChecker::CreateEnumStringValuesArray(ETSEnumInterface *const enumType) -{ - return MakeArray(this, VarBinder()->AsETSBinder(), enumType, "StringValuesArray", GlobalETSStringLiteralType(), - [this, enumType](const ir::TSEnumMember *const member) { - auto *const init = member->AsTSEnumMember()->Init(); - util::StringView stringValue; - - if (enumType->IsETSStringEnumType()) { - stringValue = init->AsStringLiteral()->Str(); - } else { - auto str = - std::to_string(init->AsNumberLiteral()->Number().GetValue()); - stringValue = util::UString(str, Allocator()).View(); - } - - auto *const enumValueStringLiteral = AllocNode(stringValue); - enumValueStringLiteral->SetTsType(GlobalETSStringLiteralType()); - return enumValueStringLiteral; - }); -} - -ir::Identifier *ETSChecker::CreateEnumItemsArray(ETSEnumInterface *const enumType) -{ - return MakeArray( - this, VarBinder()->AsETSBinder(), enumType, "ItemsArray", enumType, - [this, enumType](const ir::TSEnumMember *const member) { - auto *const enumTypeIdent = AllocNode(enumType->GetName(), Allocator()); - enumTypeIdent->SetTsType(enumType); - enumTypeIdent->SetReference(); - - auto *const enumMemberIdent = - AllocNode(member->AsTSEnumMember()->Key()->AsIdentifier()->Name(), Allocator()); - enumMemberIdent->SetReference(); - auto *const enumMemberExpr = AllocNode( - enumTypeIdent, enumMemberIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - enumMemberExpr->SetTsType(member->AsTSEnumMember()->Key()->AsIdentifier()->Variable()->TsType()); - - return enumMemberExpr; - }); -} - -ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const namesArrayIdent, - ETSEnumInterface *const enumType) -{ - auto *const paramScope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - - auto *const inputOrdinalIdent = - MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", GlobalIntType()); - - auto *const inArraySizeExpr = [this, namesArrayIdent, inputOrdinalIdent]() { - auto *const lengthIdent = AllocNode("length", Allocator()); - auto *const valuesArrayLengthExpr = AllocNode( - namesArrayIdent, lengthIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - auto *const expr = AllocNode(inputOrdinalIdent, valuesArrayLengthExpr, - lexer::TokenType::PUNCTUATOR_LESS_THAN); - expr->SetOperationType(GlobalIntType()); - expr->SetTsType(GlobalETSBooleanType()); - return expr; - }(); - - auto *const returnEnumStmt = [this, inputOrdinalIdent, enumType]() { - auto *const identClone = inputOrdinalIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(enumType); - return AllocNode(identClone); - }(); - - auto *const ifOrdinalExistsStmt = AllocNode(inArraySizeExpr, returnEnumStmt, nullptr); - - auto *const throwNoEnumStmt = [this, inputOrdinalIdent, enumType]() { - auto *const exceptionReference = MakeTypeReference(this, "Exception"); - - util::UString messageString(util::StringView("No enum constant in "), Allocator()); - messageString.Append(enumType->GetName()); - messageString.Append(" with ordinal value "); - - auto *const identClone = inputOrdinalIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(GlobalIntType()); - - auto *const message = AllocNode(messageString.View()); - auto *const newExprArg = - AllocNode(message, identClone, lexer::TokenType::PUNCTUATOR_PLUS); - ArenaVector newExprArgs(Allocator()->Adapter()); - newExprArgs.push_back(newExprArg); - - auto *const newExpr = AllocNode( - exceptionReference, std::move(newExprArgs), - GlobalBuiltinExceptionType()->GetDeclNode()->AsClassDefinition()); - - newExpr->SetSignature( - ResolveConstructExpression(GlobalBuiltinExceptionType(), newExpr->GetArguments(), newExpr->Start())); - newExpr->SetTsType(GlobalBuiltinExceptionType()); - - return AllocNode(newExpr); - }(); - - auto *const identClone = inputOrdinalIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(inputOrdinalIdent->TsType()); - ArenaVector params(Allocator()->Adapter()); - params.push_back(identClone); - - ArenaVector body(Allocator()->Adapter()); - body.push_back(ifOrdinalExistsStmt); - body.push_back(throwNoEnumStmt); - body.push_back(returnEnumStmt); - - auto *const enumTypeAnnotation = MakeTypeReference(this, enumType->GetName()); - - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), - std::move(body), enumTypeAnnotation, enumType->GetDecl()->IsDeclare()); - function->AddFlag(ir::ScriptFunctionFlags::THROWS); - - auto *const ident = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::FROM_INT_METHOD_NAME); - function->SetIdent(ident); - function->Scope()->BindInternalName(ident->Name()); - - MakeMethodDef(this, VarBinder()->AsETSBinder(), ident, function); - - ident->SetReference(); - - return {MakeGlobalSignature(this, function, enumType), nullptr}; -} - -ETSEnumType::Method ETSChecker::CreateEnumToStringMethod(ir::Identifier *const stringValuesArrayIdent, - ETSEnumInterface *const enumType) -{ - auto *const paramScope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalClassScope()); - - auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", enumType); - - auto *const returnStmt = [this, inputEnumIdent, stringValuesArrayIdent]() { - auto *const arrayAccessExpr = AllocNode( - stringValuesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); - arrayAccessExpr->SetTsType(GlobalETSStringLiteralType()); - - return AllocNode(arrayAccessExpr); - }(); - - ArenaVector body(Allocator()->Adapter()); - body.push_back(returnStmt); - - auto *const identClone = inputEnumIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(enumType); - ArenaVector params(Allocator()->Adapter()); - params.push_back(identClone); - - auto *const stringTypeAnnotation = MakeTypeReference(this, GlobalBuiltinETSStringType()->Name()); - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), - std::move(body), stringTypeAnnotation, enumType->GetDecl()->IsDeclare()); - - auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::TO_STRING_METHOD_NAME); - function->SetIdent(functionIdent); - function->Scope()->BindInternalName(functionIdent->Name()); - - MakeMethodDef(this, VarBinder()->AsETSBinder(), functionIdent, function); - - functionIdent->SetReference(); - - return { - MakeGlobalSignature(this, function, GlobalETSStringLiteralType()), - MakeProxyFunctionType(this, ETSEnumType::TO_STRING_METHOD_NAME, {}, function, GlobalETSStringLiteralType())}; -} - -ETSEnumType::Method ETSChecker::CreateEnumGetValueMethod(ir::Identifier *const valuesArrayIdent, - ETSEnumType *const enumType) -{ - auto *const paramScope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalClassScope()); - - auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "e", enumType); - - auto *const returnStmt = [this, inputEnumIdent, valuesArrayIdent]() { - auto *const arrayAccessExpr = AllocNode( - valuesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); - arrayAccessExpr->SetTsType(GlobalIntType()); - - return AllocNode(arrayAccessExpr); - }(); - - ArenaVector body(Allocator()->Adapter()); - body.push_back(returnStmt); - - auto *const identClone = inputEnumIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(enumType); - ArenaVector params(Allocator()->Adapter()); - params.push_back(identClone); - - auto *const intTypeAnnotation = AllocNode(ir::PrimitiveType::INT); - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), - std::move(body), intTypeAnnotation, enumType->GetDecl()->IsDeclare()); - - auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::GET_VALUE_METHOD_NAME); - function->SetIdent(functionIdent); - function->Scope()->BindInternalName(functionIdent->Name()); - - MakeMethodDef(this, VarBinder()->AsETSBinder(), functionIdent, function); - - functionIdent->SetReference(); - - return {MakeGlobalSignature(this, function, GlobalIntType()), - MakeProxyFunctionType(this, ETSEnumType::GET_VALUE_METHOD_NAME, {}, function, GlobalIntType())}; -} - -ETSEnumType::Method ETSChecker::CreateEnumGetNameMethod(ir::Identifier *const namesArrayIdent, - ETSEnumInterface *const enumType) -{ - auto *const paramScope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - - auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", enumType); - - auto *const returnStmt = [this, inputEnumIdent, namesArrayIdent]() { - auto *const arrayAccessExpr = AllocNode( - namesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); - arrayAccessExpr->SetTsType(GlobalBuiltinETSStringType()); - - return AllocNode(arrayAccessExpr); - }(); - - ArenaVector body(Allocator()->Adapter()); - body.push_back(returnStmt); - - auto *const identClone = inputEnumIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(enumType); - ArenaVector params(Allocator()->Adapter()); - params.push_back(identClone); - - auto *const stringTypeAnnotation = MakeTypeReference(this, GlobalBuiltinETSStringType()->Name()); - - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), - std::move(body), stringTypeAnnotation, enumType->GetDecl()->IsDeclare()); - - auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::GET_NAME_METHOD_NAME); - function->SetIdent(functionIdent); - function->Scope()->BindInternalName(functionIdent->Name()); - - MakeMethodDef(this, VarBinder()->AsETSBinder(), functionIdent, function); - - functionIdent->SetReference(); - - return {MakeGlobalSignature(this, function, GlobalBuiltinETSStringType()), - MakeProxyFunctionType(this, ETSEnumType::GET_NAME_METHOD_NAME, {}, function, GlobalBuiltinETSStringType())}; -} - -ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const namesArrayIdent, - ETSEnumInterface *const enumType) -{ - auto *const paramScope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - - varbinder::LexicalScope loopDeclScope(VarBinder()); - - auto *const forLoopIIdent = [this]() { - auto *const ident = AllocNode("i", Allocator()); - ident->SetTsType(GlobalIntType()); - auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); - ident->SetVariable(var); - var->SetTsType(GlobalIntType()); - var->SetScope(VarBinder()->GetScope()); - var->AddFlag(varbinder::VariableFlags::LOCAL); - decl->BindNode(ident); - return ident; - }(); - - auto *const forLoopInitVarDecl = [this, forLoopIIdent]() { - auto *const init = AllocNode("0"); - init->SetTsType(GlobalIntType()); - auto *const decl = AllocNode(ir::VariableDeclaratorFlag::LET, forLoopIIdent, init); - decl->SetTsType(GlobalIntType()); - ArenaVector decls(Allocator()->Adapter()); - decls.push_back(decl); - return AllocNode(ir::VariableDeclaration::VariableDeclarationKind::LET, Allocator(), - std::move(decls), false); - }(); - - auto *const forLoopTest = [this, namesArrayIdent, forLoopIIdent]() { - auto *const lengthIdent = AllocNode("length", Allocator()); - auto *const arrayLengthExpr = AllocNode( - namesArrayIdent, lengthIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - arrayLengthExpr->SetTsType(GlobalIntType()); - auto *const binaryExpr = - AllocNode(forLoopIIdent, arrayLengthExpr, lexer::TokenType::PUNCTUATOR_LESS_THAN); - binaryExpr->SetOperationType(GlobalIntType()); - binaryExpr->SetTsType(GlobalETSBooleanType()); - return binaryExpr; - }(); - - auto *const forLoopUpdate = [this, forLoopIIdent]() { - auto *const incrementExpr = - AllocNode(forLoopIIdent, lexer::TokenType::PUNCTUATOR_PLUS_PLUS, true); - incrementExpr->SetTsType(GlobalIntType()); - return incrementExpr; - }(); - - auto *const inputNameIdent = - MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "name", GlobalBuiltinETSStringType()); - - auto *const ifStmt = [this, namesArrayIdent, forLoopIIdent, inputNameIdent]() { - auto *const identClone = namesArrayIdent->Clone(this->Allocator(), nullptr); - identClone->SetTsType(namesArrayIdent->TsType()); - auto *const namesArrayElementExpr = AllocNode( - identClone, forLoopIIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); - namesArrayElementExpr->SetTsType(GlobalBuiltinETSStringType()); - - auto *const namesEqualExpr = - AllocNode(inputNameIdent, namesArrayElementExpr, lexer::TokenType::PUNCTUATOR_EQUAL); - namesEqualExpr->SetOperationType(GlobalBuiltinETSStringType()); - namesEqualExpr->SetTsType(GlobalETSBooleanType()); - - auto *const returnStmt = AllocNode(forLoopIIdent); - return AllocNode(namesEqualExpr, returnStmt, nullptr); - }(); - - varbinder::LexicalScope loopScope(VarBinder()); - loopScope.GetScope()->BindDecls(loopDeclScope.GetScope()); - - auto *const forLoop = AllocNode(forLoopInitVarDecl, forLoopTest, forLoopUpdate, ifStmt); - loopScope.GetScope()->BindNode(forLoop); - forLoop->SetScope(loopScope.GetScope()); - loopScope.GetScope()->DeclScope()->BindNode(forLoop); - - auto *const throwStmt = [this, inputNameIdent, enumType]() { - util::UString messageString(util::StringView("No enum constant "), Allocator()); - messageString.Append(enumType->GetName()); - messageString.Append('.'); - - auto *const identClone = inputNameIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(inputNameIdent->TsType()); - auto *const message = AllocNode(messageString.View()); - auto *const newExprArg = - AllocNode(message, identClone, lexer::TokenType::PUNCTUATOR_PLUS); - - ArenaVector newExprArgs(Allocator()->Adapter()); - newExprArgs.push_back(newExprArg); - - auto *const exceptionReference = MakeTypeReference(this, "Exception"); - - auto *const newExpr = AllocNode( - exceptionReference, std::move(newExprArgs), - GlobalBuiltinExceptionType()->GetDeclNode()->AsClassDefinition()); - newExpr->SetSignature( - ResolveConstructExpression(GlobalBuiltinExceptionType(), newExpr->GetArguments(), newExpr->Start())); - newExpr->SetTsType(GlobalBuiltinExceptionType()); - - return AllocNode(newExpr); - }(); - - ArenaVector body(Allocator()->Adapter()); - body.push_back(forLoop); - body.push_back(throwStmt); - - auto *const identClone = inputNameIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(inputNameIdent->TsType()); - ArenaVector params(Allocator()->Adapter()); - params.push_back(identClone); - - auto *const enumTypeAnnotation = MakeTypeReference(this, enumType->GetName()); - - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), - std::move(body), enumTypeAnnotation, enumType->GetDecl()->IsDeclare()); - function->AddFlag(ir::ScriptFunctionFlags::THROWS); - - auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::VALUE_OF_METHOD_NAME); - function->SetIdent(functionIdent); - function->Scope()->BindInternalName(functionIdent->Name()); - - MakeMethodDef(this, VarBinder()->AsETSBinder(), functionIdent, function); - - functionIdent->SetReference(); - - return {MakeGlobalSignature(this, function, enumType), - MakeProxyFunctionType(this, ETSEnumType::VALUE_OF_METHOD_NAME, - {function->Params()[0]->AsETSParameterExpression()->Variable()->AsLocalVariable()}, - function, enumType)}; -} - -ETSEnumType::Method ETSChecker::CreateEnumValuesMethod(ir::Identifier *const itemsArrayIdent, - ETSEnumInterface *const enumType) -{ - auto *const paramScope = - VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - - auto *const returnStmt = AllocNode(itemsArrayIdent); - ArenaVector body(Allocator()->Adapter()); - body.push_back(returnStmt); - - ArenaVector params(Allocator()->Adapter()); - - auto *const enumArrayTypeAnnotation = AllocNode(MakeTypeReference(this, enumType->GetName())); - - auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), - std::move(body), enumArrayTypeAnnotation, enumType->GetDecl()->IsDeclare()); - - auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::VALUES_METHOD_NAME); - function->SetIdent(functionIdent); - function->Scope()->BindInternalName(functionIdent->Name()); - - MakeMethodDef(this, VarBinder()->AsETSBinder(), functionIdent, function); - - functionIdent->SetReference(); - - return {MakeGlobalSignature(this, function, CreateETSArrayType(enumType)), - MakeProxyFunctionType(this, ETSEnumType::VALUES_METHOD_NAME, {}, function, CreateETSArrayType(enumType))}; -} -} // namespace ark::es2panda::checker diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 34473739d3..fdc51bbd58 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -2761,7 +2761,7 @@ bool ETSChecker::IsReturnTypeSubstitutable(Signature *const s1, Signature *const // type R2 if any of the following is true: // - If R1 is a primitive type then R2 is identical to R1. - if (r1->HasTypeFlag(TypeFlag::ETS_PRIMITIVE | TypeFlag::ETS_ENUM | TypeFlag::ETS_STRING_ENUM)) { + if (r1->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { return Relation()->IsIdenticalTo(r2, r1); } diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 7de842b0c9..570d50c511 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -551,8 +551,7 @@ void ETSChecker::ValidateMemberIdentifier(ir::Identifier *const ident, varbinder return; } - if (!IsReferenceType(type) && !type->IsETSEnumType() && !type->IsETSStringEnumType() && - !type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { + if (!IsReferenceType(type) && !type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { ThrowError(ident); } } @@ -1310,22 +1309,6 @@ Type *ETSChecker::HandleTypeAlias(ir::Expression *const name, const ir::TSTypePa return aliasType->Substitute(Relation(), aliasSub); } -Type *ETSChecker::GetTypeFromEnumReference([[maybe_unused]] varbinder::Variable *var) -{ - if (var->TsType() != nullptr) { - return var->TsType(); - } - - auto const *const enumDecl = var->Declaration()->Node()->AsTSEnumDeclaration(); - if (auto *const itemInit = enumDecl->Members().front()->AsTSEnumMember()->Init(); itemInit->IsNumberLiteral()) { - return CreateETSEnumType(enumDecl); - } else if (itemInit->IsStringLiteral()) { // NOLINT(readability-else-after-return) - return CreateETSStringEnumType(enumDecl); - } else { // NOLINT(readability-else-after-return) - ThrowTypeError("Invalid enumeration value type.", enumDecl->Start()); - } -} - Type *ETSChecker::GetTypeFromTypeParameterReference(varbinder::LocalVariable *var, const lexer::SourcePosition &pos) { ASSERT(var->Declaration()->Node()->IsTSTypeParameter()); @@ -1440,9 +1423,6 @@ Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) case ir::AstNodeType::CLASS_DEFINITION: { return GetTypeFromClassReference(refVar); } - case ir::AstNodeType::TS_ENUM_DECLARATION: { - return GetTypeFromEnumReference(refVar); - } case ir::AstNodeType::TS_TYPE_PARAMETER: { return GetTypeFromTypeParameterReference(refVar, name->Start()); } @@ -1736,8 +1716,7 @@ Type *ETSChecker::ETSBuiltinTypeAsPrimitiveType(Type *objectType) return nullptr; } - if (objectType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) || objectType->HasTypeFlag(TypeFlag::ETS_ENUM) || - objectType->HasTypeFlag(TypeFlag::ETS_STRING_ENUM)) { + if (objectType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { return objectType; } @@ -1989,13 +1968,6 @@ Type *ETSChecker::MaybeBoxedType(const varbinder::Variable *var, ArenaAllocator void ETSChecker::CheckForSameSwitchCases(ArenaVector *cases) { - // Just to avoid extra nesting level - auto const checkEnumType = [this](ir::Expression const *const caseTest, ETSEnumType const *const type) -> void { - if (caseTest->TsType()->AsETSEnumType()->IsSameEnumLiteralType(type)) { - ThrowTypeError("Case duplicate", caseTest->Start()); - } - }; - for (size_t caseNum = 0; caseNum < cases->size(); caseNum++) { for (size_t compareCase = caseNum + 1; compareCase < cases->size(); compareCase++) { auto *caseTest = cases->at(caseNum)->Test(); @@ -2005,11 +1977,6 @@ void ETSChecker::CheckForSameSwitchCases(ArenaVector continue; } - if (caseTest->TsType()->IsETSEnumType()) { - checkEnumType(caseTest, compareCaseTest->TsType()->AsETSEnumType()); - continue; - } - if (caseTest->TsType()->IsETSEnum2Type()) { ASSERT(compareCaseTest->TsType()->IsETSEnum2Type()); if (caseTest->TsType()->AsETSEnum2Type()->IsSameEnumLiteralType( @@ -2442,16 +2409,6 @@ ETSObjectType *ETSChecker::GetOriginalBaseType(Type *const object) return object->AsETSObjectType()->GetOriginalBaseType(); } -void ETSChecker::CheckValidGenericTypeParameter(Type *const argType, const lexer::SourcePosition &pos) -{ - if (!argType->IsETSEnumType() && !argType->IsETSStringEnumType()) { - return; - } - std::stringstream ss; - argType->ToString(ss); - ThrowTypeError("Type '" + ss.str() + "' is not valid for generic type arguments", pos); -} - void ETSChecker::CheckNumberOfTypeArguments(ETSObjectType *const type, ir::TSTypeParameterInstantiation *const typeArgs, const lexer::SourcePosition &pos) { diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 8af3bdab5d..b22ee024e7 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -365,133 +365,6 @@ ETSObjectType *ETSChecker::CreateETSObjectType(util::StringView name, ir::AstNod return objType; } -ETSEnumType *ETSChecker::CreateETSEnumType(ir::TSEnumDeclaration const *const enumDecl) -{ - varbinder::Variable *enumVar = enumDecl->Key()->Variable(); - ASSERT(enumVar != nullptr); - - ETSEnumType::UType ordinal = -1; - auto *const enumType = Allocator()->New(enumDecl, ordinal++); - enumType->SetVariable(enumVar); - enumVar->SetTsType(enumType); - - for (auto *const member : enumType->GetMembers()) { - auto *const memberVar = member->AsTSEnumMember()->Key()->AsIdentifier()->Variable(); - auto *const enumLiteralType = Allocator()->New(enumDecl, ordinal++, member->AsTSEnumMember()); - enumLiteralType->SetVariable(memberVar); - memberVar->SetTsType(enumLiteralType); - } - - auto *const namesArrayIdent = CreateEnumNamesArray(enumType); - - auto *identClone = namesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(namesArrayIdent->TsType()); - auto const getNameMethod = CreateEnumGetNameMethod(identClone, enumType); - enumType->SetGetNameMethod(getNameMethod); - - identClone = namesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(namesArrayIdent->TsType()); - auto const valueOfMethod = CreateEnumValueOfMethod(identClone, enumType); - enumType->SetValueOfMethod(valueOfMethod); - - identClone = namesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(namesArrayIdent->TsType()); - auto const fromIntMethod = CreateEnumFromIntMethod(identClone, enumType); - enumType->SetFromIntMethod(fromIntMethod); - - auto *const valuesArrayIdent = CreateEnumValuesArray(enumType); - - identClone = valuesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(valuesArrayIdent->TsType()); - auto const getValueMethod = CreateEnumGetValueMethod(identClone, enumType); - enumType->SetGetValueMethod(getValueMethod); - - auto *const stringValuesArrayIdent = CreateEnumStringValuesArray(enumType); - - identClone = stringValuesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(stringValuesArrayIdent->TsType()); - auto const toStringMethod = CreateEnumToStringMethod(identClone, enumType); - enumType->SetToStringMethod(toStringMethod); - - auto *const itemsArrayIdent = CreateEnumItemsArray(enumType); - - identClone = itemsArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(itemsArrayIdent->TsType()); - auto const valuesMethod = CreateEnumValuesMethod(identClone, enumType); - enumType->SetValuesMethod(valuesMethod); - - for (auto *const member : enumType->GetMembers()) { - auto *const enumLiteralType = - member->AsTSEnumMember()->Key()->AsIdentifier()->Variable()->TsType()->AsETSEnumType(); - enumLiteralType->SetGetValueMethod(getValueMethod); - enumLiteralType->SetGetNameMethod(getNameMethod); - enumLiteralType->SetToStringMethod(toStringMethod); - } - - return enumType; -} - -ETSStringEnumType *ETSChecker::CreateETSStringEnumType(ir::TSEnumDeclaration const *const enumDecl) -{ - varbinder::Variable *enumVar = enumDecl->Key()->Variable(); - ASSERT(enumVar != nullptr); - - ETSEnumType::UType ordinal = -1; - auto *const enumType = Allocator()->New(enumDecl, ordinal++); - enumType->SetVariable(enumVar); - enumVar->SetTsType(enumType); - - for (auto *const member : enumType->GetMembers()) { - auto *const memberVar = member->AsTSEnumMember()->Key()->AsIdentifier()->Variable(); - auto *const enumLiteralType = - Allocator()->New(enumDecl, ordinal++, member->AsTSEnumMember()); - enumLiteralType->SetVariable(memberVar); - memberVar->SetTsType(enumLiteralType); - } - - auto *const namesArrayIdent = CreateEnumNamesArray(enumType); - - auto *identClone = namesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(namesArrayIdent->TsType()); - auto const getNameMethod = CreateEnumGetNameMethod(identClone, enumType); - enumType->SetGetNameMethod(getNameMethod); - - identClone = namesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(namesArrayIdent->TsType()); - auto const valueOfMethod = CreateEnumValueOfMethod(identClone, enumType); - enumType->SetValueOfMethod(valueOfMethod); - - identClone = namesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(namesArrayIdent->TsType()); - auto const fromIntMethod = CreateEnumFromIntMethod(identClone, enumType); - enumType->SetFromIntMethod(fromIntMethod); - - auto *const stringValuesArrayIdent = CreateEnumStringValuesArray(enumType); - - identClone = stringValuesArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(stringValuesArrayIdent->TsType()); - auto const toStringMethod = CreateEnumToStringMethod(identClone, enumType); - enumType->SetToStringMethod(toStringMethod); - enumType->SetGetValueMethod(toStringMethod); - - auto *const itemsArrayIdent = CreateEnumItemsArray(enumType); - - identClone = itemsArrayIdent->Clone(Allocator(), nullptr); - identClone->SetTsType(itemsArrayIdent->TsType()); - auto const valuesMethod = CreateEnumValuesMethod(identClone, enumType); - enumType->SetValuesMethod(valuesMethod); - - for (auto *const member : enumType->GetMembers()) { - auto *const enumLiteralType = - member->AsTSEnumMember()->Key()->AsIdentifier()->Variable()->TsType()->AsETSStringEnumType(); - enumLiteralType->SetGetValueMethod(toStringMethod); - enumLiteralType->SetGetNameMethod(getNameMethod); - enumLiteralType->SetToStringMethod(toStringMethod); - } - - return enumType; -} - bool isEnumClass(ir::AstNode *declNode) { if (declNode->IsClassDefinition() && (declNode->AsClassDefinition()->Super() != nullptr) && diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index f166041961..8a557c9254 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -77,7 +77,6 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType for (size_t idx = 0; idx < type->TypeArguments().size(); ++idx) { auto const [typeParam, typeArg] = getTypes(idx); - checker_->CheckValidGenericTypeParameter(typeArg, pos); typeArg->Substitute(checker_->Relation(), substitution); ETSChecker::EmplaceSubstituted(substitution, typeParam, typeArg); } diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index 10ffb0c18f..ff3f0e5477 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -177,7 +177,7 @@ bool ETSEnumInterface::IsSameEnumLiteralType(const ETSEnumInterface *const other return member_ == other->member_; } -[[maybe_unused]] static const ETSEnumInterface *SpecifyEnumInterface(const checker::Type *enumType) +[[maybe_unused]] static const ETSEnumInterface *SpecifyEnumInterface([[maybe_unused]] const checker::Type *enumType) { if (enumType->IsETSEnumType()) { return enumType->AsETSEnumType(); diff --git a/ets2panda/checker/types/ets/intType.cpp b/ets2panda/checker/types/ets/intType.cpp index 0d03ee3169..9613ed03a7 100644 --- a/ets2panda/checker/types/ets/intType.cpp +++ b/ets2panda/checker/types/ets/intType.cpp @@ -57,11 +57,6 @@ void IntType::Cast(TypeRelation *const relation, Type *const target) return; } - if (target->HasTypeFlag(TypeFlag::ETS_ENUM | TypeFlag::ETS_STRING_ENUM)) { - relation->Result(true); - return; - } - if (target->HasTypeFlag(TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR)) { conversion::NarrowingPrimitive(relation, this, target); return; diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index fe3e7cfa8b..3815b2604b 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -73,11 +73,11 @@ enum class TypeFlag : uint64_t { ETS_TYPE_PARAMETER = 1ULL << 48ULL, // ETS type parameter ETS_TYPE_REFERENCE = 1ULL << 49ULL, // ETS type reference GENERIC = 1ULL << 50ULL, // ETS Generic - ETS_ENUM = 1ULL << 51ULL, // ETS Enum - ETS_STRING_ENUM = 1ULL << 52ULL, // ETS string-type Enumeration - ETS_DYNAMIC_FLAG = 1ULL << 53ULL, // ETS Dynamic flag - GETTER = 1ULL << 54ULL, // ETS Getter - SETTER = 1ULL << 55ULL, // ETS Setter + // ETS_ENUM = 1ULL << 51ULL, // ETS Enum + // ETS_STRING_ENUM = 1ULL << 52ULL, // ETS string-type Enumeration + ETS_DYNAMIC_FLAG = 1ULL << 53ULL, // ETS Dynamic flag + GETTER = 1ULL << 54ULL, // ETS Getter + SETTER = 1ULL << 55ULL, // ETS Setter ETS_EXTENSION_FUNC_HELPER = 1ULL << 56ULL, // ETS Extension Function Helper ETS_UNION = 1ULL << 57ULL, // ETS union ETS_TUPLE = 1ULL << 58ULL, // ETS tuple type @@ -89,17 +89,17 @@ enum class TypeFlag : uint64_t { ETS_ENUM2_TYPE = ETS_OBJECT | ETS_ENUM2, // ETS Enum TODO(aber) rename ETS_DYNAMIC_FUNCTION_TYPE = FUNCTION | ETS_DYNAMIC_FLAG, ETS_TYPE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID | ETS_OBJECT | ETS_ARRAY | - WILDCARD | ETS_TYPE_PARAMETER | ETS_ENUM | ETS_STRING_ENUM | ETS_DYNAMIC_TYPE | ETS_UNION | ETS_NULL | - ETS_UNDEFINED | ETS_NONNULLISH | ETS_ENUM2_TYPE, + WILDCARD | ETS_TYPE_PARAMETER | ETS_DYNAMIC_TYPE | ETS_UNION | ETS_NULL | ETS_UNDEFINED | + ETS_NONNULLISH | ETS_ENUM2_TYPE, ETS_PRIMITIVE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID, - ETS_PRIMITIVE_RETURN = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_ENUM, + ETS_PRIMITIVE_RETURN = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN, ETS_ARRAY_INDEX = BYTE | SHORT | INT, ETS_INTEGRAL = BYTE | CHAR | SHORT | INT | LONG, ETS_FLOATING_POINT = FLOAT | DOUBLE, ETS_NUMERIC = ETS_INTEGRAL | FLOAT | DOUBLE, ETS_ARRAY_OR_OBJECT = ETS_ARRAY | ETS_OBJECT, ETS_WIDE_NUMERIC = LONG | DOUBLE, - VALID_SWITCH_TYPE = BYTE | SHORT | INT | CHAR | LONG | ETS_ENUM | ETS_STRING_ENUM, + VALID_SWITCH_TYPE = BYTE | SHORT | INT | CHAR | LONG, NARROWABLE_TO_FLOAT = DOUBLE, NARROWABLE_TO_LONG = FLOAT | NARROWABLE_TO_FLOAT, NARROWABLE_TO_INT = LONG | NARROWABLE_TO_LONG, @@ -135,7 +135,7 @@ enum class TypeFlag : uint64_t { UNIT = LITERAL | UNIQUE_SYMBOL | UNDEFINED | NULL_TYPE, GETTER_SETTER = GETTER | SETTER, CONDITION_EXPRESSION_TYPE = ETS_NULL | ETS_UNDEFINED | ETS_OBJECT | ETS_ARRAY | ETS_UNION | CONSTANT | BYTE | CHAR | - SHORT | INT | LONG | FLOAT | DOUBLE | ETS_BOOLEAN | ETS_ENUM | ETS_STRING_ENUM + SHORT | INT | LONG | FLOAT | DOUBLE | ETS_BOOLEAN }; DEFINE_BITOPS(TypeFlag) diff --git a/ets2panda/checker/types/typeMapping.h b/ets2panda/checker/types/typeMapping.h index 1b7fedc04a..6d0911badf 100644 --- a/ets2panda/checker/types/typeMapping.h +++ b/ets2panda/checker/types/typeMapping.h @@ -60,8 +60,6 @@ _(TypeFlag::WILDCARD, WildcardType) \ _(TypeFlag::ETS_TYPE_PARAMETER, ETSTypeParameter) \ _(TypeFlag::ETS_NONNULLISH, ETSNonNullishType) \ - _(TypeFlag::ETS_ENUM, ETSEnumType) \ - _(TypeFlag::ETS_STRING_ENUM, ETSStringEnumType) \ _(TypeFlag::ETS_EXTENSION_FUNC_HELPER, ETSExtensionFuncHelperType) \ _(TypeFlag::ETS_TUPLE, ETSTupleType) diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 75069c7119..d974d1efe8 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -764,12 +764,13 @@ bool ETSCompiler::IsSucceedCompilationProxyMemberExpr(const ir::CallExpression * ETSGen *etsg = GetETSGen(); auto *const calleeObject = expr->callee_->AsMemberExpression()->Object(); auto const *const enumInterface = [calleeType = calleeObject->TsType()]() -> checker::ETSEnumInterface const * { - if (calleeType->IsETSEnumType()) { - return calleeType->AsETSEnumType(); - } - if (calleeType->IsETSStringEnumType()) { - return calleeType->AsETSStringEnumType(); - } + (void)calleeType; + // if (calleeType->IsETSEnumType()) { + // return calleeType->AsETSEnumType(); + // } + // if (calleeType->IsETSStringEnumType()) { + // return calleeType->AsETSStringEnumType(); + // } return nullptr; }(); @@ -1088,19 +1089,6 @@ void ETSCompiler::Compile(const ir::MemberExpression *expr) const return; } - if (objectType->IsETSEnumType() || objectType->IsETSStringEnumType()) { - auto const *const enumInterface = [objectType, expr]() -> checker::ETSEnumInterface const * { - if (objectType->IsETSEnumType()) { - return expr->TsType()->AsETSEnumType(); - } - return expr->TsType()->AsETSStringEnumType(); - }(); - - auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); - etsg->LoadAccumulatorInt(expr, enumInterface->GetOrdinal()); - return; - } - if (etsg->Checker()->IsVariableStatic(expr->PropVar())) { auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); @@ -2057,18 +2045,18 @@ void ETSCompiler::CompileCast(const ir::TSAsExpression *expr) const etsg->CastToDynamic(expr, targetType->AsETSDynamicType()); break; } - case checker::TypeFlag::ETS_STRING_ENUM: - [[fallthrough]]; - case checker::TypeFlag::ETS_ENUM: { - auto *const signature = expr->TsType()->IsETSEnumType() - ? expr->TsType()->AsETSEnumType()->FromIntMethod().globalSignature - : expr->TsType()->AsETSStringEnumType()->FromIntMethod().globalSignature; - ArenaVector arguments(etsg->Allocator()->Adapter()); - arguments.push_back(expr->expression_); - etsg->CallStatic(expr, signature, arguments); - etsg->SetAccumulatorType(signature->ReturnType()); - break; - } + // case checker::TypeFlag::ETS_STRING_ENUM: + // [[fallthrough]]; + // case checker::TypeFlag::ETS_ENUM: { + // auto *const signature = expr->TsType()->IsETSEnumType() + // ? expr->TsType()->AsETSEnumType()->FromIntMethod().globalSignature + // : expr->TsType()->AsETSStringEnumType()->FromIntMethod().globalSignature; + // ArenaVector arguments(etsg->Allocator()->Adapter()); + // arguments.push_back(expr->expression_); + // etsg->CallStatic(expr, signature, arguments); + // etsg->SetAccumulatorType(signature->ReturnType()); + // break; + // } default: { UNREACHABLE(); } diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 96d8853d54..2b0f243432 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -1102,12 +1102,12 @@ void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *targe { auto ttctx = TargetTypeContext(this, targetType); - if (node->HasAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE)) { - Ra().Emit( - node, node->AsExpression()->TsType()->AsETSEnumType()->GetValueMethod().globalSignature->InternalName(), - dummyReg_, 0); - node->RemoveAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); - } + // if (node->HasAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE)) { + // Ra().Emit( + // node, node->AsExpression()->TsType()->AsETSEnumType()->GetValueMethod().globalSignature->InternalName(), + // dummyReg_, 0); + // node->RemoveAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); + // } if ((node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::BOXING_FLAG) != 0U) { ApplyBoxingConversion(node); @@ -1702,8 +1702,8 @@ void ETSGen::CastToInt(const ir::AstNode *node) } case checker::TypeFlag::ETS_BOOLEAN: case checker::TypeFlag::CHAR: - case checker::TypeFlag::ETS_ENUM: - case checker::TypeFlag::ETS_STRING_ENUM: + // case checker::TypeFlag::ETS_ENUM: + // case checker::TypeFlag::ETS_STRING_ENUM: case checker::TypeFlag::BYTE: case checker::TypeFlag::SHORT: { break; @@ -2572,9 +2572,9 @@ void ETSGen::LoadArrayElement(const ir::AstNode *node, VReg objectReg) Ra().Emit(node, objectReg); break; } - case checker::TypeFlag::ETS_STRING_ENUM: - [[fallthrough]]; - case checker::TypeFlag::ETS_ENUM: + // case checker::TypeFlag::ETS_STRING_ENUM: + // [[fallthrough]]; + // case checker::TypeFlag::ETS_ENUM: case checker::TypeFlag::INT: { Ra().Emit(node, objectReg); break; @@ -2626,9 +2626,9 @@ void ETSGen::StoreArrayElement(const ir::AstNode *node, VReg objectReg, VReg ind Ra().Emit(node, objectReg, index); break; } - case checker::TypeFlag::ETS_STRING_ENUM: - [[fallthrough]]; - case checker::TypeFlag::ETS_ENUM: + // case checker::TypeFlag::ETS_STRING_ENUM: + // [[fallthrough]]; + // case checker::TypeFlag::ETS_ENUM: case checker::TypeFlag::INT: { Ra().Emit(node, objectReg, index); break; diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 8605cd7fb7..6fb5c7369e 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -743,8 +743,8 @@ private: BinaryNumberComparison(node, lhs, ifFalse); break; } - case checker::TypeFlag::ETS_ENUM: - case checker::TypeFlag::ETS_STRING_ENUM: + // case checker::TypeFlag::ETS_ENUM: + // case checker::TypeFlag::ETS_STRING_ENUM: case checker::TypeFlag::ETS_ENUM2_TYPE: case checker::TypeFlag::ETS_BOOLEAN: case checker::TypeFlag::BYTE: @@ -1150,13 +1150,13 @@ void ETSGen::LoadAccumulatorNumber(const ir::AstNode *node, T number, checker::T SetAccumulatorType(Checker()->GlobalDoubleType()); break; } - case checker::TypeFlag::ETS_STRING_ENUM: - [[fallthrough]]; - case checker::TypeFlag::ETS_ENUM: { - Sa().Emit(node, static_cast(number)); - SetAccumulatorType(Checker()->GlobalIntType()); - break; - } + // case checker::TypeFlag::ETS_STRING_ENUM: + // [[fallthrough]]; + // case checker::TypeFlag::ETS_ENUM: { + // Sa().Emit(node, static_cast(number)); + // SetAccumulatorType(Checker()->GlobalIntType()); + // break; + // } default: { UNREACHABLE(); } diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index c0dfac62c9..d60aed26f5 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -95,6 +95,7 @@ std::vector GetETSPhaseList() &g_interfacePropDeclPhase, &g_checkerPhase, &g_pluginsAfterCheck, + &g_enumLoweringPostPhase, &g_generateTsDeclarationsPhase, &g_opAssignmentLowering, &g_recordLowering, @@ -103,7 +104,6 @@ std::vector GetETSPhaseList() &g_tupleLowering, &g_unionLowering, &g_expandBracketsPhase, - &g_enumLoweringPostPhase, &g_pluginsAfterLowerings, }; } diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index c32f3083d0..32b867522d 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -139,22 +139,23 @@ checker::Type *MemberExpression::Check(checker::TSChecker *checker) return checker->GetAnalyzer()->Check(this); } -std::pair MemberExpression::ResolveEnumMember(checker::ETSChecker *checker, - checker::Type *type) const +std::pair MemberExpression::ResolveEnumMember( + [[maybe_unused]] checker::ETSChecker *checker, [[maybe_unused]] checker::Type *type) const { - auto const *const enumInterface = [type]() -> checker::ETSEnumInterface const * { - if (type->IsETSEnumType()) { - return type->AsETSEnumType(); - } - return type->AsETSStringEnumType(); - }(); - - if (parent_->Type() == ir::AstNodeType::CALL_EXPRESSION && parent_->AsCallExpression()->Callee() == this) { - return {enumInterface->LookupMethod(checker, object_, property_->AsIdentifier()), nullptr}; - } - - auto *const literalType = enumInterface->LookupConstant(checker, object_, property_->AsIdentifier()); - return {literalType, literalType->GetMemberVar()}; + // auto const *const enumInterface = [type]() -> checker::ETSEnumInterface const * { + // if (type->IsETSEnumType()) { + // return type->AsETSEnumType(); + // } + // return type->AsETSStringEnumType(); + // }(); + + // if (parent_->Type() == ir::AstNodeType::CALL_EXPRESSION && parent_->AsCallExpression()->Callee() == this) { + // return {enumInterface->LookupMethod(checker, object_, property_->AsIdentifier()), nullptr}; + // } + // + // auto *const literalType = enumInterface->LookupConstant(checker, object_, property_->AsIdentifier()); + // return {literalType, literalType->GetMemberVar()}; + return {nullptr, nullptr}; } std::pair MemberExpression::ResolveObjectMember( @@ -198,8 +199,8 @@ checker::Type *MemberExpression::TraverseUnionMember(checker::ETSChecker *checke if (apparent->IsETSObjectType()) { SetObjectType(apparent->AsETSObjectType()); addPropType(ResolveObjectMember(checker).first); - } else if (apparent->IsETSEnumType() || apparent->IsETSStringEnumType()) { - addPropType(ResolveEnumMember(checker, apparent).first); + // } else if (apparent->IsETSEnumType() || apparent->IsETSStringEnumType()) { + // addPropType(ResolveEnumMember(checker, apparent).first); } else { checker->ThrowTypeError({"Type ", unionType, " is illegal in union member expression."}, Start()); } -- Gitee From 95fe735b002bca1a0ea74ca7053e291bea6e6fb7 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Sat, 24 Feb 2024 09:13:05 +0300 Subject: [PATCH 30/48] declgen issue playground Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/types/ets/etsEnumType.cpp | 72 +++++++++++---------- ets2panda/checker/types/ets/etsEnumType.h | 4 +- ets2panda/util/declgenEts2Ts.cpp | 47 +------------- ets2panda/util/declgenEts2Ts.h | 2 - 4 files changed, 43 insertions(+), 82 deletions(-) diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index ff3f0e5477..b66bd5f098 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -29,21 +29,25 @@ ETSEnumInterface::ETSEnumInterface(const ir::TSEnumDeclaration *const enumDecl, { } -bool ETSEnumInterface::AssignmentSource(TypeRelation *const relation, Type *const target) -{ - auto const result = target->IsETSEnumType() - ? IsSameEnumType(target->AsETSEnumType()) - : (target->IsETSStringEnumType() ? IsSameEnumType(target->AsETSStringEnumType()) : false); - relation->Result(result); +bool ETSEnumInterface::AssignmentSource(TypeRelation *const relation, [[maybe_unused]] Type *const target) +{ + // auto const result = target->IsETSEnumType() + // ? IsSameEnumType(target->AsETSEnumType()) + // : (target->IsETSStringEnumType() ? IsSameEnumType(target->AsETSStringEnumType()) : + // false); + // relation->Result(result); + relation->Result(false); return relation->IsTrue(); } -void ETSEnumInterface::AssignmentTarget(TypeRelation *const relation, Type *const source) +void ETSEnumInterface::AssignmentTarget(TypeRelation *const relation, [[maybe_unused]] Type *const source) { - auto const result = source->IsETSEnumType() - ? IsSameEnumType(source->AsETSEnumType()) - : (source->IsETSStringEnumType() ? IsSameEnumType(source->AsETSStringEnumType()) : false); - relation->Result(result); + // auto const result = source->IsETSEnumType() + // ? IsSameEnumType(source->AsETSEnumType()) + // : (source->IsETSStringEnumType() ? IsSameEnumType(source->AsETSStringEnumType()) : + // false); + // relation->Result(result); + relation->Result(false); } void ETSEnumInterface::Cast(TypeRelation *relation, Type *target) @@ -70,12 +74,13 @@ Type *ETSEnumInterface::Instantiate([[maybe_unused]] ArenaAllocator *allocator, void ETSEnumInterface::Identical(TypeRelation *const relation, Type *const other) { ETSEnumInterface const *const otherEnumType = [other]() -> ETSEnumInterface const * { - if (other->IsETSEnumType()) { - return other->AsETSEnumType(); - } - if (other->IsETSStringEnumType()) { - return other->AsETSStringEnumType(); - } + (void)other; + // if (other->IsETSEnumType()) { + // return other->AsETSEnumType(); + // } + // if (other->IsETSStringEnumType()) { + // return other->AsETSStringEnumType(); + // } return nullptr; }(); @@ -143,16 +148,17 @@ ETSEnumInterface *ETSEnumInterface::LookupConstant(ETSChecker *const checker, co checker->ThrowTypeError({"No enum constant named '", prop->Name(), "' in enum '", this, "'"}, prop->Start()); } - auto *const enumInterface = - [enumType = member->Key()->AsIdentifier()->Variable()->TsType()]() -> checker::ETSEnumInterface * { - if (enumType->IsETSEnumType()) { - return enumType->AsETSEnumType(); - } - return enumType->AsETSStringEnumType(); - }(); - - ASSERT(enumInterface->IsLiteralType()); - return enumInterface; + // auto *const enumInterface = + // [enumType = member->Key()->AsIdentifier()->Variable()->TsType()]() -> checker::ETSEnumInterface * { + // if (enumType->IsETSEnumType()) { + // return enumType->AsETSEnumType(); + // } + // return enumType->AsETSStringEnumType(); + // }(); + // + // ASSERT(enumInterface->IsLiteralType()); + // return enumInterface; + return nullptr; } ETSFunctionType *ETSEnumInterface::LookupMethod(ETSChecker *checker, const ir::Expression *const expression, @@ -179,12 +185,12 @@ bool ETSEnumInterface::IsSameEnumLiteralType(const ETSEnumInterface *const other [[maybe_unused]] static const ETSEnumInterface *SpecifyEnumInterface([[maybe_unused]] const checker::Type *enumType) { - if (enumType->IsETSEnumType()) { - return enumType->AsETSEnumType(); - } - if (enumType->IsETSStringEnumType()) { - return enumType->AsETSStringEnumType(); - } + // if (enumType->IsETSEnumType()) { + // return enumType->AsETSEnumType(); + // } + // if (enumType->IsETSStringEnumType()) { + // return enumType->AsETSStringEnumType(); + // } return nullptr; } diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index 1e67220dee..37a2813fd7 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -190,7 +190,7 @@ private: class ETSEnumType : public ETSEnumInterface, public ETSEnumValueType { public: explicit ETSEnumType(const ir::TSEnumDeclaration *enumDecl, UType ordinal, const ir::TSEnumMember *member = nullptr) - : ETSEnumInterface(enumDecl, ordinal, member, TypeFlag::ETS_ENUM) + : ETSEnumInterface(enumDecl, ordinal, member, TypeFlag::ETS_ENUM2_TYPE) { } @@ -205,7 +205,7 @@ class ETSStringEnumType : public ETSEnumInterface, public ETSEnumValueTypeIsETSImportDeclaration()) { GenImportDeclaration(globalStatement->AsETSImportDeclaration()); - } else if (globalStatement->IsTSEnumDeclaration()) { - GenEnumDeclaration(globalStatement->AsTSEnumDeclaration()); } else if (globalStatement->IsClassDeclaration()) { GenClassDeclaration(globalStatement->AsClassDeclaration()); } else if (globalStatement->IsTSInterfaceDeclaration()) { @@ -154,8 +151,8 @@ void TSDeclGen::GenType(const checker::Type *checkerType) case checker::TypeFlag::ETS_NONNULLISH: Out(checkerType->ToString()); return; - case checker::TypeFlag::ETS_ENUM: - GenEnumType(checkerType->AsETSEnumType()); + case checker::TypeFlag::ETS_ENUM2_TYPE: + // GenEnumType(checkerType->AsETSEnumType()); return; case checker::TypeFlag::ETS_OBJECT: case checker::TypeFlag::ETS_DYNAMIC_TYPE: @@ -257,32 +254,6 @@ void TSDeclGen::GenFunctionType(const checker::ETSFunctionType *etsFunctionType, } } -void TSDeclGen::GenEnumType(const checker::ETSEnumType *enumType) -{ - for (auto *member : enumType->GetMembers()) { - Out(INDENT); - if (!member->IsTSEnumMember()) { - ThrowError("Member of enum not of type TSEnumMember", member->Start()); - } - - const auto *enumMember = member->AsTSEnumMember(); - Out(GetKeyName(enumMember->Key())); - const auto *init = enumMember->Init(); - if (init != nullptr) { - Out(" = "); - - if (!init->IsLiteral()) { - ThrowError("Only literal enum initializers are supported", member->Start()); - } - - GenLiteral(init->AsLiteral()); - } - - Out(","); - OutEndl(); - } -} - void TSDeclGen::GenUnionType(const checker::ETSUnionType *unionType) { for (auto *ctype : unionType->ConstituentTypes()) { @@ -410,20 +381,6 @@ void TSDeclGen::GenTypeAliasDeclaration(const ir::TSTypeAliasDeclaration *typeAl OutEndl(2U); } -void TSDeclGen::GenEnumDeclaration(const ir::TSEnumDeclaration *enumDecl) -{ - const auto enumName = GetKeyName(enumDecl->Key()); - DebugPrint("GenEnumDeclaration: " + enumName); - Out("export enum ", enumName, " {"); - OutEndl(); - - ASSERT(enumDecl->TsType()->IsETSEnumType()); - GenEnumType(enumDecl->TsType()->AsETSEnumType()); - - Out("}"); - OutEndl(2U); -} - void TSDeclGen::GenInterfaceDeclaration(const ir::TSInterfaceDeclaration *interfaceDecl) { state_.inInterface = true; diff --git a/ets2panda/util/declgenEts2Ts.h b/ets2panda/util/declgenEts2Ts.h index 238a133fe8..96f341953d 100644 --- a/ets2panda/util/declgenEts2Ts.h +++ b/ets2panda/util/declgenEts2Ts.h @@ -49,12 +49,10 @@ private: void GenType(const checker::Type *checkerType); void GenFunctionType(const checker::ETSFunctionType *functionType, const ir::MethodDefinition *methodDef = nullptr); void GenObjectType(const checker::ETSObjectType *objectType); - void GenEnumType(const checker::ETSEnumType *enumType); void GenUnionType(const checker::ETSUnionType *unionType); void GenImportDeclaration(const ir::ETSImportDeclaration *importDeclaration); void GenTypeAliasDeclaration(const ir::TSTypeAliasDeclaration *typeAlias); - void GenEnumDeclaration(const ir::TSEnumDeclaration *enumDecl); void GenInterfaceDeclaration(const ir::TSInterfaceDeclaration *interfaceDecl); void GenClassDeclaration(const ir::ClassDeclaration *classDecl); void GenMethodDeclaration(const ir::MethodDefinition *methodDef); -- Gitee From 5169590ee2e2d0f3f8f91700e1140571a395e9ee Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Sat, 24 Feb 2024 09:53:00 +0300 Subject: [PATCH 31/48] project-wide: remove former enum implementation code Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/types/ets/etsEnumType.cpp | 8 +-- ets2panda/checker/types/typeFlag.h | 22 +++--- ets2panda/compiler/core/ETSCompiler.cpp | 70 ------------------- ets2panda/compiler/core/ETSCompiler.h | 1 - ets2panda/compiler/core/ETSGen.cpp | 15 ---- ets2panda/compiler/core/ETSGen.h | 9 --- ets2panda/ir/expressions/memberExpression.cpp | 21 ------ ets2panda/ir/expressions/memberExpression.h | 2 - 8 files changed, 14 insertions(+), 134 deletions(-) diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index b66bd5f098..ebe2d5c124 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -52,10 +52,10 @@ void ETSEnumInterface::AssignmentTarget(TypeRelation *const relation, [[maybe_un void ETSEnumInterface::Cast(TypeRelation *relation, Type *target) { - if (target->HasTypeFlag(TypeFlag::ENUM | TypeFlag::ETS_ENUM | TypeFlag::ETS_STRING_ENUM)) { - conversion::Identity(relation, this, target); - return; - } + // if (target->HasTypeFlag(TypeFlag::ENUM | TypeFlag::ETS_ENUM | TypeFlag::ETS_STRING_ENUM)) { + // conversion::Identity(relation, this, target); + // return; + // } if (target->IsIntType()) { relation->Result(true); diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index 3815b2604b..7994f06d40 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -73,18 +73,16 @@ enum class TypeFlag : uint64_t { ETS_TYPE_PARAMETER = 1ULL << 48ULL, // ETS type parameter ETS_TYPE_REFERENCE = 1ULL << 49ULL, // ETS type reference GENERIC = 1ULL << 50ULL, // ETS Generic - // ETS_ENUM = 1ULL << 51ULL, // ETS Enum - // ETS_STRING_ENUM = 1ULL << 52ULL, // ETS string-type Enumeration - ETS_DYNAMIC_FLAG = 1ULL << 53ULL, // ETS Dynamic flag - GETTER = 1ULL << 54ULL, // ETS Getter - SETTER = 1ULL << 55ULL, // ETS Setter - ETS_EXTENSION_FUNC_HELPER = 1ULL << 56ULL, // ETS Extension Function Helper - ETS_UNION = 1ULL << 57ULL, // ETS union - ETS_TUPLE = 1ULL << 58ULL, // ETS tuple type - ETS_NULL = 1ULL << 59ULL, // ETS null - ETS_UNDEFINED = 1ULL << 60ULL, // ETS undefined - ETS_NONNULLISH = 1ULL << 61ULL, // ETS nonnullish type parameter - ETS_ENUM2 = 1ULL << 62ULL, // ETS Enum TODO(aber) rename after removal old + ETS_DYNAMIC_FLAG = 1ULL << 51ULL, // ETS Dynamic flag + GETTER = 1ULL << 52ULL, // ETS Getter + SETTER = 1ULL << 53ULL, // ETS Setter + ETS_EXTENSION_FUNC_HELPER = 1ULL << 54ULL, // ETS Extension Function Helper + ETS_UNION = 1ULL << 55ULL, // ETS union + ETS_TUPLE = 1ULL << 56ULL, // ETS tuple type + ETS_NULL = 1ULL << 57ULL, // ETS null + ETS_UNDEFINED = 1ULL << 58ULL, // ETS undefined + ETS_NONNULLISH = 1ULL << 59ULL, // ETS nonnullish type parameter + ETS_ENUM2 = 1ULL << 60ULL, // ETS Enum TODO(aber) rename after removal old ETS_DYNAMIC_TYPE = ETS_OBJECT | ETS_DYNAMIC_FLAG, ETS_ENUM2_TYPE = ETS_OBJECT | ETS_ENUM2, // ETS Enum TODO(aber) rename ETS_DYNAMIC_FUNCTION_TYPE = FUNCTION | ETS_DYNAMIC_FLAG, diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index d974d1efe8..8a18432b7d 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -759,57 +759,6 @@ void ETSCompiler::Compile(const ir::BlockExpression *expr) const UNREACHABLE(); } -bool ETSCompiler::IsSucceedCompilationProxyMemberExpr(const ir::CallExpression *expr) const -{ - ETSGen *etsg = GetETSGen(); - auto *const calleeObject = expr->callee_->AsMemberExpression()->Object(); - auto const *const enumInterface = [calleeType = calleeObject->TsType()]() -> checker::ETSEnumInterface const * { - (void)calleeType; - // if (calleeType->IsETSEnumType()) { - // return calleeType->AsETSEnumType(); - // } - // if (calleeType->IsETSStringEnumType()) { - // return calleeType->AsETSStringEnumType(); - // } - return nullptr; - }(); - - if (enumInterface != nullptr) { - ArenaVector arguments(etsg->Allocator()->Adapter()); - - checker::Signature *const signature = [expr, calleeObject, enumInterface, &arguments]() { - const auto &memberProxyMethodName = expr->Signature()->InternalName(); - - if (memberProxyMethodName == checker::ETSEnumType::TO_STRING_METHOD_NAME) { - arguments.push_back(calleeObject); - return enumInterface->ToStringMethod().globalSignature; - } - if (memberProxyMethodName == checker::ETSEnumType::GET_VALUE_METHOD_NAME) { - arguments.push_back(calleeObject); - return enumInterface->GetValueMethod().globalSignature; - } - if (memberProxyMethodName == checker::ETSEnumType::GET_NAME_METHOD_NAME) { - arguments.push_back(calleeObject); - return enumInterface->GetNameMethod().globalSignature; - } - if (memberProxyMethodName == checker::ETSEnumType::VALUES_METHOD_NAME) { - return enumInterface->ValuesMethod().globalSignature; - } - if (memberProxyMethodName == checker::ETSEnumType::VALUE_OF_METHOD_NAME) { - arguments.push_back(expr->Arguments().front()); - return enumInterface->ValueOfMethod().globalSignature; - } - UNREACHABLE(); - }(); - - ASSERT(signature->ReturnType() == expr->Signature()->ReturnType()); - etsg->CallStatic(expr, signature, arguments); - etsg->SetAccumulatorType(expr->TsType()); - } - - return enumInterface != nullptr; -} - void ETSCompiler::CompileDynamic(const ir::CallExpression *expr, compiler::VReg &calleeReg) const { ETSGen *etsg = GetETSGen(); @@ -917,13 +866,6 @@ 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()) { - if (IsSucceedCompilationProxyMemberExpr(expr)) { - return; - } - } - bool isStatic = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); bool isReference = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE); bool isDynamic = expr->Callee()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_DYNAMIC_FLAG); @@ -2045,18 +1987,6 @@ void ETSCompiler::CompileCast(const ir::TSAsExpression *expr) const etsg->CastToDynamic(expr, targetType->AsETSDynamicType()); break; } - // case checker::TypeFlag::ETS_STRING_ENUM: - // [[fallthrough]]; - // case checker::TypeFlag::ETS_ENUM: { - // auto *const signature = expr->TsType()->IsETSEnumType() - // ? expr->TsType()->AsETSEnumType()->FromIntMethod().globalSignature - // : expr->TsType()->AsETSStringEnumType()->FromIntMethod().globalSignature; - // ArenaVector arguments(etsg->Allocator()->Adapter()); - // arguments.push_back(expr->expression_); - // etsg->CallStatic(expr, signature, arguments); - // etsg->SetAccumulatorType(signature->ReturnType()); - // break; - // } default: { UNREACHABLE(); } diff --git a/ets2panda/compiler/core/ETSCompiler.h b/ets2panda/compiler/core/ETSCompiler.h index 2074e90a13..9abea22231 100644 --- a/ets2panda/compiler/core/ETSCompiler.h +++ b/ets2panda/compiler/core/ETSCompiler.h @@ -34,7 +34,6 @@ public: #undef DECLARE_ETSCOMPILER_COMPILE_METHOD private: - bool IsSucceedCompilationProxyMemberExpr(const ir::CallExpression *expr) const; void CompileDynamic(const ir::CallExpression *expr, compiler::VReg &calleeReg) const; void CompileCastUnboxable(const ir::TSAsExpression *expr) const; void CompileCast(const ir::TSAsExpression *expr) const; diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 2b0f243432..2a9d594b3d 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -1102,13 +1102,6 @@ void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *targe { auto ttctx = TargetTypeContext(this, targetType); - // if (node->HasAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE)) { - // Ra().Emit( - // node, node->AsExpression()->TsType()->AsETSEnumType()->GetValueMethod().globalSignature->InternalName(), - // dummyReg_, 0); - // node->RemoveAstNodeFlags(ir::AstNodeFlags::ENUM_GET_VALUE); - // } - if ((node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::BOXING_FLAG) != 0U) { ApplyBoxingConversion(node); return; @@ -1702,8 +1695,6 @@ void ETSGen::CastToInt(const ir::AstNode *node) } case checker::TypeFlag::ETS_BOOLEAN: case checker::TypeFlag::CHAR: - // case checker::TypeFlag::ETS_ENUM: - // case checker::TypeFlag::ETS_STRING_ENUM: case checker::TypeFlag::BYTE: case checker::TypeFlag::SHORT: { break; @@ -2572,9 +2563,6 @@ void ETSGen::LoadArrayElement(const ir::AstNode *node, VReg objectReg) Ra().Emit(node, objectReg); break; } - // case checker::TypeFlag::ETS_STRING_ENUM: - // [[fallthrough]]; - // case checker::TypeFlag::ETS_ENUM: case checker::TypeFlag::INT: { Ra().Emit(node, objectReg); break; @@ -2626,9 +2614,6 @@ void ETSGen::StoreArrayElement(const ir::AstNode *node, VReg objectReg, VReg ind Ra().Emit(node, objectReg, index); break; } - // case checker::TypeFlag::ETS_STRING_ENUM: - // [[fallthrough]]; - // case checker::TypeFlag::ETS_ENUM: case checker::TypeFlag::INT: { Ra().Emit(node, objectReg, index); break; diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 6fb5c7369e..13d0768d12 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -743,8 +743,6 @@ private: BinaryNumberComparison(node, lhs, ifFalse); break; } - // case checker::TypeFlag::ETS_ENUM: - // case checker::TypeFlag::ETS_STRING_ENUM: case checker::TypeFlag::ETS_ENUM2_TYPE: case checker::TypeFlag::ETS_BOOLEAN: case checker::TypeFlag::BYTE: @@ -1150,13 +1148,6 @@ void ETSGen::LoadAccumulatorNumber(const ir::AstNode *node, T number, checker::T SetAccumulatorType(Checker()->GlobalDoubleType()); break; } - // case checker::TypeFlag::ETS_STRING_ENUM: - // [[fallthrough]]; - // case checker::TypeFlag::ETS_ENUM: { - // Sa().Emit(node, static_cast(number)); - // SetAccumulatorType(Checker()->GlobalIntType()); - // break; - // } default: { UNREACHABLE(); } diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 32b867522d..986588bcc4 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -139,25 +139,6 @@ checker::Type *MemberExpression::Check(checker::TSChecker *checker) return checker->GetAnalyzer()->Check(this); } -std::pair MemberExpression::ResolveEnumMember( - [[maybe_unused]] checker::ETSChecker *checker, [[maybe_unused]] checker::Type *type) const -{ - // auto const *const enumInterface = [type]() -> checker::ETSEnumInterface const * { - // if (type->IsETSEnumType()) { - // return type->AsETSEnumType(); - // } - // return type->AsETSStringEnumType(); - // }(); - - // if (parent_->Type() == ir::AstNodeType::CALL_EXPRESSION && parent_->AsCallExpression()->Callee() == this) { - // return {enumInterface->LookupMethod(checker, object_, property_->AsIdentifier()), nullptr}; - // } - // - // auto *const literalType = enumInterface->LookupConstant(checker, object_, property_->AsIdentifier()); - // return {literalType, literalType->GetMemberVar()}; - return {nullptr, nullptr}; -} - std::pair MemberExpression::ResolveObjectMember( checker::ETSChecker *checker) const { @@ -199,8 +180,6 @@ checker::Type *MemberExpression::TraverseUnionMember(checker::ETSChecker *checke if (apparent->IsETSObjectType()) { SetObjectType(apparent->AsETSObjectType()); addPropType(ResolveObjectMember(checker).first); - // } else if (apparent->IsETSEnumType() || apparent->IsETSStringEnumType()) { - // addPropType(ResolveEnumMember(checker, apparent).first); } else { checker->ThrowTypeError({"Type ", unionType, " is illegal in union member expression."}, Start()); } diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 9d5da48de7..caf819d34b 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -199,8 +199,6 @@ protected: } private: - std::pair ResolveEnumMember(checker::ETSChecker *checker, - checker::Type *type) const; std::pair ResolveObjectMember(checker::ETSChecker *checker) const; checker::Type *AdjustType(checker::ETSChecker *checker, checker::Type *type); -- Gitee From 5fa08f839edd4280f67b53f054ccef1a129749d4 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Sat, 24 Feb 2024 10:58:28 +0300 Subject: [PATCH 32/48] re-test/check cast from Enum class to int (should it be ordinal value?) Signed-off-by: Vadim Lomovtsev --- ets2panda/test/runtime/ets/Enum3.ets | 15 ++------- ets2panda/test/runtime/ets/Enum4.ets | 47 +++++++++------------------- ets2panda/test/runtime/ets/Enum5.ets | 34 +++++--------------- 3 files changed, 25 insertions(+), 71 deletions(-) diff --git a/ets2panda/test/runtime/ets/Enum3.ets b/ets2panda/test/runtime/ets/Enum3.ets index 0eca0c7e14..34582f07c1 100644 --- a/ets2panda/test/runtime/ets/Enum3.ets +++ b/ets2panda/test/runtime/ets/Enum3.ets @@ -48,17 +48,8 @@ function main(): void { } catch (e) {} let one: int = 1; - let green = one as Color; - assert green == Color.Green; + let green : Color = Color.Green; + assert green as int == one; - try { - let x = 5 as Color; - assert false; - } catch (e: Exception) { - assert (e as Object).toString().startsWith("No enum constant in Color with ordinal value 5"); - } - - assert 2 as Color as int == 2; - assert Color.Blue as int as Color == Color.Blue; - assert (Color.Red as int + 1) as Color == (Color.Blue as int - 1) as Color; + assert (Color.Red as int + 1) == (Color.Blue as int - 1); } diff --git a/ets2panda/test/runtime/ets/Enum4.ets b/ets2panda/test/runtime/ets/Enum4.ets index 861bb43cd3..670173ce6f 100644 --- a/ets2panda/test/runtime/ets/Enum4.ets +++ b/ets2panda/test/runtime/ets/Enum4.ets @@ -43,24 +43,25 @@ function main(): void { assert values[2] == Color.Blue; let red1: Color = Color.Red; - let red2: Color; - assert(red2 as int == 0) - assert(red2.getValue() == 0) - assert(red2.getName() == "Green") - assert(red2.toString() == "0") + let red2: Color = red1; + assert(red2 as int == 1) + assert(red2.getValue() == 2) + assert(red2.getName() == "Red") + assert(red2.toString() == "2") //cons.print("\nDefault ordinal = " + red2 as int + ", value = " + red2.getValue() + ", name: '" + red2.getName() + "', ToString: '" + red2.toString() + "'\n\n") try { red2 = Color.valueOf("Red"); + assert red2 == Color.Red } catch (e) { assert (e as Object).toString().startsWith("No enum constant Color.Red"); //cons.print(e.toString() + "\n"); } - //cons.print( "GetName: Color.Red: '" + Color.Red.getName() + "', = Red: '" + red1.getName() + "', ValueOf(Red): '" + red2.getName() + "'\n") - //cons.print( "GetValue: Color.Red = " + Color.Red.getValue() + ", = Red = " + red1.getValue() + ", ValueOf(Red) = " + red2.getValue() + "\n") - //cons.print( "Ordinal (as int): Color.Red = " + Color.Red as int + ", = Red = " + red1 as int + ", ValueOf(Red) = " + red2 as int + "\n") - //cons.print( "ToString: Color.Red = '" + Color.Red.toString() + "', = Red = '" + red1.toString() + "', ValueOf(Red) = '" + red2.toString() + "'\n") + // cons.print( "GetName: Color.Red: '" + Color.Red.getName() + "', = Red: '" + red1.getName() + "', ValueOf(Red): '" + red2.getName() + "'\n") + // cons.print( "GetValue: Color.Red = " + Color.Red.getValue() + ", = Red = " + red1.getValue() + ", ValueOf(Red) = " + red2.getValue() + "\n") + // cons.print( "Ordinal (as int): Color.Red = " + Color.Red as int + ", = Red = " + red1 as int + ", ValueOf(Red) = " + red2 as int + "\n") + // cons.print( "ToString: Color.Red = '" + Color.Red.toString() + "', = Red = '" + red1.toString() + "', ValueOf(Red) = '" + red2.toString() + "'\n") assert(red1 as int == 1) assert(red1.getValue() == 2) @@ -76,13 +77,6 @@ function main(): void { assert(red2 == Color.Red); assert(red2 == red1); - let ord: int = 2; - blue = ord as Color; - assert(blue as int == 2) - assert(blue.getValue() == 3) - assert(blue.getName() == "Blue") - assert(blue.toString() == "3") - try { let yellow: Color = Color.valueOf("Yellow"); assert false; @@ -90,23 +84,10 @@ function main(): void { assert (e as Object).toString().startsWith("No enum constant Color.Yellow"); } catch (e) {} - ord = 0; - let green: Color = ord as Color; + let ord: int = 0; + let green : Color = Color.Green //cons.print("Green = " + green as int + ", Color.Green = " + Color.Green as int + "\n") - assert green == Color.Green; + assert green as int == ord; - try { - let x = 5 as Color; - assert false; - } catch (e: Exception) { - assert (e as Object).toString().startsWith("No enum constant in Color with ordinal value 5"); - } - - assert 2 as Color as int == 2; - assert Color.Blue as int as Color == Color.Blue; - assert (Color.Green as int + 1) as Color == (Color.Blue as int - 1) as Color; - try { - assert (Color.Green as int + 1) as Color == Color.valueOf("Red"); - } catch (e) { - } + assert (Color.Green as int + 1) == (Color.Blue as int - 1); } diff --git a/ets2panda/test/runtime/ets/Enum5.ets b/ets2panda/test/runtime/ets/Enum5.ets index fac33b900d..68d06e1d56 100644 --- a/ets2panda/test/runtime/ets/Enum5.ets +++ b/ets2panda/test/runtime/ets/Enum5.ets @@ -44,11 +44,11 @@ function main(): void { assert values[2] == Color.Blue; let red1: Color = Color.Red; - let red2: Color; - assert(red2 as int == 0) - assert(red2.getValue() == "red") - assert(red2.getName() == "Green") - assert(red2.toString() == "red") + let red2: Color = red1; + assert(red2 as int == 1) + assert(red2.getValue() == "blue") + assert(red2.getName() == "Red") + assert(red2.toString() == "blue") //cons.print("\nDefault ordinal = " + red2 as int + ", value = " + red2.getValue() + ", name: '" + red2.getName() + "', ToString: '" + red2.toString() + "'\n\n") try { @@ -78,11 +78,6 @@ function main(): void { assert(red2 == red1); let ord: int = 2; - blue = ord as Color; - assert(blue as int == 2) - assert(blue.getValue() == "green") - assert(blue.getName() == "Blue") - assert(blue.toString() == "green") try { let yellow: Color = Color.valueOf("Yellow"); @@ -92,22 +87,9 @@ function main(): void { } catch (e) {} ord = 0; - let green: Color = ord as Color; + let green: Color = Color.Green; //cons.print("Green = " + green as int + ", Color.Green = " + Color.Green as int + "\n") - assert green == Color.Green; - - try { - let x = 5 as Color; - assert false; - } catch (e: Exception) { - assert (e as Object).toString().startsWith("No enum constant in Color with ordinal value 5"); - } + assert green as int == ord; - assert 2 as Color as int == 2; - assert Color.Blue as int as Color == Color.Blue; - assert (Color.Green as int + 1) as Color == (Color.Blue as int - 1) as Color; - try { - assert (Color.Green as int + 1) as Color == Color.valueOf("Red"); - } catch (e) { - } + assert values[(Color.Green as int + 1)] == values[(Color.Blue as int - 1)]; } -- Gitee From 2e462a2bfa5a615fb774b38a4380c51c150d66c5 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Sat, 24 Feb 2024 21:43:21 +0300 Subject: [PATCH 33/48] use post-processing for binary expressions Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/arithmetic.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index d16132dd78..ad483506d7 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -478,8 +478,12 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater( } if (promotedType == nullptr && !bothConst) { - if (0) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 6" << std::endl; + if ((left->Parent() == right->Parent()) && + (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && + (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { + left->Parent()->SetPostBit(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED); + return {nullptr, nullptr}; + } ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } -- Gitee From 3fdb634a04551951828d7fdc63149e04f3229cbc Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Sat, 24 Feb 2024 21:47:53 +0300 Subject: [PATCH 34/48] update tests, with respect to fixed '==' expression Signed-off-by: Vadim Lomovtsev --- ets2panda/test/runtime/ets/Enum4.ets | 1 + 1 file changed, 1 insertion(+) diff --git a/ets2panda/test/runtime/ets/Enum4.ets b/ets2panda/test/runtime/ets/Enum4.ets index 670173ce6f..3eb0ac5196 100644 --- a/ets2panda/test/runtime/ets/Enum4.ets +++ b/ets2panda/test/runtime/ets/Enum4.ets @@ -64,6 +64,7 @@ function main(): void { // cons.print( "ToString: Color.Red = '" + Color.Red.toString() + "', = Red = '" + red1.toString() + "', ValueOf(Red) = '" + red2.toString() + "'\n") assert(red1 as int == 1) + assert(red1 == 2) assert(red1.getValue() == 2) assert(red1.getName() == "Red") assert(red1.toString() == "2") -- Gitee From 4a57bb94d74cc82899f53d7d497a7bdc2319010c Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 26 Feb 2024 09:13:31 +0300 Subject: [PATCH 35/48] defaulParameterLowering: use initializer over 'as' expression Signed-off-by: Vadim Lomovtsev --- .../lowering/ets/defaultParameterLowering.cpp | 29 +++++++++++-------- .../lowering/ets/defaultParameterLowering.h | 1 + 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp index 737fc13af3..792c6611d3 100644 --- a/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp +++ b/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp @@ -247,6 +247,20 @@ void DefaultParameterLowering::CreateOverloadFunction(ir::AstNode *ast, ArenaVec overloadMethod->SetParent(method); } +ir::Expression *DefaultParameterLowering::CreateInializerExpression(ir::ETSParameterExpression *par, + checker::ETSChecker *checker) +{ + ir::Expression *clone = nullptr; + if (par->Initializer()->IsArrowFunctionExpression()) { + clone = par->Initializer(); + } else { + auto *value = par->Initializer()->Clone(checker->Allocator(), nullptr)->AsExpression(); + auto *type = par->TypeAnnotation()->Clone(checker->Allocator(), nullptr)->AsTypeNode(); + clone = checker->AllocNode(value, type, false); + } + return clone; +} + void DefaultParameterLowering::RemoveInitializers(ArenaVector params) { std::for_each(params.begin(), params.end(), [](ir::Expression *expr) { @@ -298,18 +312,9 @@ void DefaultParameterLowering::ProcessGlobalFunctionDefinition(ir::AstNode *ast, // calls foo(0, 1, 2) auto pt = it; do { - // extract default value from pt and make the function call argument out of it - // for now simple put whole parameter node to vector - ir::Expression *clone = nullptr; - auto *par = (*pt)->AsETSParameterExpression(); - if (par->Initializer()->IsArrowFunctionExpression()) { - clone = par->Initializer(); - } else { - clone = par->Initializer()->Clone(checker->Allocator(), nullptr)->AsExpression(); - } - if (clone != nullptr) { - defaultArgs.push_back(clone); - } + // extract default value from pt and make the function call argument out of it. + // use 'as' expression to force type cast for further signature check & assign. + defaultArgs.push_back(CreateInializerExpression((*pt)->AsETSParameterExpression(), checker)); } while (params.rbegin() != pt--); // ok, now we need to copy the 'valid' (for now) arguments from original function diff --git a/ets2panda/compiler/lowering/ets/defaultParameterLowering.h b/ets2panda/compiler/lowering/ets/defaultParameterLowering.h index 0baf532b60..2c5d439c0d 100644 --- a/ets2panda/compiler/lowering/ets/defaultParameterLowering.h +++ b/ets2panda/compiler/lowering/ets/defaultParameterLowering.h @@ -42,6 +42,7 @@ class DefaultParameterLowering : public Phase { ArenaVector funcCallArgs); void CreateOverloadFunction(ir::AstNode *ast, ArenaVector funcCallArgs, ArenaVector funcDefinitionArgs, CompilerContext *ctx); + ir::Expression *CreateInializerExpression(ir::ETSParameterExpression *par, checker::ETSChecker *checker); void RemoveInitializers(ArenaVector params); void ProcessGlobalFunctionDefinition(ir::AstNode *ast, CompilerContext *ctx); -- Gitee From 3e2c9883d67fab792a51bc61d058d1dbe74b1fb4 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 26 Feb 2024 10:14:07 +0300 Subject: [PATCH 36/48] enum do not throw exception if cast from Enum to Enum (not EnumConst) Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ETSAnalyzer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 5db7b03151..d5f88d52b4 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2573,6 +2573,7 @@ checker::Type *ETSAnalyzer::Check(ir::TSArrayType *node) const checker::Type *ETSAnalyzer::Check(ir::TSAsExpression *expr) const { ETSChecker *checker = GetETSChecker(); + TypeRelationFlag extraFlags = TypeRelationFlag::NONE; auto *const targetType = expr->TypeAnnotation()->AsTypeNode()->GetType(checker); // Object expression requires that its type be set by the context before checking. in this case, the target type @@ -2595,8 +2596,13 @@ checker::Type *ETSAnalyzer::Check(ir::TSAsExpression *expr) const } } + // NOTE: this is to address spec/enum/issue14636_1.ets test failure + if (targetType->IsETSEnum2Type() && sourceType->IsETSEnum2Type()) { + extraFlags |= TypeRelationFlag::NO_THROW; + } + const checker::CastingContext ctx(checker->Relation(), expr->Expr(), sourceType, targetType, expr->Expr()->Start(), - {"Cannot cast type '", sourceType, "' to '", targetType, "'"}); + {"Cannot cast type '", sourceType, "' to '", targetType, "'"}, extraFlags); if (sourceType->IsETSDynamicType() && targetType->IsLambdaObject()) { // NOTE: itrubachev. change targetType to created lambdaobject type. -- Gitee From cf143854af74769485b54a038d4041b33a41ac1d Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 26 Feb 2024 16:41:17 +0300 Subject: [PATCH 37/48] place asserts to catch old code invokations Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/arithmetic.cpp | 22 ++++++++------- ets2panda/checker/types/ets/etsEnumType.cpp | 31 +++++++++++++++++++++ ets2panda/checker/types/ets/etsEnumType.h | 11 ++++++++ 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index ad483506d7..c2e8128dee 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -191,7 +191,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorMulDivMod(ir::Expression *left, ir } if (promotedType == nullptr && !bothConst) { - if (0) + if (1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 1" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -212,7 +212,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp if (leftType->IsETSStringType() || rightType->IsETSStringType()) { if (operationType == lexer::TokenType::PUNCTUATOR_MINUS || operationType == lexer::TokenType::PUNCTUATOR_MINUS_EQUAL) { - if (0) + if (1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 2" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -231,7 +231,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp FlagExpressionWithUnboxing(rightType, unboxedR, right); if (promotedType == nullptr && !bothConst) { - if (0) + if (1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 3" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type or String.", pos); } @@ -260,7 +260,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorShift(ir::Expression *left, ir::Ex if (promotedLeftType == nullptr || !promotedLeftType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) || promotedRightType == nullptr || !promotedRightType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { - if (0) + if (1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 4" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -308,7 +308,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: if (unboxedL != nullptr && unboxedL->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && unboxedR != nullptr && unboxedR->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { - if (0) + if (1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 52" << std::endl; FlagExpressionWithUnboxing(leftType, unboxedL, left); FlagExpressionWithUnboxing(rightType, unboxedR, right); @@ -325,19 +325,19 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: if ((left->Parent() == right->Parent()) && (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { - if (0) + if (1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; left->Parent()->SetPostBit(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return nullptr; } - if (0) + if (1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 5" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } if (bothConst) { - // if(0) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 53" << std::endl; + // if(1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 53" << std::endl; return HandleBitwiseOperationOnTypes(leftType, rightType, operationType); } @@ -478,6 +478,8 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater( } if (promotedType == nullptr && !bothConst) { + if (1) + std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 6" << std::endl; if ((left->Parent() == right->Parent()) && (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { @@ -655,12 +657,12 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, checker::Type *const rightType = right->Check(this); if ((leftType == nullptr) || (rightType == nullptr)) { if (checkIfBitSet(left) || checkIfBitSet(right)) { - if (0) + if (1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; expr->SetPostBit(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return {nullptr, nullptr}; } else { - if (0) + if (1) std::cout << "Erroneos expression:" << expr->DumpJSON() << std::endl; ThrowTypeError("Unexpected type error in binary expression", pos); } diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index ebe2d5c124..d7f6f6ee76 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -27,6 +27,7 @@ ETSEnumInterface::ETSEnumInterface(const ir::TSEnumDeclaration *const enumDecl, const ir::TSEnumMember *const member, TypeFlag const typeFlag) : Type(typeFlag), decl_(enumDecl), ordinal_ {ordinal}, member_(member) { + ASSERT(false); } bool ETSEnumInterface::AssignmentSource(TypeRelation *const relation, [[maybe_unused]] Type *const target) @@ -36,6 +37,7 @@ bool ETSEnumInterface::AssignmentSource(TypeRelation *const relation, [[maybe_un // : (target->IsETSStringEnumType() ? IsSameEnumType(target->AsETSStringEnumType()) : // false); // relation->Result(result); + ASSERT(false); relation->Result(false); return relation->IsTrue(); } @@ -47,11 +49,13 @@ void ETSEnumInterface::AssignmentTarget(TypeRelation *const relation, [[maybe_un // : (source->IsETSStringEnumType() ? IsSameEnumType(source->AsETSStringEnumType()) : // false); // relation->Result(result); + ASSERT(false); relation->Result(false); } void ETSEnumInterface::Cast(TypeRelation *relation, Type *target) { + ASSERT(false); // if (target->HasTypeFlag(TypeFlag::ENUM | TypeFlag::ETS_ENUM | TypeFlag::ETS_STRING_ENUM)) { // conversion::Identity(relation, this, target); // return; @@ -68,11 +72,13 @@ void ETSEnumInterface::Cast(TypeRelation *relation, Type *target) Type *ETSEnumInterface::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, [[maybe_unused]] GlobalTypesHolder *globalTypes) { + ASSERT(false); return this; } void ETSEnumInterface::Identical(TypeRelation *const relation, Type *const other) { + ASSERT(false); ETSEnumInterface const *const otherEnumType = [other]() -> ETSEnumInterface const * { (void)other; // if (other->IsETSEnumType()) { @@ -89,49 +95,58 @@ void ETSEnumInterface::Identical(TypeRelation *const relation, Type *const other void ETSEnumInterface::ToAssemblerType(std::stringstream &ss) const { + ASSERT(false); ToAssemblerTypeImpl(ss); } void ETSEnumInterface::ToDebugInfoType(std::stringstream &ss) const { + ASSERT(false); ToDebugInfoTypeImpl(ss); } void ETSEnumInterface::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { + ASSERT(false); ss << decl_->Key()->Name(); } const ir::TSEnumDeclaration *ETSEnumInterface::GetDecl() const noexcept { + ASSERT(false); return decl_; } const ArenaVector &ETSEnumInterface::GetMembers() const noexcept { + ASSERT(false); return decl_->Members(); } varbinder::LocalVariable *ETSEnumInterface::GetMemberVar() const noexcept { ASSERT(IsLiteralType()); + ASSERT(false); return member_->Key()->AsIdentifier()->Variable()->AsLocalVariable(); } util::StringView ETSEnumInterface::GetName() const noexcept { + ASSERT(false); return decl_->Key()->Name(); } ETSEnumInterface::UType ETSEnumInterface::GetOrdinal() const noexcept { ASSERT(IsLiteralType()); + ASSERT(false); return ordinal_; } ETSEnumInterface *ETSEnumInterface::LookupConstant(ETSChecker *const checker, const ir::Expression *const expression, const ir::Identifier *const prop) const { + ASSERT(false); if (!IsEnumTypeExpression(expression)) { if (expression->IsIdentifier() && expression->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::TYPE_ALIAS)) { @@ -164,6 +179,7 @@ ETSEnumInterface *ETSEnumInterface::LookupConstant(ETSChecker *const checker, co ETSFunctionType *ETSEnumInterface::LookupMethod(ETSChecker *checker, const ir::Expression *const expression, const ir::Identifier *const prop) const { + ASSERT(false); if (IsEnumTypeExpression(expression)) { return LookupTypeMethod(checker, prop); } @@ -174,17 +190,20 @@ ETSFunctionType *ETSEnumInterface::LookupMethod(ETSChecker *checker, const ir::E bool ETSEnumInterface::IsSameEnumType(const ETSEnumInterface *const other) const noexcept { + ASSERT(false); return other->decl_ == decl_; } bool ETSEnumInterface::IsSameEnumLiteralType(const ETSEnumInterface *const other) const noexcept { + ASSERT(false); ASSERT(IsLiteralType() && IsSameEnumType(other)); return member_ == other->member_; } [[maybe_unused]] static const ETSEnumInterface *SpecifyEnumInterface([[maybe_unused]] const checker::Type *enumType) { + ASSERT(false); // if (enumType->IsETSEnumType()) { // return enumType->AsETSEnumType(); // } @@ -203,6 +222,7 @@ bool ETSEnumInterface::IsEnumInstanceExpression(const ir::Expression *const expr bool ETSEnumInterface::IsEnumLiteralExpression(const ir::Expression *const expression) const noexcept { + ASSERT(false); ASSERT(IsSameEnumType(SpecifyEnumInterface(expression->TsType()))); if (expression->IsMemberExpression()) { @@ -216,6 +236,7 @@ bool ETSEnumInterface::IsEnumLiteralExpression(const ir::Expression *const expre bool ETSEnumInterface::IsEnumTypeExpression(const ir::Expression *const expression) const noexcept { + ASSERT(false); auto specifiedEnumInterface = SpecifyEnumInterface(expression->TsType()); if (specifiedEnumInterface != nullptr) { ASSERT(IsSameEnumType(specifiedEnumInterface)); @@ -244,47 +265,55 @@ bool ETSEnumInterface::IsEnumTypeExpression(const ir::Expression *const expressi ETSEnumInterface::Method ETSEnumInterface::FromIntMethod() const noexcept { + ASSERT(false); ASSERT(fromIntMethod_.globalSignature != nullptr && fromIntMethod_.memberProxyType == nullptr); return fromIntMethod_; } ETSEnumInterface::Method ETSEnumInterface::GetValueMethod() const noexcept { + ASSERT(false); ASSERT(getValueMethod_.globalSignature != nullptr && getValueMethod_.memberProxyType != nullptr); return getValueMethod_; } ETSEnumInterface::Method ETSEnumInterface::GetNameMethod() const noexcept { + ASSERT(false); ASSERT(getNameMethod_.globalSignature != nullptr && getNameMethod_.memberProxyType != nullptr); return getNameMethod_; } ETSEnumInterface::Method ETSEnumInterface::ToStringMethod() const noexcept { + ASSERT(false); ASSERT(toStringMethod_.globalSignature != nullptr && toStringMethod_.memberProxyType != nullptr); return toStringMethod_; } ETSEnumInterface::Method ETSEnumInterface::ValueOfMethod() const noexcept { + ASSERT(false); ASSERT(valueOfMethod_.globalSignature != nullptr && valueOfMethod_.memberProxyType != nullptr); return valueOfMethod_; } ETSEnumInterface::Method ETSEnumInterface::ValuesMethod() const noexcept { + ASSERT(false); ASSERT(valuesMethod_.globalSignature != nullptr && valuesMethod_.memberProxyType != nullptr); return valuesMethod_; } bool ETSEnumInterface::IsLiteralType() const noexcept { + ASSERT(false); return member_ != nullptr; } ir::TSEnumMember *ETSEnumInterface::FindMember(const util::StringView &name) const noexcept { + ASSERT(false); ASSERT(!IsLiteralType()); const auto &members = GetMembers(); auto memberIt = std::find_if(members.begin(), members.end(), [name](const ir::AstNode *const node) { @@ -301,6 +330,7 @@ ir::TSEnumMember *ETSEnumInterface::FindMember(const util::StringView &name) con ETSFunctionType *ETSEnumInterface::LookupConstantMethod(ETSChecker *const checker, const ir::Identifier *const prop) const { + ASSERT(false); if (prop->Name() == TO_STRING_METHOD_NAME) { ASSERT(toStringMethod_.memberProxyType != nullptr); return toStringMethod_.memberProxyType; @@ -321,6 +351,7 @@ ETSFunctionType *ETSEnumInterface::LookupConstantMethod(ETSChecker *const checke ETSFunctionType *ETSEnumInterface::LookupTypeMethod(ETSChecker *const checker, const ir::Identifier *const prop) const { + ASSERT(false); if (prop->Name() == VALUES_METHOD_NAME) { ASSERT(valuesMethod_.memberProxyType != nullptr); return valuesMethod_.memberProxyType; diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index 37a2813fd7..ee3a9c1e15 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -106,41 +106,48 @@ public: [[nodiscard]] Method ToStringMethod() const noexcept; void SetToStringMethod(Method const &method) noexcept { + ASSERT(false); toStringMethod_ = method; } [[nodiscard]] Method GetValueMethod() const noexcept; void SetGetValueMethod(Method const &method) noexcept { + ASSERT(false); getValueMethod_ = method; } [[nodiscard]] Method GetNameMethod() const noexcept; void SetGetNameMethod(Method const &method) noexcept { + ASSERT(false); getNameMethod_ = method; } [[nodiscard]] Method ValueOfMethod() const noexcept; void SetValueOfMethod(Method const &method) noexcept { + ASSERT(false); valueOfMethod_ = method; } [[nodiscard]] Method ValuesMethod() const noexcept; void SetValuesMethod(Method const &method) noexcept { + ASSERT(false); valuesMethod_ = method; } [[nodiscard]] Method FromIntMethod() const noexcept; void SetFromIntMethod(Method const &method) noexcept { + ASSERT(false); fromIntMethod_ = method; } std::tuple ResolveConditionExpr() const override { + ASSERT(false); return {true, !GetMembers().empty()}; } @@ -165,6 +172,7 @@ private: template void ToAssemblerTypeImpl(std::stringstream &ss) const noexcept { + ASSERT(false); if constexpr (std::is_same_v) { ss << compiler::Signatures::PRIMITIVE_LONG; } else if constexpr (std::is_same_v) { @@ -177,6 +185,7 @@ private: template void ToDebugInfoTypeImpl(std::stringstream &ss) const noexcept { + ASSERT(false); if constexpr (std::is_same_v) { ss << compiler::Signatures::TYPE_DESCRIPTOR_LONG; } else if constexpr (std::is_same_v) { @@ -192,6 +201,7 @@ public: explicit ETSEnumType(const ir::TSEnumDeclaration *enumDecl, UType ordinal, const ir::TSEnumMember *member = nullptr) : ETSEnumInterface(enumDecl, ordinal, member, TypeFlag::ETS_ENUM2_TYPE) { + ASSERT(false); } NO_COPY_SEMANTIC(ETSEnumType); @@ -207,6 +217,7 @@ public: const ir::TSEnumMember *member = nullptr) : ETSEnumInterface(enumDecl, ordinal, member, TypeFlag::ETS_ENUM2_TYPE) { + ASSERT(false); } NO_COPY_SEMANTIC(ETSStringEnumType); -- Gitee From 598cfbed122fac312c1019b22dac8a91ffcba5e8 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 26 Feb 2024 16:41:50 +0300 Subject: [PATCH 38/48] declgen minor fix (no more special case for enum) Signed-off-by: Vadim Lomovtsev --- ets2panda/util/declgenEts2Ts.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/ets2panda/util/declgenEts2Ts.cpp b/ets2panda/util/declgenEts2Ts.cpp index ed0b94f22e..4c8227291d 100644 --- a/ets2panda/util/declgenEts2Ts.cpp +++ b/ets2panda/util/declgenEts2Ts.cpp @@ -152,8 +152,6 @@ void TSDeclGen::GenType(const checker::Type *checkerType) Out(checkerType->ToString()); return; case checker::TypeFlag::ETS_ENUM2_TYPE: - // GenEnumType(checkerType->AsETSEnumType()); - return; case checker::TypeFlag::ETS_OBJECT: case checker::TypeFlag::ETS_DYNAMIC_TYPE: GenObjectType(checkerType->AsETSObjectType()); -- Gitee From efe8b6f118063a8dba57e8efe1c1de5c8cae6cb0 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Mon, 26 Feb 2024 18:26:29 +0300 Subject: [PATCH 39/48] explcit cast by 'as' is not allowed between different enums Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ETSAnalyzer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index d5f88d52b4..636a311495 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2597,7 +2597,8 @@ checker::Type *ETSAnalyzer::Check(ir::TSAsExpression *expr) const } // NOTE: this is to address spec/enum/issue14636_1.ets test failure - if (targetType->IsETSEnum2Type() && sourceType->IsETSEnum2Type()) { + if (targetType->IsETSEnum2Type() && sourceType->IsETSEnum2Type() && + targetType->AsETSEnum2Type()->IsSameEnumType(sourceType->AsETSEnum2Type())) { extraFlags |= TypeRelationFlag::NO_THROW; } -- Gitee From 20ff4eca4c2e5f614f746f8c3ef64974325f3bf1 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 27 Feb 2024 10:33:24 +0300 Subject: [PATCH 40/48] remove ETSEnumInterface and relevant classes Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/types/ets/etsEnumType.cpp | 341 -------------------- ets2panda/checker/types/ets/etsEnumType.h | 196 ----------- ets2panda/parser/ETSparser.cpp | 6 +- 3 files changed, 3 insertions(+), 540 deletions(-) diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index d7f6f6ee76..78b146a111 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -23,347 +23,6 @@ #include "ir/ts/tsEnumMember.h" namespace ark::es2panda::checker { -ETSEnumInterface::ETSEnumInterface(const ir::TSEnumDeclaration *const enumDecl, UType ordinal, - const ir::TSEnumMember *const member, TypeFlag const typeFlag) - : Type(typeFlag), decl_(enumDecl), ordinal_ {ordinal}, member_(member) -{ - ASSERT(false); -} - -bool ETSEnumInterface::AssignmentSource(TypeRelation *const relation, [[maybe_unused]] Type *const target) -{ - // auto const result = target->IsETSEnumType() - // ? IsSameEnumType(target->AsETSEnumType()) - // : (target->IsETSStringEnumType() ? IsSameEnumType(target->AsETSStringEnumType()) : - // false); - // relation->Result(result); - ASSERT(false); - relation->Result(false); - return relation->IsTrue(); -} - -void ETSEnumInterface::AssignmentTarget(TypeRelation *const relation, [[maybe_unused]] Type *const source) -{ - // auto const result = source->IsETSEnumType() - // ? IsSameEnumType(source->AsETSEnumType()) - // : (source->IsETSStringEnumType() ? IsSameEnumType(source->AsETSStringEnumType()) : - // false); - // relation->Result(result); - ASSERT(false); - relation->Result(false); -} - -void ETSEnumInterface::Cast(TypeRelation *relation, Type *target) -{ - ASSERT(false); - // if (target->HasTypeFlag(TypeFlag::ENUM | TypeFlag::ETS_ENUM | TypeFlag::ETS_STRING_ENUM)) { - // conversion::Identity(relation, this, target); - // return; - // } - - if (target->IsIntType()) { - relation->Result(true); - return; - } - - conversion::Forbidden(relation); -} - -Type *ETSEnumInterface::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, - [[maybe_unused]] GlobalTypesHolder *globalTypes) -{ - ASSERT(false); - return this; -} - -void ETSEnumInterface::Identical(TypeRelation *const relation, Type *const other) -{ - ASSERT(false); - ETSEnumInterface const *const otherEnumType = [other]() -> ETSEnumInterface const * { - (void)other; - // if (other->IsETSEnumType()) { - // return other->AsETSEnumType(); - // } - // if (other->IsETSStringEnumType()) { - // return other->AsETSStringEnumType(); - // } - return nullptr; - }(); - - relation->Result(otherEnumType != nullptr && IsSameEnumType(otherEnumType) && member_ == otherEnumType->member_); -} - -void ETSEnumInterface::ToAssemblerType(std::stringstream &ss) const -{ - ASSERT(false); - ToAssemblerTypeImpl(ss); -} - -void ETSEnumInterface::ToDebugInfoType(std::stringstream &ss) const -{ - ASSERT(false); - ToDebugInfoTypeImpl(ss); -} - -void ETSEnumInterface::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const -{ - ASSERT(false); - ss << decl_->Key()->Name(); -} - -const ir::TSEnumDeclaration *ETSEnumInterface::GetDecl() const noexcept -{ - ASSERT(false); - return decl_; -} - -const ArenaVector &ETSEnumInterface::GetMembers() const noexcept -{ - ASSERT(false); - return decl_->Members(); -} - -varbinder::LocalVariable *ETSEnumInterface::GetMemberVar() const noexcept -{ - ASSERT(IsLiteralType()); - ASSERT(false); - return member_->Key()->AsIdentifier()->Variable()->AsLocalVariable(); -} - -util::StringView ETSEnumInterface::GetName() const noexcept -{ - ASSERT(false); - return decl_->Key()->Name(); -} - -ETSEnumInterface::UType ETSEnumInterface::GetOrdinal() const noexcept -{ - ASSERT(IsLiteralType()); - ASSERT(false); - return ordinal_; -} - -ETSEnumInterface *ETSEnumInterface::LookupConstant(ETSChecker *const checker, const ir::Expression *const expression, - const ir::Identifier *const prop) const -{ - ASSERT(false); - if (!IsEnumTypeExpression(expression)) { - if (expression->IsIdentifier() && - expression->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::TYPE_ALIAS)) { - checker->ThrowTypeError({"Cannot refer to enum members through type alias."}, prop->Start()); - } else if (IsLiteralType()) { - checker->ThrowTypeError({"Cannot refer to enum members through variable."}, prop->Start()); - } else { - checker->ThrowTypeError({"Enum constant does not have property '", prop->Name(), "'."}, prop->Start()); - } - } - - auto *const member = FindMember(prop->Name()); - if (member == nullptr) { - checker->ThrowTypeError({"No enum constant named '", prop->Name(), "' in enum '", this, "'"}, prop->Start()); - } - - // auto *const enumInterface = - // [enumType = member->Key()->AsIdentifier()->Variable()->TsType()]() -> checker::ETSEnumInterface * { - // if (enumType->IsETSEnumType()) { - // return enumType->AsETSEnumType(); - // } - // return enumType->AsETSStringEnumType(); - // }(); - // - // ASSERT(enumInterface->IsLiteralType()); - // return enumInterface; - return nullptr; -} - -ETSFunctionType *ETSEnumInterface::LookupMethod(ETSChecker *checker, const ir::Expression *const expression, - const ir::Identifier *const prop) const -{ - ASSERT(false); - if (IsEnumTypeExpression(expression)) { - return LookupTypeMethod(checker, prop); - } - - ASSERT(IsEnumInstanceExpression(expression)); - return LookupConstantMethod(checker, prop); -} - -bool ETSEnumInterface::IsSameEnumType(const ETSEnumInterface *const other) const noexcept -{ - ASSERT(false); - return other->decl_ == decl_; -} - -bool ETSEnumInterface::IsSameEnumLiteralType(const ETSEnumInterface *const other) const noexcept -{ - ASSERT(false); - ASSERT(IsLiteralType() && IsSameEnumType(other)); - return member_ == other->member_; -} - -[[maybe_unused]] static const ETSEnumInterface *SpecifyEnumInterface([[maybe_unused]] const checker::Type *enumType) -{ - ASSERT(false); - // if (enumType->IsETSEnumType()) { - // return enumType->AsETSEnumType(); - // } - // if (enumType->IsETSStringEnumType()) { - // return enumType->AsETSStringEnumType(); - // } - return nullptr; -} - -bool ETSEnumInterface::IsEnumInstanceExpression(const ir::Expression *const expression) const noexcept -{ - ASSERT(IsSameEnumType(SpecifyEnumInterface(expression->TsType()))); - - return IsEnumLiteralExpression(expression) || !IsEnumTypeExpression(expression); -} - -bool ETSEnumInterface::IsEnumLiteralExpression(const ir::Expression *const expression) const noexcept -{ - ASSERT(false); - ASSERT(IsSameEnumType(SpecifyEnumInterface(expression->TsType()))); - - if (expression->IsMemberExpression()) { - const auto *const memberExpr = expression->AsMemberExpression(); - return memberExpr->Kind() == ir::MemberExpressionKind::PROPERTY_ACCESS && - IsEnumTypeExpression(memberExpr->Object()); - } - - return false; -} - -bool ETSEnumInterface::IsEnumTypeExpression(const ir::Expression *const expression) const noexcept -{ - ASSERT(false); - auto specifiedEnumInterface = SpecifyEnumInterface(expression->TsType()); - if (specifiedEnumInterface != nullptr) { - ASSERT(IsSameEnumType(specifiedEnumInterface)); - } else { - return false; - } - - if (expression->IsCallExpression()) { - return false; - } - - const auto *const localVar = [expression]() -> const varbinder::LocalVariable * { - if (expression->IsMemberExpression()) { - const auto *const memberExpr = expression->AsMemberExpression(); - return memberExpr->PropVar() != nullptr - ? memberExpr->PropVar() - : memberExpr->Object()->AsIdentifier()->Variable()->AsLocalVariable(); - } - return expression->AsIdentifier()->Variable()->AsLocalVariable(); - }(); - - ASSERT(localVar->Declaration() == decl_->Key()->AsIdentifier()->Variable()->Declaration() || - !localVar->HasFlag(varbinder::VariableFlags::ENUM_LITERAL)); - return localVar->HasFlag(varbinder::VariableFlags::ENUM_LITERAL); -} - -ETSEnumInterface::Method ETSEnumInterface::FromIntMethod() const noexcept -{ - ASSERT(false); - ASSERT(fromIntMethod_.globalSignature != nullptr && fromIntMethod_.memberProxyType == nullptr); - return fromIntMethod_; -} - -ETSEnumInterface::Method ETSEnumInterface::GetValueMethod() const noexcept -{ - ASSERT(false); - ASSERT(getValueMethod_.globalSignature != nullptr && getValueMethod_.memberProxyType != nullptr); - return getValueMethod_; -} - -ETSEnumInterface::Method ETSEnumInterface::GetNameMethod() const noexcept -{ - ASSERT(false); - ASSERT(getNameMethod_.globalSignature != nullptr && getNameMethod_.memberProxyType != nullptr); - return getNameMethod_; -} - -ETSEnumInterface::Method ETSEnumInterface::ToStringMethod() const noexcept -{ - ASSERT(false); - ASSERT(toStringMethod_.globalSignature != nullptr && toStringMethod_.memberProxyType != nullptr); - return toStringMethod_; -} - -ETSEnumInterface::Method ETSEnumInterface::ValueOfMethod() const noexcept -{ - ASSERT(false); - ASSERT(valueOfMethod_.globalSignature != nullptr && valueOfMethod_.memberProxyType != nullptr); - return valueOfMethod_; -} - -ETSEnumInterface::Method ETSEnumInterface::ValuesMethod() const noexcept -{ - ASSERT(false); - ASSERT(valuesMethod_.globalSignature != nullptr && valuesMethod_.memberProxyType != nullptr); - return valuesMethod_; -} - -bool ETSEnumInterface::IsLiteralType() const noexcept -{ - ASSERT(false); - return member_ != nullptr; -} - -ir::TSEnumMember *ETSEnumInterface::FindMember(const util::StringView &name) const noexcept -{ - ASSERT(false); - ASSERT(!IsLiteralType()); - const auto &members = GetMembers(); - auto memberIt = std::find_if(members.begin(), members.end(), [name](const ir::AstNode *const node) { - return node->AsTSEnumMember()->Key()->AsIdentifier()->Name() == name; - }); - - if (memberIt != members.end()) { - return (*memberIt)->AsTSEnumMember(); - } - - return nullptr; -} - -ETSFunctionType *ETSEnumInterface::LookupConstantMethod(ETSChecker *const checker, - const ir::Identifier *const prop) const -{ - ASSERT(false); - if (prop->Name() == TO_STRING_METHOD_NAME) { - ASSERT(toStringMethod_.memberProxyType != nullptr); - return toStringMethod_.memberProxyType; - } - - if (prop->Name() == GET_VALUE_METHOD_NAME) { - ASSERT(getValueMethod_.memberProxyType != nullptr); - return getValueMethod_.memberProxyType; - } - - if (prop->Name() == GET_NAME_METHOD_NAME) { - ASSERT(getNameMethod_.memberProxyType != nullptr); - return getNameMethod_.memberProxyType; - } - - checker->ThrowTypeError({"No enum item method called '", prop->Name(), "'"}, prop->Start()); -} - -ETSFunctionType *ETSEnumInterface::LookupTypeMethod(ETSChecker *const checker, const ir::Identifier *const prop) const -{ - ASSERT(false); - if (prop->Name() == VALUES_METHOD_NAME) { - ASSERT(valuesMethod_.memberProxyType != nullptr); - return valuesMethod_.memberProxyType; - } - - if (prop->Name() == VALUE_OF_METHOD_NAME) { - ASSERT(valueOfMethod_.memberProxyType != nullptr); - return valueOfMethod_.memberProxyType; - } - - checker->ThrowTypeError({"No enum type method called '", prop->Name(), "'"}, prop->Start()); -} std::string EnumDescription(util::StringView name) { diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index ee3a9c1e15..dee7f833a8 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -30,202 +30,6 @@ class LocalVariable; } // namespace ark::es2panda::varbinder namespace ark::es2panda::checker { -template -struct ETSEnumValueType { - using ValueType = T; -}; - -class ETSEnumInterface : public Type { -public: - using UType = std::int32_t; - - explicit ETSEnumInterface(const ir::TSEnumDeclaration *enumDecl, UType ordinal, const ir::TSEnumMember *member, - TypeFlag typeFlag); - - NO_COPY_SEMANTIC(ETSEnumInterface); - NO_MOVE_SEMANTIC(ETSEnumInterface); - - ETSEnumInterface() = delete; - ~ETSEnumInterface() override = default; - - [[nodiscard]] bool AssignmentSource(TypeRelation *relation, Type *target) override; - - void AssignmentTarget(TypeRelation *relation, Type *source) override; - - void Cast(TypeRelation *relation, Type *target) override; - - Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - - void Identical(TypeRelation *relation, Type *other) override; - - void ToAssemblerType(std::stringstream &ss) const override; - void ToDebugInfoType(std::stringstream &ss) const override; - - void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; - - [[nodiscard]] const ir::TSEnumDeclaration *GetDecl() const noexcept; - - [[nodiscard]] const ArenaVector &GetMembers() const noexcept; - - [[nodiscard]] varbinder::LocalVariable *GetMemberVar() const noexcept; - - [[nodiscard]] util::StringView GetName() const noexcept; - - [[nodiscard]] UType GetOrdinal() const noexcept; - - [[nodiscard]] ETSEnumInterface *LookupConstant(ETSChecker *checker, const ir::Expression *expression, - const ir::Identifier *prop) const; - - [[nodiscard]] ETSFunctionType *LookupMethod(ETSChecker *checker, const ir::Expression *expression, - const ir::Identifier *prop) const; - - [[nodiscard]] bool IsLiteralType() const noexcept; - - [[nodiscard]] bool IsSameEnumType(const ETSEnumInterface *const other) const noexcept; - - [[nodiscard]] bool IsSameEnumLiteralType(const ETSEnumInterface *const other) const noexcept; - - [[nodiscard]] bool IsEnumInstanceExpression(const ir::Expression *expression) const noexcept; - - [[nodiscard]] bool IsEnumLiteralExpression(const ir::Expression *expression) const noexcept; - - [[nodiscard]] bool IsEnumTypeExpression(const ir::Expression *expression) const noexcept; - - static constexpr std::string_view const TO_STRING_METHOD_NAME {"toString"}; - static constexpr std::string_view const GET_VALUE_METHOD_NAME {"getValue"}; - static constexpr std::string_view const GET_NAME_METHOD_NAME {"getName"}; - static constexpr std::string_view const VALUE_OF_METHOD_NAME {"valueOf"}; - static constexpr std::string_view const VALUES_METHOD_NAME {"values"}; - static constexpr std::string_view const FROM_INT_METHOD_NAME {"fromInt"}; - - struct Method { - Signature *globalSignature; - ETSFunctionType *memberProxyType; - }; - - [[nodiscard]] Method ToStringMethod() const noexcept; - void SetToStringMethod(Method const &method) noexcept - { - ASSERT(false); - toStringMethod_ = method; - } - - [[nodiscard]] Method GetValueMethod() const noexcept; - void SetGetValueMethod(Method const &method) noexcept - { - ASSERT(false); - getValueMethod_ = method; - } - - [[nodiscard]] Method GetNameMethod() const noexcept; - void SetGetNameMethod(Method const &method) noexcept - { - ASSERT(false); - getNameMethod_ = method; - } - - [[nodiscard]] Method ValueOfMethod() const noexcept; - void SetValueOfMethod(Method const &method) noexcept - { - ASSERT(false); - valueOfMethod_ = method; - } - - [[nodiscard]] Method ValuesMethod() const noexcept; - void SetValuesMethod(Method const &method) noexcept - { - ASSERT(false); - valuesMethod_ = method; - } - - [[nodiscard]] Method FromIntMethod() const noexcept; - void SetFromIntMethod(Method const &method) noexcept - { - ASSERT(false); - fromIntMethod_ = method; - } - - std::tuple ResolveConditionExpr() const override - { - ASSERT(false); - return {true, !GetMembers().empty()}; - } - -private: - const ir::TSEnumDeclaration *decl_; - const UType ordinal_; - const ir::TSEnumMember *member_; - - Method toStringMethod_ {}; - Method getValueMethod_ {}; - Method getNameMethod_ {}; - Method valueOfMethod_ {}; - Method valuesMethod_ {}; - Method fromIntMethod_ {}; - - [[nodiscard]] ir::TSEnumMember *FindMember(const util::StringView &name) const noexcept; - - [[nodiscard]] ETSFunctionType *LookupConstantMethod(ETSChecker *checker, const ir::Identifier *prop) const; - - [[nodiscard]] ETSFunctionType *LookupTypeMethod(ETSChecker *checker, const ir::Identifier *prop) const; - - template - void ToAssemblerTypeImpl(std::stringstream &ss) const noexcept - { - ASSERT(false); - if constexpr (std::is_same_v) { - ss << compiler::Signatures::PRIMITIVE_LONG; - } else if constexpr (std::is_same_v) { - ss << compiler::Signatures::PRIMITIVE_INT; - } else { - static_assert(dependent_false_v, "Invalid underlying type for enumeration."); - } - } - - template - void ToDebugInfoTypeImpl(std::stringstream &ss) const noexcept - { - ASSERT(false); - if constexpr (std::is_same_v) { - ss << compiler::Signatures::TYPE_DESCRIPTOR_LONG; - } else if constexpr (std::is_same_v) { - ss << compiler::Signatures::TYPE_DESCRIPTOR_INT; - } else { - static_assert(dependent_false_v, "Invalid underlying type for enumeration."); - } - } -}; - -class ETSEnumType : public ETSEnumInterface, public ETSEnumValueType { -public: - explicit ETSEnumType(const ir::TSEnumDeclaration *enumDecl, UType ordinal, const ir::TSEnumMember *member = nullptr) - : ETSEnumInterface(enumDecl, ordinal, member, TypeFlag::ETS_ENUM2_TYPE) - { - ASSERT(false); - } - - NO_COPY_SEMANTIC(ETSEnumType); - NO_MOVE_SEMANTIC(ETSEnumType); - - ETSEnumType() = delete; - ~ETSEnumType() override = default; -}; - -class ETSStringEnumType : public ETSEnumInterface, public ETSEnumValueType { -public: - explicit ETSStringEnumType(const ir::TSEnumDeclaration *enumDecl, UType ordinal, - const ir::TSEnumMember *member = nullptr) - : ETSEnumInterface(enumDecl, ordinal, member, TypeFlag::ETS_ENUM2_TYPE) - { - ASSERT(false); - } - - NO_COPY_SEMANTIC(ETSStringEnumType); - NO_MOVE_SEMANTIC(ETSStringEnumType); - - ETSStringEnumType() = delete; - ~ETSStringEnumType() override = default; -}; std::string EnumDescription(util::StringView name); diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index b9dda5ffca..9324c6fd91 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -3988,7 +3988,7 @@ ir::TSEnumDeclaration *ETSParser::ParseEnumMembers(ir::Identifier *const key, co void ETSParser::ParseNumberEnum(ArenaVector &members) { - checker::ETSEnumType::ValueType currentValue {}; + int32_t currentValue = 0; // Lambda to parse enum member (maybe with initializer) auto const parseMember = [this, &members, ¤tValue]() { @@ -4015,13 +4015,13 @@ void ETSParser::ParseNumberEnum(ArenaVector &members) } ordinal = ParseNumberLiteral()->AsNumberLiteral(); - if (!ordinal->Number().CanGetValue()) { + if (!ordinal->Number().CanGetValue()) { ThrowSyntaxError(INVALID_ENUM_VALUE); } else if (minusSign) { ordinal->Number().Negate(); } - currentValue = ordinal->Number().GetValue(); + currentValue = ordinal->Number().GetValue(); endLoc = ordinal->End(); } else { -- Gitee From cced8ba4495f42e08938ba3b540bf9dcbbd1f225 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 27 Feb 2024 16:13:41 +0300 Subject: [PATCH 41/48] arithmetic.cpp: remove debug traces Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/arithmetic.cpp | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index c2e8128dee..44ff07c8e5 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -191,8 +191,6 @@ checker::Type *ETSChecker::CheckBinaryOperatorMulDivMod(ir::Expression *left, ir } if (promotedType == nullptr && !bothConst) { - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 1" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -212,8 +210,6 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp if (leftType->IsETSStringType() || rightType->IsETSStringType()) { if (operationType == lexer::TokenType::PUNCTUATOR_MINUS || operationType == lexer::TokenType::PUNCTUATOR_MINUS_EQUAL) { - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 2" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -231,8 +227,6 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp FlagExpressionWithUnboxing(rightType, unboxedR, right); if (promotedType == nullptr && !bothConst) { - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 3" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type or String.", pos); } @@ -260,8 +254,6 @@ checker::Type *ETSChecker::CheckBinaryOperatorShift(ir::Expression *left, ir::Ex if (promotedLeftType == nullptr || !promotedLeftType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) || promotedRightType == nullptr || !promotedRightType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 4" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -308,8 +300,6 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: if (unboxedL != nullptr && unboxedL->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && unboxedR != nullptr && unboxedR->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 52" << std::endl; FlagExpressionWithUnboxing(leftType, unboxedL, left); FlagExpressionWithUnboxing(rightType, unboxedR, right); return HandleBooleanLogicalOperators(unboxedL, unboxedR, operationType); @@ -325,19 +315,14 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: if ((left->Parent() == right->Parent()) && (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; left->Parent()->SetPostBit(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return nullptr; } - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 5" << std::endl; ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } if (bothConst) { - // if(1) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 53" << std::endl; return HandleBitwiseOperationOnTypes(leftType, rightType, operationType); } @@ -478,8 +463,6 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater( } if (promotedType == nullptr && !bothConst) { - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 6" << std::endl; if ((left->Parent() == right->Parent()) && (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { @@ -657,13 +640,9 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, checker::Type *const rightType = right->Check(this); if ((leftType == nullptr) || (rightType == nullptr)) { if (checkIfBitSet(left) || checkIfBitSet(right)) { - if (1) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] set it to update AST later!" << std::endl; expr->SetPostBit(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return {nullptr, nullptr}; } else { - if (1) - std::cout << "Erroneos expression:" << expr->DumpJSON() << std::endl; ThrowTypeError("Unexpected type error in binary expression", pos); } } -- Gitee From 1875d72e9ac43cea1b076757b0af61b7b7d537f3 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 27 Feb 2024 17:09:28 +0300 Subject: [PATCH 42/48] use EnumConstant name instead of EnumConst Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/types/ets/etsEnumType.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index dee7f833a8..d53a8768dc 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -56,7 +56,7 @@ public: static constexpr std::string_view GetIndexMethodName() { - return "std.core.EnumConst.getIndex:i32;"; // TODO(aber) signatures.yaml + return "std.core.EnumConstant.getIndex:i32;"; // TODO(aber) signatures.yaml } private: -- Gitee From 9e914177823f7b3fa5f14653458b534a42e288df Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Wed, 28 Feb 2024 14:04:13 +0300 Subject: [PATCH 43/48] fix erroneous condition Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/helpers.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 570d50c511..ef8fa67a50 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -81,10 +81,10 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) if (0) std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 1" << std::endl; if (expr->IsBinaryExpression() && - (!expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED))) { - ThrowTypeError("Condition must be of possible condition type", expr->Start()); + (expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED))) { + return; } - return; + ThrowTypeError("Condition must be of possible condition type", expr->Start()); } if (unboxedType == GlobalBuiltinVoidType() || unboxedType->IsETSVoidType()) { -- Gitee From 81a03d5ec98e67024ec3c9d93f4be08bfedc44fd Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Tue, 27 Feb 2024 18:35:05 +0300 Subject: [PATCH 44/48] fix coding style issues Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ETSAnalyzer.cpp | 8 +- ets2panda/checker/ets/arithmetic.cpp | 22 +- ets2panda/checker/ets/helpers.cpp | 17 +- ets2panda/checker/ets/typeCreation.cpp | 6 +- ets2panda/checker/types/ets/etsEnumType.cpp | 79 +++--- ets2panda/checker/types/ets/etsEnumType.h | 29 +-- ets2panda/checker/types/ets/etsObjectType.h | 2 +- ets2panda/checker/types/type.h | 19 +- ets2panda/checker/types/typeFlag.h | 6 +- ets2panda/compiler/core/ETSCompiler.cpp | 2 +- ets2panda/compiler/core/ETSGen.cpp | 16 +- ets2panda/compiler/core/ETSGen.h | 2 +- .../lowering/ets/enumLoweringPostPhase.cpp | 91 +++---- .../lowering/ets/enumLoweringPrePhase.cpp | 226 +++++++++--------- ets2panda/ir/astNode.h | 18 +- ets2panda/ir/astNodeFlags.h | 3 +- ets2panda/test/parser/ets/enum10.ets | 2 +- ets2panda/util/declgenEts2Ts.cpp | 2 +- 18 files changed, 250 insertions(+), 300 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 636a311495..a7fcf5a169 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2439,9 +2439,9 @@ checker::Type *ETSAnalyzer::Check(ir::SwitchStatement *st) const validCaseType = true; if (caseType->HasTypeFlag(checker::TypeFlag::CHAR)) { validCaseType = comparedExprType->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL); - } else if (caseType->IsETSEnum2Type() && st->Discriminant()->TsType()->IsETSEnum2Type()) { + } else if (caseType->IsETSEnumType() && st->Discriminant()->TsType()->IsETSEnumType()) { validCaseType = - st->Discriminant()->TsType()->AsETSEnum2Type()->IsSameEnumType(caseType->AsETSEnum2Type()); + st->Discriminant()->TsType()->AsETSEnumType()->IsSameEnumType(caseType->AsETSEnumType()); } else { checker::AssignmentContext( checker->Relation(), st->discriminant_, caseType, unboxedDiscType, it->Test()->Start(), @@ -2597,8 +2597,8 @@ checker::Type *ETSAnalyzer::Check(ir::TSAsExpression *expr) const } // NOTE: this is to address spec/enum/issue14636_1.ets test failure - if (targetType->IsETSEnum2Type() && sourceType->IsETSEnum2Type() && - targetType->AsETSEnum2Type()->IsSameEnumType(sourceType->AsETSEnum2Type())) { + if (targetType->IsETSEnumType() && sourceType->IsETSEnumType() && + targetType->AsETSEnumType()->IsSameEnumType(sourceType->AsETSEnumType())) { extraFlags |= TypeRelationFlag::NO_THROW; } diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 44ff07c8e5..ee1d50e930 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -314,7 +314,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: if (promotedType == nullptr && !bothConst) { if ((left->Parent() == right->Parent()) && (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && - (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { + (rightType->IsETSEnumType() || leftType->IsETSEnumType())) { left->Parent()->SetPostBit(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return nullptr; } @@ -383,8 +383,8 @@ std::tuple ETSChecker::CheckBinaryOperatorEqual( { checker::Type *tsType {}; - if (leftType->IsETSEnum2Type() && rightType->IsETSEnum2Type()) { - if (!leftType->AsETSEnum2Type()->IsSameEnumType(rightType->AsETSEnum2Type())) { + if (leftType->IsETSEnumType() && rightType->IsETSEnumType()) { + if (!leftType->AsETSEnumType()->IsSameEnumType(rightType->AsETSEnumType())) { ThrowTypeError("Bad operand type, the types of the operands must be the same enum type.", pos); } @@ -465,7 +465,7 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater( if (promotedType == nullptr && !bothConst) { if ((left->Parent() == right->Parent()) && (!left->Parent()->IsPostBitSet(ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) && - (rightType->IsETSEnum2Type() || leftType->IsETSEnum2Type())) { + (rightType->IsETSEnumType() || leftType->IsETSEnumType())) { left->Parent()->SetPostBit(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return {nullptr, nullptr}; } @@ -623,13 +623,10 @@ static std::tuple CheckBinaryOperatorHelper(ETSChecker *checker, return {tsType, tsType}; } -static bool checkIfBitSet(ir::Expression *expr) +bool CheckIfBitSet(ir::Expression *expr) { - if (expr->IsBinaryExpression() && - expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) { - return true; - } - return false; + return (expr->IsBinaryExpression() && + expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED)); } std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, ir::Expression *right, @@ -639,12 +636,11 @@ std::tuple ETSChecker::CheckBinaryOperator(ir::Expression *left, checker::Type *const leftType = left->Check(this); checker::Type *const rightType = right->Check(this); if ((leftType == nullptr) || (rightType == nullptr)) { - if (checkIfBitSet(left) || checkIfBitSet(right)) { + if (CheckIfBitSet(left) || CheckIfBitSet(right)) { expr->SetPostBit(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED); return {nullptr, nullptr}; - } else { - ThrowTypeError("Unexpected type error in binary expression", pos); } + ThrowTypeError("Unexpected type error in binary expression", pos); } const bool isLogicalExtendedOperator = diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index ef8fa67a50..e2e0490de3 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -78,8 +78,6 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) auto *unboxedType = ETSBuiltinTypeAsConditionalType(type); if (unboxedType == nullptr) { - if (0) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 1" << std::endl; if (expr->IsBinaryExpression() && (expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED))) { return; @@ -92,12 +90,7 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) } if (!unboxedType->IsConditionalExprType()) { - if (0) - std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] got 2" << std::endl; - if (expr->IsBinaryExpression() && - (!expr->AsBinaryExpression()->IsPostBitSet(ir::ENUM_LOWERING_POST_PROCESSING_REQUIRED))) { - ThrowTypeError("Condition must be of possible condition type", expr->Start()); - } + ThrowTypeError("Condition must be of possible condition type", expr->Start()); } if (unboxedType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { @@ -1977,10 +1970,10 @@ void ETSChecker::CheckForSameSwitchCases(ArenaVector continue; } - if (caseTest->TsType()->IsETSEnum2Type()) { - ASSERT(compareCaseTest->TsType()->IsETSEnum2Type()); - if (caseTest->TsType()->AsETSEnum2Type()->IsSameEnumLiteralType( - compareCaseTest->TsType()->AsETSEnum2Type())) { + if (caseTest->TsType()->IsETSEnumType()) { + ASSERT(compareCaseTest->TsType()->IsETSEnumType()); + if (caseTest->TsType()->AsETSEnumType()->IsSameEnumLiteralType( + compareCaseTest->TsType()->AsETSEnumType())) { ThrowTypeError("Case enum duplicate", caseTest->Start()); } continue; diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index b22ee024e7..3580100c67 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -365,7 +365,7 @@ ETSObjectType *ETSChecker::CreateETSObjectType(util::StringView name, ir::AstNod return objType; } -bool isEnumClass(ir::AstNode *declNode) +bool IsEnumClass(ir::AstNode *declNode) { if (declNode->IsClassDefinition() && (declNode->AsClassDefinition()->Super() != nullptr) && declNode->AsClassDefinition()->Super()->IsETSTypeReference()) { @@ -431,8 +431,8 @@ ETSObjectType *ETSChecker::CreateNewETSObjectType(util::StringView name, ir::Ast ; } - if (isEnumClass(declNode)) { - auto ret = Allocator()->New(this, name, assemblerName, declNode, flags, Relation()); + if (IsEnumClass(declNode)) { + auto ret = Allocator()->New(this, name, assemblerName, declNode, flags, Relation()); return ret; } diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index 78b146a111..d0818d4ff2 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -29,59 +29,59 @@ std::string EnumDescription(util::StringView name) return "#Enum#" + static_cast(name); } -ETSEnum2Type::ETSEnum2Type(ETSChecker *checker, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags, TypeRelation *relation) - : ETSObjectType(checker->Allocator(), name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2, relation) +ETSEnumType::ETSEnumType(ETSChecker *checker, util::StringView name, util::StringView assemblerName, + ir::AstNode *declNode, ETSObjectFlags flags, TypeRelation *relation) + : ETSObjectType(checker->Allocator(), name, assemblerName, declNode, flags | ETSObjectFlags::ENUM2, relation) { - AddTypeFlag(TypeFlag::ETS_ENUM2); - CreateLiteralTypes(checker, name, assembler_name, decl_node, flags, relation); + AddTypeFlag(TypeFlag::ETS_ENUM); + CreateLiteralTypes(checker, name, assemblerName, declNode, flags, relation); } -ETSEnum2Type::ETSEnum2Type(ArenaAllocator *allocator, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value, TypeRelation *relation) - : ETSObjectType(allocator, name, assembler_name, decl_node, flags | ETSObjectFlags::ENUM2, relation), value_(value) +ETSEnumType::ETSEnumType(ArenaAllocator *allocator, util::StringView name, util::StringView assemblerName, + ir::AstNode *declNode, ETSObjectFlags flags, ir::Literal *value, TypeRelation *relation) + : ETSObjectType(allocator, name, assemblerName, declNode, flags | ETSObjectFlags::ENUM2, relation), value_(value) { - AddTypeFlag(TypeFlag::ETS_ENUM2); + AddTypeFlag(TypeFlag::ETS_ENUM); ASSERT(value); } -bool ETSEnum2Type::IsSameEnumType(const ETSEnum2Type *const other) const noexcept +bool ETSEnumType::IsSameEnumType(const ETSEnumType *const other) const noexcept { return GetDeclNode() != nullptr && other->GetDeclNode() == GetDeclNode(); } -bool ETSEnum2Type::IsLiteralType() const noexcept +bool ETSEnumType::IsLiteralType() const noexcept { return value_ != nullptr; } -bool ETSEnum2Type::IsSameEnumLiteralType(const ETSEnum2Type *other) const noexcept +bool ETSEnumType::IsSameEnumLiteralType(const ETSEnumType *other) const noexcept { ASSERT(IsLiteralType() && IsSameEnumType(other)); return value_ == other->value_; } -bool ETSEnum2Type::AssignmentSource(TypeRelation *const relation, Type *const target) +bool ETSEnumType::AssignmentSource(TypeRelation *const relation, Type *const target) { - bool result = target->IsETSEnum2Type() && IsSameEnumType(target->AsETSEnum2Type()); + bool result = target->IsETSEnumType() && IsSameEnumType(target->AsETSEnumType()); relation->Result(result); return relation->IsTrue(); } -void ETSEnum2Type::AssignmentTarget(TypeRelation *const relation, Type *const source) +void ETSEnumType::AssignmentTarget(TypeRelation *const relation, Type *const source) { - bool result = source->IsETSEnum2Type() && IsSameEnumType(source->AsETSEnum2Type()); + bool result = source->IsETSEnumType() && IsSameEnumType(source->AsETSEnumType()); relation->Result(result); } -void ETSEnum2Type::Identical(TypeRelation *const relation, Type *const other) +void ETSEnumType::Identical(TypeRelation *const relation, Type *const other) { bool result = - other->IsETSEnum2Type() && IsSameEnumType(other->AsETSEnum2Type()) && value_ == other->AsETSEnum2Type()->value_; + other->IsETSEnumType() && IsSameEnumType(other->AsETSEnumType()) && value_ == other->AsETSEnumType()->value_; relation->Result(result); } -void ETSEnum2Type::Cast(TypeRelation *relation, Type *target) +void ETSEnumType::Cast(TypeRelation *relation, Type *target) { if (target->IsIntType()) { relation->Result(true); @@ -91,32 +91,33 @@ void ETSEnum2Type::Cast(TypeRelation *relation, Type *target) conversion::Forbidden(relation); } -void ETSEnum2Type::CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags, TypeRelation *relation) +void ETSEnumType::CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assemblerName, + ir::AstNode *declNode, ETSObjectFlags flags, TypeRelation *relation) { - ASSERT(decl_node->IsClassDefinition()); + const int32_t argsCount = 4; + const int32_t argIdx = 2; - for (auto &it : decl_node->AsClassDefinition()->Body()) { + ASSERT(declNode->IsClassDefinition()); + + for (auto &it : declNode->AsClassDefinition()->Body()) { if (!it->IsClassProperty() || !it->AsClassProperty()->Value()->IsCallExpression()) { // arr property - auto *arr_ident = it->AsClassProperty()->Id(); - auto *arr_var = arr_ident->Variable(); - ASSERT(arr_ident->Name() == "arr" && arr_var != nullptr); + auto *arrIdent = it->AsClassProperty()->Id(); + auto *arrVar = arrIdent->Variable(); + ASSERT(arrIdent->Name() == "arr" && arrVar != nullptr); - auto *array_type = checker->CreateETSArrayType(this); - array_type->SetVariable(arr_var); - arr_var->SetTsType(array_type); + auto *arrayType = checker->CreateETSArrayType(this); + arrayType->SetVariable(arrVar); + arrVar->SetTsType(arrayType); break; } - // if (decl_node->IsClassDefinition()) continue; - auto *ident = it->AsClassProperty()->Id(); auto *var = ident->Variable(); - auto &create_args = it->AsClassProperty()->Value()->AsCallExpression()->Arguments(); - ASSERT(create_args.size() == 4); - auto *value = create_args[2]; + auto &createArgs = it->AsClassProperty()->Value()->AsCallExpression()->Arguments(); + ASSERT(createArgs.size() == argsCount); + auto *value = createArgs[argIdx]; ir::Literal *literal = nullptr; if (value->IsNumberLiteral()) { @@ -127,13 +128,13 @@ void ETSEnum2Type::CreateLiteralTypes(ETSChecker *checker, util::StringView name UNREACHABLE(); } - auto *enum_literal_type = Allocator()->New(checker->Allocator(), name, assembler_name, decl_node, - flags, literal, relation); + auto *enumLiteraltype = Allocator()->New(checker->Allocator(), name, assemblerName, declNode, + flags, literal, relation); - enum_literal_type->SetVariable(var); - var->SetTsType(enum_literal_type); + enumLiteraltype->SetVariable(var); + var->SetTsType(enumLiteraltype); - checker->GetSuperType(enum_literal_type); + checker->GetSuperType(enumLiteraltype); } } } // namespace ark::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index d53a8768dc..7b47f80b5d 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -21,32 +21,23 @@ #include "ir/ts/tsEnumDeclaration.h" #include "checker/types/ets/etsObjectType.h" -template -// NOLINTNEXTLINE(readability-identifier-naming) -inline constexpr bool dependent_false_v = false; - -namespace ark::es2panda::varbinder { -class LocalVariable; -} // namespace ark::es2panda::varbinder - namespace ark::es2panda::checker { std::string EnumDescription(util::StringView name); -// TODO(aber) rename ETSEnum2Type after removal old code -class ETSEnum2Type : public ETSObjectType { +class ETSEnumType : public ETSObjectType { public: - ETSEnum2Type(ETSChecker *checker, util::StringView name, util::StringView assembler_name, ir::AstNode *decl_node, - ETSObjectFlags flags, TypeRelation *relation); + ETSEnumType(ETSChecker *checker, util::StringView name, util::StringView assemblerName, ir::AstNode *declNode, + ETSObjectFlags flags, TypeRelation *relation); - ETSEnum2Type(ArenaAllocator *allocator, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags, ir::Literal *value, TypeRelation *relation); + ETSEnumType(ArenaAllocator *allocator, util::StringView name, util::StringView assemblerName, ir::AstNode *declNode, + ETSObjectFlags flags, ir::Literal *value, TypeRelation *relation); - bool IsSameEnumType(const ETSEnum2Type *other) const noexcept; + bool IsSameEnumType(const ETSEnumType *other) const noexcept; bool IsLiteralType() const noexcept; - bool IsSameEnumLiteralType(const ETSEnum2Type *other) const noexcept; + bool IsSameEnumLiteralType(const ETSEnumType *other) const noexcept; bool AssignmentSource(TypeRelation *relation, Type *target) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; @@ -56,12 +47,12 @@ public: static constexpr std::string_view GetIndexMethodName() { - return "std.core.EnumConstant.getIndex:i32;"; // TODO(aber) signatures.yaml + return "std.core.EnumConstant.getIndex:i32;"; // NOTE(aber) signatures.yaml } private: - void CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assembler_name, - ir::AstNode *decl_node, ETSObjectFlags flags, TypeRelation *relation); + void CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assemblerName, + ir::AstNode *declNode, ETSObjectFlags flags, TypeRelation *relation); ir::Literal *value_ = nullptr; }; diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index ca9235e4ce..4c23615409 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -56,7 +56,7 @@ enum class ETSObjectFlags : uint32_t { BUILTIN_FLOAT = 1U << 30U, BUILTIN_DOUBLE = 1U << 31U, - ENUM2 = 1U << 21U, // TODO(aber) rename after removal code with ENUM (is it needed at all?!) + ENUM2 = 1U << 21U, // NOTE(aber) rename after removal code with ENUM UNBOXABLE_TYPE = BUILTIN_BOOLEAN | BUILTIN_BYTE | BUILTIN_CHAR | BUILTIN_SHORT | BUILTIN_INT | BUILTIN_LONG | BUILTIN_FLOAT | BUILTIN_DOUBLE, diff --git a/ets2panda/checker/types/type.h b/ets2panda/checker/types/type.h index ae910c525a..67ff266dc6 100644 --- a/ets2panda/checker/types/type.h +++ b/ets2panda/checker/types/type.h @@ -37,7 +37,7 @@ class ETSAsyncFuncReturnType; class ETSChecker; class ETSDynamicFunctionType; class ETSTypeParameter; -class ETSEnum2Type; +class ETSEnumType; // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DECLARE_TYPENAMES(typeFlag, typeName) class typeName; @@ -134,22 +134,21 @@ public: return reinterpret_cast(this); } - // TODO(aber) rename after - bool IsETSEnum2Type() const + bool IsETSEnumType() const { - return IsETSObjectType() && HasTypeFlag(TypeFlag::ETS_ENUM2); + return IsETSObjectType() && HasTypeFlag(TypeFlag::ETS_ENUM); } - ETSEnum2Type *AsETSEnum2Type() + ETSEnumType *AsETSEnumType() { - ASSERT(IsETSEnum2Type()); - return reinterpret_cast(this); + ASSERT(IsETSEnumType()); + return reinterpret_cast(this); } - const ETSEnum2Type *AsETSEnum2Type() const + const ETSEnumType *AsETSEnumType() const { - ASSERT(IsETSEnum2Type()); - return reinterpret_cast(this); + ASSERT(IsETSEnumType()); + return reinterpret_cast(this); } ETSAsyncFuncReturnType *AsETSAsyncFuncReturnType() diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index 7994f06d40..a5e3610897 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -82,13 +82,13 @@ enum class TypeFlag : uint64_t { ETS_NULL = 1ULL << 57ULL, // ETS null ETS_UNDEFINED = 1ULL << 58ULL, // ETS undefined ETS_NONNULLISH = 1ULL << 59ULL, // ETS nonnullish type parameter - ETS_ENUM2 = 1ULL << 60ULL, // ETS Enum TODO(aber) rename after removal old + ETS_ENUM = 1ULL << 60ULL, // ETS Enum ETS_DYNAMIC_TYPE = ETS_OBJECT | ETS_DYNAMIC_FLAG, - ETS_ENUM2_TYPE = ETS_OBJECT | ETS_ENUM2, // ETS Enum TODO(aber) rename + ETS_ENUM_TYPE = ETS_OBJECT | ETS_ENUM, // ETS Enum type ETS_DYNAMIC_FUNCTION_TYPE = FUNCTION | ETS_DYNAMIC_FLAG, ETS_TYPE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID | ETS_OBJECT | ETS_ARRAY | WILDCARD | ETS_TYPE_PARAMETER | ETS_DYNAMIC_TYPE | ETS_UNION | ETS_NULL | ETS_UNDEFINED | - ETS_NONNULLISH | ETS_ENUM2_TYPE, + ETS_NONNULLISH | ETS_ENUM_TYPE, ETS_PRIMITIVE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID, ETS_PRIMITIVE_RETURN = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN, ETS_ARRAY_INDEX = BYTE | SHORT | INT, diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 8a18432b7d..ded9c7b01f 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -1979,7 +1979,7 @@ void ETSCompiler::CompileCast(const ir::TSAsExpression *expr) const case checker::TypeFlag::ETS_UNION: case checker::TypeFlag::ETS_NULL: case checker::TypeFlag::ETS_UNDEFINED: - case checker::TypeFlag::ETS_ENUM2_TYPE: { + case checker::TypeFlag::ETS_ENUM_TYPE: { etsg->CastToReftype(expr, targetType, expr->isUncheckedCast_); break; } diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 2a9d594b3d..de3481e6b7 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -650,10 +650,10 @@ void ETSGen::CreateLambdaObjectFromMemberReference(const ir::AstNode *node, ir:: } // NOLINTBEGIN(cppcoreguidelines-macro-usage, readability-container-size-empty) -#define CONV_LAMBDA_CTOR_ARG(idx) \ - ASSERT((idx) < arguments.size()); \ - auto *paramType##idx = signature->Params()[(idx)] -> TsType(); \ - auto ttctx##idx = TargetTypeContext(this, paramType##idx); \ +#define CONV_LAMBDA_CTOR_ARG(idx) \ + ASSERT((idx) < arguments.size()); \ + auto *paramType##idx = signature->Params()[(idx)]->TsType(); \ + auto ttctx##idx = TargetTypeContext(this, paramType##idx); \ ApplyConversion(node, paramType##idx) void ETSGen::InitLambdaObject(const ir::AstNode *node, checker::Signature *signature, std::vector &arguments) @@ -1716,11 +1716,11 @@ void ETSGen::CastToInt(const ir::AstNode *node) Sa().Emit(node); break; } - case checker::TypeFlag::ETS_ENUM2_TYPE: { + case checker::TypeFlag::ETS_ENUM_TYPE: { RegScope rs(this); VReg objReg = AllocReg(); StoreAccumulator(node, objReg); - Ra().Emit(node, checker::ETSEnum2Type::GetIndexMethodName(), objReg, dummyReg_); + Ra().Emit(node, checker::ETSEnumType::GetIndexMethodName(), objReg, dummyReg_); break; } @@ -2588,7 +2588,7 @@ void ETSGen::LoadArrayElement(const ir::AstNode *node, VReg objectReg) break; } // WARNING: this seems to fix assert bu cause later run-time verifier failures - case checker::TypeFlag::ETS_ENUM2_TYPE: { + case checker::TypeFlag::ETS_ENUM_TYPE: { Ra().Emit(node, objectReg); break; } @@ -2634,7 +2634,7 @@ void ETSGen::StoreArrayElement(const ir::AstNode *node, VReg objectReg, VReg ind case checker::TypeFlag::ETS_OBJECT: case checker::TypeFlag::ETS_TYPE_PARAMETER: case checker::TypeFlag::ETS_UNION: - case checker::TypeFlag::ETS_ENUM2_TYPE: + case checker::TypeFlag::ETS_ENUM_TYPE: case checker::TypeFlag::ETS_DYNAMIC_TYPE: { Ra().Emit(node, objectReg, index); break; diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 13d0768d12..9212ecc42b 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -743,7 +743,7 @@ private: BinaryNumberComparison(node, lhs, ifFalse); break; } - case checker::TypeFlag::ETS_ENUM2_TYPE: + case checker::TypeFlag::ETS_ENUM_TYPE: case checker::TypeFlag::ETS_BOOLEAN: case checker::TypeFlag::BYTE: case checker::TypeFlag::CHAR: diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index 2e8687d537..780d8a3695 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -30,18 +30,18 @@ namespace ark::es2panda::compiler { -const char *ENUM_GETVALUE_METHOD_NAME = "getValue"; +const char *g_enumGetvalueMethodName = "getValue"; ir::CallExpression *CreateCallExpression(ir::Expression *id, checker::ETSChecker *checker) { - auto *const callee = checker->AllocNode(ENUM_GETVALUE_METHOD_NAME, checker->Allocator()); + auto *const callee = checker->AllocNode(g_enumGetvalueMethodName, checker->Allocator()); callee->SetReference(); ir::Expression *const accessor = checker->AllocNode(id, callee, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); id->SetParent(accessor); callee->SetParent(accessor); - ir::CallExpression *callExpression = checker->AllocNode( + auto *callExpression = checker->AllocNode( accessor, ArenaVector(checker->Allocator()->Adapter()), nullptr, false); accessor->SetParent(callExpression); return callExpression; @@ -70,25 +70,19 @@ ir::Expression *CreateTestExpression(ir::Identifier *id, CompilerContext *ctx, i return testExpr; } -ir::Expression *checkBinaryBranch(ir::Expression *ast, CompilerContext *ctx) +ir::Expression *CheckBinaryBranch(ir::Expression *ast, CompilerContext *ctx) { auto updateExpression = [ctx](ir::Expression *object, ir::Expression *ast) -> ir::Expression * { if (object->IsIdentifier() && object->AsIdentifier()->Variable() != nullptr) { - // .. auto *checker = ctx->Checker()->AsETSChecker(); auto *type = checker->GetTypeOfVariable(object->AsIdentifier()->Variable()); ASSERT(type != nullptr); - if (!type->IsETSEnum2Type()) { - if (0) - std::cout << "[DEBUG] Not a ETSEnum2Type object!" << std::endl; + if (!type->IsETSEnumType()) { return ast; } - if (0) - std::cout << "[DEBUG] Found ETSEnum2Type identifier!" << std::endl; - auto *callExpr = - CreateCallExpression(ast /*->AsMemberExpression()->Clone(checker->Allocator(), nullptr)*/, checker); + auto *callExpr = CreateCallExpression(ast, checker); return callExpr; } @@ -96,22 +90,18 @@ ir::Expression *checkBinaryBranch(ir::Expression *ast, CompilerContext *ctx) }; if (ast->IsMemberExpression()) { // i.e. we have following: - // enum Color {Red, Blue, Green, Yellow}; + // 'enum Color {Red, Blue, Green, Yellow}' // - // so for such 'imcomplete' accessors like - // Color.Red + // so for such 'imcomplete' accessors like: + // 'Color.Red' // // we'd need to replace it with - // color.Red.getValue() + // 'color.Red.getValue()' if (auto *object = ast->AsMemberExpression()->Object(); object != nullptr) { - // .. return updateExpression(object, ast); } } else if (ast->IsIdentifier()) { return updateExpression(ast->AsIdentifier(), ast); - } else { - if (0) - std::cout << "[DEBUG] Neither MemberExpression nor identifier!" << std::endl; } return ast; } @@ -123,9 +113,9 @@ ir::AstNode *UpdateMemberExpression(ir::AstNode *ast, CompilerContext *ctx) ASSERT(scope != nullptr); auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); - ast->AsBinaryExpression()->SetLeft(checkBinaryBranch( + ast->AsBinaryExpression()->SetLeft(CheckBinaryBranch( ast->AsBinaryExpression()->Left()->Clone(checker->Allocator(), nullptr)->AsExpression(), ctx)); - ast->AsBinaryExpression()->SetRight(checkBinaryBranch( + ast->AsBinaryExpression()->SetRight(CheckBinaryBranch( ast->AsBinaryExpression()->Right()->Clone(checker->Allocator(), nullptr)->AsExpression(), ctx)); InitScopesPhaseETS::RunExternalNode(ast, ctx->VarBinder()); @@ -142,63 +132,50 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p [[maybe_unused]] checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - for (auto &[_, ext_programs] : program->ExternalSources()) { + for (auto &[_, extPrograms] : program->ExternalSources()) { (void)_; - for (auto *ext_prog : ext_programs) { - Perform(ctx, ext_prog); + for (auto *extProg : extPrograms) { + Perform(ctx, extProg); } } program->Ast()->TransformChildrenRecursively([checker, ctx](ir::AstNode *ast) -> ir::AstNode * { - if (ast->IsCallExpression()) { - // check & update call expression with explicit cast to new type - // e.g. for the following - // - // enum Color {Red, Blue, Green, Yellow}; - // function foo(a:Color) {..} - // function main():void { - // foo(1); - // } - // - // so the foo(1) should be translated to foo(Color.Blue) - } else if (ast->IsBinaryExpression()) { + if (ast->IsBinaryExpression()) { if (ast->AsBinaryExpression()->IsPostBitSet( ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) { return UpdateMemberExpression(ast, ctx->compilerContext); - } else { - // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] Skip this one, no need to update!" << - // std::endl; - return ast; } - } else if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || - ast->IsForUpdateStatement() || ast->IsConditionalExpression()) { - // so far let's put this only for test script + return ast; + } + if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || + ast->IsForUpdateStatement() || ast->IsConditionalExpression()) { ir::Expression *test = nullptr; ir::Expression *testExpr = nullptr; - if (ast->IsIfStatement()) + if (ast->IsIfStatement()) { test = ast->AsIfStatement()->Test(); - if (ast->IsWhileStatement()) + } else if (ast->IsWhileStatement()) { test = ast->AsWhileStatement()->Test(); - if (ast->IsDoWhileStatement()) + } else if (ast->IsDoWhileStatement()) { test = ast->AsDoWhileStatement()->Test(); - if (ast->IsForUpdateStatement()) + } else if (ast->IsForUpdateStatement()) { test = ast->AsForUpdateStatement()->Test(); - if (ast->IsConditionalExpression()) + } else if (ast->IsConditionalExpression()) { test = ast->AsConditionalExpression()->Test(); + } if (test == nullptr) { return ast; } if (test->IsIdentifier()) { - // we got simple variable test expression, test against non-zero value + // we got simple variable test expression, test against non-zero value if (test->AsIdentifier()->Variable() == nullptr) { return ast; } auto *type = checker->GetTypeOfVariable(test->AsIdentifier()->Variable()); ASSERT(type != nullptr); - if (!type->IsETSEnum2Type()) { + if (!type->IsETSEnumType()) { return ast; } // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' @@ -208,7 +185,7 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } else if (test->IsCallExpression()) { // simple call expression with default non-zero test, i.e. // - // if (v.getValue()) + // 'if (v.getValue())' // // this wll always be treated as 'true' since getValue() returns the EnumConst // object,but not the enum value @@ -216,7 +193,7 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p // need to checkif we're calling to getValue() for enum constant // and convert it into binary expression with '!= 0' test, i.e. // - // if (v.getValue() != 0) + // 'if (v.getValue() != 0)' // // same for loop expressions. // @@ -230,13 +207,13 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } auto *type = checker->GetTypeOfVariable(id->Variable()); ASSERT(type != nullptr); - if (!type->IsETSEnum2Type()) { - return ast; // do not modify it, it is not ETSEnum2Type + if (!type->IsETSEnumType()) { + return ast; } if (ir::Expression *prop = callee->AsMemberExpression()->Property(); prop != nullptr) { - if (prop->IsIdentifier() && (prop->AsIdentifier()->Name() == ENUM_GETVALUE_METHOD_NAME)) { - // now we need tow rap it to the binary expression .. != 0 + if (prop->IsIdentifier() && (prop->AsIdentifier()->Name() == g_enumGetvalueMethodName)) { + // now we need to wrap it to the binary expression .. != 0 testExpr = CreateTestExpression(prop->AsIdentifier(), ctx->compilerContext, test->AsCallExpression()); } diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index 0a94c65bb5..1ff66d4e63 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -32,12 +32,11 @@ namespace ark::es2panda::compiler { -// const char* EnumConstantClassName = "EnumConst"; -const char *ENUM_INT_BASE_CLASS_NAME = "EnumIntType"; -const char *ENUM_STR_BASE_CLASS_NAME = "EnumStrType"; -const char *ENUM_CONSTANT_CREATE_METHOD_NAME = "create"; -const char *ENUM_VALUE_OF_LIB_FUNCTION_NAME = "enumValueOf"; -const char *ENUM_CONSTANT_ARRAY_NAME = "arr"; +const char *g_enumIntBaseClassName = "EnumIntType"; +const char *g_enumStrBaseClassName = "EnumStrType"; +const char *g_enumConstantCreateMethodName = "create"; +const char *g_enumValueOfLibFunctionName = "enumValueOf"; +const char *g_enumConstantArrayName = "arr"; ir::Identifier *CreateIdentifierRef(util::StringView const name, checker::ETSChecker *checker) { @@ -48,44 +47,44 @@ ir::Identifier *CreateIdentifierRef(util::StringView const name, checker::ETSChe auto CreateETSTypeReference(util::StringView const name, checker::ETSChecker *checker) { - auto *name_ident = CreateIdentifierRef(name, checker); - auto *reference_part = checker->AllocNode(name_ident); - return checker->AllocNode(reference_part); + auto *nameIdent = CreateIdentifierRef(name, checker); + auto *referencePart = checker->AllocNode(nameIdent); + return checker->AllocNode(referencePart); } -auto CreateETSParameterExpression(util::StringView const par_name, util::StringView const type_name, +auto CreateETSParameterExpression(util::StringView const parName, util::StringView const typeName, checker::ETSChecker *checker) { - auto *type_annot = CreateETSTypeReference(type_name, checker); - auto *name = checker->AllocNode(par_name, type_annot, checker->Allocator()); + auto *typeAnnot = CreateETSTypeReference(typeName, checker); + auto *name = checker->AllocNode(parName, typeAnnot, checker->Allocator()); return checker->AllocNode(name, nullptr); } -ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enum_name, - ir::TSTypeParameterInstantiation *tp_par_inst, checker::ETSChecker *checker) +ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enumName, ir::TSTypeParameterInstantiation *tpParInst, + checker::ETSChecker *checker) { ArenaVector params(checker->Allocator()->Adapter()); params.push_back(CreateETSParameterExpression("name", "string", checker)); - auto *ret_type = CreateETSTypeReference(enum_name, checker); + auto *retType = CreateETSTypeReference(enumName, checker); ArenaVector statements(checker->Allocator()->Adapter()); ArenaVector args(checker->Allocator()->Adapter()); - auto *arg0_obj = CreateIdentifierRef(enum_name, checker); - auto *arg0_prop = CreateIdentifierRef(ENUM_CONSTANT_ARRAY_NAME, checker); - args.push_back(checker->AllocNode(arg0_obj, arg0_prop, + auto *arg0Obj = CreateIdentifierRef(enumName, checker); + auto *arg0Prop = CreateIdentifierRef(g_enumConstantArrayName, checker); + args.push_back(checker->AllocNode(arg0Obj, arg0Prop, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false)); auto *arg1 = CreateIdentifierRef("name", checker); args.push_back(arg1); - auto *callee = CreateIdentifierRef(ENUM_VALUE_OF_LIB_FUNCTION_NAME, checker); - auto *express = checker->AllocNode(std::move(callee), std::move(args), tp_par_inst, false); - auto *argument = checker->AllocNode(std::move(express), ret_type, false); - statements.push_back(checker->AllocNode(std::move(argument))); + auto *callee = CreateIdentifierRef(g_enumValueOfLibFunctionName, checker); + auto *express = checker->AllocNode(callee, std::move(args), tpParInst, false); + auto *argument = checker->AllocNode(express, retType, false); + statements.push_back(checker->AllocNode(argument)); auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); auto *func = checker->AllocNode( - ir::FunctionSignature(nullptr, std::move(params), ret_type->Clone(checker->Allocator(), nullptr)), body, + ir::FunctionSignature(nullptr, std::move(params), retType->Clone(checker->Allocator(), nullptr)), body, ir::ScriptFunctionFlags::HAS_RETURN | ir::ScriptFunctionFlags::THROWS, false, Language(Language::Id::ETS)); func->AddModifier(ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC); auto *key = checker->AllocNode("valueOf", checker->Allocator()); @@ -102,34 +101,33 @@ ir::MethodDefinition *CreateMethodValueOf(const util::StringView &enum_name, return method; } -ir::MethodDefinition *CreateMethodCreate(const util::StringView &enum_name, bool is_int_enum, - checker::ETSChecker *checker) +ir::MethodDefinition *CreateMethodCreate(const util::StringView &enumName, bool isIntEnum, checker::ETSChecker *checker) { auto id = checker->AllocNode("ret", checker->Allocator()); auto init = checker->AllocNode( - CreateETSTypeReference(enum_name, checker), ArenaVector(checker->Allocator()->Adapter()), + CreateETSTypeReference(enumName, checker), ArenaVector(checker->Allocator()->Adapter()), nullptr); auto declarator = checker->AllocNode(ir::VariableDeclaratorFlag::LET, id, init); ArenaVector declarators(checker->Allocator()->Adapter()); - declarators.push_back(std::move(declarator)); + declarators.push_back(declarator); - auto var_kind = ir::VariableDeclaration::VariableDeclarationKind::LET; - auto *var_decl = - checker->AllocNode(var_kind, checker->Allocator(), std::move(declarators), false); + auto varKind = ir::VariableDeclaration::VariableDeclarationKind::LET; + auto *varDecl = + checker->AllocNode(varKind, checker->Allocator(), std::move(declarators), false); ArenaVector statements(checker->Allocator()->Adapter()); - statements.push_back(std::move(var_decl)); + statements.push_back(varDecl); - auto *callee_obj = CreateIdentifierRef("ret", checker); - auto *callee_prop = CreateIdentifierRef("init", checker); - auto *callee = checker->AllocNode(std::move(callee_obj), std::move(callee_prop), + auto *calleeObj = CreateIdentifierRef("ret", checker); + auto *calleeProp = CreateIdentifierRef("init", checker); + auto *callee = checker->AllocNode(calleeObj, calleeProp, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); ArenaVector args(checker->Allocator()->Adapter()); args.push_back(CreateIdentifierRef("typ", checker)); args.push_back(CreateIdentifierRef("name", checker)); args.push_back(CreateIdentifierRef("val", checker)); args.push_back(CreateIdentifierRef("idx", checker)); - auto *expression = checker->AllocNode(std::move(callee), std::move(args), nullptr, false); + auto *expression = checker->AllocNode(callee, std::move(args), nullptr, false); statements.push_back(checker->AllocNode(expression)); statements.push_back(checker->AllocNode(CreateIdentifierRef("ret", checker))); @@ -139,35 +137,35 @@ ir::MethodDefinition *CreateMethodCreate(const util::StringView &enum_name, bool ArenaVector params(checker->Allocator()->Adapter()); params.push_back(CreateETSParameterExpression("typ", "string", checker)); params.push_back(CreateETSParameterExpression("name", "string", checker)); - params.push_back(CreateETSParameterExpression("val", is_int_enum ? "Int" : "String", checker)); + params.push_back(CreateETSParameterExpression("val", isIntEnum ? "Int" : "String", checker)); params.push_back(CreateETSParameterExpression("idx", "Int", checker)); auto *func = checker->AllocNode( - ir::FunctionSignature(nullptr, std::move(params), CreateETSTypeReference(enum_name, checker)), body, + ir::FunctionSignature(nullptr, std::move(params), CreateETSTypeReference(enumName, checker)), body, ir::ScriptFunctionFlags::HAS_RETURN, false, Language(Language::Id::ETS)); func->AddModifier(ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE); - auto *key = CreateIdentifierRef(ENUM_CONSTANT_CREATE_METHOD_NAME, checker); + auto *key = CreateIdentifierRef(g_enumConstantCreateMethodName, checker); func->SetIdent(key); auto *value = checker->AllocNode(func); auto flags = ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE; - auto *method = checker->AllocNode( - ir::MethodDefinitionKind::METHOD, std::move(key->Clone(checker->Allocator(), nullptr)->AsIdentifier()), - std::move(value), flags, checker->Allocator(), false); + auto *method = checker->AllocNode(ir::MethodDefinitionKind::METHOD, + key->Clone(checker->Allocator(), nullptr)->AsIdentifier(), + value, flags, checker->Allocator(), false); return method; } -ir::MethodDefinition *CreateMethodValues(const util::StringView &enum_name, checker::ETSChecker *checker) +ir::MethodDefinition *CreateMethodValues(const util::StringView &enumName, checker::ETSChecker *checker) { ArenaVector params(checker->Allocator()->Adapter()); ArenaVector statements(checker->Allocator()->Adapter()); - auto *arg_obj = CreateIdentifierRef(enum_name, checker); - auto *arg_prop = CreateIdentifierRef(ENUM_CONSTANT_ARRAY_NAME, checker); - auto *argument = checker->AllocNode(arg_obj, arg_prop, + auto *argObj = CreateIdentifierRef(enumName, checker); + auto *argProp = CreateIdentifierRef(g_enumConstantArrayName, checker); + auto *argument = checker->AllocNode(argObj, argProp, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); statements.push_back(checker->AllocNode(argument)); auto *body = checker->AllocNode(checker->Allocator(), std::move(statements)); @@ -213,10 +211,10 @@ ir::MethodDefinition *CreateConstructor(checker::ETSChecker *checker) return method; } -ir::MemberExpression *CreateEnumConstantArrayElement(const util::StringView &enum_name, const ir::TSEnumMember *member, +ir::MemberExpression *CreateEnumConstantArrayElement(const util::StringView &enumName, const ir::TSEnumMember *member, checker::ETSChecker *checker) { - auto *object = CreateIdentifierRef(enum_name, checker); + auto *object = CreateIdentifierRef(enumName, checker); auto *prop = CreateIdentifierRef(member->Name(), checker); auto *elem = checker->AllocNode(object, prop, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -224,33 +222,33 @@ ir::MemberExpression *CreateEnumConstantArrayElement(const util::StringView &enu return elem; } -ir::ClassProperty *CreateEnumConstantArray(const util::StringView &enum_name, ArenaVector &&elements, +ir::ClassProperty *CreateEnumConstantArray(const util::StringView &enumName, ArenaVector &&elements, checker::ETSChecker *checker) { - auto *key = checker->AllocNode(ENUM_CONSTANT_ARRAY_NAME, checker->Allocator()); + auto *key = checker->AllocNode(g_enumConstantArrayName, checker->Allocator()); auto *value = checker->AllocNode(std::move(elements), checker->Allocator()); - auto prop_modif = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; + auto propModif = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC; - auto *el_type = CreateETSTypeReference(enum_name, checker); - auto *type_annotation = checker->AllocNode(el_type); + auto *elType = CreateETSTypeReference(enumName, checker); + auto *typeAnnotation = checker->AllocNode(elType); - auto *class_prop = - checker->AllocNode(key, value, type_annotation, prop_modif, checker->Allocator(), false); + auto *classProp = + checker->AllocNode(key, value, typeAnnotation, propModif, checker->Allocator(), false); - return class_prop; + return classProp; } -ir::ClassProperty *CreateEnumConstantClassProperty(const util::StringView &enum_name, const ir::TSEnumMember *member, +ir::ClassProperty *CreateEnumConstantClassProperty(const util::StringView &enumName, const ir::TSEnumMember *member, int idx, checker::ETSChecker *checker) { ArenaVector args(checker->Allocator()->Adapter()); - util::UString enum_desc(checker::EnumDescription(enum_name), checker->Allocator()); - args.push_back(checker->AllocNode(enum_desc.View())); + util::UString enumDesc(checker::EnumDescription(enumName), checker->Allocator()); + args.push_back(checker->AllocNode(enumDesc.View())); - util::UString enum_const_name(member->Name(), checker->Allocator()); - args.push_back(checker->AllocNode(enum_const_name.View())); + util::UString enumConstName(member->Name(), checker->Allocator()); + args.push_back(checker->AllocNode(enumConstName.View())); if (member->Init()->IsNumberLiteral()) { args.push_back(checker->AllocNode(member->Init()->AsNumberLiteral()->Number())); @@ -261,21 +259,21 @@ ir::ClassProperty *CreateEnumConstantClassProperty(const util::StringView &enum_ } args.push_back(checker->AllocNode(lexer::Number(idx))); - auto *callee_obj = CreateIdentifierRef(enum_name, checker); - auto *callee_prop = CreateIdentifierRef(ENUM_CONSTANT_CREATE_METHOD_NAME, checker); - auto *callee = checker->AllocNode(std::move(callee_obj), std::move(callee_prop), + auto *calleeObj = CreateIdentifierRef(enumName, checker); + auto *calleeProp = CreateIdentifierRef(g_enumConstantCreateMethodName, checker); + auto *callee = checker->AllocNode(calleeObj, calleeProp, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - auto *value = checker->AllocNode(std::move(callee), std::move(args), nullptr, false); + auto *value = checker->AllocNode(callee, std::move(args), nullptr, false); - auto prop_modif = + auto propModif = ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC | ir::ModifierFlags::READONLY | ir::ModifierFlags::CONST; - auto *type_annot = CreateETSTypeReference(enum_name, checker); + auto *typeAnnot = CreateETSTypeReference(enumName, checker); auto *key = checker->AllocNode(member->Name(), checker->Allocator()); - auto *class_prop = - checker->AllocNode(key, value, type_annot, prop_modif, checker->Allocator(), false); + auto *classProp = + checker->AllocNode(key, value, typeAnnot, propModif, checker->Allocator(), false); - return class_prop; + return classProp; } void CreateCCtor(ArenaVector &properties, const lexer::SourcePosition &loc, checker::ETSChecker *checker) @@ -293,76 +291,75 @@ void CreateCCtor(ArenaVector &properties, const lexer::SourcePosi func->AddModifier(ir::ModifierFlags::STATIC); func->SetIdent(id); - auto *func_expr = checker->AllocNode(func); - auto *static_block = checker->AllocNode(func_expr, checker->Allocator()); - static_block->AddModifier(ir::ModifierFlags::STATIC); - static_block->SetRange({loc, loc}); - properties.push_back(static_block); + auto *funcExpr = checker->AllocNode(func); + auto *staticBlock = checker->AllocNode(funcExpr, checker->Allocator()); + staticBlock->AddModifier(ir::ModifierFlags::STATIC); + staticBlock->SetRange({loc, loc}); + properties.push_back(staticBlock); } -ir::TSTypeParameterInstantiation *CreateTypeParameterInstantiation(bool is_int_enum, checker::ETSChecker *checker) +ir::TSTypeParameterInstantiation *CreateTypeParameterInstantiation(bool isIntEnum, checker::ETSChecker *checker) { ArenaVector params(checker->Allocator()->Adapter()); - auto *par_part_name = CreateIdentifierRef("", checker); - if (is_int_enum) { - par_part_name->SetName("Int"); + auto *parPartName = CreateIdentifierRef("", checker); + if (isIntEnum) { + parPartName->SetName("Int"); } else { - par_part_name->SetName("string"); + parPartName->SetName("string"); } - auto *par_part = checker->AllocNode(par_part_name); - params.push_back(checker->AllocNode(par_part)); + auto *parPart = checker->AllocNode(parPartName); + params.push_back(checker->AllocNode(parPart)); return checker->AllocNode(std::move(params)); } -ir::AstNode *CreateEnumClassFromEnumDeclaration(ir::TSEnumDeclaration *enum_decl, checker::ETSChecker *checker, - varbinder::ETSBinder * /*varbinder*/, parser::Program * /*program*/) +ir::AstNode *CreateEnumClassFromEnumDeclaration(ir::TSEnumDeclaration *enumDecl, checker::ETSChecker *checker) { - auto &enum_name = enum_decl->Key()->Name(); - auto *ident = checker->AllocNode(enum_name, checker->Allocator()); + auto &enumName = enumDecl->Key()->Name(); + auto *ident = checker->AllocNode(enumName, checker->Allocator()); ArenaVector body(checker->Allocator()->Adapter()); - ArenaVector array_elements(checker->Allocator()->Adapter()); + ArenaVector arrayElements(checker->Allocator()->Adapter()); int idx = 0; - for (auto &member : enum_decl->Members()) { - body.push_back(CreateEnumConstantClassProperty(enum_name, member->AsTSEnumMember(), idx++, checker)); - array_elements.push_back(CreateEnumConstantArrayElement(enum_name, member->AsTSEnumMember(), checker)); + for (auto &member : enumDecl->Members()) { + body.push_back(CreateEnumConstantClassProperty(enumName, member->AsTSEnumMember(), idx++, checker)); + arrayElements.push_back(CreateEnumConstantArrayElement(enumName, member->AsTSEnumMember(), checker)); } - bool is_int_enum = false; - auto member0 = enum_decl->Members()[0]->AsTSEnumMember(); + bool isIntEnum = false; + auto member0 = enumDecl->Members()[0]->AsTSEnumMember(); if (member0->Init()->IsNumberLiteral()) { - is_int_enum = true; + isIntEnum = true; } else if (!member0->Init()->IsStringLiteral()) { UNREACHABLE(); } - auto *tp_par_inst = CreateTypeParameterInstantiation(is_int_enum, checker); + auto *tpParInst = CreateTypeParameterInstantiation(isIntEnum, checker); - body.push_back(CreateEnumConstantArray(enum_name, std::move(array_elements), checker)); + body.push_back(CreateEnumConstantArray(enumName, std::move(arrayElements), checker)); - body.push_back(CreateMethodCreate(enum_name, is_int_enum, checker)); - body.push_back(CreateMethodValues(enum_name, checker)); - body.push_back(CreateMethodValueOf(enum_name, tp_par_inst, checker)); + body.push_back(CreateMethodCreate(enumName, isIntEnum, checker)); + body.push_back(CreateMethodValues(enumName, checker)); + body.push_back(CreateMethodValueOf(enumName, tpParInst, checker)); body.push_back(CreateConstructor(checker)); - CreateCCtor(body, enum_decl->Start(), checker); + CreateCCtor(body, enumDecl->Start(), checker); - auto def_modif = ir::ClassDefinitionModifiers::ID_REQUIRED | ir::ClassDefinitionModifiers::HAS_SUPER | - ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::DECLARATION; - auto *class_def = checker->AllocNode(checker->Allocator(), ident, std::move(body), def_modif, - Language(Language::Id::ETS)); - if (is_int_enum) { - class_def->SetSuper(CreateETSTypeReference(ENUM_INT_BASE_CLASS_NAME, checker)); + auto defModif = ir::ClassDefinitionModifiers::ID_REQUIRED | ir::ClassDefinitionModifiers::HAS_SUPER | + ir::ClassDefinitionModifiers::CLASS_DECL | ir::ClassDefinitionModifiers::DECLARATION; + auto *classDef = checker->AllocNode(checker->Allocator(), ident, std::move(body), defModif, + Language(Language::Id::ETS)); + if (isIntEnum) { + classDef->SetSuper(CreateETSTypeReference(g_enumIntBaseClassName, checker)); } else { - class_def->SetSuper(CreateETSTypeReference(ENUM_STR_BASE_CLASS_NAME, checker)); + classDef->SetSuper(CreateETSTypeReference(g_enumStrBaseClassName, checker)); } - auto *class_decl = checker->AllocNode(class_def, checker->Allocator()); - class_decl->SetRange({enum_decl->Start(), enum_decl->End()}); + auto *classDecl = checker->AllocNode(classDef, checker->Allocator()); + classDecl->SetRange({enumDecl->Start(), enumDecl->End()}); - class_decl->SetParent(enum_decl->Parent()); + classDecl->SetParent(enumDecl->Parent()); - return class_decl; + return classDecl; } bool EnumLoweringPrePhase::Perform(public_lib::Context *ctx, parser::Program *program) @@ -373,17 +370,16 @@ bool EnumLoweringPrePhase::Perform(public_lib::Context *ctx, parser::Program *pr checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - for (auto &[_, ext_programs] : program->ExternalSources()) { + for (auto &[_, extPrograms] : program->ExternalSources()) { (void)_; - for (auto *ext_prog : ext_programs) { - Perform(ctx, ext_prog); + for (auto *extProg : extPrograms) { + Perform(ctx, extProg); } } - program->Ast()->TransformChildrenRecursively([checker, ctx, program](ir::AstNode *ast) -> ir::AstNode * { + program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsTSEnumDeclaration()) { - return CreateEnumClassFromEnumDeclaration(ast->AsTSEnumDeclaration(), checker, - ctx->compilerContext->VarBinder()->AsETSBinder(), program); + return CreateEnumClassFromEnumDeclaration(ast->AsTSEnumDeclaration(), checker); } return ast; }); diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 17dd047ff8..16f84181ec 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -513,22 +513,21 @@ public: // are reffered at the node. based on that the loewring could do some additional transformations // and the must re-start checker again. in order to track that we would use bit register per each // affected lowering. - void SetPostBit(PostProcessingBits bit) - { - post_ |= bit; - // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] bit " << bit << std::endl; - } void ClearPostBit(PostProcessingBits bit) { - // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] bit " << bit << std::endl; post_ &= bit; } + bool IsPostBitSet(PostProcessingBits bit) { - // std::cout << __func__ << ":" << __LINE__ << ": [DEBUG] bit " << bit << std::endl; return (bit & post_) != 0; } + void SetPostBit(PostProcessingBits bit) + { + post_ |= bit; + } + protected: AstNode(AstNode const &other); @@ -545,10 +544,9 @@ protected: ModifierFlags flags_ {}; mutable AstNodeFlags astNodeFlags_ {}; mutable BoxingUnboxingFlags boxingUnboxingFlags_ {}; - // NOLINTEND(misc-non-private-member-variables-in-classes) - // post processing bits per lowerings - uint64_t post_; + uint64_t post_ {}; + // NOLINTEND(misc-non-private-member-variables-in-classes) }; template diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index 2a8d6d9264..4fdf00fcdb 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -111,8 +111,7 @@ enum class BoxingUnboxingFlags : uint32_t { }; enum PostProcessingBits : uint64_t { -#define BIT(x) ((uint64_t)1 << x) - ENUM_LOWERING_POST_PROCESSING_REQUIRED = BIT(0), + ENUM_LOWERING_POST_PROCESSING_REQUIRED = (1LLU << 0LLU), }; } // namespace ark::es2panda::ir diff --git a/ets2panda/test/parser/ets/enum10.ets b/ets2panda/test/parser/ets/enum10.ets index aa337a03bf..4a0f93fe52 100644 --- a/ets2panda/test/parser/ets/enum10.ets +++ b/ets2panda/test/parser/ets/enum10.ets @@ -17,5 +17,5 @@ enum Color { Red } function main(): void { let values: Color[] = Color.values(); - let valuesFail: Color[] = values[0].values(); // TODO(aber) + let valuesFail: Color[] = values[0].values(); } diff --git a/ets2panda/util/declgenEts2Ts.cpp b/ets2panda/util/declgenEts2Ts.cpp index 4c8227291d..b83f30f56c 100644 --- a/ets2panda/util/declgenEts2Ts.cpp +++ b/ets2panda/util/declgenEts2Ts.cpp @@ -151,7 +151,7 @@ void TSDeclGen::GenType(const checker::Type *checkerType) case checker::TypeFlag::ETS_NONNULLISH: Out(checkerType->ToString()); return; - case checker::TypeFlag::ETS_ENUM2_TYPE: + case checker::TypeFlag::ETS_ENUM_TYPE: case checker::TypeFlag::ETS_OBJECT: case checker::TypeFlag::ETS_DYNAMIC_TYPE: GenObjectType(checkerType->AsETSObjectType()); -- Gitee From 029b0a4b8c04bbdf86ddd3872f39cec116478fb2 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Wed, 28 Feb 2024 17:21:42 +0300 Subject: [PATCH 45/48] enumLowerings: fixes of code checker issues. Commmit will be squashed. Signed-off-by: Vadim Lomovtsev --- .../compiler/lowering/ets/enumLoweringPostPhase.cpp | 10 +++++----- .../compiler/lowering/ets/enumLoweringPostPhase.h | 2 +- .../compiler/lowering/ets/enumLoweringPrePhase.cpp | 2 +- ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index 780d8a3695..afb57128d7 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -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 @@ -72,21 +72,21 @@ ir::Expression *CreateTestExpression(ir::Identifier *id, CompilerContext *ctx, i ir::Expression *CheckBinaryBranch(ir::Expression *ast, CompilerContext *ctx) { - auto updateExpression = [ctx](ir::Expression *object, ir::Expression *ast) -> ir::Expression * { + auto updateExpression = [ctx](ir::Expression *object, ir::Expression *node) -> ir::Expression * { if (object->IsIdentifier() && object->AsIdentifier()->Variable() != nullptr) { auto *checker = ctx->Checker()->AsETSChecker(); auto *type = checker->GetTypeOfVariable(object->AsIdentifier()->Variable()); ASSERT(type != nullptr); if (!type->IsETSEnumType()) { - return ast; + return node; } - auto *callExpr = CreateCallExpression(ast, checker); + auto *callExpr = CreateCallExpression(node, checker); return callExpr; } - return ast; + return node; }; if (ast->IsMemberExpression()) { // i.e. we have following: diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h index 2543c4690e..b9199c3cbe 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.h @@ -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 diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp index 1ff66d4e63..b4ff758184 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.cpp @@ -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 diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h index 846c3cab93..a3fcb9d505 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h +++ b/ets2panda/compiler/lowering/ets/enumLoweringPrePhase.h @@ -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 -- Gitee From ff4f3ecd649874b0278b980b5b12bfab1a80e34f Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Thu, 29 Feb 2024 10:48:53 +0300 Subject: [PATCH 46/48] remove ETSObjectFlags:ENUM usage Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/helpers.cpp | 7 ------- ets2panda/checker/ets/typeRelationContext.h | 3 --- ets2panda/checker/types/ets/etsObjectType.h | 6 ++---- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index e2e0490de3..cc65e150f6 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1041,7 +1041,6 @@ checker::Type *ETSChecker::CheckArrayElements(ir::Identifier *ident, ir::ArrayEx checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::TypeNode *typeAnnotation, ir::Expression *init, ir::ModifierFlags flags) { - const util::StringView &varName = ident->Name(); ASSERT(ident->Variable()); varbinder::Variable *const bindingVar = ident->Variable(); checker::Type *annotationType = nullptr; @@ -1132,12 +1131,6 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T return bindingVar->TsType(); } - if (initType->IsETSObjectType() && initType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::ENUM) && - !init->IsMemberExpression()) { - ThrowTypeError({"Cannot assign type '", initType->AsETSObjectType()->Name(), "' for variable ", varName, "."}, - init->Start()); - } - isConst ? bindingVar->SetTsType(initType) : bindingVar->SetTsType(GetNonConstantTypeFromPrimitiveType(initType)); return bindingVar->TsType(); diff --git a/ets2panda/checker/ets/typeRelationContext.h b/ets2panda/checker/ets/typeRelationContext.h index 4e6bb913ef..b921869632 100644 --- a/ets2panda/checker/ets/typeRelationContext.h +++ b/ets2panda/checker/ets/typeRelationContext.h @@ -151,9 +151,6 @@ public: const lexer::SourcePosition &pos) : checker_(checker) { - if (type->HasObjectFlag(ETSObjectFlags::ENUM)) { - return; - } InstantiateType(type, typeArgs, pos); } diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 4c23615409..9ba77b05c2 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -32,7 +32,6 @@ enum class ETSObjectFlags : uint32_t { INSTANCE = 1U << 2U, ABSTRACT = 1U << 3U, GLOBAL = 1U << 4U, - ENUM = 1U << 5U, FUNCTIONAL = 1U << 6U, RESOLVED_INTERFACES = 1U << 7U, RESOLVED_SUPER = 1U << 8U, @@ -61,8 +60,7 @@ enum class ETSObjectFlags : uint32_t { UNBOXABLE_TYPE = BUILTIN_BOOLEAN | BUILTIN_BYTE | BUILTIN_CHAR | BUILTIN_SHORT | BUILTIN_INT | BUILTIN_LONG | BUILTIN_FLOAT | BUILTIN_DOUBLE, BUILTIN_TYPE = BUILTIN_STRING | BUILTIN_BIGINT | UNBOXABLE_TYPE, - VALID_SWITCH_TYPE = - BUILTIN_BYTE | BUILTIN_CHAR | BUILTIN_SHORT | BUILTIN_INT | BUILTIN_LONG | BUILTIN_STRING | ENUM, + VALID_SWITCH_TYPE = BUILTIN_BYTE | BUILTIN_CHAR | BUILTIN_SHORT | BUILTIN_INT | BUILTIN_LONG | BUILTIN_STRING, GLOBAL_CLASS = CLASS | GLOBAL, FUNCTIONAL_INTERFACE = INTERFACE | ABSTRACT | FUNCTIONAL, RESOLVED_HEADER = RESOLVED_INTERFACES | RESOLVED_SUPER | RESOLVED_TYPE_PARAMS, @@ -584,7 +582,7 @@ private: ir::TSTypeParameterDeclaration *GetTypeParams() const { - if (HasObjectFlag(ETSObjectFlags::ENUM) || !HasTypeFlag(TypeFlag::GENERIC)) { + if (!HasTypeFlag(TypeFlag::GENERIC)) { return nullptr; } -- Gitee From 2475c38941f63c43d490194a64ffe3943a2ae003 Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Thu, 29 Feb 2024 11:10:16 +0300 Subject: [PATCH 47/48] rename ETSObjectFlags ENUM2 to ENUM Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ets/helpers.cpp | 2 +- ets2panda/checker/types/ets/etsEnumType.cpp | 4 ++-- ets2panda/checker/types/ets/etsObjectType.h | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index cc65e150f6..e3603850f1 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1678,7 +1678,7 @@ void ETSChecker::CheckSwitchDiscriminant(ir::Expression *discriminant) } if (discriminantType->IsETSObjectType() && - discriminantType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::ENUM2)) { + discriminantType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::ENUM)) { return; } diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index d0818d4ff2..8acc962cd8 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -31,7 +31,7 @@ std::string EnumDescription(util::StringView name) ETSEnumType::ETSEnumType(ETSChecker *checker, util::StringView name, util::StringView assemblerName, ir::AstNode *declNode, ETSObjectFlags flags, TypeRelation *relation) - : ETSObjectType(checker->Allocator(), name, assemblerName, declNode, flags | ETSObjectFlags::ENUM2, relation) + : ETSObjectType(checker->Allocator(), name, assemblerName, declNode, flags | ETSObjectFlags::ENUM, relation) { AddTypeFlag(TypeFlag::ETS_ENUM); CreateLiteralTypes(checker, name, assemblerName, declNode, flags, relation); @@ -39,7 +39,7 @@ ETSEnumType::ETSEnumType(ETSChecker *checker, util::StringView name, util::Strin ETSEnumType::ETSEnumType(ArenaAllocator *allocator, util::StringView name, util::StringView assemblerName, ir::AstNode *declNode, ETSObjectFlags flags, ir::Literal *value, TypeRelation *relation) - : ETSObjectType(allocator, name, assemblerName, declNode, flags | ETSObjectFlags::ENUM2, relation), value_(value) + : ETSObjectType(allocator, name, assemblerName, declNode, flags | ETSObjectFlags::ENUM, relation), value_(value) { AddTypeFlag(TypeFlag::ETS_ENUM); ASSERT(value); diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 9ba77b05c2..085bb1fa9a 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -32,6 +32,7 @@ enum class ETSObjectFlags : uint32_t { INSTANCE = 1U << 2U, ABSTRACT = 1U << 3U, GLOBAL = 1U << 4U, + ENUM = 1U << 5U, FUNCTIONAL = 1U << 6U, RESOLVED_INTERFACES = 1U << 7U, RESOLVED_SUPER = 1U << 8U, @@ -55,8 +56,6 @@ enum class ETSObjectFlags : uint32_t { BUILTIN_FLOAT = 1U << 30U, BUILTIN_DOUBLE = 1U << 31U, - ENUM2 = 1U << 21U, // NOTE(aber) rename after removal code with ENUM - UNBOXABLE_TYPE = BUILTIN_BOOLEAN | BUILTIN_BYTE | BUILTIN_CHAR | BUILTIN_SHORT | BUILTIN_INT | BUILTIN_LONG | BUILTIN_FLOAT | BUILTIN_DOUBLE, BUILTIN_TYPE = BUILTIN_STRING | BUILTIN_BIGINT | UNBOXABLE_TYPE, -- Gitee From e896cbc5b416d704608fe89dc97a8164fd165e0f Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Thu, 29 Feb 2024 12:01:51 +0300 Subject: [PATCH 48/48] fix OHOS CI code check issues Signed-off-by: Vadim Lomovtsev --- ets2panda/checker/ETSchecker.h | 3 + ets2panda/checker/ets/helpers.cpp | 101 +++++---- ets2panda/checker/ets/typeCreation.cpp | 1 - ets2panda/checker/types/ets/etsEnumType.cpp | 2 + ets2panda/compiler/core/ETSCompiler.cpp | 75 +++--- .../lowering/ets/enumLoweringPostPhase.cpp | 214 ++++++++++-------- ets2panda/ir/astNode.h | 1 + 7 files changed, 216 insertions(+), 181 deletions(-) diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 5878a5d14e..19debfb9d7 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -452,6 +452,8 @@ public: bool isCondExpr = false); Type *HandleBooleanLogicalOperators(Type *leftType, Type *rightType, lexer::TokenType tokenType); Type *HandleBooleanLogicalOperatorsExtended(Type *leftType, Type *rightType, ir::BinaryExpression *expr); + void VariableDeclCheckHelper(ir::Identifier *ident, ir::TypeNode *typeAnnotation, ir::Expression *init, + checker::Type *annotationType, varbinder::Variable *const bindingVar); checker::Type *CheckVariableDeclaration(ir::Identifier *ident, ir::TypeNode *typeAnnotation, ir::Expression *init, ir::ModifierFlags flags); void CheckTruthinessOfType(ir::Expression *expr); @@ -493,6 +495,7 @@ public: Type *MaybePromotedBuiltinType(Type *type) const; Type const *MaybePromotedBuiltinType(Type const *type) const; Type *MaybePrimitiveBuiltinType(Type *type) const; + void CompareSwitchCases(size_t caseNum, ArenaVector *cases); void CheckForSameSwitchCases(ArenaVector *cases); std::string GetStringFromIdentifierValue(checker::Type *caseType) const; bool CompareIdentifiersValuesAreDifferent(ir::Expression *compareValue, const std::string &caseValue); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index e3603850f1..b0f3910d98 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1038,24 +1038,9 @@ checker::Type *ETSChecker::CheckArrayElements(ir::Identifier *ident, ir::ArrayEx return annotationType; } -checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::TypeNode *typeAnnotation, - ir::Expression *init, ir::ModifierFlags flags) +void ETSChecker::VariableDeclCheckHelper(ir::Identifier *ident, ir::TypeNode *typeAnnotation, ir::Expression *init, + checker::Type *annotationType, varbinder::Variable *const bindingVar) { - ASSERT(ident->Variable()); - varbinder::Variable *const bindingVar = ident->Variable(); - checker::Type *annotationType = nullptr; - - const bool isConst = (flags & ir::ModifierFlags::CONST) != 0; - - if (typeAnnotation != nullptr) { - annotationType = typeAnnotation->GetType(this); - bindingVar->SetTsType(annotationType); - } - - if (init == nullptr) { - return annotationType; - } - if (typeAnnotation == nullptr) { if (init->IsArrayExpression()) { annotationType = CheckArrayElements(ident, init->AsArrayExpression()); @@ -1098,6 +1083,27 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T InferTypesForLambda(lambda, typeAnnotation->AsETSFunctionType()); } } +} +checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::TypeNode *typeAnnotation, + ir::Expression *init, ir::ModifierFlags flags) +{ + ASSERT(ident->Variable()); + varbinder::Variable *const bindingVar = ident->Variable(); + checker::Type *annotationType = nullptr; + + const bool isConst = (flags & ir::ModifierFlags::CONST) != 0; + + if (typeAnnotation != nullptr) { + annotationType = typeAnnotation->GetType(this); + bindingVar->SetTsType(annotationType); + } + + if (init == nullptr) { + return annotationType; + } + + VariableDeclCheckHelper(ident, typeAnnotation, init, annotationType, bindingVar); + checker::Type *initType = init->Check(this); if (initType == nullptr) { @@ -1952,41 +1958,46 @@ Type *ETSChecker::MaybeBoxedType(const varbinder::Variable *var, ArenaAllocator return varType; } -void ETSChecker::CheckForSameSwitchCases(ArenaVector *cases) +void ETSChecker::CompareSwitchCases(size_t caseNum, ArenaVector *cases) { - for (size_t caseNum = 0; caseNum < cases->size(); caseNum++) { - for (size_t compareCase = caseNum + 1; compareCase < cases->size(); compareCase++) { - auto *caseTest = cases->at(caseNum)->Test(); - auto *compareCaseTest = cases->at(compareCase)->Test(); - - if (caseTest == nullptr || compareCaseTest == nullptr) { - continue; - } + for (size_t compareCase = caseNum + 1; compareCase < cases->size(); compareCase++) { + auto *caseTest = cases->at(caseNum)->Test(); + auto *compareCaseTest = cases->at(compareCase)->Test(); - if (caseTest->TsType()->IsETSEnumType()) { - ASSERT(compareCaseTest->TsType()->IsETSEnumType()); - if (caseTest->TsType()->AsETSEnumType()->IsSameEnumLiteralType( - compareCaseTest->TsType()->AsETSEnumType())) { - ThrowTypeError("Case enum duplicate", caseTest->Start()); - } - continue; - } - if (caseTest->IsIdentifier() || caseTest->IsMemberExpression()) { - CheckIdentifierSwitchCase(caseTest, compareCaseTest, cases->at(caseNum)->Start()); - continue; - } + if (caseTest == nullptr || compareCaseTest == nullptr) { + continue; + } - if (compareCaseTest->IsIdentifier() || compareCaseTest->IsMemberExpression()) { - CheckIdentifierSwitchCase(compareCaseTest, caseTest, cases->at(compareCase)->Start()); - continue; + if (caseTest->TsType()->IsETSEnumType()) { + ASSERT(compareCaseTest->TsType()->IsETSEnumType()); + if (caseTest->TsType()->AsETSEnumType()->IsSameEnumLiteralType( + compareCaseTest->TsType()->AsETSEnumType())) { + ThrowTypeError("Case enum duplicate", caseTest->Start()); } + continue; + } + if (caseTest->IsIdentifier() || caseTest->IsMemberExpression()) { + CheckIdentifierSwitchCase(caseTest, compareCaseTest, cases->at(caseNum)->Start()); + continue; + } - if (GetStringFromLiteral(caseTest) != GetStringFromLiteral(compareCaseTest)) { - continue; - } + if (compareCaseTest->IsIdentifier() || compareCaseTest->IsMemberExpression()) { + CheckIdentifierSwitchCase(compareCaseTest, caseTest, cases->at(compareCase)->Start()); + continue; + } - ThrowTypeError("Case duplicate", cases->at(compareCase)->Start()); + if (GetStringFromLiteral(caseTest) != GetStringFromLiteral(compareCaseTest)) { + continue; } + + ThrowTypeError("Case duplicate", cases->at(compareCase)->Start()); + } +} + +void ETSChecker::CheckForSameSwitchCases(ArenaVector *cases) +{ + for (size_t caseNum = 0; caseNum < cases->size(); caseNum++) { + CompareSwitchCases(caseNum, cases); } } diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 3580100c67..9ccee35270 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -371,7 +371,6 @@ bool IsEnumClass(ir::AstNode *declNode) declNode->AsClassDefinition()->Super()->IsETSTypeReference()) { auto superType = declNode->AsClassDefinition()->Super()->AsETSTypeReference(); auto typeName = superType->BaseName()->Name(); - if (typeName == "EnumIntType" || typeName == "EnumStrType") { return true; } diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index 8acc962cd8..fe746a38fe 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -94,7 +94,9 @@ void ETSEnumType::Cast(TypeRelation *relation, Type *target) void ETSEnumType::CreateLiteralTypes(ETSChecker *checker, util::StringView name, util::StringView assemblerName, ir::AstNode *declNode, ETSObjectFlags flags, TypeRelation *relation) { +#if !defined(NDEBUG) const int32_t argsCount = 4; +#endif const int32_t argIdx = 2; ASSERT(declNode->IsClassDefinition()); diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index ded9c7b01f..de788b0b9a 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -998,6 +998,21 @@ static bool CompileComputed(compiler::ETSGen *etsg, const ir::MemberExpression * return true; } +void CompileStaticVariable(ETSGen *etsg, const ir::MemberExpression *expr, const util::StringView &propName) +{ + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + + if (expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { + checker::Signature *sig = expr->PropVar()->TsType()->AsETSFunctionType()->FindGetter(); + etsg->CallStatic0(expr, sig->InternalName()); + etsg->SetAccumulatorType(expr->TsType()); + return; + } + + util::StringView fullName = etsg->FormClassPropReference(expr->Object()->TsType()->AsETSObjectType(), propName); + etsg->LoadStaticProperty(expr, expr->TsType(), fullName); +} + void ETSCompiler::Compile(const ir::MemberExpression *expr) const { ETSGen *etsg = GetETSGen(); @@ -1032,17 +1047,7 @@ void ETSCompiler::Compile(const ir::MemberExpression *expr) const } if (etsg->Checker()->IsVariableStatic(expr->PropVar())) { - auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); - - if (expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { - checker::Signature *sig = expr->PropVar()->TsType()->AsETSFunctionType()->FindGetter(); - etsg->CallStatic0(expr, sig->InternalName()); - etsg->SetAccumulatorType(expr->TsType()); - return; - } - - util::StringView fullName = etsg->FormClassPropReference(expr->Object()->TsType()->AsETSObjectType(), propName); - etsg->LoadStaticProperty(expr, expr->TsType(), fullName); + CompileStaticVariable(etsg, expr, propName); return; } @@ -1938,40 +1943,24 @@ void ETSCompiler::CompileCast(const ir::TSAsExpression *expr) const { ETSGen *etsg = GetETSGen(); auto *targetType = etsg->Checker()->GetApparentType(expr->TsType()); + std::map castHandlers { + {checker::TypeFlag::ETS_BOOLEAN, + [](const ir::TSAsExpression *expr, ETSGen *etsg) { etsg->CastToBoolean(expr); }}, + {checker::TypeFlag::CHAR, [](const ir::TSAsExpression *expr, ETSGen *etsg) { etsg->CastToChar(expr); }}, + {checker::TypeFlag::BYTE, [](const ir::TSAsExpression *expr, ETSGen *etsg) { etsg->CastToByte(expr); }}, + {checker::TypeFlag::SHORT, [](const ir::TSAsExpression *expr, ETSGen *etsg) { etsg->CastToShort(expr); }}, + {checker::TypeFlag::INT, [](const ir::TSAsExpression *expr, ETSGen *etsg) { etsg->CastToInt(expr); }}, + {checker::TypeFlag::LONG, [](const ir::TSAsExpression *expr, ETSGen *etsg) { etsg->CastToLong(expr); }}, + {checker::TypeFlag::FLOAT, [](const ir::TSAsExpression *expr, ETSGen *etsg) { etsg->CastToFloat(expr); }}, + {checker::TypeFlag::DOUBLE, [](const ir::TSAsExpression *expr, ETSGen *etsg) { etsg->CastToDouble(expr); }}}; + + auto result = castHandlers.find(checker::ETSChecker::TypeKind(targetType)); + if (result != castHandlers.end()) { + result->second(expr, etsg); + return; + } switch (checker::ETSChecker::TypeKind(targetType)) { - case checker::TypeFlag::ETS_BOOLEAN: { - etsg->CastToBoolean(expr); - break; - } - case checker::TypeFlag::CHAR: { - etsg->CastToChar(expr); - break; - } - case checker::TypeFlag::BYTE: { - etsg->CastToByte(expr); - break; - } - case checker::TypeFlag::SHORT: { - etsg->CastToShort(expr); - break; - } - case checker::TypeFlag::INT: { - etsg->CastToInt(expr); - break; - } - case checker::TypeFlag::LONG: { - etsg->CastToLong(expr); - break; - } - case checker::TypeFlag::FLOAT: { - etsg->CastToFloat(expr); - break; - } - case checker::TypeFlag::DOUBLE: { - etsg->CastToDouble(expr); - break; - } case checker::TypeFlag::ETS_ARRAY: case checker::TypeFlag::ETS_OBJECT: case checker::TypeFlag::ETS_TYPE_PARAMETER: diff --git a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp index afb57128d7..cc7b3ba7ce 100644 --- a/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp +++ b/ets2panda/compiler/lowering/ets/enumLoweringPostPhase.cpp @@ -124,14 +124,132 @@ ir::AstNode *UpdateMemberExpression(ir::AstNode *ast, CompilerContext *ctx) return ast; } +ir::Expression *GetTestExpression(ir::AstNode *ast) +{ + ASSERT(ast != nullptr); + ASSERT(ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || + ast->IsForUpdateStatement() || ast->IsConditionalExpression()); + ir::Expression *test = nullptr; + + if (ast->IsIfStatement()) { + test = ast->AsIfStatement()->Test(); + } else if (ast->IsWhileStatement()) { + test = ast->AsWhileStatement()->Test(); + } else if (ast->IsDoWhileStatement()) { + test = ast->AsDoWhileStatement()->Test(); + } else if (ast->IsForUpdateStatement()) { + test = ast->AsForUpdateStatement()->Test(); + } else if (ast->IsConditionalExpression()) { + test = ast->AsConditionalExpression()->Test(); + } + return test; +} + +void SetTestExpression(ir::Expression *testExpr, ir::AstNode *ast) +{ + ASSERT(testExpr != nullptr); + ASSERT(ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || + ast->IsForUpdateStatement() || ast->IsConditionalExpression()); + + if (ast->IsIfStatement()) { + ast->AsIfStatement()->SetTest(testExpr); + } else if (ast->IsWhileStatement()) { + ast->AsWhileStatement()->SetTest(testExpr); + } else if (ast->IsDoWhileStatement()) { + ast->AsDoWhileStatement()->SetTest(testExpr); + } else if (ast->IsForUpdateStatement()) { + ast->AsForUpdateStatement()->SetTest(testExpr); + } else if (ast->IsConditionalExpression()) { + ast->AsConditionalExpression()->SetTest(testExpr); + } + testExpr->SetParent(ast); +} + +ir::Expression *UpdateCallExpression(ir::Expression *test, public_lib::Context *ctx) +{ + checker::ETSChecker *checker = ctx->checker->AsETSChecker(); + // simple call expression with default non-zero test, i.e. + // + // 'if (v.getValue())' + // + // this wll always be treated as 'true' since getValue() returns the EnumConst + // object,but not the enum value + // + // need to checkif we're calling to getValue() for enum constant + // and convert it into binary expression with '!= 0' test, i.e. + // + // 'if (v.getValue() != 0)' + // + // same for loop expressions. + // + ir::Expression *callee = test->AsCallExpression()->Callee(); + if (!((callee != nullptr) && (callee->IsMemberExpression()))) { + return nullptr; + } + + if ((callee->AsMemberExpression()->Object() != nullptr) && callee->AsMemberExpression()->Object()->IsIdentifier()) { + auto *id = callee->AsMemberExpression()->Object()->AsIdentifier(); + if (id->Variable() == nullptr) { + return nullptr; + } + + auto *type = checker->GetTypeOfVariable(id->Variable()); + ASSERT(type != nullptr); + if (!type->IsETSEnumType()) { + return nullptr; + } + + if (ir::Expression *prop = callee->AsMemberExpression()->Property(); prop != nullptr) { + if (prop->IsIdentifier() && (prop->AsIdentifier()->Name() == g_enumGetvalueMethodName)) { + // now we need to wrap it to the binary expression .. != 0 + return CreateTestExpression(prop->AsIdentifier(), ctx->compilerContext, test->AsCallExpression()); + } + } + } + return nullptr; +} + +ir::AstNode *UpdateTestNode(ir::AstNode *ast, public_lib::Context *ctx) +{ + checker::ETSChecker *checker = ctx->checker->AsETSChecker(); + ir::Expression *testExpr = nullptr; + ir::Expression *test = GetTestExpression(ast); + if (test == nullptr) { + return ast; + } + + if (test->IsIdentifier()) { + // we got simple variable test expression, test against non-zero value + if (test->AsIdentifier()->Variable() == nullptr) { + return ast; + } + auto *type = checker->GetTypeOfVariable(test->AsIdentifier()->Variable()); + ASSERT(type != nullptr); + + if (!type->IsETSEnumType()) { + return ast; + } + // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' + // NOTE: what about string as enum constant? + testExpr = CreateTestExpression(test->AsIdentifier(), ctx->compilerContext, nullptr); + } else if (test->IsCallExpression()) { + testExpr = UpdateCallExpression(test, ctx); + } + + if (testExpr == nullptr) { + return ast; + } + + SetTestExpression(testExpr, ast); + return ast; +} + bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *program) { if (program->Extension() != ScriptExtension::ETS) { return true; } - [[maybe_unused]] checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - for (auto &[_, extPrograms] : program->ExternalSources()) { (void)_; for (auto *extProg : extPrograms) { @@ -139,7 +257,7 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } } - program->Ast()->TransformChildrenRecursively([checker, ctx](ir::AstNode *ast) -> ir::AstNode * { + program->Ast()->TransformChildrenRecursively([ctx](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsBinaryExpression()) { if (ast->AsBinaryExpression()->IsPostBitSet( ir::PostProcessingBits::ENUM_LOWERING_POST_PROCESSING_REQUIRED)) { @@ -149,99 +267,11 @@ bool EnumLoweringPostPhase::Perform(public_lib::Context *ctx, parser::Program *p } if (ast->IsIfStatement() || ast->IsWhileStatement() || ast->IsDoWhileStatement() || ast->IsForUpdateStatement() || ast->IsConditionalExpression()) { - ir::Expression *test = nullptr; - ir::Expression *testExpr = nullptr; - - if (ast->IsIfStatement()) { - test = ast->AsIfStatement()->Test(); - } else if (ast->IsWhileStatement()) { - test = ast->AsWhileStatement()->Test(); - } else if (ast->IsDoWhileStatement()) { - test = ast->AsDoWhileStatement()->Test(); - } else if (ast->IsForUpdateStatement()) { - test = ast->AsForUpdateStatement()->Test(); - } else if (ast->IsConditionalExpression()) { - test = ast->AsConditionalExpression()->Test(); - } - - if (test == nullptr) { - return ast; - } - if (test->IsIdentifier()) { - // we got simple variable test expression, test against non-zero value - if (test->AsIdentifier()->Variable() == nullptr) { - return ast; - } - auto *type = checker->GetTypeOfVariable(test->AsIdentifier()->Variable()); - ASSERT(type != nullptr); - - if (!type->IsETSEnumType()) { - return ast; - } - // ok now we need to replace 'if (v)' to 'if (v.getValue() != 0)' - // NOTE: what about string as enum constant? - testExpr = CreateTestExpression(test->AsIdentifier(), ctx->compilerContext, nullptr); - - } else if (test->IsCallExpression()) { - // simple call expression with default non-zero test, i.e. - // - // 'if (v.getValue())' - // - // this wll always be treated as 'true' since getValue() returns the EnumConst - // object,but not the enum value - // - // need to checkif we're calling to getValue() for enum constant - // and convert it into binary expression with '!= 0' test, i.e. - // - // 'if (v.getValue() != 0)' - // - // same for loop expressions. - // - if (ir::Expression *callee = test->AsCallExpression()->Callee(); - (callee != nullptr) && (callee->IsMemberExpression())) { - if ((callee->AsMemberExpression()->Object() != nullptr) && - callee->AsMemberExpression()->Object()->IsIdentifier()) { - auto *id = callee->AsMemberExpression()->Object()->AsIdentifier(); - if (id->Variable() == nullptr) { - return ast; - } - auto *type = checker->GetTypeOfVariable(id->Variable()); - ASSERT(type != nullptr); - if (!type->IsETSEnumType()) { - return ast; - } - - if (ir::Expression *prop = callee->AsMemberExpression()->Property(); prop != nullptr) { - if (prop->IsIdentifier() && (prop->AsIdentifier()->Name() == g_enumGetvalueMethodName)) { - // now we need to wrap it to the binary expression .. != 0 - testExpr = CreateTestExpression(prop->AsIdentifier(), ctx->compilerContext, - test->AsCallExpression()); - } - } - } - } - } - if (testExpr == nullptr) { - return ast; - } - if (ast->IsIfStatement()) { - ast->AsIfStatement()->SetTest(testExpr); - } else if (ast->IsWhileStatement()) { - ast->AsWhileStatement()->SetTest(testExpr); - } else if (ast->IsDoWhileStatement()) { - ast->AsDoWhileStatement()->SetTest(testExpr); - } else if (ast->IsForUpdateStatement()) { - ast->AsForUpdateStatement()->SetTest(testExpr); - } else if (ast->IsConditionalExpression()) { - ast->AsConditionalExpression()->SetTest(testExpr); - } - testExpr->SetParent(ast); - return ast; + return UpdateTestNode(ast, ctx); } return ast; }); return true; } - } // namespace ark::es2panda::compiler diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 16f84181ec..4d23536862 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -650,6 +650,7 @@ protected: : Annotated(type, typeAnnotation) { } + explicit AnnotatedAstNode(AstNodeType const type) : Annotated(type) {} explicit AnnotatedAstNode(AstNodeType const type, ModifierFlags const flags) : Annotated(type, flags) {} -- Gitee