• Home
  • Raw
  • Download

Lines Matching +full:checker +full:-

2  * Copyright (c) 2021-2024 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()
77 if (node->Kind() == ir::TSIndexSignature::TSIndexSignatureKind::NUMBER) { in Check()
78 placeholder->Desc()->numberIndexInfo = info; in Check()
80 placeholder->Desc()->stringIndexInfo = info; in Check()
83 node->SetTsType(placeholder); in Check()
87 checker::Type *TSAnalyzer::Check(ir::TSMethodSignature *node) const in Check()
89 TSChecker *checker = GetTSChecker(); in Check() local
90 if (node->Computed()) { in Check()
91 checker->CheckComputedPropertyName(node->Key()); in Check()
94 checker::ScopeContext scopeCtx(checker, node->Scope()); in Check()
96 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
97 checker->CheckFunctionParameterDeclarations(node->Params(), signatureInfo); in Check()
99 …auto *callSignature = checker->Allocator()->New<checker::Signature>(signatureInfo, checker->Global… in Check()
100 node->Variable()->SetTsType(checker->CreateFunctionTypeWithSignature(callSignature)); in Check()
102 auto returnType = node->ReturnTypeAnnotation(); in Check()
104 checker->ThrowTypeError( in Check()
105 … "Method signature, which lacks return-type annotation, implicitly has an 'any' return type.", in Check()
106 node->Start()); in Check()
109 returnType->Check(checker); in Check()
110 callSignature->SetReturnType(returnType->GetType(checker)); in Check()
115 checker::Type *TSAnalyzer::Check(ir::TSPropertySignature *node) const in Check()
117 TSChecker *checker = GetTSChecker(); in Check() local
118 if (node->TypeAnnotation() != nullptr) { in Check()
119 node->TypeAnnotation()->Check(checker); in Check()
122 if (node->Computed()) { in Check()
123 checker->CheckComputedPropertyName(node->Key()); in Check()
126 if (node->TypeAnnotation() != nullptr) { in Check()
127 node->Variable()->SetTsType(node->TypeAnnotation()->GetType(checker)); in Check()
131 checker->ThrowTypeError("Property implicitly has an 'any' type.", node->Start()); in Check()
135 checker::Type *TSAnalyzer::Check(ir::TSSignatureDeclaration *node) const in Check()
137 TSChecker *checker = GetTSChecker(); in Check() local
138 if (node->TsType() != nullptr) { in Check()
139 return node->TsType(); in Check()
142 checker::ScopeContext scopeCtx(checker, node->Scope()); in Check()
144 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
145 checker->CheckFunctionParameterDeclarations(node->Params(), signatureInfo); in Check()
147 …bool isCallSignature = (node->Kind() == ir::TSSignatureDeclaration::TSSignatureDeclarationKind::CA… in Check()
149 if (node->ReturnTypeAnnotation() == nullptr) { in Check()
151 checker->ThrowTypeError( in Check()
152 … "Call signature, which lacks return-type annotation, implicitly has an 'any' return type.", in Check()
153 node->Start()); in Check()
156 checker->ThrowTypeError( in Check()
157 … "Construct signature, which lacks return-type annotation, implicitly has an 'any' return type.", in Check()
158 node->Start()); in Check()
161 node->ReturnTypeAnnotation()->Check(checker); in Check()
162 checker::Type *returnType = node->ReturnTypeAnnotation()->GetType(checker); in Check()
164 auto *signature = checker->Allocator()->New<checker::Signature>(signatureInfo, returnType); in Check()
166 checker::Type *placeholderObj = nullptr; in Check()
169 placeholderObj = checker->CreateObjectTypeWithCallSignature(signature); in Check()
171 placeholderObj = checker->CreateObjectTypeWithConstructSignature(signature); in Check()
174 node->SetTsType(placeholderObj); in Check()
178 static void GetSpreadElementType(checker::TSChecker *checker, checker::Type *spreadType, in GetSpreadElementType() argument
179 … ArenaVector<checker::Type *> &elementTypes, const lexer::SourcePosition &loc) in GetSpreadElementType()
181 bool inConstContext = checker->HasStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in GetSpreadElementType()
183 if (spreadType->IsObjectType() && spreadType->AsObjectType()->IsTupleType()) { in GetSpreadElementType()
184 ArenaVector<checker::Type *> tupleElementTypes(checker->Allocator()->Adapter()); in GetSpreadElementType()
185 checker::TupleType *spreadTuple = spreadType->AsObjectType()->AsTupleType(); in GetSpreadElementType()
187 for (auto *it : spreadTuple->Properties()) { in GetSpreadElementType()
189 elementTypes.push_back(it->TsType()); in GetSpreadElementType()
193 tupleElementTypes.push_back(it->TsType()); in GetSpreadElementType()
200 elementTypes.push_back(checker->CreateUnionType(std::move(tupleElementTypes))); in GetSpreadElementType()
204 if (!spreadType->IsUnionType()) { in GetSpreadElementType()
205 checker->ThrowTypeError( in GetSpreadElementType()
210 ArenaVector<checker::Type *> spreadTypes(checker->Allocator()->Adapter()); in GetSpreadElementType()
213 for (auto *type : spreadType->AsUnionType()->ConstituentTypes()) { in GetSpreadElementType()
214 if (type->IsArrayType()) { in GetSpreadElementType()
215 spreadTypes.push_back(type->AsArrayType()->ElementType()); in GetSpreadElementType()
219 if (type->IsObjectType() && type->AsObjectType()->IsTupleType()) { in GetSpreadElementType()
220 checker::TupleType *tuple = type->AsObjectType()->AsTupleType(); in GetSpreadElementType()
222 for (auto *it : tuple->Properties()) { in GetSpreadElementType()
223 spreadTypes.push_back(it->TsType()); in GetSpreadElementType()
234 elementTypes.push_back(checker->CreateUnionType(std::move(spreadTypes))); in GetSpreadElementType()
238 checker->ThrowTypeError( in GetSpreadElementType()
242 checker::Type *TSAnalyzer::Check(ir::ArrayExpression *expr) const in Check()
244 TSChecker *checker = GetTSChecker(); in Check() local
245 ArenaVector<checker::Type *> elementTypes(checker->Allocator()->Adapter()); in Check()
246 ArenaVector<checker::ElementFlags> elementFlags(checker->Allocator()->Adapter()); in Check()
247 bool inConstContext = checker->HasStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in Check()
248 bool createTuple = checker->HasStatus(checker::CheckerStatus::FORCE_TUPLE); in Check()
250 for (auto *it : expr->Elements()) { in Check()
251 if (it->IsSpreadElement()) { in Check()
252 checker::Type *spreadType = it->AsSpreadElement()->Argument()->Check(checker); in Check()
254 if (spreadType->IsArrayType()) { in Check()
255 … elementTypes.push_back(inConstContext ? spreadType : spreadType->AsArrayType()->ElementType()); in Check()
256 elementFlags.push_back(checker::ElementFlags::VARIADIC); in Check()
260 GetSpreadElementType(checker, spreadType, elementTypes, it->Start()); in Check()
261 elementFlags.push_back(checker::ElementFlags::REST); in Check()
265 checker::Type *elementType = it->Check(checker); in Check()
268 elementType = checker->GetBaseTypeOfLiteralType(elementType); in Check()
271 elementFlags.push_back(checker::ElementFlags::REQUIRED); in Check()
276checker::ObjectDescriptor *desc = checker->Allocator()->New<checker::ObjectDescriptor>(checker->Al… in Check()
280 util::StringView memberIndex = util::Helpers::ToStringView(checker->Allocator(), index); in Check()
282 checker->Allocator(), memberIndex, varbinder::VariableFlags::PROPERTY, nullptr); in Check()
285 tupleMember->AddFlag(varbinder::VariableFlags::READONLY); in Check()
288 tupleMember->SetTsType(*it); in Check()
289 desc->properties.push_back(tupleMember); in Check()
292 …const checker::TupleTypeInfo tupleTypeInfo = {ElementFlags::REQUIRED, index, index, inConstContext… in Check()
293 return checker->CreateTupleType(desc, std::move(elementFlags), tupleTypeInfo); in Check()
296 checker::Type *arrayElementType = nullptr; in Check()
298 arrayElementType = checker->GlobalAnyType(); in Check()
300 arrayElementType = checker->CreateUnionType(std::move(elementTypes)); in Check()
303 return checker->Allocator()->New<checker::ArrayType>(arrayElementType); in Check()
306 checker::Type *TSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const in Check()
308 TSChecker *checker = GetTSChecker(); in Check() local
311 if (expr->Function()->Parent()->Parent() != nullptr && in Check()
312 expr->Function()->Parent()->Parent()->IsVariableDeclarator() && in Check()
313 expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { in Check()
314 …funcVar = expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Vari… in Check()
317 checker::ScopeContext scopeCtx(checker, expr->Function()->Scope()); in Check()
319 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
320 checker->CheckFunctionParameterDeclarations(expr->Function()->Params(), signatureInfo); in Check()
322 …auto *signature = checker->Allocator()->New<checker::Signature>(signatureInfo, checker->GlobalReso… in Check()
323 expr->Function()); in Check()
324 checker::Type *funcType = checker->CreateFunctionTypeWithSignature(signature); in Check()
326 if (funcVar != nullptr && funcVar->TsType() == nullptr) { in Check()
327 funcVar->SetTsType(funcType); in Check()
330 signature->SetReturnType(checker->HandleFunctionReturn(expr->Function())); in Check()
332 if (!expr->Function()->Body()->IsExpression()) { in Check()
333 expr->Function()->Body()->Check(checker); in Check()
339 checker::Type *TSAnalyzer::CheckAssignmentExprOperatorType(ir::AssignmentExpression *expr, checker:… in CheckAssignmentExprOperatorType()
340 checker::Type *rightType) const in CheckAssignmentExprOperatorType()
342 TSChecker *checker = GetTSChecker(); in CheckAssignmentExprOperatorType() local
346 switch (expr->OperatorType()) { in CheckAssignmentExprOperatorType()
358 return checker->CheckBinaryOperator(&leftRightType, expr->Left(), expr->Right(), expr, in CheckAssignmentExprOperatorType()
359 expr->OperatorType()); in CheckAssignmentExprOperatorType()
362 …return checker->CheckPlusOperator(&leftRightType, expr->Left(), expr->Right(), expr, expr->Operato… in CheckAssignmentExprOperatorType()
365checker->CheckAssignmentOperator(expr->OperatorType(), expr->Left(), leftType, rightType); in CheckAssignmentExprOperatorType()
377 checker::Type *TSAnalyzer::Check(ir::AssignmentExpression *expr) const in Check()
379 TSChecker *checker = GetTSChecker(); in Check() local
380 if (expr->Left()->IsArrayPattern()) { in Check()
381 … auto savedContext = checker::SavedCheckerContext(checker, checker::CheckerStatus::FORCE_TUPLE); in Check()
383checker::ArrayDestructuringContext({checker, expr->Left(), true, true, nullptr, expr->Right()}); in Check()
388 if (expr->Left()->IsObjectPattern()) { in Check()
389 … auto savedContext = checker::SavedCheckerContext(checker, checker::CheckerStatus::FORCE_TUPLE); in Check()
391checker::ObjectDestructuringContext({checker, expr->Left(), true, true, nullptr, expr->Right()}); in Check()
396 if (expr->Left()->IsIdentifier() && expr->Left()->AsIdentifier()->Variable() != nullptr && in Check()
397 expr->Left()->AsIdentifier()->Variable()->Declaration()->IsConstDecl()) { in Check()
398 checker->ThrowTypeError( in Check()
399 … {"Cannot assign to ", expr->Left()->AsIdentifier()->Name(), " because it is a constant."}, in Check()
400 expr->Left()->Start()); in Check()
403 auto *leftType = expr->Left()->Check(checker); in Check()
405 if (leftType->HasTypeFlag(checker::TypeFlag::READONLY)) { in Check()
406checker->ThrowTypeError("Cannot assign to this property because it is readonly.", expr->Left()->St… in Check()
409 if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { in Check()
410 checker->ElaborateElementwise(leftType, expr->Right(), expr->Left()->Start()); in Check()
411 return checker->CheckTypeCached(expr->Right()); in Check()
414 auto *rightType = expr->Right()->Check(checker); in Check()
419 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::AwaitExpression *expr) const in Check()
421 TSChecker *checker = GetTSChecker(); in Check() local
423 return checker->GlobalAnyType(); in Check()
426 checker::Type *TSAnalyzer::CheckBinaryExprArithmLogical(ir::BinaryExpression *expr, ExpressionTypeI… in CheckBinaryExprArithmLogical()
427 TSChecker *checker) const in CheckBinaryExprArithmLogical()
429 switch (expr->OperatorType()) { in CheckBinaryExprArithmLogical()
441 …return checker->CheckBinaryOperator(leftRightType, expr->Left(), expr->Right(), expr, expr->Operat… in CheckBinaryExprArithmLogical()
444 …return checker->CheckPlusOperator(leftRightType, expr->Left(), expr->Right(), expr, expr->Operator… in CheckBinaryExprArithmLogical()
447 … return checker->CheckAndOperator(leftRightType->leftType, leftRightType->rightType, expr->Left()); in CheckBinaryExprArithmLogical()
450 … return checker->CheckOrOperator(leftRightType->leftType, leftRightType->rightType, expr->Left()); in CheckBinaryExprArithmLogical()
458 checker::Type *TSAnalyzer::Check(ir::BinaryExpression *expr) const in Check()
460 TSChecker *checker = GetTSChecker(); in Check() local
462 leftRightType.leftType = expr->Left()->Check(checker); in Check()
463 leftRightType.rightType = expr->Right()->Check(checker); in Check()
465 auto *checkBinaryExprPunctuator = CheckBinaryExprArithmLogical(expr, &leftRightType, checker); in Check()
470 switch (expr->OperatorType()) { in Check()
473 return checker->CheckCompareOperator(&leftRightType, expr->Left(), expr->Right(), expr, in Check()
474 expr->OperatorType()); in Check()
480 … if (checker->IsTypeEqualityComparableTo(leftRightType.leftType, leftRightType.rightType) || in Check()
481checker->IsTypeEqualityComparableTo(leftRightType.rightType, leftRightType.leftType)) { in Check()
482 return checker->GlobalBooleanType(); in Check()
485checker->ThrowBinaryLikeError(expr->OperatorType(), leftRightType.leftType, leftRightType.rightTyp… in Check()
486 expr->Start()); in Check()
489 // NOTE: Csaba Repasi. Implement checker for nullish coalescing in Check()
490 return checker->GlobalAnyType(); in Check()
493checker->CheckAssignmentOperator(expr->OperatorType(), expr->Left(), leftRightType.leftType, in Check()
498 …return checker->CheckInstanceofExpression(leftRightType.leftType, leftRightType.rightType, expr->R… in Check()
502 … return checker->CheckInExpression(leftRightType.leftType, leftRightType.rightType, expr->Left(), in Check()
503 expr->Right(), expr); in Check()
514 checker::Type *TSAnalyzer::Check(ir::CallExpression *expr) const in Check()
516 TSChecker *checker = GetTSChecker(); in Check() local
517 checker::Type *calleeType = expr->callee_->Check(checker); in Check()
520 if (calleeType->IsObjectType()) { in Check()
521 checker::ObjectType *calleeObj = calleeType->AsObjectType(); in Check()
522 …return checker->ResolveCallOrNewExpression(calleeObj->CallSignatures(), expr->Arguments(), expr->S… in Check()
525 checker->ThrowTypeError("This expression is not callable.", expr->Start()); in Check()
529 checker::Type *TSAnalyzer::Check(ir::ChainExpression *expr) const in Check()
531 TSChecker *checker = GetTSChecker(); in Check() local
532 return expr->expression_->Check(checker); in Check()
535 checker::Type *TSAnalyzer::Check(ir::ConditionalExpression *expr) const in Check()
537 TSChecker *checker = GetTSChecker(); in Check() local
538 checker::Type *testType = expr->Test()->Check(checker); in Check()
540 checker->CheckTruthinessOfType(testType, expr->Test()->Start()); in Check()
541checker->CheckTestingKnownTruthyCallableOrAwaitableType(expr->Test(), testType, expr->Consequent()… in Check()
543 checker::Type *consequentType = expr->Consequent()->Check(checker); in Check()
544 checker::Type *alternateType = expr->Alternate()->Check(checker); in Check()
546 return checker->CreateUnionType({consequentType, alternateType}); in Check()
549 checker::Type *TSAnalyzer::Check(ir::FunctionExpression *expr) const in Check()
551 TSChecker *checker = GetTSChecker(); in Check() local
554 if (expr->Function()->Parent()->Parent() != nullptr && in Check()
555 expr->Function()->Parent()->Parent()->IsVariableDeclarator() && in Check()
556 expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { in Check()
557 …funcVar = expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Vari… in Check()
560 checker::ScopeContext scopeCtx(checker, expr->Function()->Scope()); in Check()
562 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
563 checker->CheckFunctionParameterDeclarations(expr->Function()->Params(), signatureInfo); in Check()
565 …auto *signature = checker->Allocator()->New<checker::Signature>(signatureInfo, checker->GlobalReso… in Check()
566 expr->Function()); in Check()
567 checker::Type *funcType = checker->CreateFunctionTypeWithSignature(signature); in Check()
569 if (funcVar != nullptr && funcVar->TsType() == nullptr) { in Check()
570 funcVar->SetTsType(funcType); in Check()
573 signature->SetReturnType(checker->HandleFunctionReturn(expr->Function())); in Check()
575 expr->Function()->Body()->Check(checker); in Check()
580 checker::Type *TSAnalyzer::Check(ir::Identifier *expr) const in Check()
582 TSChecker *checker = GetTSChecker(); in Check() local
583 if (expr->Variable() == nullptr) { in Check()
584 if (expr->Name().Is("undefined")) { in Check()
585 return checker->GlobalUndefinedType(); in Check()
588 checker->ThrowTypeError({"Cannot find name ", expr->Name()}, expr->Start()); in Check()
591 const varbinder::Decl *decl = expr->Variable()->Declaration(); in Check()
593 if (decl->IsTypeAliasDecl() || decl->IsInterfaceDecl()) { in Check()
594checker->ThrowTypeError({expr->Name(), " only refers to a type, but is being used as a value here.… in Check()
595 expr->Start()); in Check()
598 expr->SetTsType(checker->GetTypeOfVariable(expr->Variable())); in Check()
599 return expr->TsType(); in Check()
602 void TSAnalyzer::CheckComputed(ir::MemberExpression *expr, checker::Type *indexType) const in CheckComputed()
604 TSChecker *checker = GetTSChecker(); in CheckComputed() local
605 if (!indexType->HasTypeFlag(checker::TypeFlag::STRING_LIKE | checker::TypeFlag::NUMBER_LIKE)) { in CheckComputed()
606checker->ThrowTypeError({"Type ", indexType, " cannot be used as index type"}, expr->Property()->S… in CheckComputed()
609 if (indexType->IsNumberType()) { in CheckComputed()
610checker->ThrowTypeError("No index signature with a parameter of type 'string' was found on type th… in CheckComputed()
611 expr->Start()); in CheckComputed()
614 if (indexType->IsStringType()) { in CheckComputed()
615checker->ThrowTypeError("No index signature with a parameter of type 'number' was found on type th… in CheckComputed()
616 expr->Start()); in CheckComputed()
619 switch (expr->Property()->Type()) { in CheckComputed()
621 checker->ThrowTypeError( in CheckComputed()
622 … {"Property ", expr->Property()->AsIdentifier()->Name(), " does not exist on this type."}, in CheckComputed()
623 expr->Property()->Start()); in CheckComputed()
626 checker->ThrowTypeError( in CheckComputed()
627 … {"Property ", expr->Property()->AsNumberLiteral()->Str(), " does not exist on this type."}, in CheckComputed()
628 expr->Property()->Start()); in CheckComputed()
631 checker->ThrowTypeError( in CheckComputed()
632 … {"Property ", expr->Property()->AsStringLiteral()->Str(), " does not exist on this type."}, in CheckComputed()
633 expr->Property()->Start()); in CheckComputed()
641 checker::Type *TSAnalyzer::Check(ir::MemberExpression *expr) const in Check()
643 TSChecker *checker = GetTSChecker(); in Check() local
644checker::Type *baseType = checker->CheckNonNullType(expr->Object()->Check(checker), expr->Object() in Check()
646 if (expr->IsComputed()) { in Check()
647 checker::Type *indexType = expr->Property()->Check(checker); in Check()
648checker::Type *indexedAccessType = checker->GetPropertyTypeForIndexType(baseType, indexType); in Check()
656 …varbinder::Variable *prop = checker->GetPropertyOfType(baseType, expr->Property()->AsIdentifier()- in Check()
659 checker::Type *propType = checker->GetTypeOfVariable(prop); in Check()
660 if (prop->HasFlag(varbinder::VariableFlags::READONLY)) { in Check()
661 propType->AddTypeFlag(checker::TypeFlag::READONLY); in Check()
667 if (baseType->IsObjectType()) { in Check()
668 checker::ObjectType *objType = baseType->AsObjectType(); in Check()
670 if (objType->StringIndexInfo() != nullptr) { in Check()
671 checker::Type *indexType = objType->StringIndexInfo()->GetType(); in Check()
672 if (objType->StringIndexInfo()->Readonly()) { in Check()
673 indexType->AddTypeFlag(checker::TypeFlag::READONLY); in Check()
680checker->ThrowTypeError({"Property ", expr->Property()->AsIdentifier()->Name(), " does not exist o… in Check()
681 expr->Property()->Start()); in Check()
685 checker::Type *TSAnalyzer::Check(ir::NewExpression *expr) const in Check()
687 TSChecker *checker = GetTSChecker(); in Check() local
688 checker::Type *calleeType = expr->callee_->Check(checker); in Check()
690 if (calleeType->IsObjectType()) { in Check()
691 checker::ObjectType *calleeObj = calleeType->AsObjectType(); in Check()
692 …return checker->ResolveCallOrNewExpression(calleeObj->ConstructSignatures(), expr->Arguments(), ex… in Check()
695 checker->ThrowTypeError("This expression is not callable.", expr->Start()); in Check()
700 if (key->IsIdentifier()) { in GetPropertyName()
701 return key->AsIdentifier()->Name(); in GetPropertyName()
704 if (key->IsStringLiteral()) { in GetPropertyName()
705 return key->AsStringLiteral()->Str(); in GetPropertyName()
708 ASSERT(key->IsNumberLiteral()); in GetPropertyName()
709 return key->AsNumberLiteral()->Str(); in GetPropertyName()
714 if (!prop->IsMethod()) { in GetFlagsForProperty()
720 if (prop->IsAccessor() && prop->Kind() == ir::PropertyKind::GET) { in GetFlagsForProperty()
727 static checker::Type *GetTypeForProperty(ir::Property *prop, checker::TSChecker *checker) in GetTypeForProperty() argument
729 if (prop->IsAccessor()) { in GetTypeForProperty()
730 checker::Type *funcType = prop->Value()->Check(checker); in GetTypeForProperty()
732 if (prop->Kind() == ir::PropertyKind::SET) { in GetTypeForProperty()
733 return checker->GlobalAnyType(); in GetTypeForProperty()
736 ASSERT(funcType->IsObjectType() && funcType->AsObjectType()->IsFunctionType()); in GetTypeForProperty()
737 return funcType->AsObjectType()->CallSignatures()[0]->ReturnType(); in GetTypeForProperty()
740 if (prop->IsShorthand()) { in GetTypeForProperty()
741 return prop->Key()->Check(checker); in GetTypeForProperty()
744 return prop->Value()->Check(checker); in GetTypeForProperty()
748 checker::ObjectDescriptor *desc, ir::Expression *it) const in CheckSpread()
750 TSChecker *checker = GetTSChecker(); in CheckSpread() local
751 ASSERT(it->IsSpreadElement()); in CheckSpread()
753 checker::Type *const spreadType = it->AsSpreadElement()->Argument()->Check(checker); in CheckSpread()
756 if (!spreadType->IsObjectType()) { in CheckSpread()
757 checker->ThrowTypeError("Spread types may only be created from object types.", it->Start()); in CheckSpread()
760 for (auto *spreadProp : spreadType->AsObjectType()->Properties()) { in CheckSpread()
761 auto found = allPropertiesMap.find(spreadProp->Name()); in CheckSpread()
763checker->ThrowTypeError({found->first, " is specified more than once, so this usage will be overwr… in CheckSpread()
764 found->second); in CheckSpread()
767 varbinder::LocalVariable *foundMember = desc->FindProperty(spreadProp->Name()); in CheckSpread()
770 foundMember->SetTsType(spreadProp->TsType()); in CheckSpread()
774 desc->properties.push_back(spreadProp); in CheckSpread()
778 void TSAnalyzer::CheckNonComputed(checker::ObjectDescriptor *desc, ir::Expression *it, in CheckNonComputed()
782 TSChecker *checker = GetTSChecker(); in CheckNonComputed() local
783 auto *prop = it->AsProperty(); in CheckNonComputed()
784 checker::Type *propType = GetTypeForProperty(prop, checker); in CheckNonComputed()
786 const util::StringView &propName = GetPropertyName(prop->Key()); in CheckNonComputed()
788 auto *memberVar = varbinder::Scope::CreateVar(checker->Allocator(), propName, flags, it); in CheckNonComputed()
791 memberVar->AddFlag(varbinder::VariableFlags::READONLY); in CheckNonComputed()
793 propType = checker->GetBaseTypeOfLiteralType(propType); in CheckNonComputed()
796 memberVar->SetTsType(propType); in CheckNonComputed()
798 if (prop->Key()->IsNumberLiteral()) { in CheckNonComputed()
799 memberVar->AddFlag(varbinder::VariableFlags::NUMERIC_NAME); in CheckNonComputed()
802 varbinder::LocalVariable *foundMember = desc->FindProperty(propName); in CheckNonComputed()
803 allPropertiesMap.insert({propName, it->Start()}); in CheckNonComputed()
806 foundMember->SetTsType(propType); in CheckNonComputed()
810 desc->properties.push_back(memberVar); in CheckNonComputed()
813 checker::IndexInfo *TSAnalyzer::CreateUnionTypeHelper(ArenaVector<checker::Type *> &computedPropTyp… in CreateUnionTypeHelper()
816 TSChecker *checker = GetTSChecker(); in CreateUnionTypeHelper() local
818 …return checker->Allocator()->New<checker::IndexInfo>(checker->CreateUnionType(std::move(computedPr… in CreateUnionTypeHelper()
822 checker::Type *TSAnalyzer::Check(ir::ObjectExpression *expr) const in Check()
824 TSChecker *checker = GetTSChecker(); in Check() local
826checker::ObjectDescriptor *desc = checker->Allocator()->New<checker::ObjectDescriptor>(checker->Al… in Check()
828 bool inConstContext = checker->HasStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in Check()
829 ArenaVector<checker::Type *> computedNumberPropTypes(checker->Allocator()->Adapter()); in Check()
830 ArenaVector<checker::Type *> computedStringPropTypes(checker->Allocator()->Adapter()); in Check()
835 for (auto *it : expr->Properties()) { in Check()
836 if (it->IsProperty()) { in Check()
837 auto *prop = it->AsProperty(); in Check()
839 … if (prop->IsComputed() && checker->CheckComputedPropertyName(prop->Key())->IsNumberType()) { in Check()
841 computedNumberPropTypes.push_back(prop->Value()->Check(checker)); in Check()
845 … if (prop->IsComputed() && checker->CheckComputedPropertyName(prop->Key())->IsStringType()) { in Check()
847 computedStringPropTypes.push_back(prop->Value()->Check(checker)); in Check()
854 if (it->IsSpreadElement()) { in Check()
861 for (auto *it : desc->properties) { in Check()
862 computedStringPropTypes.push_back(it->TsType()); in Check()
864 if (hasComputedNumberProperty && it->HasFlag(varbinder::VariableFlags::NUMERIC_NAME)) { in Check()
865 computedNumberPropTypes.push_back(it->TsType()); in Check()
870 desc->numberIndexInfo = CreateUnionTypeHelper(computedNumberPropTypes, inConstContext); in Check()
874 desc->stringIndexInfo = CreateUnionTypeHelper(computedStringPropTypes, inConstContext); in Check()
878 checker::Type *returnType = checker->Allocator()->New<checker::ObjectLiteralType>(desc); in Check()
879 returnType->AsObjectType()->AddObjectFlag(checker::ObjectFlags::RESOLVED_MEMBERS | in Check()
880 checker::ObjectFlags::CHECK_EXCESS_PROPS); in Check()
884 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::OmittedExpression *expr) const in Check()
886 TSChecker *checker = GetTSChecker(); in Check() local
887 return checker->GlobalUndefinedType(); in Check()
890 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::OpaqueTypeNode *expr) const in Check()
892 return expr->TsType(); in Check()
895 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::SequenceExpression *expr) const in Check()
897 TSChecker *checker = GetTSChecker(); in Check() local
899 return checker->GlobalAnyType(); in Check()
902 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::SuperExpression *expr) const in Check()
904 TSChecker *checker = GetTSChecker(); in Check() local
906 return checker->GlobalAnyType(); in Check()
909 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TaggedTemplateExpression *expr) const in Check()
911 TSChecker *checker = GetTSChecker(); in Check() local
913 return checker->GlobalAnyType(); in Check()
916 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TemplateLiteral *expr) const in Check()
918 TSChecker *checker = GetTSChecker(); in Check() local
920 return checker->GlobalAnyType(); in Check()
923 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ThisExpression *expr) const in Check()
925 TSChecker *checker = GetTSChecker(); in Check() local
927 return checker->GlobalAnyType(); in Check()
930 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TypeofExpression *expr) const in Check()
932 TSChecker *checker = GetTSChecker(); in Check() local
933 return checker->GlobalStringType(); in Check()
936 checker::Type *TSAnalyzer::CheckDeleteKeyword([[maybe_unused]] checker::TSChecker *checker, in CheckDeleteKeyword() argument
939 checker::Type *propType = expr->argument_->Check(checker); in CheckDeleteKeyword()
940 if (!expr->Argument()->IsMemberExpression()) { in CheckDeleteKeyword()
941 checker->ThrowTypeError("The operand of a delete operator must be a property reference.", in CheckDeleteKeyword()
942 expr->Argument()->Start()); in CheckDeleteKeyword()
944 if (propType->Variable()->HasFlag(varbinder::VariableFlags::READONLY)) { in CheckDeleteKeyword()
945 checker->ThrowTypeError("The operand of a delete operator cannot be a readonly property.", in CheckDeleteKeyword()
946 expr->Argument()->Start()); in CheckDeleteKeyword()
948 if (!propType->Variable()->HasFlag(varbinder::VariableFlags::OPTIONAL)) { in CheckDeleteKeyword()
949checker->ThrowTypeError("The operand of a delete operator must be a optional.", expr->Argument()->… in CheckDeleteKeyword()
951 return checker->GlobalBooleanType(); in CheckDeleteKeyword()
954 checker::Type *TSAnalyzer::CheckLiteral([[maybe_unused]] checker::TSChecker *checker, ir::UnaryExpr… in CheckLiteral() argument
956 if (!expr->Argument()->IsLiteral()) { in CheckLiteral()
960 const ir::Literal *lit = expr->Argument()->AsLiteral(); in CheckLiteral()
961 if (lit->IsNumberLiteral()) { in CheckLiteral()
962 auto numberValue = lit->AsNumberLiteral()->Number().GetDouble(); in CheckLiteral()
963 if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS) { in CheckLiteral()
964 return checker->CreateNumberLiteralType(numberValue); in CheckLiteral()
966 if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_MINUS) { in CheckLiteral()
967 return checker->CreateNumberLiteralType(-numberValue); in CheckLiteral()
969 … } else if (lit->IsBigIntLiteral() && expr->OperatorType() == lexer::TokenType::PUNCTUATOR_MINUS) { in CheckLiteral()
970 return checker->CreateBigintLiteralType(lit->AsBigIntLiteral()->Str(), true); in CheckLiteral()
976 checker::Type *TSAnalyzer::Check(ir::UnaryExpression *expr) const in Check()
978 TSChecker *checker = GetTSChecker(); in Check() local
979 checker::Type *operandType = expr->argument_->Check(checker); in Check()
981 if (expr->operator_ == lexer::TokenType::KEYW_TYPEOF) { in Check()
985 if (expr->operator_ == lexer::TokenType::KEYW_DELETE) { in Check()
986 return CheckDeleteKeyword(checker, expr); in Check()
989 auto *res = CheckLiteral(checker, expr); in Check()
994 switch (expr->operator_) { in Check()
998 checker->CheckNonNullType(operandType, expr->Start()); in Check()
1001 if (expr->operator_ == lexer::TokenType::PUNCTUATOR_PLUS) { in Check()
1002 … if (checker::TSChecker::MaybeTypeOfKind(operandType, checker::TypeFlag::BIGINT_LIKE)) { in Check()
1003checker->ThrowTypeError({"Operator '+' cannot be applied to type '", operandType, "'"}, in Check()
1004 expr->Start()); in Check()
1007 return checker->GlobalNumberType(); in Check()
1010 return checker->GetUnaryResultType(operandType); in Check()
1013 checker->CheckTruthinessOfType(operandType, expr->Start()); in Check()
1014 auto facts = operandType->GetTypeFacts(); in Check()
1015 if ((facts & checker::TypeFacts::TRUTHY) != 0) { in Check()
1016 return checker->GlobalFalseType(); in Check()
1019 if ((facts & checker::TypeFacts::FALSY) != 0) { in Check()
1020 return checker->GlobalTrueType(); in Check()
1023 return checker->GlobalBooleanType(); in Check()
1033 checker::Type *TSAnalyzer::Check(ir::UpdateExpression *expr) const in Check()
1035 TSChecker *checker = GetTSChecker(); in Check() local
1036 checker::Type *operandType = expr->argument_->Check(checker); in Check()
1037 checker->CheckNonNullType(operandType, expr->Start()); in Check()
1039 if (!operandType->HasTypeFlag(checker::TypeFlag::VALID_ARITHMETIC_TYPE)) { in Check()
1040checker->ThrowTypeError("An arithmetic operand must be of type 'any', 'number', 'bigint' or an enu… in Check()
1041 expr->Start()); in Check()
1044 checker->CheckReferenceExpression( in Check()
1045 …expr->argument_, "The operand of an increment or decrement operator must be a variable or a proper… in Check()
1048 return checker->GetUnaryResultType(operandType); in Check()
1051 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::YieldExpression *expr) const in Check()
1053 TSChecker *checker = GetTSChecker(); in Check() local
1055 return checker->GlobalAnyType(); in Check()
1058 checker::Type *TSAnalyzer::Check(ir::BigIntLiteral *expr) const in Check()
1060 TSChecker *checker = GetTSChecker(); in Check() local
1061 auto search = checker->BigintLiteralMap().find(expr->Str()); in Check()
1062 if (search != checker->BigintLiteralMap().end()) { in Check()
1063 return search->second; in Check()
1066 …auto *newBigintLiteralType = checker->Allocator()->New<checker::BigintLiteralType>(expr->Str(), fa… in Check()
1067 checker->BigintLiteralMap().insert({expr->Str(), newBigintLiteralType}); in Check()
1071 checker::Type *TSAnalyzer::Check(ir::BooleanLiteral *expr) const in Check()
1073 TSChecker *checker = GetTSChecker(); in Check() local
1074 return expr->Value() ? checker->GlobalTrueType() : checker->GlobalFalseType(); in Check()
1077 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::NullLiteral *expr) const in Check()
1079 TSChecker *checker = GetTSChecker(); in Check() local
1080 return checker->GlobalNullType(); in Check()
1083 checker::Type *TSAnalyzer::Check(ir::NumberLiteral *expr) const in Check()
1085 TSChecker *checker = GetTSChecker(); in Check() local
1086 auto search = checker->NumberLiteralMap().find(expr->Number().GetDouble()); in Check()
1087 if (search != checker->NumberLiteralMap().end()) { in Check()
1088 return search->second; in Check()
1091 …auto *newNumLiteralType = checker->Allocator()->New<checker::NumberLiteralType>(expr->Number().Get… in Check()
1092 checker->NumberLiteralMap().insert({expr->Number().GetDouble(), newNumLiteralType}); in Check()
1096 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::RegExpLiteral *expr) const in Check()
1098 TSChecker *checker = GetTSChecker(); in Check() local
1100 return checker->GlobalAnyType(); in Check()
1103 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::AnnotationDeclaration *expr) const in Check()
1108 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::AnnotationUsage *expr) const in Check()
1113 checker::Type *TSAnalyzer::Check(ir::StringLiteral *expr) const in Check()
1115 TSChecker *checker = GetTSChecker(); in Check() local
1116 auto search = checker->StringLiteralMap().find(expr->Str()); in Check()
1117 if (search != checker->StringLiteralMap().end()) { in Check()
1118 return search->second; in Check()
1121 auto *newStrLiteralType = checker->Allocator()->New<checker::StringLiteralType>(expr->Str()); in Check()
1122 checker->StringLiteralMap().insert({expr->Str(), newStrLiteralType}); in Check()
1127 checker::Type *TSAnalyzer::Check(ir::BlockStatement *st) const in Check()
1129 TSChecker *checker = GetTSChecker(); in Check() local
1130 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1132 for (auto *it : st->Statements()) { in Check()
1133 it->Check(checker); in Check()
1139 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::BreakStatement *st) const in Check()
1144 checker::Type *TSAnalyzer::Check(ir::DoWhileStatement *st) const in Check()
1146 TSChecker *checker = GetTSChecker(); in Check() local
1147 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1149 checker::Type *testType = st->Test()->Check(checker); in Check()
1150 checker->CheckTruthinessOfType(testType, st->Test()->Start()); in Check()
1151 st->Body()->Check(checker); in Check()
1156 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::EmptyStatement *st) const in Check()
1161 checker::Type *TSAnalyzer::Check(ir::ExpressionStatement *st) const in Check()
1163 TSChecker *checker = GetTSChecker(); in Check() local
1164 return st->GetExpression()->Check(checker); in Check()
1167 checker::Type *TSAnalyzer::Check(ir::ForUpdateStatement *st) const in Check()
1169 TSChecker *checker = GetTSChecker(); in Check() local
1170 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1172 if (st->Init() != nullptr) { in Check()
1173 st->Init()->Check(checker); in Check()
1176 if (st->Test() != nullptr) { in Check()
1177 checker::Type *testType = st->Test()->Check(checker); in Check()
1178 checker->CheckTruthinessOfType(testType, st->Start()); in Check()
1181 if (st->Update() != nullptr) { in Check()
1182 st->Update()->Check(checker); in Check()
1185 st->Body()->Check(checker); in Check()
1190 checker::Type *TSAnalyzer::Check(ir::FunctionDeclaration *st) const in Check()
1192 TSChecker *checker = GetTSChecker(); in Check() local
1193 if (st->Function()->IsOverload()) { in Check()
1197 const util::StringView &funcName = st->Function()->Id()->Name(); in Check()
1198 auto result = checker->Scope()->Find(funcName); in Check()
1201 checker::ScopeContext scopeCtx(checker, st->Function()->Scope()); in Check()
1203 if (result.variable->TsType() == nullptr) { in Check()
1204checker->InferFunctionDeclarationType(result.variable->Declaration()->AsFunctionDecl(), result.var… in Check()
1207 st->Function()->Body()->Check(checker); in Check()
1212 checker::Type *TSAnalyzer::Check(ir::IfStatement *st) const in Check()
1214 TSChecker *checker = GetTSChecker(); in Check() local
1215 checker::Type *testType = st->Test()->Check(checker); in Check()
1216 checker->CheckTruthinessOfType(testType, st->Start()); in Check()
1217 checker->CheckTestingKnownTruthyCallableOrAwaitableType(st->Test(), testType, st->Consequent()); in Check()
1219 st->Consequent()->Check(checker); in Check()
1221 if (st->Alternate() != nullptr) { in Check()
1222 st->Alternate()->Check(checker); in Check()
1228 checker::Type *TSAnalyzer::Check(ir::ReturnStatement *st) const in Check()
1230 TSChecker *checker = GetTSChecker(); in Check() local
1232 ASSERT(ancestor && ancestor->IsScriptFunction()); in Check()
1233 auto *containingFunc = ancestor->AsScriptFunction(); in Check()
1235 if (containingFunc->Parent()->Parent()->IsMethodDefinition()) { in Check()
1236 …const ir::MethodDefinition *containingClassMethod = containingFunc->Parent()->Parent()->AsMethodDe… in Check()
1237 if (containingClassMethod->Kind() == ir::MethodDefinitionKind::SET) { in Check()
1238 checker->ThrowTypeError("Setters cannot return a value", st->Start()); in Check()
1242 if (containingFunc->ReturnTypeAnnotation() != nullptr) { in Check()
1243 checker::Type *returnType = checker->GlobalUndefinedType(); in Check()
1244 checker::Type *funcReturnType = containingFunc->ReturnTypeAnnotation()->GetType(checker); in Check()
1246 if (st->Argument() != nullptr) { in Check()
1247 checker->ElaborateElementwise(funcReturnType, st->Argument(), st->Start()); in Check()
1248 returnType = checker->CheckTypeCached(st->Argument()); in Check()
1251 checker->IsTypeAssignableTo(returnType, funcReturnType, in Check()
1253 st->Start()); in Check()
1259 checker::Type *TSAnalyzer::Check(ir::SwitchStatement *st) const in Check()
1261 TSChecker *checker = GetTSChecker(); in Check() local
1262 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1264 checker::Type *exprType = st->Discriminant()->Check(checker); in Check()
1265 bool exprIsLiteral = checker::TSChecker::IsLiteralType(exprType); in Check()
1267 for (auto *it : st->Cases()) { in Check()
1268 if (it->Test() != nullptr) { in Check()
1269 checker::Type *caseType = it->Test()->Check(checker); in Check()
1270 bool caseIsLiteral = checker::TSChecker::IsLiteralType(caseType); in Check()
1271 checker::Type *comparedExprType = exprType; in Check()
1274 caseType = caseIsLiteral ? checker->GetBaseTypeOfLiteralType(caseType) : caseType; in Check()
1275 comparedExprType = checker->GetBaseTypeOfLiteralType(exprType); in Check()
1278 if (!checker->IsTypeEqualityComparableTo(comparedExprType, caseType) && in Check()
1279 !checker->IsTypeComparableTo(caseType, comparedExprType)) { in Check()
1280checker->ThrowTypeError({"Type ", caseType, " is not comparable to type ", comparedExprType}, in Check()
1281 it->Test()->Start()); in Check()
1285 for (auto *caseStmt : it->Consequent()) { in Check()
1286 caseStmt->Check(checker); in Check()
1293 checker::Type *TSAnalyzer::Check(ir::TryStatement *st) const in Check()
1295 TSChecker *checker = GetTSChecker(); in Check() local
1296 st->Block()->Check(checker); in Check()
1298 for (auto *catchClause : st->CatchClauses()) { in Check()
1300 catchClause->Check(checker); in Check()
1304 if (st->HasFinalizer()) { in Check()
1305 st->finalizer_->Check(checker); in Check()
1311 static void CheckSimpleVariableDeclaration(checker::TSChecker *checker, ir::VariableDeclarator *dec… in CheckSimpleVariableDeclaration() argument
1313 varbinder::Variable *const bindingVar = declarator->Id()->AsIdentifier()->Variable(); in CheckSimpleVariableDeclaration()
1314 checker::Type *previousType = bindingVar->TsType(); in CheckSimpleVariableDeclaration()
1315 auto *const typeAnnotation = declarator->Id()->AsIdentifier()->TypeAnnotation(); in CheckSimpleVariableDeclaration()
1316 auto *const initializer = declarator->Init(); in CheckSimpleVariableDeclaration()
1317 const bool isConst = declarator->Parent()->AsVariableDeclaration()->Kind() == in CheckSimpleVariableDeclaration()
1321 checker->AddStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in CheckSimpleVariableDeclaration()
1325 typeAnnotation->Check(checker); in CheckSimpleVariableDeclaration()
1329 checker::Type *const annotationType = typeAnnotation->GetType(checker); in CheckSimpleVariableDeclaration()
1330 checker->ElaborateElementwise(annotationType, initializer, declarator->Id()->Start()); in CheckSimpleVariableDeclaration()
1331 bindingVar->SetTsType(annotationType); in CheckSimpleVariableDeclaration()
1333 bindingVar->SetTsType(typeAnnotation->GetType(checker)); in CheckSimpleVariableDeclaration()
1335 checker::Type *initializerType = checker->CheckTypeCached(initializer); in CheckSimpleVariableDeclaration()
1338 initializerType = checker->GetBaseTypeOfLiteralType(initializerType); in CheckSimpleVariableDeclaration()
1341 if (initializerType->IsNullType()) { in CheckSimpleVariableDeclaration()
1342 checker->ThrowTypeError( in CheckSimpleVariableDeclaration()
1343 … {"Cannot infer type for variable '", declarator->Id()->AsIdentifier()->Name(), "'."}, in CheckSimpleVariableDeclaration()
1344 declarator->Id()->Start()); in CheckSimpleVariableDeclaration()
1347 bindingVar->SetTsType(initializerType); in CheckSimpleVariableDeclaration()
1349checker->ThrowTypeError({"Variable ", declarator->Id()->AsIdentifier()->Name(), " implicitly has a… in CheckSimpleVariableDeclaration()
1350 declarator->Id()->Start()); in CheckSimpleVariableDeclaration()
1354 checker->IsTypeIdenticalTo(bindingVar->TsType(), previousType, in CheckSimpleVariableDeclaration()
1356 … bindingVar->Name(), "' must be of type '", previousType, "', but here has type '", in CheckSimpleVariableDeclaration()
1357 bindingVar->TsType(), "'."}, in CheckSimpleVariableDeclaration()
1358 declarator->Id()->Start()); in CheckSimpleVariableDeclaration()
1361 checker->RemoveStatus(checker::CheckerStatus::IN_CONST_CONTEXT); in CheckSimpleVariableDeclaration()
1364 checker::Type *TSAnalyzer::Check(ir::VariableDeclarator *st) const in Check()
1366 TSChecker *checker = GetTSChecker(); in Check() local
1368 if (st->TsType() == st->CHECKED) { in Check()
1372 if (st->Id()->IsIdentifier()) { in Check()
1373 CheckSimpleVariableDeclaration(checker, st); in Check()
1374 st->SetTsType(st->CHECKED); in Check()
1378 if (st->Id()->IsArrayPattern()) { in Check()
1379 auto context = checker::SavedCheckerContext(checker, checker::CheckerStatus::FORCE_TUPLE); in Check()
1380 checker::ArrayDestructuringContext({checker, st->Id(), false, in Check()
1381 st->Id()->AsArrayPattern()->TypeAnnotation() == nullptr, in Check()
1382 … st->Id()->AsArrayPattern()->TypeAnnotation(), st->Init()}) in Check()
1385 st->SetTsType(st->CHECKED); in Check()
1389 ASSERT(st->Id()->IsObjectPattern()); in Check()
1390 auto context = checker::SavedCheckerContext(checker, checker::CheckerStatus::FORCE_TUPLE); in Check()
1391 checker::ObjectDestructuringContext({checker, st->Id(), false, in Check()
1392 st->Id()->AsObjectPattern()->TypeAnnotation() == nullptr, in Check()
1393 st->Id()->AsObjectPattern()->TypeAnnotation(), st->Init()}) in Check()
1396 st->SetTsType(st->CHECKED); in Check()
1400 checker::Type *TSAnalyzer::Check(ir::VariableDeclaration *st) const in Check()
1402 TSChecker *checker = GetTSChecker(); in Check() local
1403 for (auto *it : st->Declarators()) { in Check()
1404 it->Check(checker); in Check()
1410 checker::Type *TSAnalyzer::Check(ir::WhileStatement *st) const in Check()
1412 TSChecker *checker = GetTSChecker(); in Check() local
1413 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1415 checker::Type *testType = st->Test()->Check(checker); in Check()
1416 checker->CheckTruthinessOfType(testType, st->Test()->Start()); in Check()
1418 st->Body()->Check(checker); in Check()
1422 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSAnyKeyword *node) const in Check()
1427 checker::Type *TSAnalyzer::Check(ir::TSArrayType *node) const in Check()
1429 TSChecker *checker = GetTSChecker(); in Check() local
1430 node->elementType_->Check(checker); in Check()
1434 static bool IsValidConstAssertionArgument(checker::Checker *checker, const ir::AstNode *arg) in IsValidConstAssertionArgument() argument
1436 switch (arg->Type()) { in IsValidConstAssertionArgument()
1447 const ir::UnaryExpression *unaryExpr = arg->AsUnaryExpression(); in IsValidConstAssertionArgument()
1448 lexer::TokenType op = unaryExpr->OperatorType(); in IsValidConstAssertionArgument()
1449 const ir::Expression *unaryArg = unaryExpr->Argument(); in IsValidConstAssertionArgument()
1450 return (op == lexer::TokenType::PUNCTUATOR_MINUS && unaryArg->IsLiteral() && in IsValidConstAssertionArgument()
1451 … (unaryArg->AsLiteral()->IsNumberLiteral() || unaryArg->AsLiteral()->IsBigIntLiteral())) || in IsValidConstAssertionArgument()
1452 (op == lexer::TokenType::PUNCTUATOR_PLUS && unaryArg->IsLiteral() && in IsValidConstAssertionArgument()
1453 unaryArg->AsLiteral()->IsNumberLiteral()); in IsValidConstAssertionArgument()
1456 const ir::MemberExpression *memberExpr = arg->AsMemberExpression(); in IsValidConstAssertionArgument()
1457 if (memberExpr->Object()->IsIdentifier()) { in IsValidConstAssertionArgument()
1458 auto result = checker->Scope()->Find(memberExpr->Object()->AsIdentifier()->Name()); in IsValidConstAssertionArgument()
1459 … constexpr auto ENUM_LITERAL_TYPE = checker::EnumLiteralType::EnumLiteralTypeKind::LITERAL; in IsValidConstAssertionArgument()
1461 result.variable->TsType()->HasTypeFlag(checker::TypeFlag::ENUM_LITERAL) && in IsValidConstAssertionArgument()
1462 result.variable->TsType()->AsEnumLiteralType()->Kind() == ENUM_LITERAL_TYPE) { in IsValidConstAssertionArgument()
1473 checker::Type *TSAnalyzer::Check(ir::TSAsExpression *expr) const in Check()
1475 TSChecker *checker = GetTSChecker(); in Check() local
1476 if (expr->IsConst()) { in Check()
1477 … auto context = checker::SavedCheckerContext(checker, checker::CheckerStatus::IN_CONST_CONTEXT); in Check()
1478 checker::Type *exprType = expr->Expr()->Check(checker); in Check()
1480 if (!IsValidConstAssertionArgument(checker, expr->Expr())) { in Check()
1481 checker->ThrowTypeError( in Check()
1484 expr->Expr()->Start()); in Check()
1490 auto context = checker::SavedCheckerContext(checker, checker::CheckerStatus::NO_OPTS); in Check()
1492 expr->TypeAnnotation()->Check(checker); in Check()
1493 checker::Type *exprType = checker->GetBaseTypeOfLiteralType(expr->Expr()->Check(checker)); in Check()
1494 checker::Type *targetType = expr->TypeAnnotation()->GetType(checker); in Check()
1496 checker->IsTypeComparableTo( in Check()
1501 expr->Start()); in Check()
1506 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSBigintKeyword *node) const in Check()
1511 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSBooleanKeyword *node) const in Check()
1516 checker::Type *TSAnalyzer::Check(ir::TSConstructorType *node) const in Check()
1518 TSChecker *checker = GetTSChecker(); in Check() local
1519 checker::ScopeContext scopeCtx(checker, node->Scope()); in Check()
1521 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
1522 checker->CheckFunctionParameterDeclarations(node->Params(), signatureInfo); in Check()
1523 node->ReturnType()->Check(checker); in Check()
1525checker->Allocator()->New<checker::Signature>(signatureInfo, node->ReturnType()->GetType(checker)); in Check()
1527 return checker->CreateConstructorTypeWithSignature(constructSignature); in Check()
1530 static varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varbinder::EnumV… in EvaluateIdentifier() argument
1533 if (expr->Name() == "NaN") { in EvaluateIdentifier()
1536 if (expr->Name() == "Infinity") { in EvaluateIdentifier()
1540 varbinder::Variable *enumMember = expr->AsIdentifier()->Variable(); in EvaluateIdentifier()
1543 checker->ThrowTypeError({"Cannot find name ", expr->AsIdentifier()->Name()}, in EvaluateIdentifier()
1544 enumVar->Declaration()->Node()->Start()); in EvaluateIdentifier()
1547 if (enumMember->IsEnumVariable()) { in EvaluateIdentifier()
1548 varbinder::EnumVariable *exprEnumVar = enumMember->AsEnumVariable(); in EvaluateIdentifier()
1549 if (std::holds_alternative<bool>(exprEnumVar->Value())) { in EvaluateIdentifier()
1550 checker->ThrowTypeError( in EvaluateIdentifier()
1554 enumVar->Declaration()->Node()->Start()); in EvaluateIdentifier()
1557 return exprEnumVar->Value(); in EvaluateIdentifier()
1598 case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) in GetOperationResulForDouble()
1601 case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) in GetOperationResulForDouble()
1611 return std::get<double>(left) - std::get<double>(right); in GetOperationResulForDouble()
1631 varbinder::EnumMemberResult TSAnalyzer::EvaluateBinaryExpression(checker::TSChecker *checker, in EvaluateBinaryExpression() argument
1635 …varbinder::EnumMemberResult left = EvaluateEnumMember(checker, enumVar, expr->AsBinaryExpression() in EvaluateBinaryExpression()
1636 …arbinder::EnumMemberResult right = EvaluateEnumMember(checker, enumVar, expr->AsBinaryExpression() in EvaluateBinaryExpression()
1638 GetOperationResulForDouble(expr->AsBinaryExpression()->OperatorType(), left, right); in EvaluateBinaryExpression()
1642 expr->AsBinaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS) { in EvaluateBinaryExpression()
1646 util::UString res(ss.str(), checker->Allocator()); in EvaluateBinaryExpression()
1653 varbinder::EnumMemberResult TSAnalyzer::EvaluateUnaryExpression(checker::TSChecker *checker, in EvaluateUnaryExpression() argument
1657 varbinder::EnumMemberResult value = EvaluateEnumMember(checker, enumVar, expr->Argument()); in EvaluateUnaryExpression()
1662 switch (expr->OperatorType()) { in EvaluateUnaryExpression()
1667 return -std::get<double>(value); in EvaluateUnaryExpression()
1670 … return static_cast<double>(~ToInt(std::get<double>(value))); // NOLINT(hicpp-signed-bitwise) in EvaluateUnaryExpression()
1680 varbinder::EnumMemberResult TSAnalyzer::EvaluateEnumMember(checker::TSChecker *checker, in EvaluateEnumMember() argument
1684 switch (expr->Type()) { in EvaluateEnumMember()
1686 return EvaluateUnaryExpression(checker, enumVar, expr->AsUnaryExpression()); in EvaluateEnumMember()
1689 return EvaluateBinaryExpression(checker, enumVar, expr->AsBinaryExpression()); in EvaluateEnumMember()
1692 return expr->AsNumberLiteral()->Number().GetDouble(); in EvaluateEnumMember()
1695 return expr->AsStringLiteral()->Str(); in EvaluateEnumMember()
1698 return EvaluateIdentifier(checker, enumVar, expr->AsIdentifier()); in EvaluateEnumMember()
1701 return EvaluateEnumMember(checker, enumVar, expr->AsMemberExpression()); in EvaluateEnumMember()
1712 if (init->IsLiteral()) { in IsComputedEnumMember()
1713 return !init->AsLiteral()->IsStringLiteral() && !init->AsLiteral()->IsNumberLiteral(); in IsComputedEnumMember()
1716 if (init->IsTemplateLiteral()) { in IsComputedEnumMember()
1717 return !init->AsTemplateLiteral()->Quasis().empty(); in IsComputedEnumMember()
1723 static void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbinder::EnumVari… in AddEnumValueDeclaration() argument
1725 variable->SetTsType(checker->GlobalNumberType()); in AddEnumValueDeclaration()
1727 util::StringView memberStr = util::Helpers::ToStringView(checker->Allocator(), number); in AddEnumValueDeclaration()
1729 varbinder::LocalScope *enumScope = checker->Scope()->AsLocalScope(); in AddEnumValueDeclaration()
1730 …varbinder::Variable *res = enumScope->FindLocal(memberStr, varbinder::ResolveBindingOptions::BINDI… in AddEnumValueDeclaration()
1734 auto *decl = checker->Allocator()->New<varbinder::EnumDecl>(memberStr); in AddEnumValueDeclaration()
1735 decl->BindNode(variable->Declaration()->Node()); in AddEnumValueDeclaration()
1736 enumScope->AddDecl(checker->Allocator(), decl, ScriptExtension::TS); in AddEnumValueDeclaration()
1737 res = enumScope->FindLocal(memberStr, varbinder::ResolveBindingOptions::BINDINGS); in AddEnumValueDeclaration()
1738 ASSERT(res && res->IsEnumVariable()); in AddEnumValueDeclaration()
1739 enumVar = res->AsEnumVariable(); in AddEnumValueDeclaration()
1740 enumVar->AsEnumVariable()->SetBackReference(); in AddEnumValueDeclaration()
1741 enumVar->SetTsType(checker->GlobalStringType()); in AddEnumValueDeclaration()
1743 ASSERT(res->IsEnumVariable()); in AddEnumValueDeclaration()
1744 enumVar = res->AsEnumVariable(); in AddEnumValueDeclaration()
1745 auto *decl = checker->Allocator()->New<varbinder::EnumDecl>(memberStr); in AddEnumValueDeclaration()
1746 decl->BindNode(variable->Declaration()->Node()); in AddEnumValueDeclaration()
1747 enumVar->ResetDecl(decl); in AddEnumValueDeclaration()
1750 enumVar->SetValue(variable->Declaration()->Name()); in AddEnumValueDeclaration()
1753 // NOLINTBEGIN(modernize-avoid-c-arrays)
1761 "'const' enum member initializer was evaluated to a non-finite value.";
1762 // NOLINTEND(modernize-avoid-c-arrays)
1767 TSChecker *checker = GetTSChecker(); in InferEnumVariableType() local
1768 const ir::Expression *init = variable->Declaration()->Node()->AsTSEnumMember()->Init(); in InferEnumVariableType()
1771checker->ThrowTypeError("Enum member must have initializer.", variable->Declaration()->Node()->Sta… in InferEnumVariableType()
1775 variable->SetValue(++(*value)); in InferEnumVariableType()
1776 AddEnumValueDeclaration(checker, *value, variable); in InferEnumVariableType()
1782 checker->ThrowTypeError(INVALID_COMPUTED_WITH_STRING, init->Start()); in InferEnumVariableType()
1785 varbinder::EnumMemberResult res = EvaluateEnumMember(checker, variable, init); in InferEnumVariableType()
1788 variable->SetTsType(checker->GlobalStringType()); in InferEnumVariableType()
1795 checker->ThrowTypeError(INVALID_CONST_MEMBER, init->Start()); in InferEnumVariableType()
1803 variable->SetValue(res); in InferEnumVariableType()
1807 checker->ThrowTypeError(INVALID_CONST_NAN, init->Start()); in InferEnumVariableType()
1811 checker->ThrowTypeError(INVALID_CONST_INF, init->Start()); in InferEnumVariableType()
1815 AddEnumValueDeclaration(checker, *value, variable); in InferEnumVariableType()
1818 checker::Type *TSAnalyzer::InferType(checker::TSChecker *checker, bool isConst, ir::TSEnumDeclarati… in InferType() argument
1820 double value = -1.0; in InferType()
1822 varbinder::LocalScope *enumScope = checker->Scope()->AsLocalScope(); in InferType()
1826 size_t localsSize = enumScope->Decls().size(); in InferType()
1829 const util::StringView &currentName = enumScope->Decls()[i]->Name(); in InferType()
1830 …varbinder::Variable *currentVar = enumScope->FindLocal(currentName, varbinder::ResolveBindingOptio… in InferType()
1831 ASSERT(currentVar && currentVar->IsEnumVariable()); in InferType()
1832 … InferEnumVariableType(currentVar->AsEnumVariable(), &value, &initNext, &isLiteralEnum, isConst); in InferType()
1835 checker::Type *enumType = checker->Allocator()->New<checker::EnumLiteralType>( in InferType()
1836 st->Key()->Name(), checker->Scope(), in InferType()
1837 isLiteralEnum ? checker::EnumLiteralType::EnumLiteralTypeKind::LITERAL in InferType()
1838 : checker::EnumLiteralType::EnumLiteralTypeKind::NUMERIC); in InferType()
1843 checker::Type *TSAnalyzer::Check(ir::TSEnumDeclaration *st) const in Check()
1845 TSChecker *checker = GetTSChecker(); in Check() local
1846 varbinder::Variable *enumVar = st->Key()->Variable(); in Check()
1849 if (enumVar->TsType() == nullptr) { in Check()
1850 checker::ScopeContext scopeCtx(checker, st->Scope()); in Check()
1851 checker::Type *enumType = InferType(checker, st->IsConst(), st); in Check()
1852 enumType->SetVariable(enumVar); in Check()
1853 enumVar->SetTsType(enumType); in Check()
1859 checker::Type *TSAnalyzer::Check(ir::TSFunctionType *node) const in Check()
1861 TSChecker *checker = GetTSChecker(); in Check() local
1862 checker::ScopeContext scopeCtx(checker, node->Scope()); in Check()
1864 auto *signatureInfo = checker->Allocator()->New<checker::SignatureInfo>(checker->Allocator()); in Check()
1865 checker->CheckFunctionParameterDeclarations(node->Params(), signatureInfo); in Check()
1866 node->ReturnType()->Check(checker); in Check()
1868checker->Allocator()->New<checker::Signature>(signatureInfo, node->ReturnType()->GetType(checker)); in Check()
1870 return checker->CreateFunctionTypeWithSignature(callSignature); in Check()
1873 checker::Type *TSAnalyzer::Check(ir::TSIndexedAccessType *node) const in Check()
1875 TSChecker *checker = GetTSChecker(); in Check() local
1876 node->objectType_->Check(checker); in Check()
1877 node->indexType_->Check(checker); in Check()
1878 checker::Type *resolved = node->GetType(checker); in Check()
1884 checker::Type *indexType = checker->CheckTypeCached(node->indexType_); in Check()
1886 if (!indexType->HasTypeFlag(checker::TypeFlag::STRING_LIKE | checker::TypeFlag::NUMBER_LIKE)) { in Check()
1887checker->ThrowTypeError({"Type ", indexType, " cannot be used as index type"}, node->IndexType()->… in Check()
1890 if (indexType->IsNumberType()) { in Check()
1891 checker->ThrowTypeError("Type has no matching signature for type 'number'", node->Start()); in Check()
1894 checker->ThrowTypeError("Type has no matching signature for type 'string'", node->Start()); in Check()
1898 checker::Type *TSAnalyzer::Check(ir::TSInterfaceBody *expr) const in Check()
1900 TSChecker *checker = GetTSChecker(); in Check() local
1901 for (auto *it : expr->Body()) { in Check()
1902 it->Check(checker); in Check()
1908 static void CheckInheritedPropertiesAreIdentical(checker::TSChecker *checker, checker::InterfaceTyp… in CheckInheritedPropertiesAreIdentical() argument
1911 checker->GetBaseTypes(type); in CheckInheritedPropertiesAreIdentical()
1914 if (type->Bases().size() < BASE_SIZE_LIMIT) { in CheckInheritedPropertiesAreIdentical()
1918 checker->ResolveDeclaredMembers(type); in CheckInheritedPropertiesAreIdentical()
1920 checker::InterfacePropertyMap properties; in CheckInheritedPropertiesAreIdentical()
1922 for (auto *it : type->Properties()) { in CheckInheritedPropertiesAreIdentical()
1923 properties.insert({it->Name(), {it, type}}); in CheckInheritedPropertiesAreIdentical()
1926 for (auto *base : type->Bases()) { in CheckInheritedPropertiesAreIdentical()
1927 checker->ResolveStructuredTypeMembers(base); in CheckInheritedPropertiesAreIdentical()
1928 … ArenaVector<varbinder::LocalVariable *> inheritedProperties(checker->Allocator()->Adapter()); in CheckInheritedPropertiesAreIdentical()
1929 base->AsInterfaceType()->CollectProperties(&inheritedProperties); in CheckInheritedPropertiesAreIdentical()
1932 auto res = properties.find(inheritedProp->Name()); in CheckInheritedPropertiesAreIdentical()
1934 … properties.insert({inheritedProp->Name(), {inheritedProp, base->AsInterfaceType()}}); in CheckInheritedPropertiesAreIdentical()
1935 } else if (res->second.second != type) { in CheckInheritedPropertiesAreIdentical()
1936 checker::Type *sourceType = checker->GetTypeOfVariable(inheritedProp); in CheckInheritedPropertiesAreIdentical()
1937 checker::Type *targetType = checker->GetTypeOfVariable(res->second.first); in CheckInheritedPropertiesAreIdentical()
1938 checker->IsTypeIdenticalTo(sourceType, targetType, in CheckInheritedPropertiesAreIdentical()
1940 … res->second.second, "' and '", base->AsInterfaceType(), "'."}, in CheckInheritedPropertiesAreIdentical()
1947 checker::Type *TSAnalyzer::Check(ir::TSInterfaceDeclaration *st) const in Check()
1949 TSChecker *checker = GetTSChecker(); in Check() local
1950 varbinder::Variable *var = st->Id()->Variable(); in Check()
1951 ASSERT(var->Declaration()->Node() && var->Declaration()->Node()->IsTSInterfaceDeclaration()); in Check()
1953 if (st == var->Declaration()->Node()) { in Check()
1954 checker::Type *resolvedType = var->TsType(); in Check()
1957 checker::ObjectDescriptor *desc = in Check()
1958 checker->Allocator()->New<checker::ObjectDescriptor>(checker->Allocator()); in Check()
1960checker->Allocator()->New<checker::InterfaceType>(checker->Allocator(), st->Id()->Name(), desc); in Check()
1961 resolvedType->SetVariable(var); in Check()
1962 var->SetTsType(resolvedType); in Check()
1965 checker::InterfaceType *resolvedInterface = resolvedType->AsObjectType()->AsInterfaceType(); in Check()
1966 CheckInheritedPropertiesAreIdentical(checker, resolvedInterface, st->Id()->Start()); in Check()
1968 for (auto *base : resolvedInterface->Bases()) { in Check()
1969 checker->IsTypeAssignableTo( in Check()
1971 …{"Interface '", st->Id()->Name(), "' incorrectly extends interface '", base, "'"}, st->Id()->Start… in Check()
1974 checker->CheckIndexConstraints(resolvedInterface); in Check()
1977 st->Body()->Check(checker); in Check()
1982 checker::Type *TSAnalyzer::Check(ir::TSLiteralType *node) const in Check()
1984 TSChecker *checker = GetTSChecker(); in Check() local
1985 node->GetType(checker); in Check()
1989 checker::Type *TSAnalyzer::Check(ir::TSNamedTupleMember *node) const in Check()
1991 TSChecker *checker = GetTSChecker(); in Check() local
1992 node->ElementType()->Check(checker); in Check()
1996 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSNeverKeyword *node) const in Check()
2001 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSNullKeyword *node) const in Check()
2006 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSNumberKeyword *node) const in Check()
2011 checker::Type *TSAnalyzer::Check(ir::TSParenthesizedType *node) const in Check()
2013 TSChecker *checker = GetTSChecker(); in Check() local
2014 node->type_->Check(checker); in Check()
2018 checker::Type *TSAnalyzer::Check(ir::TSQualifiedName *expr) const in Check()
2020 TSChecker *checker = GetTSChecker(); in Check() local
2021checker::Type *baseType = checker->CheckNonNullType(expr->Left()->Check(checker), expr->Left()->St… in Check()
2022 varbinder::Variable *prop = checker->GetPropertyOfType(baseType, expr->Right()->Name()); in Check()
2025 return checker->GetTypeOfVariable(prop); in Check()
2028 if (baseType->IsObjectType()) { in Check()
2029 checker::ObjectType *objType = baseType->AsObjectType(); in Check()
2031 if (objType->StringIndexInfo() != nullptr) { in Check()
2032 return objType->StringIndexInfo()->GetType(); in Check()
2036 checker->ThrowTypeError({"Property ", expr->Right()->Name(), " does not exist on this type."}, in Check()
2037 expr->Right()->Start()); in Check()
2041 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSStringKeyword *node) const in Check()
2046 checker::Type *TSAnalyzer::Check(ir::TSTupleType *node) const in Check()
2048 TSChecker *checker = GetTSChecker(); in Check() local
2049 for (auto *it : node->ElementType()) { in Check()
2050 it->Check(checker); in Check()
2053 node->GetType(checker); in Check()
2057 checker::Type *TSAnalyzer::Check(ir::TSTypeAliasDeclaration *st) const in Check()
2059 TSChecker *checker = GetTSChecker(); in Check() local
2060 st->TypeAnnotation()->Check(checker); in Check()
2064 checker::Type *TSAnalyzer::Check(ir::TSTypeLiteral *node) const in Check()
2066 TSChecker *checker = GetTSChecker(); in Check() local
2068 for (auto *it : node->Members()) { in Check()
2069 it->Check(checker); in Check()
2072 checker::Type *type = node->GetType(checker); in Check()
2073 checker->CheckIndexConstraints(type); in Check()
2078 checker::Type *TSAnalyzer::Check(ir::TSTypeQuery *node) const in Check()
2080 TSChecker *checker = GetTSChecker(); in Check() local
2081 if (node->TsType() != nullptr) { in Check()
2082 return node->TsType(); in Check()
2085 node->SetTsType(node->exprName_->Check(checker)); in Check()
2086 return node->TsType(); in Check()
2089 checker::Type *TSAnalyzer::Check(ir::TSTypeReference *node) const in Check()
2091 TSChecker *checker = GetTSChecker(); in Check() local
2092 node->GetType(checker); in Check()
2096 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSUndefinedKeyword *node) const in Check()
2101 checker::Type *TSAnalyzer::Check(ir::TSUnionType *node) const in Check()
2103 TSChecker *checker = GetTSChecker(); in Check() local
2104 for (auto *it : node->Types()) { in Check()
2105 it->Check(checker); in Check()
2108 node->GetType(checker); in Check()
2112 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSUnknownKeyword *node) const in Check()
2117 checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSVoidKeyword *node) const in Check()
2121 } // namespace ark::es2panda::checker