• Home
  • Raw
  • Download

Lines Matching +full:checker +full:-

2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
7 * http://www.apache.org/licenses/LICENSE-2.0
18 #include "checker/TSchecker.h"
19 #include "checker/ts/destructuringContext.h"
21 namespace ark::es2panda::checker { namespace
29 checker::Type *TSAnalyzer::Check(ir::CatchClause *st) const in Check()
31 TSChecker *checker = GetTSChecker(); in Check() local
32 ir::Expression *typeAnnotation = st->Param()->AsAnnotatedExpression()->TypeAnnotation(); in Check()
35 checker::Type *catchParamType = typeAnnotation->Check(checker); in Check()
37 if (!catchParamType->HasTypeFlag(checker::TypeFlag::ANY_OR_UNKNOWN)) { in Check()
38checker->ThrowTypeError("Catch clause variable type annotation must be 'any' or 'unknown' if speci… in Check()
39 st->Start()); in Check()
43 st->Body()->Check(checker); in Check()
48 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ClassDefinition *node) const in Check()
50 TSChecker *checker = GetTSChecker(); in Check() local
52 return checker->GlobalAnyType(); in Check()
55 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::MetaProperty *expr) const in Check()
57 TSChecker *checker = GetTSChecker(); in Check() local
59 return checker->GlobalAnyType(); in Check()
62 checker::Type *TSAnalyzer::Check(ir::TSIndexSignature *node) const in Check()
64 TSChecker *checker = GetTSChecker(); in Check() local
65 if (node->TsType() != nullptr) { in Check()
66 return node->TsType(); in Check()
69 const util::StringView &paramName = node->Param()->AsIdentifier()->Name(); in Check()
70 node->typeAnnotation_->Check(checker); in Check()
71 checker::Type *indexType = node->typeAnnotation_->GetType(checker); in Check()
72 checker::IndexInfo *info = in Check()
73checker->Allocator()->New<checker::IndexInfo>(indexType, paramName, node->Readonly(), node->Start(… in Check()
74checker::ObjectDescriptor *desc = checker->Allocator()->New<checker::ObjectDescriptor>(checker->Al… in Check()
75 checker::ObjectType *placeholder = checker->Allocator()->New<checker::ObjectLiteralType>(desc); in Check()
78 if (node->Kind() == ir::TSIndexSignature::TSIndexSignatureKind::NUMBER) { in Check()
79 placeholder->Desc()->numberIndexInfo = info; in Check()
81 placeholder->Desc()->stringIndexInfo = info; in Check()
84 node->SetTsType(placeholder); in Check()
88 checker::Type *TSAnalyzer::Check(ir::TSMethodSignature *node) const in Check()
90 TSChecker *checker = GetTSChecker(); in Check() local
91 if (node->Computed()) { in Check()
92 checker->CheckComputedPropertyName(node->Key()); in Check()
95 checker::ScopeContext scopeCtx(checker, node->Scope()); in Check()
97 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
98 checker->CheckFunctionParameterDeclarations(node->Params(), signatureInfo); in Check()
100 …auto *callSignature = checker->Allocator()->New<checker::Signature>(signatureInfo, checker->Global… in Check()
101 node->Variable()->SetTsType(checker->CreateFunctionTypeWithSignature(callSignature)); in Check()
103 auto returnType = node->ReturnTypeAnnotation(); in Check()
105 checker->ThrowTypeError( in Check()
106 … "Method signature, which lacks return-type annotation, implicitly has an 'any' return type.", in Check()
107 node->Start()); in Check()
110 returnType->Check(checker); in Check()
112 callSignature->SetReturnType(returnType->GetType(checker)); in Check()
117 checker::Type *TSAnalyzer::Check(ir::TSPropertySignature *node) const in Check()
119 TSChecker *checker = GetTSChecker(); in Check() local
120 if (node->TypeAnnotation() != nullptr) { in Check()
121 node->TypeAnnotation()->Check(checker); in Check()
124 if (node->Computed()) { in Check()
125 checker->CheckComputedPropertyName(node->Key()); in Check()
128 if (node->TypeAnnotation() != nullptr) { in Check()
129 node->Variable()->SetTsType(node->TypeAnnotation()->GetType(checker)); in Check()
133 checker->ThrowTypeError("Property implicitly has an 'any' type.", node->Start()); in Check()
137 checker::Type *TSAnalyzer::Check(ir::TSSignatureDeclaration *node) const in Check()
139 TSChecker *checker = GetTSChecker(); in Check() local
140 if (node->TsType() != nullptr) { in Check()
141 return node->TsType(); in Check()
144 checker::ScopeContext scopeCtx(checker, node->Scope()); in Check()
146 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
147 checker->CheckFunctionParameterDeclarations(node->Params(), signatureInfo); in Check()
149 …bool isCallSignature = (node->Kind() == ir::TSSignatureDeclaration::TSSignatureDeclarationKind::CA… in Check()
151 if (node->ReturnTypeAnnotation() == nullptr) { in Check()
153 checker->ThrowTypeError( in Check()
154 … "Call signature, which lacks return-type annotation, implicitly has an 'any' return type.", in Check()
155 node->Start()); in Check()
158 checker->ThrowTypeError( in Check()
159 … "Construct signature, which lacks return-type annotation, implicitly has an 'any' return type.", in Check()
160 node->Start()); in Check()
163 node->ReturnTypeAnnotation()->Check(checker); in Check()
164 checker::Type *returnType = node->ReturnTypeAnnotation()->GetType(checker); in Check()
166 auto *signature = checker->Allocator()->New<checker::Signature>(signatureInfo, returnType); in Check()
168 checker::Type *placeholderObj = nullptr; in Check()
171 placeholderObj = checker->CreateObjectTypeWithCallSignature(signature); in Check()
173 placeholderObj = checker->CreateObjectTypeWithConstructSignature(signature); in Check()
176 node->SetTsType(placeholderObj); in Check()
180 static void GetSpreadElementType(checker::TSChecker *checker, checker::Type *spreadType, in GetSpreadElementType() argument
181 … ArenaVector<checker::Type *> &elementTypes, const lexer::SourcePosition &loc) in GetSpreadElementType()
183 bool inConstContext = checker->HasStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in GetSpreadElementType()
185 if (spreadType->IsObjectType() && spreadType->AsObjectType()->IsTupleType()) { in GetSpreadElementType()
186 ArenaVector<checker::Type *> tupleElementTypes(checker->Allocator()->Adapter()); in GetSpreadElementType()
187 checker::TupleType *spreadTuple = spreadType->AsObjectType()->AsTupleType(); in GetSpreadElementType()
189 for (auto *it : spreadTuple->Properties()) { in GetSpreadElementType()
191 elementTypes.push_back(it->TsType()); in GetSpreadElementType()
195 tupleElementTypes.push_back(it->TsType()); in GetSpreadElementType()
202 elementTypes.push_back(checker->CreateUnionType(std::move(tupleElementTypes))); in GetSpreadElementType()
206 if (!spreadType->IsUnionType()) { in GetSpreadElementType()
207 checker->ThrowTypeError( in GetSpreadElementType()
212 ArenaVector<checker::Type *> spreadTypes(checker->Allocator()->Adapter()); in GetSpreadElementType()
215 for (auto *type : spreadType->AsUnionType()->ConstituentTypes()) { in GetSpreadElementType()
216 if (type->IsArrayType()) { in GetSpreadElementType()
217 spreadTypes.push_back(type->AsArrayType()->ElementType()); in GetSpreadElementType()
221 if (type->IsObjectType() && type->AsObjectType()->IsTupleType()) { in GetSpreadElementType()
222 checker::TupleType *tuple = type->AsObjectType()->AsTupleType(); in GetSpreadElementType()
224 for (auto *it : tuple->Properties()) { in GetSpreadElementType()
225 spreadTypes.push_back(it->TsType()); in GetSpreadElementType()
236 elementTypes.push_back(checker->CreateUnionType(std::move(spreadTypes))); in GetSpreadElementType()
240 checker->ThrowTypeError( in GetSpreadElementType()
244 checker::Type *TSAnalyzer::Check(ir::ArrayExpression *expr) const in Check()
246 TSChecker *checker = GetTSChecker(); in Check() local
247 ArenaVector<checker::Type *> elementTypes(checker->Allocator()->Adapter()); in Check()
248 ArenaVector<checker::ElementFlags> elementFlags(checker->Allocator()->Adapter()); in Check()
249 bool inConstContext = checker->HasStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in Check()
250 bool createTuple = checker->HasStatus(checker::CheckerStatus::FORCE_TUPLE); in Check()
252 for (auto *it : expr->Elements()) { in Check()
253 if (it->IsSpreadElement()) { in Check()
254 checker::Type *spreadType = it->AsSpreadElement()->Argument()->Check(checker); in Check()
256 if (spreadType->IsArrayType()) { in Check()
257 … elementTypes.push_back(inConstContext ? spreadType : spreadType->AsArrayType()->ElementType()); in Check()
258 elementFlags.push_back(checker::ElementFlags::VARIADIC); in Check()
262 GetSpreadElementType(checker, spreadType, elementTypes, it->Start()); in Check()
263 elementFlags.push_back(checker::ElementFlags::REST); in Check()
267 checker::Type *elementType = it->Check(checker); in Check()
270 elementType = checker->GetBaseTypeOfLiteralType(elementType); in Check()
273 elementFlags.push_back(checker::ElementFlags::REQUIRED); in Check()
278checker::ObjectDescriptor *desc = checker->Allocator()->New<checker::ObjectDescriptor>(checker->Al… in Check()
282 util::StringView memberIndex = util::Helpers::ToStringView(checker->Allocator(), index); in Check()
284 checker->Allocator(), memberIndex, varbinder::VariableFlags::PROPERTY, nullptr); in Check()
287 tupleMember->AddFlag(varbinder::VariableFlags::READONLY); in Check()
290 tupleMember->SetTsType(*it); in Check()
292 desc->properties.push_back(tupleMember); in Check()
295 …const checker::TupleTypeInfo tupleTypeInfo = {ElementFlags::REQUIRED, index, index, inConstContext… in Check()
296 return checker->CreateTupleType(desc, std::move(elementFlags), tupleTypeInfo); in Check()
299 checker::Type *arrayElementType = nullptr; in Check()
301 arrayElementType = checker->GlobalAnyType(); in Check()
303 arrayElementType = checker->CreateUnionType(std::move(elementTypes)); in Check()
306 return checker->Allocator()->New<checker::ArrayType>(arrayElementType); in Check()
309 checker::Type *TSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const in Check()
311 TSChecker *checker = GetTSChecker(); in Check() local
314 if (expr->Function()->Parent()->Parent() != nullptr && in Check()
315 expr->Function()->Parent()->Parent()->IsVariableDeclarator() && in Check()
316 expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { in Check()
317 …funcVar = expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Vari… in Check()
320 checker::ScopeContext scopeCtx(checker, expr->Function()->Scope()); in Check()
322 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
323 checker->CheckFunctionParameterDeclarations(expr->Function()->Params(), signatureInfo); in Check()
325 …auto *signature = checker->Allocator()->New<checker::Signature>(signatureInfo, checker->GlobalReso… in Check()
326 expr->Function()); in Check()
327 checker::Type *funcType = checker->CreateFunctionTypeWithSignature(signature); in Check()
329 if (funcVar != nullptr && funcVar->TsType() == nullptr) { in Check()
330 funcVar->SetTsType(funcType); in Check()
333 signature->SetReturnType(checker->HandleFunctionReturn(expr->Function())); in Check()
335 if (!expr->Function()->Body()->IsExpression()) { in Check()
336 expr->Function()->Body()->Check(checker); in Check()
342 checker::Type *TSAnalyzer::CheckAssignmentExprOperatorType(ir::AssignmentExpression *expr, checker:… in CheckAssignmentExprOperatorType()
343 checker::Type *rightType) const in CheckAssignmentExprOperatorType()
345 TSChecker *checker = GetTSChecker(); in CheckAssignmentExprOperatorType() local
349 switch (expr->OperatorType()) { in CheckAssignmentExprOperatorType()
361 return checker->CheckBinaryOperator(&leftRightType, expr->Left(), expr->Right(), expr, in CheckAssignmentExprOperatorType()
362 expr->OperatorType()); in CheckAssignmentExprOperatorType()
365 …return checker->CheckPlusOperator(&leftRightType, expr->Left(), expr->Right(), expr, expr->Operato… in CheckAssignmentExprOperatorType()
368checker->CheckAssignmentOperator(expr->OperatorType(), expr->Left(), leftType, rightType); in CheckAssignmentExprOperatorType()
380 checker::Type *TSAnalyzer::Check(ir::AssignmentExpression *expr) const in Check()
382 TSChecker *checker = GetTSChecker(); in Check() local
383 if (expr->Left()->IsArrayPattern()) { in Check()
384 … auto savedContext = checker::SavedCheckerContext(checker, checker::CheckerStatus::FORCE_TUPLE); in Check()
386checker::ArrayDestructuringContext({checker, expr->Left(), true, true, nullptr, expr->Right()}); in Check()
391 if (expr->Left()->IsObjectPattern()) { in Check()
392 … auto savedContext = checker::SavedCheckerContext(checker, checker::CheckerStatus::FORCE_TUPLE); in Check()
394checker::ObjectDestructuringContext({checker, expr->Left(), true, true, nullptr, expr->Right()}); in Check()
399 if (expr->Left()->IsIdentifier() && expr->Left()->AsIdentifier()->Variable() != nullptr && in Check()
400 expr->Left()->AsIdentifier()->Variable()->Declaration()->IsConstDecl()) { in Check()
401 checker->ThrowTypeError( in Check()
402 … {"Cannot assign to ", expr->Left()->AsIdentifier()->Name(), " because it is a constant."}, in Check()
403 expr->Left()->Start()); in Check()
406 auto *leftType = expr->Left()->Check(checker); in Check()
408 if (leftType->HasTypeFlag(checker::TypeFlag::READONLY)) { in Check()
409checker->ThrowTypeError("Cannot assign to this property because it is readonly.", expr->Left()->St… in Check()
412 if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { in Check()
413 checker->ElaborateElementwise(leftType, expr->Right(), expr->Left()->Start()); in Check()
414 return checker->CheckTypeCached(expr->Right()); in Check()
417 auto *rightType = expr->Right()->Check(checker); in Check()
422 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::AwaitExpression *expr) const in Check()
424 TSChecker *checker = GetTSChecker(); in Check() local
426 return checker->GlobalAnyType(); in Check()
429 checker::Type *TSAnalyzer::CheckBinaryExprArithmLogical(ir::BinaryExpression *expr, ExpressionTypeI… in CheckBinaryExprArithmLogical()
430 TSChecker *checker) const in CheckBinaryExprArithmLogical()
432 switch (expr->OperatorType()) { in CheckBinaryExprArithmLogical()
444 …return checker->CheckBinaryOperator(leftRightType, expr->Left(), expr->Right(), expr, expr->Operat… in CheckBinaryExprArithmLogical()
447 …return checker->CheckPlusOperator(leftRightType, expr->Left(), expr->Right(), expr, expr->Operator… in CheckBinaryExprArithmLogical()
450 … return checker->CheckAndOperator(leftRightType->leftType, leftRightType->rightType, expr->Left()); in CheckBinaryExprArithmLogical()
453 … return checker->CheckOrOperator(leftRightType->leftType, leftRightType->rightType, expr->Left()); in CheckBinaryExprArithmLogical()
461 checker::Type *TSAnalyzer::Check(ir::BinaryExpression *expr) const in Check()
463 TSChecker *checker = GetTSChecker(); in Check() local
465 leftRightType.leftType = expr->Left()->Check(checker); in Check()
466 leftRightType.rightType = expr->Right()->Check(checker); in Check()
468 auto *checkBinaryExprPunctuator = CheckBinaryExprArithmLogical(expr, &leftRightType, checker); in Check()
473 switch (expr->OperatorType()) { in Check()
476 return checker->CheckCompareOperator(&leftRightType, expr->Left(), expr->Right(), expr, in Check()
477 expr->OperatorType()); in Check()
483 … if (checker->IsTypeEqualityComparableTo(leftRightType.leftType, leftRightType.rightType) || in Check()
484checker->IsTypeEqualityComparableTo(leftRightType.rightType, leftRightType.leftType)) { in Check()
485 return checker->GlobalBooleanType(); in Check()
488checker->ThrowBinaryLikeError(expr->OperatorType(), leftRightType.leftType, leftRightType.rightTyp… in Check()
489 expr->Start()); in Check()
492 // NOTE: Csaba Repasi. Implement checker for nullish coalescing in Check()
493 return checker->GlobalAnyType(); in Check()
496checker->CheckAssignmentOperator(expr->OperatorType(), expr->Left(), leftRightType.leftType, in Check()
501 …return checker->CheckInstanceofExpression(leftRightType.leftType, leftRightType.rightType, expr->R… in Check()
505 … return checker->CheckInExpression(leftRightType.leftType, leftRightType.rightType, expr->Left(), in Check()
506 expr->Right(), expr); in Check()
517 checker::Type *TSAnalyzer::Check(ir::CallExpression *expr) const in Check()
519 TSChecker *checker = GetTSChecker(); in Check() local
520 checker::Type *calleeType = expr->callee_->Check(checker); in Check()
523 if (calleeType->IsObjectType()) { in Check()
524 checker::ObjectType *calleeObj = calleeType->AsObjectType(); in Check()
525 …return checker->ResolveCallOrNewExpression(calleeObj->CallSignatures(), expr->Arguments(), expr->S… in Check()
528 checker->ThrowTypeError("This expression is not callable.", expr->Start()); in Check()
532 checker::Type *TSAnalyzer::Check(ir::ChainExpression *expr) const in Check()
534 TSChecker *checker = GetTSChecker(); in Check() local
535 return expr->expression_->Check(checker); in Check()
538 checker::Type *TSAnalyzer::Check(ir::ConditionalExpression *expr) const in Check()
540 TSChecker *checker = GetTSChecker(); in Check() local
541 checker::Type *testType = expr->Test()->Check(checker); in Check()
543 checker->CheckTruthinessOfType(testType, expr->Test()->Start()); in Check()
544checker->CheckTestingKnownTruthyCallableOrAwaitableType(expr->Test(), testType, expr->Consequent()… in Check()
546 checker::Type *consequentType = expr->Consequent()->Check(checker); in Check()
547 checker::Type *alternateType = expr->Alternate()->Check(checker); in Check()
549 return checker->CreateUnionType({consequentType, alternateType}); in Check()
552 checker::Type *TSAnalyzer::Check(ir::FunctionExpression *expr) const in Check()
554 TSChecker *checker = GetTSChecker(); in Check() local
557 if (expr->Function()->Parent()->Parent() != nullptr && in Check()
558 expr->Function()->Parent()->Parent()->IsVariableDeclarator() && in Check()
559 expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { in Check()
560 …funcVar = expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Vari… in Check()
563 checker::ScopeContext scopeCtx(checker, expr->Function()->Scope()); in Check()
565 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
566 checker->CheckFunctionParameterDeclarations(expr->Function()->Params(), signatureInfo); in Check()
568 …auto *signature = checker->Allocator()->New<checker::Signature>(signatureInfo, checker->GlobalReso… in Check()
569 expr->Function()); in Check()
570 checker::Type *funcType = checker->CreateFunctionTypeWithSignature(signature); in Check()
572 if (funcVar != nullptr && funcVar->TsType() == nullptr) { in Check()
573 funcVar->SetTsType(funcType); in Check()
576 signature->SetReturnType(checker->HandleFunctionReturn(expr->Function())); in Check()
578 expr->Function()->Body()->Check(checker); in Check()
583 checker::Type *TSAnalyzer::Check(ir::Identifier *expr) const in Check()
585 TSChecker *checker = GetTSChecker(); in Check() local
586 if (expr->Variable() == nullptr) { in Check()
587 if (expr->Name().Is("undefined")) { in Check()
588 return checker->GlobalUndefinedType(); in Check()
591 checker->ThrowTypeError({"Cannot find name ", expr->Name()}, expr->Start()); in Check()
594 const varbinder::Decl *decl = expr->Variable()->Declaration(); in Check()
596 if (decl->IsTypeAliasDecl() || decl->IsInterfaceDecl()) { in Check()
597checker->ThrowTypeError({expr->Name(), " only refers to a type, but is being used as a value here.… in Check()
598 expr->Start()); in Check()
601 expr->SetTsType(checker->GetTypeOfVariable(expr->Variable())); in Check()
602 return expr->TsType(); in Check()
605 void TSAnalyzer::CheckComputed(ir::MemberExpression *expr, checker::Type *indexType) const in CheckComputed()
607 TSChecker *checker = GetTSChecker(); in CheckComputed() local
608 if (!indexType->HasTypeFlag(checker::TypeFlag::STRING_LIKE | checker::TypeFlag::NUMBER_LIKE)) { in CheckComputed()
609checker->ThrowTypeError({"Type ", indexType, " cannot be used as index type"}, expr->Property()->S… in CheckComputed()
612 if (indexType->IsNumberType()) { in CheckComputed()
613checker->ThrowTypeError("No index signature with a parameter of type 'string' was found on type th… in CheckComputed()
614 expr->Start()); in CheckComputed()
617 if (indexType->IsStringType()) { in CheckComputed()
618checker->ThrowTypeError("No index signature with a parameter of type 'number' was found on type th… in CheckComputed()
619 expr->Start()); in CheckComputed()
622 switch (expr->Property()->Type()) { in CheckComputed()
624 checker->ThrowTypeError( in CheckComputed()
625 … {"Property ", expr->Property()->AsIdentifier()->Name(), " does not exist on this type."}, in CheckComputed()
626 expr->Property()->Start()); in CheckComputed()
629 checker->ThrowTypeError( in CheckComputed()
630 … {"Property ", expr->Property()->AsNumberLiteral()->Str(), " does not exist on this type."}, in CheckComputed()
631 expr->Property()->Start()); in CheckComputed()
634 checker->ThrowTypeError( in CheckComputed()
635 … {"Property ", expr->Property()->AsStringLiteral()->Str(), " does not exist on this type."}, in CheckComputed()
636 expr->Property()->Start()); in CheckComputed()
644 checker::Type *TSAnalyzer::Check(ir::MemberExpression *expr) const in Check()
646 TSChecker *checker = GetTSChecker(); in Check() local
647checker::Type *baseType = checker->CheckNonNullType(expr->Object()->Check(checker), expr->Object() in Check()
649 if (expr->IsComputed()) { in Check()
650 checker::Type *indexType = expr->Property()->Check(checker); in Check()
651checker::Type *indexedAccessType = checker->GetPropertyTypeForIndexType(baseType, indexType); in Check()
659 …varbinder::Variable *prop = checker->GetPropertyOfType(baseType, expr->Property()->AsIdentifier()- in Check()
662 checker::Type *propType = checker->GetTypeOfVariable(prop); in Check()
663 if (prop->HasFlag(varbinder::VariableFlags::READONLY)) { in Check()
664 propType->AddTypeFlag(checker::TypeFlag::READONLY); in Check()
670 if (baseType->IsObjectType()) { in Check()
671 checker::ObjectType *objType = baseType->AsObjectType(); in Check()
673 if (objType->StringIndexInfo() != nullptr) { in Check()
674 checker::Type *indexType = objType->StringIndexInfo()->GetType(); in Check()
675 if (objType->StringIndexInfo()->Readonly()) { in Check()
676 indexType->AddTypeFlag(checker::TypeFlag::READONLY); in Check()
683checker->ThrowTypeError({"Property ", expr->Property()->AsIdentifier()->Name(), " does not exist o… in Check()
684 expr->Property()->Start()); in Check()
688 checker::Type *TSAnalyzer::Check(ir::NewExpression *expr) const in Check()
690 TSChecker *checker = GetTSChecker(); in Check() local
691 checker::Type *calleeType = expr->callee_->Check(checker); in Check()
693 if (calleeType->IsObjectType()) { in Check()
694 checker::ObjectType *calleeObj = calleeType->AsObjectType(); in Check()
695 …return checker->ResolveCallOrNewExpression(calleeObj->ConstructSignatures(), expr->Arguments(), ex… in Check()
698 checker->ThrowTypeError("This expression is not callable.", expr->Start()); in Check()
703 if (key->IsIdentifier()) { in GetPropertyName()
704 return key->AsIdentifier()->Name(); in GetPropertyName()
707 if (key->IsStringLiteral()) { in GetPropertyName()
708 return key->AsStringLiteral()->Str(); in GetPropertyName()
711 ES2PANDA_ASSERT(key->IsNumberLiteral()); in GetPropertyName()
712 return key->AsNumberLiteral()->Str(); in GetPropertyName()
717 if (!prop->IsMethod()) { in GetFlagsForProperty()
723 if (prop->IsAccessor() && prop->Kind() == ir::PropertyKind::GET) { in GetFlagsForProperty()
730 static checker::Type *GetTypeForProperty(ir::Property *prop, checker::TSChecker *checker) in GetTypeForProperty() argument
732 if (prop->IsAccessor()) { in GetTypeForProperty()
733 checker::Type *funcType = prop->Value()->Check(checker); in GetTypeForProperty()
735 if (prop->Kind() == ir::PropertyKind::SET) { in GetTypeForProperty()
736 return checker->GlobalAnyType(); in GetTypeForProperty()
739 ES2PANDA_ASSERT(funcType->IsObjectType() && funcType->AsObjectType()->IsFunctionType()); in GetTypeForProperty()
740 return funcType->AsObjectType()->CallSignatures()[0]->ReturnType(); in GetTypeForProperty()
743 if (prop->IsShorthand()) { in GetTypeForProperty()
744 return prop->Key()->Check(checker); in GetTypeForProperty()
747 return prop->Value()->Check(checker); in GetTypeForProperty()
751 checker::ObjectDescriptor *desc, ir::Expression *it) const in CheckSpread()
753 TSChecker *checker = GetTSChecker(); in CheckSpread() local
754 ES2PANDA_ASSERT(it->IsSpreadElement()); in CheckSpread()
756 checker::Type *const spreadType = it->AsSpreadElement()->Argument()->Check(checker); in CheckSpread()
759 if (!spreadType->IsObjectType()) { in CheckSpread()
760 checker->ThrowTypeError("Spread types may only be created from object types.", it->Start()); in CheckSpread()
763 for (auto *spreadProp : spreadType->AsObjectType()->Properties()) { in CheckSpread()
764 auto found = allPropertiesMap.find(spreadProp->Name()); in CheckSpread()
766checker->ThrowTypeError({found->first, " is specified more than once, so this usage will be overwr… in CheckSpread()
767 found->second); in CheckSpread()
770 varbinder::LocalVariable *foundMember = desc->FindProperty(spreadProp->Name()); in CheckSpread()
773 foundMember->SetTsType(spreadProp->TsType()); in CheckSpread()
777 desc->properties.push_back(spreadProp); in CheckSpread()
781 void TSAnalyzer::CheckNonComputed(checker::ObjectDescriptor *desc, ir::Expression *it, in CheckNonComputed()
785 TSChecker *checker = GetTSChecker(); in CheckNonComputed() local
786 auto *prop = it->AsProperty(); in CheckNonComputed()
787 checker::Type *propType = GetTypeForProperty(prop, checker); in CheckNonComputed()
789 util::StringView propName = GetPropertyName(prop->Key()); in CheckNonComputed()
791 auto *memberVar = varbinder::Scope::CreateVar(checker->Allocator(), propName, flags, it); in CheckNonComputed()
795 memberVar->AddFlag(varbinder::VariableFlags::READONLY); in CheckNonComputed()
797 propType = checker->GetBaseTypeOfLiteralType(propType); in CheckNonComputed()
800 memberVar->SetTsType(propType); in CheckNonComputed()
802 if (prop->Key()->IsNumberLiteral()) { in CheckNonComputed()
803 memberVar->AddFlag(varbinder::VariableFlags::NUMERIC_NAME); in CheckNonComputed()
806 varbinder::LocalVariable *foundMember = desc->FindProperty(propName); in CheckNonComputed()
807 allPropertiesMap.insert({propName, it->Start()}); in CheckNonComputed()
810 foundMember->SetTsType(propType); in CheckNonComputed()
814 desc->properties.push_back(memberVar); in CheckNonComputed()
817 checker::IndexInfo *TSAnalyzer::CreateUnionTypeHelper(ArenaVector<checker::Type *> &computedPropTyp… in CreateUnionTypeHelper()
820 TSChecker *checker = GetTSChecker(); in CreateUnionTypeHelper() local
822 …return checker->Allocator()->New<checker::IndexInfo>(checker->CreateUnionType(std::move(computedPr… in CreateUnionTypeHelper()
826 checker::Type *TSAnalyzer::Check(ir::ObjectExpression *expr) const in Check()
828 TSChecker *checker = GetTSChecker(); in Check() local
830checker::ObjectDescriptor *desc = checker->Allocator()->New<checker::ObjectDescriptor>(checker->Al… in Check()
832 bool inConstContext = checker->HasStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in Check()
833 ArenaVector<checker::Type *> computedNumberPropTypes(checker->Allocator()->Adapter()); in Check()
834 ArenaVector<checker::Type *> computedStringPropTypes(checker->Allocator()->Adapter()); in Check()
839 for (auto *it : expr->Properties()) { in Check()
840 if (it->IsProperty()) { in Check()
841 auto *prop = it->AsProperty(); in Check()
843 … if (prop->IsComputed() && checker->CheckComputedPropertyName(prop->Key())->IsNumberType()) { in Check()
845 computedNumberPropTypes.push_back(prop->Value()->Check(checker)); in Check()
849 … if (prop->IsComputed() && checker->CheckComputedPropertyName(prop->Key())->IsStringType()) { in Check()
851 computedStringPropTypes.push_back(prop->Value()->Check(checker)); in Check()
858 if (it->IsSpreadElement()) { in Check()
865 for (auto *it : desc->properties) { in Check()
866 computedStringPropTypes.push_back(it->TsType()); in Check()
868 if (hasComputedNumberProperty && it->HasFlag(varbinder::VariableFlags::NUMERIC_NAME)) { in Check()
869 computedNumberPropTypes.push_back(it->TsType()); in Check()
874 desc->numberIndexInfo = CreateUnionTypeHelper(computedNumberPropTypes, inConstContext); in Check()
878 desc->stringIndexInfo = CreateUnionTypeHelper(computedStringPropTypes, inConstContext); in Check()
882 checker::Type *returnType = checker->Allocator()->New<checker::ObjectLiteralType>(desc); in Check()
884 returnType->AsObjectType()->AddObjectFlag(checker::ObjectFlags::RESOLVED_MEMBERS | in Check()
885 checker::ObjectFlags::CHECK_EXCESS_PROPS); in Check()
889 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::OmittedExpression *expr) const in Check()
891 TSChecker *checker = GetTSChecker(); in Check() local
892 return checker->GlobalUndefinedType(); in Check()
895 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::OpaqueTypeNode *expr) const in Check()
897 return expr->TsType(); in Check()
900 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::BrokenTypeNode *expr) const in Check()
905 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::SequenceExpression *expr) const in Check()
907 TSChecker *checker = GetTSChecker(); in Check() local
909 return checker->GlobalAnyType(); in Check()
912 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::SuperExpression *expr) const in Check()
914 TSChecker *checker = GetTSChecker(); in Check() local
916 return checker->GlobalAnyType(); in Check()
919 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TaggedTemplateExpression *expr) const in Check()
921 TSChecker *checker = GetTSChecker(); in Check() local
923 return checker->GlobalAnyType(); in Check()
926 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TemplateLiteral *expr) const in Check()
928 TSChecker *checker = GetTSChecker(); in Check() local
930 return checker->GlobalAnyType(); in Check()
933 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ThisExpression *expr) const in Check()
935 TSChecker *checker = GetTSChecker(); in Check() local
937 return checker->GlobalAnyType(); in Check()
940 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TypeofExpression *expr) const in Check()
942 TSChecker *checker = GetTSChecker(); in Check() local
943 return checker->GlobalStringType(); in Check()
946 checker::Type *TSAnalyzer::CheckDeleteKeyword([[maybe_unused]] checker::TSChecker *checker, in CheckDeleteKeyword() argument
949 checker::Type *propType = expr->argument_->Check(checker); in CheckDeleteKeyword()
950 if (!expr->Argument()->IsMemberExpression()) { in CheckDeleteKeyword()
951 checker->ThrowTypeError("The operand of a delete operator must be a property reference.", in CheckDeleteKeyword()
952 expr->Argument()->Start()); in CheckDeleteKeyword()
954 if (propType->Variable()->HasFlag(varbinder::VariableFlags::READONLY)) { in CheckDeleteKeyword()
955 checker->ThrowTypeError("The operand of a delete operator cannot be a readonly property.", in CheckDeleteKeyword()
956 expr->Argument()->Start()); in CheckDeleteKeyword()
958 if (!propType->Variable()->HasFlag(varbinder::VariableFlags::OPTIONAL)) { in CheckDeleteKeyword()
959checker->ThrowTypeError("The operand of a delete operator must be a optional.", expr->Argument()->… in CheckDeleteKeyword()
961 return checker->GlobalBooleanType(); in CheckDeleteKeyword()
964 checker::Type *TSAnalyzer::CheckLiteral([[maybe_unused]] checker::TSChecker *checker, ir::UnaryExpr… in CheckLiteral() argument
966 if (!expr->Argument()->IsLiteral()) { in CheckLiteral()
970 const ir::Literal *lit = expr->Argument()->AsLiteral(); in CheckLiteral()
971 if (lit->IsNumberLiteral()) { in CheckLiteral()
972 auto numberValue = lit->AsNumberLiteral()->Number().GetDouble(); in CheckLiteral()
973 if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS) { in CheckLiteral()
974 return checker->CreateNumberLiteralType(numberValue); in CheckLiteral()
976 if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_MINUS) { in CheckLiteral()
977 return checker->CreateNumberLiteralType(-numberValue); in CheckLiteral()
979 … } else if (lit->IsBigIntLiteral() && expr->OperatorType() == lexer::TokenType::PUNCTUATOR_MINUS) { in CheckLiteral()
980 return checker->CreateBigintLiteralType(lit->AsBigIntLiteral()->Str(), true); in CheckLiteral()
986 checker::Type *TSAnalyzer::Check(ir::UnaryExpression *expr) const in Check()
988 TSChecker *checker = GetTSChecker(); in Check() local
989 checker::Type *operandType = expr->argument_->Check(checker); in Check()
991 if (expr->operator_ == lexer::TokenType::KEYW_TYPEOF) { in Check()
995 if (expr->operator_ == lexer::TokenType::KEYW_DELETE) { in Check()
996 return CheckDeleteKeyword(checker, expr); in Check()
999 auto *res = CheckLiteral(checker, expr); in Check()
1004 switch (expr->operator_) { in Check()
1008 checker->CheckNonNullType(operandType, expr->Start()); in Check()
1011 if (expr->operator_ == lexer::TokenType::PUNCTUATOR_PLUS) { in Check()
1012 … if (checker::TSChecker::MaybeTypeOfKind(operandType, checker::TypeFlag::BIGINT_LIKE)) { in Check()
1013checker->ThrowTypeError({"Operator '+' cannot be applied to type '", operandType, "'"}, in Check()
1014 expr->Start()); in Check()
1017 return checker->GlobalNumberType(); in Check()
1020 return checker->GetUnaryResultType(operandType); in Check()
1023 checker->CheckTruthinessOfType(operandType, expr->Start()); in Check()
1024 auto facts = operandType->GetTypeFacts(); in Check()
1025 if ((facts & checker::TypeFacts::TRUTHY) != 0) { in Check()
1026 return checker->GlobalFalseType(); in Check()
1029 if ((facts & checker::TypeFacts::FALSY) != 0) { in Check()
1030 return checker->GlobalTrueType(); in Check()
1033 return checker->GlobalBooleanType(); in Check()
1043 checker::Type *TSAnalyzer::Check(ir::UpdateExpression *expr) const in Check()
1045 TSChecker *checker = GetTSChecker(); in Check() local
1046 checker::Type *operandType = expr->argument_->Check(checker); in Check()
1047 checker->CheckNonNullType(operandType, expr->Start()); in Check()
1049 if (!operandType->HasTypeFlag(checker::TypeFlag::VALID_ARITHMETIC_TYPE)) { in Check()
1050checker->ThrowTypeError("An arithmetic operand must be of type 'any', 'number', 'bigint' or an enu… in Check()
1051 expr->Start()); in Check()
1054 checker->CheckReferenceExpression( in Check()
1055 …expr->argument_, "The operand of an increment or decrement operator must be a variable or a proper… in Check()
1058 return checker->GetUnaryResultType(operandType); in Check()
1061 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::YieldExpression *expr) const in Check()
1063 TSChecker *checker = GetTSChecker(); in Check() local
1065 return checker->GlobalAnyType(); in Check()
1068 checker::Type *TSAnalyzer::Check(ir::BigIntLiteral *expr) const in Check()
1070 TSChecker *checker = GetTSChecker(); in Check() local
1071 auto search = checker->BigintLiteralMap().find(expr->Str()); in Check()
1072 if (search != checker->BigintLiteralMap().end()) { in Check()
1073 return search->second; in Check()
1076 …auto *newBigintLiteralType = checker->Allocator()->New<checker::BigintLiteralType>(expr->Str(), fa… in Check()
1077 checker->BigintLiteralMap().insert({expr->Str(), newBigintLiteralType}); in Check()
1081 checker::Type *TSAnalyzer::Check(ir::BooleanLiteral *expr) const in Check()
1083 TSChecker *checker = GetTSChecker(); in Check() local
1084 return expr->Value() ? checker->GlobalTrueType() : checker->GlobalFalseType(); in Check()
1087 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::NullLiteral *expr) const in Check()
1089 TSChecker *checker = GetTSChecker(); in Check() local
1090 return checker->GlobalNullType(); in Check()
1093 checker::Type *TSAnalyzer::Check(ir::NumberLiteral *expr) const in Check()
1095 TSChecker *checker = GetTSChecker(); in Check() local
1096 auto search = checker->NumberLiteralMap().find(expr->Number().GetDouble()); in Check()
1097 if (search != checker->NumberLiteralMap().end()) { in Check()
1098 return search->second; in Check()
1101 …auto *newNumLiteralType = checker->Allocator()->New<checker::NumberLiteralType>(expr->Number().Get… in Check()
1102 checker->NumberLiteralMap().insert({expr->Number().GetDouble(), newNumLiteralType}); in Check()
1106 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::RegExpLiteral *expr) const in Check()
1108 TSChecker *checker = GetTSChecker(); in Check() local
1110 return checker->GlobalAnyType(); in Check()
1113 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::AnnotationDeclaration *expr) const in Check()
1118 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::AnnotationUsage *expr) const in Check()
1123 checker::Type *TSAnalyzer::Check(ir::StringLiteral *expr) const in Check()
1125 TSChecker *checker = GetTSChecker(); in Check() local
1126 auto search = checker->StringLiteralMap().find(expr->Str()); in Check()
1127 if (search != checker->StringLiteralMap().end()) { in Check()
1128 return search->second; in Check()
1131 auto *newStrLiteralType = checker->Allocator()->New<checker::StringLiteralType>(expr->Str()); in Check()
1132 checker->StringLiteralMap().insert({expr->Str(), newStrLiteralType}); in Check()
1137 checker::Type *TSAnalyzer::Check(ir::BlockStatement *st) const in Check()
1139 TSChecker *checker = GetTSChecker(); in Check() local
1140 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1142 for (auto *it : st->Statements()) { in Check()
1143 it->Check(checker); in Check()
1149 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::BreakStatement *st) const in Check()
1154 checker::Type *TSAnalyzer::Check(ir::DoWhileStatement *st) const in Check()
1156 TSChecker *checker = GetTSChecker(); in Check() local
1157 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1159 checker::Type *testType = st->Test()->Check(checker); in Check()
1160 checker->CheckTruthinessOfType(testType, st->Test()->Start()); in Check()
1161 st->Body()->Check(checker); in Check()
1166 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::EmptyStatement *st) const in Check()
1171 checker::Type *TSAnalyzer::Check(ir::ExpressionStatement *st) const in Check()
1173 TSChecker *checker = GetTSChecker(); in Check() local
1174 return st->GetExpression()->Check(checker); in Check()
1177 checker::Type *TSAnalyzer::Check(ir::ForUpdateStatement *st) const in Check()
1179 TSChecker *checker = GetTSChecker(); in Check() local
1180 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1182 if (st->Init() != nullptr) { in Check()
1183 st->Init()->Check(checker); in Check()
1186 if (st->Test() != nullptr) { in Check()
1187 checker::Type *testType = st->Test()->Check(checker); in Check()
1188 checker->CheckTruthinessOfType(testType, st->Start()); in Check()
1191 if (st->Update() != nullptr) { in Check()
1192 st->Update()->Check(checker); in Check()
1195 st->Body()->Check(checker); in Check()
1200 checker::Type *TSAnalyzer::Check(ir::FunctionDeclaration *st) const in Check()
1202 TSChecker *checker = GetTSChecker(); in Check() local
1203 if (st->Function()->IsOverload()) { in Check()
1207 const util::StringView &funcName = st->Function()->Id()->Name(); in Check()
1208 auto result = checker->Scope()->Find(funcName); in Check()
1211 checker::ScopeContext scopeCtx(checker, st->Function()->Scope()); in Check()
1213 if (result.variable->TsType() == nullptr) { in Check()
1214checker->InferFunctionDeclarationType(result.variable->Declaration()->AsFunctionDecl(), result.var… in Check()
1217 st->Function()->Body()->Check(checker); in Check()
1222 checker::Type *TSAnalyzer::Check(ir::IfStatement *st) const in Check()
1224 TSChecker *checker = GetTSChecker(); in Check() local
1225 checker::Type *testType = st->Test()->Check(checker); in Check()
1226 checker->CheckTruthinessOfType(testType, st->Start()); in Check()
1227 checker->CheckTestingKnownTruthyCallableOrAwaitableType(st->Test(), testType, st->Consequent()); in Check()
1229 st->Consequent()->Check(checker); in Check()
1231 if (st->Alternate() != nullptr) { in Check()
1232 st->Alternate()->Check(checker); in Check()
1238 checker::Type *TSAnalyzer::Check(ir::ReturnStatement *st) const in Check()
1240 TSChecker *checker = GetTSChecker(); in Check() local
1242 ES2PANDA_ASSERT(ancestor && ancestor->IsScriptFunction()); in Check()
1243 auto *containingFunc = ancestor->AsScriptFunction(); in Check()
1245 if (containingFunc->Parent()->Parent()->IsMethodDefinition()) { in Check()
1246 …const ir::MethodDefinition *containingClassMethod = containingFunc->Parent()->Parent()->AsMethodDe… in Check()
1247 if (containingClassMethod->Kind() == ir::MethodDefinitionKind::SET) { in Check()
1248 checker->ThrowTypeError("Setters cannot return a value", st->Start()); in Check()
1252 if (containingFunc->ReturnTypeAnnotation() != nullptr) { in Check()
1253 checker::Type *returnType = checker->GlobalUndefinedType(); in Check()
1254 checker::Type *funcReturnType = containingFunc->ReturnTypeAnnotation()->GetType(checker); in Check()
1256 if (st->Argument() != nullptr) { in Check()
1257 checker->ElaborateElementwise(funcReturnType, st->Argument(), st->Start()); in Check()
1258 returnType = checker->CheckTypeCached(st->Argument()); in Check()
1261 checker->IsTypeAssignableTo(returnType, funcReturnType, diagnostic::INVALID_ASSIGNMNENT_2, in Check()
1262 {returnType, funcReturnType}, st->Start()); in Check()
1268 checker::Type *TSAnalyzer::Check(ir::SwitchStatement *st) const in Check()
1270 TSChecker *checker = GetTSChecker(); in Check() local
1271 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1273 checker::Type *exprType = st->Discriminant()->Check(checker); in Check()
1274 bool exprIsLiteral = checker::TSChecker::IsLiteralType(exprType); in Check()
1276 for (auto *it : st->Cases()) { in Check()
1277 if (it->Test() != nullptr) { in Check()
1278 checker::Type *caseType = it->Test()->Check(checker); in Check()
1279 bool caseIsLiteral = checker::TSChecker::IsLiteralType(caseType); in Check()
1280 checker::Type *comparedExprType = exprType; in Check()
1283 caseType = caseIsLiteral ? checker->GetBaseTypeOfLiteralType(caseType) : caseType; in Check()
1284 comparedExprType = checker->GetBaseTypeOfLiteralType(exprType); in Check()
1287 if (!checker->IsTypeEqualityComparableTo(comparedExprType, caseType) && in Check()
1288 !checker->IsTypeComparableTo(caseType, comparedExprType)) { in Check()
1289checker->ThrowTypeError({"Type ", caseType, " is not comparable to type ", comparedExprType}, in Check()
1290 it->Test()->Start()); in Check()
1294 for (auto *caseStmt : it->Consequent()) { in Check()
1295 caseStmt->Check(checker); in Check()
1302 checker::Type *TSAnalyzer::Check(ir::TryStatement *st) const in Check()
1304 TSChecker *checker = GetTSChecker(); in Check() local
1305 st->Block()->Check(checker); in Check()
1307 for (auto *catchClause : st->CatchClauses()) { in Check()
1309 catchClause->Check(checker); in Check()
1313 if (st->HasFinalizer()) { in Check()
1314 st->finalizer_->Check(checker); in Check()
1320 static void CheckSimpleVariableDeclaration(checker::TSChecker *checker, ir::VariableDeclarator *dec… in CheckSimpleVariableDeclaration() argument
1322 varbinder::Variable *const bindingVar = declarator->Id()->AsIdentifier()->Variable(); in CheckSimpleVariableDeclaration()
1323 checker::Type *previousType = bindingVar->TsType(); in CheckSimpleVariableDeclaration()
1324 auto *const typeAnnotation = declarator->Id()->AsIdentifier()->TypeAnnotation(); in CheckSimpleVariableDeclaration()
1325 auto *const initializer = declarator->Init(); in CheckSimpleVariableDeclaration()
1326 const bool isConst = declarator->Parent()->AsVariableDeclaration()->Kind() == in CheckSimpleVariableDeclaration()
1330 checker->AddStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in CheckSimpleVariableDeclaration()
1334 typeAnnotation->Check(checker); in CheckSimpleVariableDeclaration()
1338 checker::Type *const annotationType = typeAnnotation->GetType(checker); in CheckSimpleVariableDeclaration()
1339 checker->ElaborateElementwise(annotationType, initializer, declarator->Id()->Start()); in CheckSimpleVariableDeclaration()
1340 bindingVar->SetTsType(annotationType); in CheckSimpleVariableDeclaration()
1342 bindingVar->SetTsType(typeAnnotation->GetType(checker)); in CheckSimpleVariableDeclaration()
1344 checker::Type *initializerType = checker->CheckTypeCached(initializer); in CheckSimpleVariableDeclaration()
1347 initializerType = checker->GetBaseTypeOfLiteralType(initializerType); in CheckSimpleVariableDeclaration()
1351 if (initializerType->IsNullType()) { in CheckSimpleVariableDeclaration()
1352 checker->ThrowTypeError( in CheckSimpleVariableDeclaration()
1353 … {"Cannot infer type for variable '", declarator->Id()->AsIdentifier()->Name(), "'."}, in CheckSimpleVariableDeclaration()
1354 declarator->Id()->Start()); in CheckSimpleVariableDeclaration()
1357 bindingVar->SetTsType(initializerType); in CheckSimpleVariableDeclaration()
1359checker->ThrowTypeError({"Variable ", declarator->Id()->AsIdentifier()->Name(), " implicitly has a… in CheckSimpleVariableDeclaration()
1360 declarator->Id()->Start()); in CheckSimpleVariableDeclaration()
1364checker->IsTypeIdenticalTo(bindingVar->TsType(), previousType, diagnostic::DIFFERENT_SUBSEQ_DECL, in CheckSimpleVariableDeclaration()
1365 … {bindingVar->Name(), previousType, bindingVar->TsType()}, declarator->Id()->Start()); in CheckSimpleVariableDeclaration()
1368 checker->RemoveStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in CheckSimpleVariableDeclaration()
1371 checker::Type *TSAnalyzer::Check(ir::VariableDeclarator *st) const in Check()
1373 TSChecker *checker = GetTSChecker(); in Check() local
1375 if (st->TsType() == st->CHECKED) { in Check()
1379 if (st->Id()->IsIdentifier()) { in Check()
1380 CheckSimpleVariableDeclaration(checker, st); in Check()
1381 st->SetTsType(st->CHECKED); in Check()
1385 if (st->Id()->IsArrayPattern()) { in Check()
1386 auto context = checker::SavedCheckerContext(checker, checker::CheckerStatus::FORCE_TUPLE); in Check()
1387 checker::ArrayDestructuringContext({checker, st->Id(), false, in Check()
1388 st->Id()->AsArrayPattern()->TypeAnnotation() == nullptr, in Check()
1389 … st->Id()->AsArrayPattern()->TypeAnnotation(), st->Init()}) in Check()
1392 st->SetTsType(st->CHECKED); in Check()
1396 ES2PANDA_ASSERT(st->Id()->IsObjectPattern()); in Check()
1397 auto context = checker::SavedCheckerContext(checker, checker::CheckerStatus::FORCE_TUPLE); in Check()
1398 checker::ObjectDestructuringContext({checker, st->Id(), false, in Check()
1399 st->Id()->AsObjectPattern()->TypeAnnotation() == nullptr, in Check()
1400 st->Id()->AsObjectPattern()->TypeAnnotation(), st->Init()}) in Check()
1403 st->SetTsType(st->CHECKED); in Check()
1407 checker::Type *TSAnalyzer::Check(ir::VariableDeclaration *st) const in Check()
1409 TSChecker *checker = GetTSChecker(); in Check() local
1410 for (auto *it : st->Declarators()) { in Check()
1411 it->Check(checker); in Check()
1417 checker::Type *TSAnalyzer::Check(ir::WhileStatement *st) const in Check()
1419 TSChecker *checker = GetTSChecker(); in Check() local
1420 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1422 checker::Type *testType = st->Test()->Check(checker); in Check()
1423 checker->CheckTruthinessOfType(testType, st->Test()->Start()); in Check()
1425 st->Body()->Check(checker); in Check()
1429 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSAnyKeyword *node) const in Check()
1434 checker::Type *TSAnalyzer::Check(ir::TSArrayType *node) const in Check()
1436 TSChecker *checker = GetTSChecker(); in Check() local
1437 node->elementType_->Check(checker); in Check()
1441 static bool IsValidConstAssertionArgument(checker::Checker *checker, const ir::AstNode *arg) in IsValidConstAssertionArgument() argument
1443 switch (arg->Type()) { in IsValidConstAssertionArgument()
1454 const ir::UnaryExpression *unaryExpr = arg->AsUnaryExpression(); in IsValidConstAssertionArgument()
1455 lexer::TokenType op = unaryExpr->OperatorType(); in IsValidConstAssertionArgument()
1456 const ir::Expression *unaryArg = unaryExpr->Argument(); in IsValidConstAssertionArgument()
1457 return (op == lexer::TokenType::PUNCTUATOR_MINUS && unaryArg->IsLiteral() && in IsValidConstAssertionArgument()
1458 … (unaryArg->AsLiteral()->IsNumberLiteral() || unaryArg->AsLiteral()->IsBigIntLiteral())) || in IsValidConstAssertionArgument()
1459 (op == lexer::TokenType::PUNCTUATOR_PLUS && unaryArg->IsLiteral() && in IsValidConstAssertionArgument()
1460 unaryArg->AsLiteral()->IsNumberLiteral()); in IsValidConstAssertionArgument()
1463 const ir::MemberExpression *memberExpr = arg->AsMemberExpression(); in IsValidConstAssertionArgument()
1464 if (memberExpr->Object()->IsIdentifier()) { in IsValidConstAssertionArgument()
1465 auto result = checker->Scope()->Find(memberExpr->Object()->AsIdentifier()->Name()); in IsValidConstAssertionArgument()
1466 … constexpr auto ENUM_LITERAL_TYPE = checker::EnumLiteralType::EnumLiteralTypeKind::LITERAL; in IsValidConstAssertionArgument()
1468 result.variable->TsType()->HasTypeFlag(checker::TypeFlag::ENUM_LITERAL) && in IsValidConstAssertionArgument()
1469 result.variable->TsType()->AsEnumLiteralType()->Kind() == ENUM_LITERAL_TYPE) { in IsValidConstAssertionArgument()
1480 checker::Type *TSAnalyzer::Check(ir::TSAsExpression *expr) const in Check()
1482 TSChecker *checker = GetTSChecker(); in Check() local
1483 if (expr->IsConst()) { in Check()
1484 … auto context = checker::SavedCheckerContext(checker, checker::CheckerStatus::IN_CONST_CONTEXT); in Check()
1485 checker::Type *exprType = expr->Expr()->Check(checker); in Check()
1487 if (!IsValidConstAssertionArgument(checker, expr->Expr())) { in Check()
1488 checker->ThrowTypeError( in Check()
1491 expr->Expr()->Start()); in Check()
1497 auto context = checker::SavedCheckerContext(checker, checker::CheckerStatus::NO_OPTS); in Check()
1499 expr->TypeAnnotation()->Check(checker); in Check()
1500 checker::Type *exprType = checker->GetBaseTypeOfLiteralType(expr->Expr()->Check(checker)); in Check()
1501 checker::Type *targetType = expr->TypeAnnotation()->GetType(checker); in Check()
1503checker->IsTypeComparableTo(targetType, exprType, diagnostic::DISJOINT_CONVERSION, {exprType, targ… in Check()
1504 expr->Start()); in Check()
1509 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSBigintKeyword *node) const in Check()
1514 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSBooleanKeyword *node) const in Check()
1519 checker::Type *TSAnalyzer::Check(ir::TSConstructorType *node) const in Check()
1521 TSChecker *checker = GetTSChecker(); in Check() local
1522 checker::ScopeContext scopeCtx(checker, node->Scope()); in Check()
1524 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
1525 checker->CheckFunctionParameterDeclarations(node->Params(), signatureInfo); in Check()
1526 node->ReturnType()->Check(checker); in Check()
1528checker->Allocator()->New<checker::Signature>(signatureInfo, node->ReturnType()->GetType(checker)); in Check()
1530 return checker->CreateConstructorTypeWithSignature(constructSignature); in Check()
1533 static varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varbinder::EnumV… in EvaluateIdentifier() argument
1536 if (expr->Name() == "NaN") { in EvaluateIdentifier()
1539 if (expr->Name() == "Infinity") { in EvaluateIdentifier()
1543 varbinder::Variable *enumMember = expr->AsIdentifier()->Variable(); in EvaluateIdentifier()
1546 checker->ThrowTypeError({"Cannot find name ", expr->AsIdentifier()->Name()}, in EvaluateIdentifier()
1547 enumVar->Declaration()->Node()->Start()); in EvaluateIdentifier()
1550 if (enumMember->IsEnumVariable()) { in EvaluateIdentifier()
1551 varbinder::EnumVariable *exprEnumVar = enumMember->AsEnumVariable(); in EvaluateIdentifier()
1552 if (std::holds_alternative<bool>(exprEnumVar->Value())) { in EvaluateIdentifier()
1553 checker->ThrowTypeError( in EvaluateIdentifier()
1557 enumVar->Declaration()->Node()->Start()); in EvaluateIdentifier()
1560 return exprEnumVar->Value(); in EvaluateIdentifier()
1601 case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) in GetOperationResulForDouble()
1604 case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) in GetOperationResulForDouble()
1614 return std::get<double>(left) - std::get<double>(right); in GetOperationResulForDouble()
1634 varbinder::EnumMemberResult TSAnalyzer::EvaluateBinaryExpression(checker::TSChecker *checker, in EvaluateBinaryExpression() argument
1638 …varbinder::EnumMemberResult left = EvaluateEnumMember(checker, enumVar, expr->AsBinaryExpression() in EvaluateBinaryExpression()
1639 …arbinder::EnumMemberResult right = EvaluateEnumMember(checker, enumVar, expr->AsBinaryExpression() in EvaluateBinaryExpression()
1641 GetOperationResulForDouble(expr->AsBinaryExpression()->OperatorType(), left, right); in EvaluateBinaryExpression()
1645 expr->AsBinaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS) { in EvaluateBinaryExpression()
1649 util::UString res(ss.str(), checker->Allocator()); in EvaluateBinaryExpression()
1656 varbinder::EnumMemberResult TSAnalyzer::EvaluateUnaryExpression(checker::TSChecker *checker, in EvaluateUnaryExpression() argument
1660 varbinder::EnumMemberResult value = EvaluateEnumMember(checker, enumVar, expr->Argument()); in EvaluateUnaryExpression()
1665 switch (expr->OperatorType()) { in EvaluateUnaryExpression()
1670 return -std::get<double>(value); in EvaluateUnaryExpression()
1673 … return static_cast<double>(~ToInt(std::get<double>(value))); // NOLINT(hicpp-signed-bitwise) in EvaluateUnaryExpression()
1683 varbinder::EnumMemberResult TSAnalyzer::EvaluateEnumMember(checker::TSChecker *checker, in EvaluateEnumMember() argument
1687 switch (expr->Type()) { in EvaluateEnumMember()
1689 return EvaluateUnaryExpression(checker, enumVar, expr->AsUnaryExpression()); in EvaluateEnumMember()
1692 return EvaluateBinaryExpression(checker, enumVar, expr->AsBinaryExpression()); in EvaluateEnumMember()
1695 return expr->AsNumberLiteral()->Number().GetDouble(); in EvaluateEnumMember()
1698 return expr->AsStringLiteral()->Str(); in EvaluateEnumMember()
1701 return EvaluateIdentifier(checker, enumVar, expr->AsIdentifier()); in EvaluateEnumMember()
1704 return EvaluateEnumMember(checker, enumVar, expr->AsMemberExpression()); in EvaluateEnumMember()
1715 if (init->IsLiteral()) { in IsComputedEnumMember()
1716 return !init->AsLiteral()->IsStringLiteral() && !init->AsLiteral()->IsNumberLiteral(); in IsComputedEnumMember()
1719 if (init->IsTemplateLiteral()) { in IsComputedEnumMember()
1720 return !init->AsTemplateLiteral()->Quasis().empty(); in IsComputedEnumMember()
1726 static void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbinder::EnumVari… in AddEnumValueDeclaration() argument
1728 variable->SetTsType(checker->GlobalNumberType()); in AddEnumValueDeclaration()
1730 util::StringView memberStr = util::Helpers::ToStringView(checker->Allocator(), number); in AddEnumValueDeclaration()
1732 varbinder::LocalScope *enumScope = checker->Scope()->AsLocalScope(); in AddEnumValueDeclaration()
1733 …varbinder::Variable *res = enumScope->FindLocal(memberStr, varbinder::ResolveBindingOptions::BINDI… in AddEnumValueDeclaration()
1737 auto *decl = checker->Allocator()->New<varbinder::EnumDecl>(memberStr); in AddEnumValueDeclaration()
1739 decl->BindNode(variable->Declaration()->Node()); in AddEnumValueDeclaration()
1740 enumScope->AddDecl(checker->Allocator(), decl, ScriptExtension::TS); in AddEnumValueDeclaration()
1741 res = enumScope->FindLocal(memberStr, varbinder::ResolveBindingOptions::BINDINGS); in AddEnumValueDeclaration()
1742 ES2PANDA_ASSERT(res && res->IsEnumVariable()); in AddEnumValueDeclaration()
1743 enumVar = res->AsEnumVariable(); in AddEnumValueDeclaration()
1744 enumVar->AsEnumVariable()->SetBackReference(); in AddEnumValueDeclaration()
1745 enumVar->SetTsType(checker->GlobalStringType()); in AddEnumValueDeclaration()
1747 ES2PANDA_ASSERT(res->IsEnumVariable()); in AddEnumValueDeclaration()
1748 enumVar = res->AsEnumVariable(); in AddEnumValueDeclaration()
1749 auto *decl = checker->Allocator()->New<varbinder::EnumDecl>(memberStr); in AddEnumValueDeclaration()
1751 decl->BindNode(variable->Declaration()->Node()); in AddEnumValueDeclaration()
1752 enumVar->ResetDecl(decl); in AddEnumValueDeclaration()
1755 enumVar->SetValue(variable->Declaration()->Name()); in AddEnumValueDeclaration()
1758 // NOLINTBEGIN(modernize-avoid-c-arrays)
1766 "'const' enum member initializer was evaluated to a non-finite value.";
1767 // NOLINTEND(modernize-avoid-c-arrays)
1772 TSChecker *checker = GetTSChecker(); in InferEnumVariableType() local
1773 const ir::Expression *init = variable->Declaration()->Node()->AsTSEnumMember()->Init(); in InferEnumVariableType()
1776checker->ThrowTypeError("Enum member must have initializer.", variable->Declaration()->Node()->Sta… in InferEnumVariableType()
1780 variable->SetValue(++(*value)); in InferEnumVariableType()
1781 AddEnumValueDeclaration(checker, *value, variable); in InferEnumVariableType()
1787 checker->ThrowTypeError(INVALID_COMPUTED_WITH_STRING, init->Start()); in InferEnumVariableType()
1790 varbinder::EnumMemberResult res = EvaluateEnumMember(checker, variable, init); in InferEnumVariableType()
1793 variable->SetTsType(checker->GlobalStringType()); in InferEnumVariableType()
1800 checker->ThrowTypeError(INVALID_CONST_MEMBER, init->Start()); in InferEnumVariableType()
1808 variable->SetValue(res); in InferEnumVariableType()
1812 checker->ThrowTypeError(INVALID_CONST_NAN, init->Start()); in InferEnumVariableType()
1816 checker->ThrowTypeError(INVALID_CONST_INF, init->Start()); in InferEnumVariableType()
1820 AddEnumValueDeclaration(checker, *value, variable); in InferEnumVariableType()
1823 checker::Type *TSAnalyzer::InferType(checker::TSChecker *checker, bool isConst, ir::TSEnumDeclarati… in InferType() argument
1825 double value = -1.0; in InferType()
1827 varbinder::LocalScope *enumScope = checker->Scope()->AsLocalScope(); in InferType()
1831 size_t localsSize = enumScope->Decls().size(); in InferType()
1834 const util::StringView &currentName = enumScope->Decls()[i]->Name(); in InferType()
1835 …varbinder::Variable *currentVar = enumScope->FindLocal(currentName, varbinder::ResolveBindingOptio… in InferType()
1836 ES2PANDA_ASSERT(currentVar && currentVar->IsEnumVariable()); in InferType()
1837 … InferEnumVariableType(currentVar->AsEnumVariable(), &value, &initNext, &isLiteralEnum, isConst); in InferType()
1840 checker::Type *enumType = checker->Allocator()->New<checker::EnumLiteralType>( in InferType()
1841 st->Key()->Name(), checker->Scope(), in InferType()
1842 isLiteralEnum ? checker::EnumLiteralType::EnumLiteralTypeKind::LITERAL in InferType()
1843 : checker::EnumLiteralType::EnumLiteralTypeKind::NUMERIC); in InferType()
1848 checker::Type *TSAnalyzer::Check(ir::TSEnumDeclaration *st) const in Check()
1850 TSChecker *checker = GetTSChecker(); in Check() local
1851 varbinder::Variable *enumVar = st->Key()->Variable(); in Check()
1854 if (enumVar->TsType() == nullptr) { in Check()
1855 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1856 checker::Type *enumType = InferType(checker, st->IsConst(), st); in Check()
1858 enumType->SetVariable(enumVar); in Check()
1859 enumVar->SetTsType(enumType); in Check()
1865 checker::Type *TSAnalyzer::Check(ir::TSFunctionType *node) const in Check()
1867 TSChecker *checker = GetTSChecker(); in Check() local
1868 checker::ScopeContext scopeCtx(checker, node->Scope()); in Check()
1870 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
1871 checker->CheckFunctionParameterDeclarations(node->Params(), signatureInfo); in Check()
1872 node->ReturnType()->Check(checker); in Check()
1874checker->Allocator()->New<checker::Signature>(signatureInfo, node->ReturnType()->GetType(checker)); in Check()
1876 return checker->CreateFunctionTypeWithSignature(callSignature); in Check()
1879 checker::Type *TSAnalyzer::Check(ir::TSIndexedAccessType *node) const in Check()
1881 TSChecker *checker = GetTSChecker(); in Check() local
1882 node->objectType_->Check(checker); in Check()
1883 node->indexType_->Check(checker); in Check()
1884 checker::Type *resolved = node->GetType(checker); in Check()
1890 checker::Type *indexType = checker->CheckTypeCached(node->indexType_); in Check()
1892 if (!indexType->HasTypeFlag(checker::TypeFlag::STRING_LIKE | checker::TypeFlag::NUMBER_LIKE)) { in Check()
1893checker->ThrowTypeError({"Type ", indexType, " cannot be used as index type"}, node->IndexType()->… in Check()
1896 if (indexType->IsNumberType()) { in Check()
1897 checker->ThrowTypeError("Type has no matching signature for type 'number'", node->Start()); in Check()
1900 checker->ThrowTypeError("Type has no matching signature for type 'string'", node->Start()); in Check()
1904 checker::Type *TSAnalyzer::Check(ir::TSInterfaceBody *expr) const in Check()
1906 TSChecker *checker = GetTSChecker(); in Check() local
1907 for (auto *it : expr->Body()) { in Check()
1908 it->Check(checker); in Check()
1914 static void CheckInheritedPropertiesAreIdentical(checker::TSChecker *checker, checker::InterfaceTyp… in CheckInheritedPropertiesAreIdentical() argument
1917 checker->GetBaseTypes(type); in CheckInheritedPropertiesAreIdentical()
1920 if (type->Bases().size() < BASE_SIZE_LIMIT) { in CheckInheritedPropertiesAreIdentical()
1924 checker->ResolveDeclaredMembers(type); in CheckInheritedPropertiesAreIdentical()
1926 checker::InterfacePropertyMap properties; in CheckInheritedPropertiesAreIdentical()
1928 for (auto *it : type->Properties()) { in CheckInheritedPropertiesAreIdentical()
1929 properties.insert({it->Name(), {it, type}}); in CheckInheritedPropertiesAreIdentical()
1932 for (auto *base : type->Bases()) { in CheckInheritedPropertiesAreIdentical()
1933 checker->ResolveStructuredTypeMembers(base); in CheckInheritedPropertiesAreIdentical()
1934 … ArenaVector<varbinder::LocalVariable *> inheritedProperties(checker->Allocator()->Adapter()); in CheckInheritedPropertiesAreIdentical()
1935 base->AsInterfaceType()->CollectProperties(&inheritedProperties); in CheckInheritedPropertiesAreIdentical()
1938 auto res = properties.find(inheritedProp->Name()); in CheckInheritedPropertiesAreIdentical()
1940 … properties.insert({inheritedProp->Name(), {inheritedProp, base->AsInterfaceType()}}); in CheckInheritedPropertiesAreIdentical()
1941 } else if (res->second.second != type) { in CheckInheritedPropertiesAreIdentical()
1942 checker::Type *sourceType = checker->GetTypeOfVariable(inheritedProp); in CheckInheritedPropertiesAreIdentical()
1943 checker::Type *targetType = checker->GetTypeOfVariable(res->second.first); in CheckInheritedPropertiesAreIdentical()
1944checker->IsTypeIdenticalTo(sourceType, targetType, diagnostic::IFACE_MULTIPLE_EXTENSION, in CheckInheritedPropertiesAreIdentical()
1945 … {type, res->second.second, base->AsInterfaceType()}, locInfo); in CheckInheritedPropertiesAreIdentical()
1951 checker::Type *TSAnalyzer::Check(ir::TSInterfaceDeclaration *st) const in Check()
1953 TSChecker *checker = GetTSChecker(); in Check() local
1954 varbinder::Variable *var = st->Id()->Variable(); in Check()
1955 …ES2PANDA_ASSERT(var->Declaration()->Node() && var->Declaration()->Node()->IsTSInterfaceDeclaration… in Check()
1957 if (st == var->Declaration()->Node()) { in Check()
1958 checker::Type *resolvedType = var->TsType(); in Check()
1961 checker::ObjectDescriptor *desc = in Check()
1962 checker->Allocator()->New<checker::ObjectDescriptor>(checker->Allocator()); in Check()
1964checker->Allocator()->New<checker::InterfaceType>(checker->Allocator(), st->Id()->Name(), desc); in Check()
1966 resolvedType->SetVariable(var); in Check()
1967 var->SetTsType(resolvedType); in Check()
1970 checker::InterfaceType *resolvedInterface = resolvedType->AsObjectType()->AsInterfaceType(); in Check()
1971 CheckInheritedPropertiesAreIdentical(checker, resolvedInterface, st->Id()->Start()); in Check()
1973 for (auto *base : resolvedInterface->Bases()) { in Check()
1974 checker->IsTypeAssignableTo(resolvedInterface, base, diagnostic::IFACE_INVALID_EXTENDS, in Check()
1975 {st->Id()->Name(), base}, st->Id()->Start()); in Check()
1978 checker->CheckIndexConstraints(resolvedInterface); in Check()
1981 st->Body()->Check(checker); in Check()
1986 checker::Type *TSAnalyzer::Check(ir::TSLiteralType *node) const in Check()
1988 TSChecker *checker = GetTSChecker(); in Check() local
1989 node->GetType(checker); in Check()
1993 checker::Type *TSAnalyzer::Check(ir::TSNamedTupleMember *node) const in Check()
1995 TSChecker *checker = GetTSChecker(); in Check() local
1996 node->ElementType()->Check(checker); in Check()
2000 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSNeverKeyword *node) const in Check()
2005 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSNullKeyword *node) const in Check()
2010 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSNumberKeyword *node) const in Check()
2015 checker::Type *TSAnalyzer::Check(ir::TSParenthesizedType *node) const in Check()
2017 TSChecker *checker = GetTSChecker(); in Check() local
2018 node->type_->Check(checker); in Check()
2022 checker::Type *TSAnalyzer::Check(ir::TSQualifiedName *expr) const in Check()
2024 TSChecker *checker = GetTSChecker(); in Check() local
2025checker::Type *baseType = checker->CheckNonNullType(expr->Left()->Check(checker), expr->Left()->St… in Check()
2026 varbinder::Variable *prop = checker->GetPropertyOfType(baseType, expr->Right()->Name()); in Check()
2029 return checker->GetTypeOfVariable(prop); in Check()
2032 if (baseType->IsObjectType()) { in Check()
2033 checker::ObjectType *objType = baseType->AsObjectType(); in Check()
2035 if (objType->StringIndexInfo() != nullptr) { in Check()
2036 return objType->StringIndexInfo()->GetType(); in Check()
2040 checker->ThrowTypeError({"Property ", expr->Right()->Name(), " does not exist on this type."}, in Check()
2041 expr->Right()->Start()); in Check()
2045 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSStringKeyword *node) const in Check()
2050 checker::Type *TSAnalyzer::Check(ir::TSTupleType *node) const in Check()
2052 TSChecker *checker = GetTSChecker(); in Check() local
2053 for (auto *it : node->ElementType()) { in Check()
2054 it->Check(checker); in Check()
2057 node->GetType(checker); in Check()
2061 checker::Type *TSAnalyzer::Check(ir::TSTypeAliasDeclaration *st) const in Check()
2063 TSChecker *checker = GetTSChecker(); in Check() local
2064 st->TypeAnnotation()->Check(checker); in Check()
2068 checker::Type *TSAnalyzer::Check(ir::TSTypeLiteral *node) const in Check()
2070 TSChecker *checker = GetTSChecker(); in Check() local
2072 for (auto *it : node->Members()) { in Check()
2073 it->Check(checker); in Check()
2076 checker::Type *type = node->GetType(checker); in Check()
2077 checker->CheckIndexConstraints(type); in Check()
2082 checker::Type *TSAnalyzer::Check(ir::TSTypeQuery *node) const in Check()
2084 TSChecker *checker = GetTSChecker(); in Check() local
2085 if (node->TsType() != nullptr) { in Check()
2086 return node->TsType(); in Check()
2089 node->SetTsType(node->exprName_->Check(checker)); in Check()
2090 return node->TsType(); in Check()
2093 checker::Type *TSAnalyzer::Check(ir::TSTypeReference *node) const in Check()
2095 TSChecker *checker = GetTSChecker(); in Check() local
2096 node->GetType(checker); in Check()
2100 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSUndefinedKeyword *node) const in Check()
2105 checker::Type *TSAnalyzer::Check(ir::TSUnionType *node) const in Check()
2107 TSChecker *checker = GetTSChecker(); in Check() local
2108 for (auto *it : node->Types()) { in Check()
2109 it->Check(checker); in Check()
2112 node->GetType(checker); in Check()
2116 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSUnknownKeyword *node) const in Check()
2121 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSVoidKeyword *node) const in Check()
2125 } // namespace ark::es2panda::checker