Lines Matching full:ts
17 import * as ts from 'typescript';
50 export type CheckType = (this: TsUtils, t: ts.Type) => boolean;
53 private readonly tsTypeChecker: ts.TypeChecker,
57 entityNameToString(name: ts.EntityName): string {
58 if (ts.isIdentifier(name)) {
64 isNumberLikeType(tsType: ts.Type): boolean {
67 if ((tsCompType.flags & ts.TypeFlags.NumberLike) === 0) {
73 return (tsType.getFlags() & ts.TypeFlags.NumberLike) !== 0;
76 static isBooleanLikeType(tsType: ts.Type): boolean {
77 return (tsType.getFlags() & ts.TypeFlags.BooleanLike) !== 0;
80 …static isDestructuringAssignmentLHS(tsExpr: ts.ArrayLiteralExpression | ts.ObjectLiteralExpression…
87 let tsCurrentExpr: ts.Node = tsExpr;
90 ts.isBinaryExpression(tsParent) &&
98 … (ts.isForStatement(tsParent) || ts.isForInStatement(tsParent) || ts.isForOfStatement(tsParent)) &&
112 static isEnumType(tsType: ts.Type): boolean {
116 …const isEnumType = !!(tsType.flags & ts.TypeFlags.Enum) || !!(tsType.flags & ts.TypeFlags.EnumLite…
120 static isEnum(tsSymbol: ts.Symbol): boolean {
121 return !!(tsSymbol.flags & ts.SymbolFlags.Enum);
124 …static hasModifier(tsModifiers: readonly ts.Modifier[] | undefined, tsModifierKind: number): boole…
138 static unwrapParenthesized(tsExpr: ts.Expression): ts.Expression {
140 while (ts.isParenthesizedExpression(unwrappedExpr)) {
147 followIfAliased(sym: ts.Symbol): ts.Symbol {
148 if ((sym.getFlags() & ts.SymbolFlags.Alias) !== 0) {
154 private readonly trueSymbolAtLocationCache = new Map<ts.Node, ts.Symbol | null>();
156 trueSymbolAtLocation(node: ts.Node): ts.Symbol | undefined {
172 private static isTypeDeclSyntaxKind(kind: ts.SyntaxKind): boolean {
175 kind === ts.SyntaxKind.EnumDeclaration ||
176 kind === ts.SyntaxKind.ClassDeclaration ||
177 kind === ts.SyntaxKind.InterfaceDeclaration ||
178 kind === ts.SyntaxKind.TypeAliasDeclaration
182 static symbolHasDuplicateName(symbol: ts.Symbol, tsDeclKind: ts.SyntaxKind): boolean {
195 … TsUtils.isTypeDeclSyntaxKind(declKind) && tsDeclKind === ts.SyntaxKind.ModuleDeclaration ||
196 TsUtils.isTypeDeclSyntaxKind(tsDeclKind) && declKind === ts.SyntaxKind.ModuleDeclaration;
202 …if (declKind !== ts.SyntaxKind.Identifier && declKind !== tsDeclKind && !isNamespaceTypeCollision)…
211 static isPrimitiveType(type: ts.Type): boolean {
214 (f & ts.TypeFlags.Boolean) !== 0 ||
215 (f & ts.TypeFlags.BooleanLiteral) !== 0 ||
216 (f & ts.TypeFlags.Number) !== 0 ||
217 (f & ts.TypeFlags.NumberLiteral) !== 0
222 * (f & ts.TypeFlags.String) != 0 || (f & ts.TypeFlags.StringLiteral) != 0
227 static isPrimitiveLiteralType(type: ts.Type): boolean {
230 (ts.TypeFlags.BooleanLiteral |
231 ts.TypeFlags.NumberLiteral |
232 ts.TypeFlags.StringLiteral |
233 ts.TypeFlags.BigIntLiteral)
237 static isPurePrimitiveLiteralType(type: ts.Type): boolean {
238 return TsUtils.isPrimitiveLiteralType(type) && !(type.flags & ts.TypeFlags.EnumLiteral);
241 static isTypeSymbol(symbol: ts.Symbol | undefined): boolean {
245 … ((symbol.flags & ts.SymbolFlags.Class) !== 0 || (symbol.flags & ts.SymbolFlags.Interface) !== 0)
250 isGenericArrayType(tsType: ts.Type): tsType is ts.TypeReference {
260 isReadonlyArrayType(tsType: ts.Type): boolean {
270 static isConcatArrayType(tsType: ts.Type): boolean {
280 static isArrayLikeType(tsType: ts.Type): boolean {
290 isTypedArray(tsType: ts.Type, allowTypeArrays: string[]): boolean {
307 isArray(tsType: ts.Type): boolean {
313 isCollectionArrayType(tsType: ts.Type): boolean {
317 isIndexableArray(tsType: ts.Type): boolean {
328 static isTuple(tsType: ts.Type): boolean {
329 return TsUtils.isTypeReference(tsType) && !!(tsType.objectFlags & ts.ObjectFlags.Tuple);
333 isOrDerivedFrom(tsType: ts.Type, checkType: CheckType, checkedBaseTypes?: Set<ts.Type>): boolean {
346 (checkedBaseTypes = checkedBaseTypes || new Set<ts.Type>()).add(tsType);
349 …const isClassOrInterfaceDecl = ts.isClassDeclaration(tsTypeDecl) || ts.isInterfaceDeclaration(tsTy…
364 static isTypeReference(tsType: ts.Type): tsType is ts.TypeReference {
366 (tsType.getFlags() & ts.TypeFlags.Object) !== 0 &&
367 ((tsType as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference) !== 0
371 static isPrototypeSymbol(symbol: ts.Symbol | undefined): boolean {
372 return !!symbol && !!symbol.flags && (symbol.flags & ts.SymbolFlags.Prototype) !== 0;
375 static isFunctionSymbol(symbol: ts.Symbol | undefined): boolean {
376 return !!symbol && !!symbol.flags && (symbol.flags & ts.SymbolFlags.Function) !== 0;
379 static isInterfaceType(tsType: ts.Type | undefined): boolean {
381 …!!tsType && !!tsType.symbol && !!tsType.symbol.flags && (tsType.symbol.flags & ts.SymbolFlags.Inte…
385 static isAnyType(tsType: ts.Type): tsType is ts.TypeReference {
386 return (tsType.getFlags() & ts.TypeFlags.Any) !== 0;
389 static isUnknownType(tsType: ts.Type): boolean {
390 return (tsType.getFlags() & ts.TypeFlags.Unknown) !== 0;
393 static isUnsupportedType(tsType: ts.Type): boolean {
396 ((tsType.flags & ts.TypeFlags.Any) !== 0 ||
397 (tsType.flags & ts.TypeFlags.Unknown) !== 0 ||
398 (tsType.flags & ts.TypeFlags.Intersection) !== 0)
402 isUnsupportedTypeArkts2(tsType: ts.Type): boolean {
403 const typenode = this.tsTypeChecker.typeToTypeNode(tsType, undefined, ts.NodeBuilderFlags.None);
407 static isNullableUnionType(type: ts.Type): boolean {
410 if (!!(t.flags & ts.TypeFlags.Undefined) || !!(t.flags & ts.TypeFlags.Null)) {
418 static isMethodAssignment(tsSymbol: ts.Symbol | undefined): boolean {
420 …!!tsSymbol && (tsSymbol.flags & ts.SymbolFlags.Method) !== 0 && (tsSymbol.flags & ts.SymbolFlags.A…
424 static getDeclaration(tsSymbol: ts.Symbol | undefined): ts.Declaration | undefined {
431 private static isVarDeclaration(tsDecl: ts.Node): boolean {
432 return ts.isVariableDeclaration(tsDecl) && ts.isVariableDeclarationList(tsDecl.parent);
435 isValidEnumMemberInit(tsExpr: ts.Expression): boolean {
436 if (this.isNumberConstantValue(tsExpr.parent as ts.EnumMember)) {
439 if (this.isStringConstantValue(tsExpr.parent as ts.EnumMember)) {
445 private isCompileTimeExpressionHandlePropertyAccess(tsExpr: ts.Expression): boolean {
446 if (!ts.isPropertyAccessExpression(tsExpr)) {
466 return ts.isEnumDeclaration(decls[0]);
469 isCompileTimeExpression(tsExpr: ts.Expression): boolean {
471 ts.isParenthesizedExpression(tsExpr) ||
472 ts.isAsExpression(tsExpr) && tsExpr.type.kind === ts.SyntaxKind.NumberKeyword
478 case ts.SyntaxKind.PrefixUnaryExpression:
479 return this.isPrefixUnaryExprValidEnumMemberInit(tsExpr as ts.PrefixUnaryExpression);
480 case ts.SyntaxKind.ParenthesizedExpression:
481 case ts.SyntaxKind.BinaryExpression:
482 return this.isBinaryExprValidEnumMemberInit(tsExpr as ts.BinaryExpression);
483 case ts.SyntaxKind.ConditionalExpression:
484 return this.isConditionalExprValidEnumMemberInit(tsExpr as ts.ConditionalExpression);
485 case ts.SyntaxKind.Identifier:
486 return this.isIdentifierValidEnumMemberInit(tsExpr as ts.Identifier);
487 case ts.SyntaxKind.NumericLiteral:
489 case ts.SyntaxKind.StringLiteral:
491 case ts.SyntaxKind.PropertyAccessExpression:
498 private isPrefixUnaryExprValidEnumMemberInit(tsExpr: ts.PrefixUnaryExpression): boolean {
502 private isBinaryExprValidEnumMemberInit(tsExpr: ts.BinaryExpression): boolean {
510 private isConditionalExprValidEnumMemberInit(tsExpr: ts.ConditionalExpression): boolean {
514 private isIdentifierValidEnumMemberInit(tsExpr: ts.Identifier): boolean {
519 …(TsUtils.isVarDeclaration(tsDecl) && TsUtils.isConst(tsDecl.parent) || tsDecl.kind === ts.SyntaxKi…
523 …private static isUnaryOpAllowedForEnumMemberInit(tsPrefixUnaryOp: ts.PrefixUnaryOperator): boolean…
525 tsPrefixUnaryOp === ts.SyntaxKind.PlusToken ||
526 tsPrefixUnaryOp === ts.SyntaxKind.MinusToken ||
527 tsPrefixUnaryOp === ts.SyntaxKind.TildeToken
531 private static isBinaryOpAllowedForEnumMemberInit(tsBinaryOp: ts.BinaryOperatorToken): boolean {
533 tsBinaryOp.kind === ts.SyntaxKind.AsteriskToken ||
534 tsBinaryOp.kind === ts.SyntaxKind.SlashToken ||
535 tsBinaryOp.kind === ts.SyntaxKind.PercentToken ||
536 tsBinaryOp.kind === ts.SyntaxKind.MinusToken ||
537 tsBinaryOp.kind === ts.SyntaxKind.PlusToken ||
538 tsBinaryOp.kind === ts.SyntaxKind.LessThanLessThanToken ||
539 tsBinaryOp.kind === ts.SyntaxKind.GreaterThanGreaterThanToken ||
540 tsBinaryOp.kind === ts.SyntaxKind.BarBarToken ||
541 tsBinaryOp.kind === ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken ||
542 tsBinaryOp.kind === ts.SyntaxKind.AmpersandToken ||
543 tsBinaryOp.kind === ts.SyntaxKind.CaretToken ||
544 tsBinaryOp.kind === ts.SyntaxKind.BarToken ||
545 tsBinaryOp.kind === ts.SyntaxKind.AmpersandAmpersandToken
549 static isConst(tsNode: ts.Node): boolean {
550 return !!(ts.getCombinedNodeFlags(tsNode) & ts.NodeFlags.Const);
554 …tsExpr: ts.EnumMember | ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.NumericLiter…
557 tsExpr.kind === ts.SyntaxKind.NumericLiteral ?
565 …tsExpr: ts.EnumMember | ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.NumericLiter…
568 tsExpr.kind === ts.SyntaxKind.NumericLiteral ?
578 …isStringConstantValue(tsExpr: ts.EnumMember | ts.PropertyAccessExpression | ts.ElementAccessExpres…
584 relatedByInheritanceOrIdentical(typeA: ts.Type, typeB: ts.Type): boolean {
606 typeA: ts.Type,
607 typeB: ts.Type,
608 typeADecl: ts.Declaration,
611 … if (isBISendable && ts.isClassDeclaration(typeADecl) && TsUtils.hasSendableDecorator(typeADecl)) {
614 if (!ts.isClassDeclaration(typeADecl) && !ts.isInterfaceDeclaration(typeADecl)) {
624 …const processInterfaces = typeA.isClass() ? heritageClause.token !== ts.SyntaxKind.ExtendsKeyword …
632 static reduceReference(t: ts.Type): ts.Type {
637 lhsType: ts.Type,
638 rhsType: ts.Type,
639 rhsExpr: ts.Expression,
666 lhsType: ts.Type,
667 rhsType: ts.Type,
668 rhsExpr: ts.Expression,
694 … if (TsUtils.isTypeReference(rhsType) && !!(rhsType.objectFlags & ts.ObjectFlags.ArrayLiteral)) {
710 …private needToDeduceStructuralIdentityAdvancedClassChecks(lhsType: ts.Type, rhsType: ts.Type): boo…
720 needStrictMatchType(lhsType: ts.Type, rhsType: ts.Type): boolean {
732 private isStrictSendableMatch(lhsType: ts.Type, rhsType: ts.Type): boolean {
751 private processExtendedParentTypes(typeA: ts.Type, typeB: ts.Type): boolean {
754 * Most standard types in TS Stdlib do not use explicit inheritance and rely on
786 parentTypes: ts.NodeArray<ts.Expression>,
787 typeB: ts.Type,
804 parentTypes: ts.NodeArray<ts.Expression>,
806 checkedBaseTypes: Set<ts.Type>
817 isObject(tsType: ts.Type): boolean {
825 return node !== undefined && node.kind === ts.SyntaxKind.ObjectKeyword;
828 isCallToFunctionWithOmittedReturnType(tsExpr: ts.Expression): boolean {
829 if (ts.isCallExpression(tsExpr)) {
843 private static hasReadonlyFields(type: ts.Type): boolean {
855 ts.isPropertyDeclaration(value.declarations[0])
857 const propmMods = ts.getModifiers(value.declarations[0]);
858 if (TsUtils.hasModifier(propmMods, ts.SyntaxKind.ReadonlyKeyword)) {
867 private static hasDefaultCtor(type: ts.Type): boolean {
879 if ((value.flags & ts.SymbolFlags.Constructor) === 0) {
888 const declCtor = value.declarations[0] as ts.ConstructorDeclaration;
898 private static isAbstractClass(type: ts.Type): boolean {
900 const declClass = type.symbol.declarations[0] as ts.ClassDeclaration;
901 const classMods = ts.getModifiers(declClass);
902 if (TsUtils.hasModifier(classMods, ts.SyntaxKind.AbstractKeyword)) {
910 static validateObjectLiteralType(type: ts.Type | undefined): boolean {
924 hasMethods(type: ts.Type): boolean {
928 if (prop.getFlags() & ts.SymbolFlags.Method) {
936 findProperty(type: ts.Type, name: string): ts.Symbol | undefined {
949 checkTypeSet(typeSet: ts.Type, predicate: CheckType): boolean {
961 getNonNullableType(t: ts.Type): ts.Type {
969 …private isObjectLiteralAssignableToUnion(lhsType: ts.UnionType, rhsExpr: ts.ObjectLiteralExpressio…
978 …isObjectLiteralAssignable(lhsType: ts.Type | undefined, rhsExpr: ts.ObjectLiteralExpression): bool…
1028 private isDynamicObjectAssignedToStdType(lhsType: ts.Type, rhsExpr: ts.Expression): boolean {
1031 const rhsSym = ts.isCallExpression(rhsExpr) ?
1043 validateFields(objectType: ts.Type, objectLiteral: ts.ObjectLiteralExpression): boolean {
1045 if (ts.isPropertyAssignment(prop)) {
1055 getPropertySymbol(type: ts.Type, prop: ts.PropertyAssignment): ts.Symbol | undefined {
1059 ts.symbolName(propNameSymbol) :
1060 ts.isMemberName(prop.name) ?
1061 ts.idText(prop.name) :
1067 private validateField(type: ts.Type, prop: ts.PropertyAssignment): boolean {
1077 if (ts.isObjectLiteralExpression(initExpr)) {
1096 validateRecordObjectKeys(objectLiteral: ts.ObjectLiteralExpression): boolean {
1105 isValidRecordObjectLiteralKey(propName: ts.PropertyName): boolean {
1106 if (ts.isComputedPropertyName(propName)) {
1109 return ts.isStringLiteral(propName) || ts.isNumericLiteral(propName);
1112 private static isSupportedTypeNodeKind(kind: ts.SyntaxKind): boolean {
1114 kind !== ts.SyntaxKind.AnyKeyword &&
1115 kind !== ts.SyntaxKind.UnknownKeyword &&
1116 kind !== ts.SyntaxKind.SymbolKeyword &&
1117 kind !== ts.SyntaxKind.IndexedAccessType &&
1118 kind !== ts.SyntaxKind.ConditionalType &&
1119 kind !== ts.SyntaxKind.MappedType &&
1120 kind !== ts.SyntaxKind.InferType
1124 private isSupportedTypeHandleUnionTypeNode(typeNode: ts.UnionTypeNode): boolean {
1133 private isSupportedTypeHandleTupleTypeNode(typeNode: ts.TupleTypeNode): boolean {
1135 if (ts.isTypeNode(elem) && !this.isSupportedType(elem)) {
1138 if (ts.isNamedTupleMember(elem) && !this.isSupportedType(elem.type)) {
1145 isSupportedType(typeNode: ts.TypeNode): boolean {
1146 if (ts.isParenthesizedTypeNode(typeNode)) {
1150 if (ts.isArrayTypeNode(typeNode)) {
1154 if (ts.isTypeReferenceNode(typeNode) && typeNode.typeArguments) {
1163 if (ts.isUnionTypeNode(typeNode)) {
1167 if (ts.isTupleTypeNode(typeNode)) {
1172 !ts.isTypeLiteralNode(typeNode) &&
1173 (this.options.advancedClassChecks || !ts.isTypeQueryNode(typeNode)) &&
1174 !ts.isIntersectionTypeNode(typeNode) &&
1179 isStructObjectInitializer(objectLiteral: ts.ObjectLiteralExpression): boolean {
1180 if (ts.isCallLikeExpression(objectLiteral.parent)) {
1183 …return !!signDecl && ts.isConstructorDeclaration(signDecl) && isStructDeclaration(signDecl.parent);
1188 parentSymbolCache = new Map<ts.Symbol, string | undefined>();
1190 getParentSymbolName(symbol: ts.Symbol): string | undefined {
1203 isGlobalSymbol(symbol: ts.Symbol): boolean {
1208 isStdSymbol(symbol: ts.Symbol): boolean {
1213 isStdSymbolAPI(symbol: ts.Symbol): boolean {
1222 isSymbolIterator(symbol: ts.Symbol): boolean {
1231 isSymbolIteratorExpression(expr: ts.Expression): boolean {
1236 static isDefaultImport(importSpec: ts.ImportSpecifier): boolean {
1240 static getStartPos(nodeOrComment: ts.Node | ts.CommentRange): number {
1241 return nodeOrComment.kind === ts.SyntaxKind.SingleLineCommentTrivia ||
1242 nodeOrComment.kind === ts.SyntaxKind.MultiLineCommentTrivia ?
1243 (nodeOrComment as ts.CommentRange).pos :
1244 (nodeOrComment as ts.Node).getStart();
1247 static getEndPos(nodeOrComment: ts.Node | ts.CommentRange): number {
1248 return nodeOrComment.kind === ts.SyntaxKind.SingleLineCommentTrivia ||
1249 nodeOrComment.kind === ts.SyntaxKind.MultiLineCommentTrivia ?
1250 (nodeOrComment as ts.CommentRange).end :
1251 (nodeOrComment as ts.Node).getEnd();
1254 …static getHighlightRange(nodeOrComment: ts.Node | ts.CommentRange, faultId: number): [number, numb…
1287 …static getKeywordHighlightRange(nodeOrComment: ts.Node | ts.CommentRange, keyword: string): [numbe…
1292 …static getVarDeclarationHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, number]…
1297 nodeOrComment: ts.Node | ts.CommentRange
1299 const catchClauseNode = (nodeOrComment as ts.CatchClause).variableDeclaration;
1307 …static getForInStatementHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, number]…
1309 this.getEndPos((nodeOrComment as ts.ForInStatement).initializer) + 1,
1310 this.getStartPos((nodeOrComment as ts.ForInStatement).expression) - 1
1314 …static getWithStatementHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, number] …
1315 …return [this.getStartPos(nodeOrComment), (nodeOrComment as ts.WithStatement).statement.getStart() …
1318 …static getDeleteOperatorHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, number]…
1322 …static getTypeQueryHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, number] | un…
1327 nodeOrComment: ts.Node | ts.CommentRange
1329 …return this.getKeywordHighlightRange((nodeOrComment as ts.BinaryExpression).operatorToken, 'instan…
1332 …static getConstAssertionHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, number]…
1333 if (nodeOrComment.kind === ts.SyntaxKind.AsExpression) {
1335 (nodeOrComment as ts.AsExpression).expression.getEnd() + 1,
1336 (nodeOrComment as ts.AsExpression).type.getStart() - 1
1340 (nodeOrComment as ts.TypeAssertion).expression.getEnd() + 1,
1341 (nodeOrComment as ts.TypeAssertion).type.getEnd() + 1
1346 nodeOrComment: ts.Node | ts.CommentRange
1348 let node: ts.Node | undefined;
1349 if (nodeOrComment.kind === ts.SyntaxKind.FunctionExpression) {
1351 node = (nodeOrComment as ts.FunctionExpression).type;
1352 } else if (nodeOrComment.kind === ts.SyntaxKind.FunctionDeclaration) {
1353 node = (nodeOrComment as ts.FunctionDeclaration).name;
1354 } else if (nodeOrComment.kind === ts.SyntaxKind.MethodDeclaration) {
1355 node = (nodeOrComment as ts.MethodDeclaration).name;
1365 …static getLocalFunctionHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, number] …
1369 …static getFunctionApplyCallHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, numb…
1370 const pointPos = (nodeOrComment as ts.Node).getText().lastIndexOf('.');
1375 nodeOrComment: ts.Node | ts.CommentRange
1378 const nameNode: ts.Node | undefined = (nodeOrComment as ts.NamedDeclaration).name;
1387 nodeOrComment: ts.Node | ts.CommentRange
1392 …static getClassExpressionHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, number…
1396 …static getMultipleStaticBlocksHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, n…
1400 …static getParameterPropertiesHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, nu…
1401 const param = nodeOrComment as ts.ParameterDeclaration;
1402 const modifier = TsUtils.getAccessModifier(ts.getModifiers(param));
1409 …static getObjectTypeLiteralHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, numb…
1416 nodeOrComment: ts.Node | ts.CommentRange
1418 const name = (nodeOrComment as ts.PropertyDeclaration).name;
1419 const exclamationToken = (nodeOrComment as ts.PropertyDeclaration).exclamationToken;
1423 …static getStructuralIdentityHighlightRange(nodeOrComment: ts.Node | ts.CommentRange): [number, num…
1424 let node: ts.Node | undefined;
1425 if (nodeOrComment.kind === ts.SyntaxKind.ReturnStatement) {
1426 node = (nodeOrComment as ts.ReturnStatement).expression;
1427 } else if (nodeOrComment.kind === ts.SyntaxKind.PropertyDeclaration) {
1428 node = (nodeOrComment as ts.PropertyDeclaration).name;
1438 isStdRecordType(type: ts.Type): boolean {
1446 const target = (type as ts.TypeReference).target;
1456 isStdErrorType(type: ts.Type): boolean {
1465 isStdPartialType(type: ts.Type): boolean {
1470 isStdRequiredType(type: ts.Type): boolean {
1475 isStdReadonlyType(type: ts.Type): boolean {
1480 isLibraryType(type: ts.Type): boolean {
1493 hasLibraryType(node: ts.Node): boolean {
1497 isLibrarySymbol(sym: ts.Symbol | undefined): boolean {
1506 * Symbols from both *.ts and *.d.ts files should obey interop rules.
1507 * We disable such behavior for *.ts files in the test mode due to lack of 'ets'
1519 const isTs = ext === '.ts' && !srcFile.isDeclarationFile;
1533 static isOhModulesEtsSymbol(sym: ts.Symbol | undefined): boolean {
1542 isDynamicType(type: ts.Type | undefined): boolean | undefined {
1581 static isObjectType(type: ts.Type): type is ts.ObjectType {
1582 return !!(type.flags & ts.TypeFlags.Object);
1585 private static isAnonymous(type: ts.Type): boolean {
1587 return !!(type.objectFlags & ts.ObjectFlags.Anonymous);
1592 private isDynamicLiteralInitializerHandleCallExpression(callExpr: ts.CallExpression): boolean {
1599 let sym: ts.Symbol | undefined = type.symbol;
1608 if (ts.isPropertyAccessExpression(callExpr.expression)) {
1618 isDynamicLiteralInitializer(expr: ts.Expression): boolean {
1619 if (!ts.isObjectLiteralExpression(expr) && !ts.isArrayLiteralExpression(expr)) {
1627 let curNode: ts.Node = expr;
1628 while (ts.isObjectLiteralExpression(curNode) || ts.isArrayLiteralExpression(curNode)) {
1638 if (ts.isPropertyAssignment(curNode)) {
1647 …if (ts.isCallExpression(curNode) && this.isDynamicLiteralInitializerHandleCallExpression(curNode))…
1655 if (ts.isBinaryExpression(curNode)) {
1657 if (ts.isPropertyAccessExpression(binExpr.left)) {
1667 static isEsObjectType(typeNode: ts.TypeNode | undefined): boolean {
1670 ts.isTypeReferenceNode(typeNode) &&
1671 ts.isIdentifier(typeNode.typeName) &&
1676 static isInsideBlock(node: ts.Node): boolean {
1679 if (ts.isBlock(par)) {
1687 static isEsObjectPossiblyAllowed(typeRef: ts.TypeReferenceNode): boolean {
1688 return ts.isVariableDeclaration(typeRef.parent);
1691 isValueAssignableToESObject(node: ts.Node): boolean {
1692 if (ts.isArrayLiteralExpression(node) || ts.isObjectLiteralExpression(node)) {
1699 getVariableDeclarationTypeNode(node: ts.Node): ts.TypeNode | undefined {
1707 static getSymbolDeclarationTypeNode(sym: ts.Symbol): ts.TypeNode | undefined {
1709 if (!!decl && ts.isVariableDeclaration(decl)) {
1715 hasEsObjectType(node: ts.Node): boolean {
1720 static symbolHasEsObjectType(sym: ts.Symbol): boolean {
1725 static isEsObjectSymbol(sym: ts.Symbol): boolean {
1729 ts.isTypeAliasDeclaration(decl) &&
1731 decl.type.kind === ts.SyntaxKind.AnyKeyword
1735 static isAnonymousType(type: ts.Type): boolean {
1746 …(type.flags & ts.TypeFlags.Object) !== 0 && ((type as ts.ObjectType).objectFlags & ts.ObjectFlags.…
1750 getSymbolOfCallExpression(callExpr: ts.CallExpression): ts.Symbol | undefined {
1759 static isClassValueType(type: ts.Type): boolean {
1761 (type.flags & ts.TypeFlags.Object) === 0 ||
1762 ((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Anonymous) === 0
1766 return type.symbol && (type.symbol.flags & ts.SymbolFlags.Class) !== 0;
1769 isClassObjectExpression(expr: ts.Expression): boolean {
1774 return !symbol || (symbol.flags & ts.SymbolFlags.Class) === 0;
1777 isClassTypeExpression(expr: ts.Expression): boolean {
1779 return sym !== undefined && (sym.flags & ts.SymbolFlags.Class) !== 0;
1782 isFunctionCalledRecursively(funcExpr: ts.FunctionExpression): boolean {
1793 const callback = (node: ts.Node): void => {
1794 if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
1802 const stopCondition = (node: ts.Node): boolean => {
1811 getTypeOrTypeConstraintAtLocation(expr: ts.Expression): ts.Type {
1822 private areCompatibleFunctionals(lhsType: ts.Type, rhsType: ts.Type): boolean {
1829 private static isFunctionalType(type: ts.Type): boolean {
1834 private isStdFunctionType(type: ts.Type): boolean {
1839 isStdBigIntType(type: ts.Type): boolean {
1844 isStdNumberType(type: ts.Type): boolean {
1849 isStdBooleanType(type: ts.Type): boolean {
1854 isEnumStringLiteral(expr: ts.Expression): boolean {
1856 const isEnumMember = !!symbol && !!(symbol.flags & ts.SymbolFlags.EnumMember);
1858 …const isStringEnumLiteral = TsUtils.isEnumType(type) && !!(type.flags & ts.TypeFlags.StringLiteral…
1862 …isValidComputedPropertyName(computedProperty: ts.ComputedPropertyName, isRecordObjectInitializer =…
1870 return ts.isStringLiteralLike(expr) || this.isEnumStringLiteral(computedProperty.expression);
1874 decl: ts.PropertyDeclaration,
1875 sourceFile: ts.SourceFile | undefined,
1884 getScriptKind(sourceFile) === ts.ScriptKind.ETS;
1889 return m.kind === ts.SyntaxKind.PrivateKeyword;
1894 hasAccessModifier(decl: ts.HasModifiers): boolean {
1895 const modifiers = ts.getModifiers(decl);
1898 (!this.options.useRtLogic && TsUtils.hasModifier(modifiers, ts.SyntaxKind.ReadonlyKeyword) ||
1899 TsUtils.hasModifier(modifiers, ts.SyntaxKind.PublicKeyword) ||
1900 TsUtils.hasModifier(modifiers, ts.SyntaxKind.ProtectedKeyword) ||
1901 TsUtils.hasModifier(modifiers, ts.SyntaxKind.PrivateKeyword))
1906 modifiers: readonly ts.Modifier[] | undefined,
1907 modifierKind: ts.SyntaxKind
1908 ): ts.Modifier | undefined {
1917 static getAccessModifier(modifiers: readonly ts.Modifier[] | undefined): ts.Modifier | undefined {
1919 TsUtils.getModifier(modifiers, ts.SyntaxKind.PublicKeyword) ??
1920 TsUtils.getModifier(modifiers, ts.SyntaxKind.ProtectedKeyword) ??
1921 TsUtils.getModifier(modifiers, ts.SyntaxKind.PrivateKeyword)
1925 static getBaseClassType(type: ts.Type): ts.InterfaceType | undefined {
1938 static destructuringAssignmentHasSpreadOperator(node: ts.AssignmentPattern): boolean {
1939 if (ts.isArrayLiteralExpression(node)) {
1941 if (ts.isSpreadElement(x)) {
1944 if (ts.isObjectLiteralExpression(x) || ts.isArrayLiteralExpression(x)) {
1952 if (ts.isSpreadAssignment(x)) {
1956 ts.isPropertyAssignment(x) &&
1957 (ts.isObjectLiteralExpression(x.initializer) || ts.isArrayLiteralExpression(x.initializer))
1965 static destructuringDeclarationHasSpreadOperator(node: ts.BindingPattern): boolean {
1967 if (ts.isBindingElement(x)) {
1971 if (ts.isArrayBindingPattern(x.name) || ts.isObjectBindingPattern(x.name)) {
1980 static destructuringAssignmentHasDefaultValue(node: ts.AssignmentPattern): boolean {
1981 if (ts.isArrayLiteralExpression(node)) {
1983 if (ts.isBinaryExpression(x) && x.right) {
1986 if (ts.isObjectLiteralExpression(x) || ts.isArrayLiteralExpression(x)) {
1994 if (ts.isShorthandPropertyAssignment(x) && x.equalsToken) {
1998 ts.isPropertyAssignment(x) &&
1999 (ts.isObjectLiteralExpression(x.initializer) || ts.isArrayLiteralExpression(x.initializer))
2008 static destructuringDeclarationHasDefaultValue(node: ts.BindingPattern): boolean {
2010 if (ts.isBindingElement(x)) {
2014 if (ts.isArrayBindingPattern(x.name) || ts.isObjectBindingPattern(x.name)) {
2023 static isSameDimension(arr: ts.Node): boolean | undefined {
2024 if (!ts.isArrayLiteralExpression(arr)) {
2033 const e = arrElements[i] as ts.Node;
2034 if (!ts.isArrayLiteralExpression(e)) {
2059 static checkArrayLiteralHasEmptyElement(node: ts.ArrayLiteralExpression): boolean {
2061 if (ts.isOmittedExpression(x)) {
2064 if (ts.isArrayLiteralExpression(x)) {
2075 static checkArrayBindingHasEmptyElement(node: ts.ArrayBindingPattern): boolean {
2077 if (ts.isOmittedExpression(x)) {
2080 if (ts.isBindingElement(x) && ts.isArrayBindingPattern(x.name)) {
2090 static hasNestedObjectDestructuring(node: ts.ArrayBindingOrAssignmentPattern): boolean {
2091 if (ts.isArrayLiteralExpression(node)) {
2093 const elem = ts.isSpreadElement(x) ? x.expression : x;
2094 if (ts.isArrayLiteralExpression(elem)) {
2097 return ts.isObjectLiteralExpression(elem);
2102 if (ts.isBindingElement(x)) {
2103 if (ts.isArrayBindingPattern(x.name)) {
2106 return ts.isObjectBindingPattern(x.name);
2112 static getDecoratorName(decorator: ts.Decorator): string {
2114 if (ts.isIdentifier(decorator.expression)) {
2116 …} else if (ts.isCallExpression(decorator.expression) && ts.isIdentifier(decorator.expression.expre…
2122 static unwrapParenthesizedTypeNode(typeNode: ts.TypeNode): ts.TypeNode {
2124 while (ts.isParenthesizedTypeNode(unwrappedTypeNode)) {
2131 isSendableTypeNode(typeNode: ts.TypeNode, isShared: boolean = false): boolean {
2144 if (ts.isUnionTypeNode(typeNode)) {
2150 …const sym = ts.isTypeReferenceNode(typeNode) ? this.trueSymbolAtLocation(typeNode.typeName) : unde…
2152 if (sym && sym.getFlags() & ts.SymbolFlags.TypeAlias) {
2154 if (typeDecl && ts.isTypeAliasDeclaration(typeDecl)) {
2155 const typeArgs = (typeNode as ts.TypeReferenceNode).typeArguments;
2172 const type: ts.Type = this.tsTypeChecker.getTypeFromTypeNode(typeNode);
2182 isSendableType(type: ts.Type): boolean {
2185 (ts.TypeFlags.Boolean |
2186 ts.TypeFlags.Number |
2187 ts.TypeFlags.String |
2188 ts.TypeFlags.BigInt |
2189 ts.TypeFlags.Null |
2190 ts.TypeFlags.Undefined |
2191 ts.TypeFlags.TypeParameter)) !==
2206 isShareableType(tsType: ts.Type): boolean {
2225 isSendableClassOrInterface(type: ts.Type): boolean {
2237 if (ts.isClassDeclaration(decl)) {
2246 typeContainsSendableClassOrInterface(type: ts.Type): boolean {
2248 if ((type.flags & ts.TypeFlags.Union) !== 0) {
2249 return !!(type as ts.UnionType)?.types?.some((type) => {
2257 typeContainsNonSendableClassOrInterface(type: ts.Type): boolean {
2268 static isConstEnum(sym: ts.Symbol | undefined): boolean {
2269 return !!sym && sym.flags === ts.SymbolFlags.ConstEnum;
2272 isSendableUnionType(type: ts.UnionType): boolean {
2283 …static hasSendableDecorator(decl: ts.ClassDeclaration | ts.FunctionDeclaration | ts.TypeAliasDecla…
2288 decl: ts.ClassDeclaration | ts.FunctionDeclaration | ts.TypeAliasDeclaration
2289 ): ts.Decorator[] | undefined {
2290 const decorators = ts.getAllDecorators(decl);
2297 decl: ts.ClassDeclaration | ts.FunctionDeclaration | ts.TypeAliasDeclaration
2298 ): ts.Decorator | undefined {
2299 const decorators = ts.getAllDecorators(decl);
2305 …static getDecoratorsIfInSendableClass(declaration: ts.HasDecorators): readonly ts.Decorator[] | un…
2310 return ts.getDecorators(declaration);
2313 …private static getClassNodeFromDeclaration(declaration: ts.HasDecorators): ts.ClassDeclaration | u…
2314 if (declaration.kind === ts.SyntaxKind.Parameter) {
2315 … return ts.isClassDeclaration(declaration.parent.parent) ? declaration.parent.parent : undefined;
2317 return ts.isClassDeclaration(declaration.parent) ? declaration.parent : undefined;
2320 static isISendableInterface(type: ts.Type): boolean {
2329 private static isArkTSISendableDeclaration(decl: ts.Declaration): boolean {
2330 if (!ts.isInterfaceDeclaration(decl) || !decl.name || decl.name.text !== ISENDABLE_TYPE) {
2334 if (!ts.isModuleBlock(decl.parent) || decl.parent.parent.name.text !== LANG_NAMESPACE) {
2345 isAllowedIndexSignature(node: ts.IndexSignatureDeclaration): boolean {
2357 if ((paramType.flags & ts.TypeFlags.Number) === 0) {
2364 isArkTSCollectionsArrayLikeType(type: ts.Type): boolean {
2373 private isArkTSCollectionsArrayLikeDeclaration(decl: ts.Declaration): boolean {
2383 static isArkTSCollectionsClassOrInterfaceDeclaration(decl: ts.Node): boolean {
2384 if (!ts.isClassDeclaration(decl) && !ts.isInterfaceDeclaration(decl) || !decl.name) {
2387 if (!ts.isModuleBlock(decl.parent) || decl.parent.parent.name.text !== COLLECTIONS_NAMESPACE) {
2398 targetMember: ts.ClassElement,
2399 classMember: ts.ClassElement,
2404 ts.isConstructorDeclaration(classMember) &&
2407 ts.isIdentifier(x.name) &&
2410 targetMember.name as ts.Identifier,
2423 targetMember: ts.ClassElement,
2424 classType: ts.Type,
2430 const baseDecl = baseType.getSymbol()?.valueDeclaration as ts.ClassLikeDeclaration;
2440 targetMember: ts.ClassElement,
2441 tsClassLikeDecl: ts.ClassLikeDeclaration,
2443 classType?: ts.Type
2494 …private static isIdentifierOrPrivateIdentifier(node?: ts.PropertyName): node is ts.Identifier | ts…
2498 return ts.isIdentifier(node) || ts.isPrivateIdentifier(node);
2502 ident1: ts.Identifier | ts.PrivateIdentifier,
2503 ident2: ts.Identifier | ts.PrivateIdentifier,
2506 if (ts.isIdentifier(ident1) && ts.isPrivateIdentifier(ident2)) {
2509 if (ts.isIdentifier(ident2) && ts.isPrivateIdentifier(ident1)) {
2514 ts.isPrivateIdentifier(ident1) &&
2515 ts.isPrivateIdentifier(ident2)
2522 findIdentifierNameForSymbol(symbol: ts.Symbol): string | undefined {
2552 if (offset === 0 && !ts.isIdentifierStart(codePoint, undefined)) {
2556 if (!ts.isIdentifierPart(codePoint, undefined)) {
2578 private getTypeByProperty(symbol: ts.Symbol): ts.Type | undefined {
2585 !ts.isPropertyDeclaration(propDecl) &&
2586 !ts.isPropertyAssignment(propDecl) &&
2587 !ts.isPropertySignature(propDecl)
2601 static isPropertyOfInternalClassOrInterface(symbol: ts.Symbol): boolean {
2607 if (!ts.isPropertyDeclaration(propDecl) && !ts.isPropertySignature(propDecl)) {
2611 if (!ts.isClassDeclaration(propDecl.parent) && !ts.isInterfaceDeclaration(propDecl.parent)) {
2615 if (TsUtils.hasModifier(ts.getModifiers(propDecl.parent), ts.SyntaxKind.ExportKeyword)) {
2623 static isIntrinsicObjectType(type: ts.Type): boolean {
2624 return !!(type.flags & ts.TypeFlags.NonPrimitive);
2627 isStringType(tsType: ts.Type): boolean {
2628 if ((tsType.getFlags() & ts.TypeFlags.String) !== 0) {
2641 isStdMapType(type: ts.Type): boolean {
2646 hasGenericTypeParameter(type: ts.Type): boolean {
2661 static getEnclosingTopLevelStatement(node: ts.Node): ts.Node | undefined {
2662 return ts.findAncestor(node, (ancestor) => {
2663 return ts.isSourceFile(ancestor.parent);
2667 static isDeclarationStatement(node: ts.Node): node is ts.DeclarationStatement {
2670 kind === ts.SyntaxKind.FunctionDeclaration ||
2671 kind === ts.SyntaxKind.ModuleDeclaration ||
2672 kind === ts.SyntaxKind.ClassDeclaration ||
2673 kind === ts.SyntaxKind.StructDeclaration ||
2674 kind === ts.SyntaxKind.TypeAliasDeclaration ||
2675 kind === ts.SyntaxKind.InterfaceDeclaration ||
2676 kind === ts.SyntaxKind.EnumDeclaration ||
2677 kind === ts.SyntaxKind.MissingDeclaration ||
2678 kind === ts.SyntaxKind.ImportEqualsDeclaration ||
2679 kind === ts.SyntaxKind.ImportDeclaration ||
2680 kind === ts.SyntaxKind.NamespaceExportDeclaration
2684 static declarationNameExists(srcFile: ts.SourceFile, name: string): boolean {
2696 static checkDeclarationInBlockStatement(stmt: ts.Statement, name: string): boolean {
2697 if (ts.isBlock(stmt)) {
2708 static checkImportDeclaration(stmt: ts.Statement, name: string): boolean {
2709 if (ts.isImportDeclaration(stmt)) {
2714 if (ts.isNamespaceImport(stmt.importClause.namedBindings)) {
2726 static checkDeclarationInLoopStatement(stmt: ts.Statement, name: string): boolean {
2728 ts.isForStatement(stmt) ||
2729 ts.isWhileStatement(stmt) ||
2730 ts.isDoStatement(stmt) ||
2731 ts.isForOfStatement(stmt) ||
2732 ts.isForInStatement(stmt)
2734 if (ts.isBlock(stmt.statement)) {
2746 static checkDeclarationInVariableStatement(stmt: ts.Statement, name: string): boolean {
2747 if (ts.isVariableStatement(stmt)) {
2755 static checkGeneralDeclaration(stmt: ts.Statement, name: string): boolean {
2756 if (ts.isFunctionDeclaration(stmt)) {
2761 stmt.name !== undefined && ts.isIdentifier(stmt.name) && stmt.name.text === name
2767 ts.isIdentifier(stmt.name) &&
2772 …static generateUniqueName(nameGenerator: NameGenerator, srcFile: ts.SourceFile): string | undefine…
2786 static isSharedModule(sourceFile: ts.SourceFile): boolean {
2789 if (ts.isImportDeclaration(statement)) {
2794 ts.isExpressionStatement(statement) &&
2795 ts.isStringLiteral(statement.expression) &&
2802 getDeclarationNode(node: ts.Node): ts.Declaration | undefined {
2807 static isFunctionLikeDeclaration(node: ts.Declaration): boolean {
2809 ts.isFunctionDeclaration(node) ||
2810 ts.isMethodDeclaration(node) ||
2811 ts.isGetAccessorDeclaration(node) ||
2812 ts.isSetAccessorDeclaration(node) ||
2813 ts.isConstructorDeclaration(node) ||
2814 ts.isFunctionExpression(node) ||
2815 ts.isArrowFunction(node)
2819 isShareableEntity(node: ts.Node): boolean {
2828 isSendableClassOrInterfaceEntity(node: ts.Node): boolean {
2833 if (ts.isClassDeclaration(decl)) {
2836 if (ts.isInterfaceDeclaration(decl)) {
2842 static isInImportWhiteList(resolvedModule: ts.ResolvedModuleFull): boolean {
2854 static hasSendableDecoratorFunctionOverload(decl: ts.FunctionDeclaration): boolean {
2861 …static getFunctionOverloadDecorators(funcDecl: ts.FunctionDeclaration): readonly ts.Decorator[] | …
2866 let result: ts.Decorator[] = [];
2868 if (!ts.isFunctionDeclaration(decl)) {
2871 const decorators = ts.getAllDecorators(decl);
2879 static isSendableFunction(type: ts.Type): boolean {
2885 if (!decl || !ts.isFunctionDeclaration(decl)) {
2891 isSendableTypeAlias(type: ts.Type): boolean {
2896 hasSendableTypeAlias(type: ts.Type): boolean {
2905 isNonSendableFunctionTypeAlias(type: ts.Type): boolean {
2907 return !!decl && ts.isFunctionTypeNode(decl.type) && !TsUtils.hasSendableDecorator(decl);
2911 private getTypsAliasOriginalDecl(type: ts.Type): ts.TypeAliasDeclaration | undefined {
2916 if (!decl || !ts.isTypeAliasDeclaration(decl)) {
2919 if (ts.isTypeReferenceNode(decl.type)) {
2921 if (targetType.aliasSymbol && targetType.aliasSymbol.getFlags() & ts.SymbolFlags.TypeAlias) {
2929 isWrongSendableFunctionAssignment(lhsType: ts.Type, rhsType: ts.Type): boolean {
2946 private isInvalidSendableFunctionAssignmentType(type: ts.Type): boolean {
2956 static isSetExpression(accessExpr: ts.ElementAccessExpression): boolean {
2957 if (!ts.isBinaryExpression(accessExpr.parent)) {
2961 …return binaryExpr.operatorToken.kind === ts.SyntaxKind.EqualsToken && binaryExpr.left === accessEx…
2964 haveSameBaseType(type1: ts.Type, type2: ts.Type): boolean {
2968 isGetIndexableType(type: ts.Type, indexType: ts.Type): boolean {
2970 if (getDecls?.length !== 1 || getDecls[0].kind !== ts.SyntaxKind.MethodDeclaration) {
2973 const getMethodDecl = getDecls[0] as ts.MethodDeclaration;
2982 isSetIndexableType(type: ts.Type, indexType: ts.Type, valueType: ts.Type): boolean {
2985 if (setDecls?.length !== 1 || setDecls[0].kind !== ts.SyntaxKind.MethodDeclaration) {
2988 const setMethodDecl = setDecls[0] as ts.MethodDeclaration;
3006 searchFileExportDecl(sourceFile: ts.SourceFile, targetDecls?: ts.SyntaxKind[]): Set<ts.Node> {
3007 const exportDeclSet = new Set<ts.Node>();
3008 const appendDecl = (decl: ts.Node | undefined): void => {
3015 sourceFile.statements.forEach((statement: ts.Statement) => {
3016 if (ts.isExportAssignment(statement)) {
3022 } else if (ts.isExportDeclaration(statement)) {
3024 if (!statement.exportClause || !ts.isNamedExports(statement.exportClause)) {
3030 } else if (ts.canHaveModifiers(statement)) {
3032 if (!TsUtils.hasModifier(ts.getModifiers(statement), ts.SyntaxKind.ExportKeyword)) {
3035 if (!ts.isVariableStatement(statement)) {
3047 static isAmbientNode(node: ts.Node): boolean {
3051 return !!(node.flags & (ts.NodeFlags as any).Ambient);