UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

1,016 lines (1,014 loc) 30.1 kB
"use strict"; // ----------------------- // WARNING - DO NOT modify the TypeGuards class directly. It is code generated by createTypeGuardsUtility.ts // // Note: This file is excluded from code coverage reports because it's automatically maintained (low risk). // ----------------------- Object.defineProperty(exports, "__esModule", { value: true }); /* tslint:disable */ const ts = require("typescript"); /** * Type guards for checking the type of a node. */ class TypeGuards { constructor() { } /** * Gets if the node is an AbstractableNode. * @param node - Node to check. */ static isAbstractableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.SetAccessor: return true; default: return false; } } /** * Gets if the node is an AmbientableNode. * @param node - Node to check. */ static isAmbientableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.EnumDeclaration: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.ModuleDeclaration: case ts.SyntaxKind.TypeAliasDeclaration: case ts.SyntaxKind.VariableStatement: return true; default: return false; } } /** * Gets if the node is an ArgumentedNode. * @param node - Node to check. */ static isArgumentedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.CallExpression: return true; default: return false; } } /** * Gets if the node is an ArrayLiteralExpression. * @param node - Node to check. */ static isArrayLiteralExpression(node) { switch (node.getKind()) { case ts.SyntaxKind.ArrayLiteralExpression: return true; default: return false; } } /** * Gets if the node is an AsyncableNode. * @param node - Node to check. */ static isAsyncableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.FunctionDeclaration: return true; default: return false; } } /** * Gets if the node is a BindingNamedNode. * @param node - Node to check. */ static isBindingNamedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.VariableDeclaration: return true; default: return false; } } /** * Gets if the node is a BodiedNode. * @param node - Node to check. */ static isBodiedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.ModuleDeclaration: return true; default: return false; } } /** * Gets if the node is a BodyableNode. * @param node - Node to check. */ static isBodyableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.FunctionDeclaration: return true; default: return false; } } /** * Gets if the node is a CallExpression. * @param node - Node to check. */ static isCallExpression(node) { switch (node.getKind()) { case ts.SyntaxKind.CallExpression: return true; default: return false; } } /** * Gets if the node is a ClassDeclaration. * @param node - Node to check. */ static isClassDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: return true; default: return false; } } /** * Gets if the node is a ConstructSignatureDeclaration. * @param node - Node to check. */ static isConstructSignatureDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.ConstructSignature: return true; default: return false; } } /** * Gets if the node is a ConstructorDeclaration. * @param node - Node to check. */ static isConstructorDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: return true; default: return false; } } /** * Gets if the node is a DeclarationNamedNode. * @param node - Node to check. */ static isDeclarationNamedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.Parameter: return true; default: return false; } } /** * Gets if the node is a DecoratableNode. * @param node - Node to check. */ static isDecoratableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.Parameter: return true; default: return false; } } /** * Gets if the node is a Decorator. * @param node - Node to check. */ static isDecorator(node) { switch (node.getKind()) { case ts.SyntaxKind.Decorator: return true; default: return false; } } /** * Gets if the node is a DocumentationableNode. * @param node - Node to check. */ static isDocumentationableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.EnumDeclaration: case ts.SyntaxKind.EnumMember: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.ConstructSignature: case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.MethodSignature: case ts.SyntaxKind.PropertySignature: case ts.SyntaxKind.ModuleDeclaration: case ts.SyntaxKind.TypeAliasDeclaration: case ts.SyntaxKind.VariableStatement: return true; default: return false; } } /** * Gets if the node is a EnumDeclaration. * @param node - Node to check. */ static isEnumDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.EnumDeclaration: return true; default: return false; } } /** * Gets if the node is a EnumMember. * @param node - Node to check. */ static isEnumMember(node) { switch (node.getKind()) { case ts.SyntaxKind.EnumMember: return true; default: return false; } } /** * Gets if the node is a ExportDeclaration. * @param node - Node to check. */ static isExportDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.ExportDeclaration: return true; default: return false; } } /** * Gets if the node is a ExportSpecifier. * @param node - Node to check. */ static isExportSpecifier(node) { switch (node.getKind()) { case ts.SyntaxKind.ExportSpecifier: return true; default: return false; } } /** * Gets if the node is a ExportableNode. * @param node - Node to check. */ static isExportableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.EnumDeclaration: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.ModuleDeclaration: case ts.SyntaxKind.TypeAliasDeclaration: case ts.SyntaxKind.VariableStatement: return true; default: return false; } } /** * Gets if the node is a Expression. * @param node - Node to check. */ static isExpression(node) { switch (node.getKind()) { case ts.SyntaxKind.NumericLiteral: return true; default: return false; } } /** * Gets if the node is a ExpressionWithTypeArguments. * @param node - Node to check. */ static isExpressionWithTypeArguments(node) { switch (node.getKind()) { case ts.SyntaxKind.ExpressionWithTypeArguments: return true; default: return false; } } /** * Gets if the node is a ExtendsClauseableNode. * @param node - Node to check. */ static isExtendsClauseableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.InterfaceDeclaration: return true; default: return false; } } /** * Gets if the node is a FunctionDeclaration. * @param node - Node to check. */ static isFunctionDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.FunctionDeclaration: return true; default: return false; } } /** * Gets if the node is a FunctionLikeDeclaration. * @param node - Node to check. */ static isFunctionLikeDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.FunctionDeclaration: return true; default: return false; } } /** * Gets if the node is a GeneratorableNode. * @param node - Node to check. */ static isGeneratorableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.FunctionDeclaration: return true; default: return false; } } /** * Gets if the node is a GetAccessorDeclaration. * @param node - Node to check. */ static isGetAccessorDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.GetAccessor: return true; default: return false; } } /** * Gets if the node is a HeritageClause. * @param node - Node to check. */ static isHeritageClause(node) { switch (node.getKind()) { case ts.SyntaxKind.HeritageClause: return true; default: return false; } } /** * Gets if the node is a HeritageClauseableNode. * @param node - Node to check. */ static isHeritageClauseableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.InterfaceDeclaration: return true; default: return false; } } /** * Gets if the node is a Identifier. * @param node - Node to check. */ static isIdentifier(node) { switch (node.getKind()) { case ts.SyntaxKind.Identifier: return true; default: return false; } } /** * Gets if the node is a ImplementsClauseableNode. * @param node - Node to check. */ static isImplementsClauseableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: return true; default: return false; } } /** * Gets if the node is a ImportDeclaration. * @param node - Node to check. */ static isImportDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.ImportDeclaration: return true; default: return false; } } /** * Gets if the node is a ImportSpecifier. * @param node - Node to check. */ static isImportSpecifier(node) { switch (node.getKind()) { case ts.SyntaxKind.ImportSpecifier: return true; default: return false; } } /** * Gets if the node is a InitializerExpressionableNode. * @param node - Node to check. */ static isInitializerExpressionableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.EnumMember: case ts.SyntaxKind.Parameter: case ts.SyntaxKind.PropertySignature: case ts.SyntaxKind.VariableDeclaration: return true; default: return false; } } /** * Gets if the node is a InterfaceDeclaration. * @param node - Node to check. */ static isInterfaceDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.InterfaceDeclaration: return true; default: return false; } } /** * Gets if the node is a JSDoc. * @param node - Node to check. */ static isJSDoc(node) { switch (node.getKind()) { case ts.SyntaxKind.JSDocComment: return true; default: return false; } } /** * Gets if the node is a MethodDeclaration. * @param node - Node to check. */ static isMethodDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.MethodDeclaration: return true; default: return false; } } /** * Gets if the node is a MethodSignature. * @param node - Node to check. */ static isMethodSignature(node) { switch (node.getKind()) { case ts.SyntaxKind.MethodSignature: return true; default: return false; } } /** * Gets if the node is a ModifierableNode. * @param node - Node to check. */ static isModifierableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.EnumDeclaration: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.Parameter: case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.PropertySignature: case ts.SyntaxKind.ModuleDeclaration: case ts.SyntaxKind.TypeAliasDeclaration: case ts.SyntaxKind.VariableStatement: return true; default: return false; } } /** * Gets if the node is a NamedNode. * @param node - Node to check. */ static isNamedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.PropertyAccessExpression: case ts.SyntaxKind.EnumDeclaration: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.ModuleDeclaration: case ts.SyntaxKind.TypeAliasDeclaration: case ts.SyntaxKind.TypeParameter: return true; default: return false; } } /** * Gets if the node is a NamespaceChildableNode. * @param node - Node to check. */ static isNamespaceChildableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.EnumDeclaration: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.ModuleDeclaration: case ts.SyntaxKind.VariableStatement: return true; default: return false; } } /** * Gets if the node is a NamespaceDeclaration. * @param node - Node to check. */ static isNamespaceDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.ModuleDeclaration: return true; default: return false; } } /** * Gets if the node is a OverloadableNode. * @param node - Node to check. */ static isOverloadableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.FunctionDeclaration: return true; default: return false; } } /** * Gets if the node is a ParameterDeclaration. * @param node - Node to check. */ static isParameterDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.Parameter: return true; default: return false; } } /** * Gets if the node is a ParameteredNode. * @param node - Node to check. */ static isParameteredNode(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.ConstructSignature: case ts.SyntaxKind.MethodSignature: return true; default: return false; } } /** * Gets if the node is a PropertyAccessExpression. * @param node - Node to check. */ static isPropertyAccessExpression(node) { switch (node.getKind()) { case ts.SyntaxKind.PropertyAccessExpression: return true; default: return false; } } /** * Gets if the node is a PropertyDeclaration. * @param node - Node to check. */ static isPropertyDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.PropertyDeclaration: return true; default: return false; } } /** * Gets if the node is a PropertyNamedNode. * @param node - Node to check. */ static isPropertyNamedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.EnumMember: case ts.SyntaxKind.MethodSignature: case ts.SyntaxKind.PropertySignature: return true; default: return false; } } /** * Gets if the node is a PropertySignature. * @param node - Node to check. */ static isPropertySignature(node) { switch (node.getKind()) { case ts.SyntaxKind.PropertySignature: return true; default: return false; } } /** * Gets if the node is a QualifiedName. * @param node - Node to check. */ static isQualifiedName(node) { switch (node.getKind()) { case ts.SyntaxKind.QualifiedName: return true; default: return false; } } /** * Gets if the node is a QuestionTokenableNode. * @param node - Node to check. */ static isQuestionTokenableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.Parameter: case ts.SyntaxKind.MethodSignature: case ts.SyntaxKind.PropertySignature: return true; default: return false; } } /** * Gets if the node is a ReadonlyableNode. * @param node - Node to check. */ static isReadonlyableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.Parameter: case ts.SyntaxKind.PropertySignature: return true; default: return false; } } /** * Gets if the node is a ReturnTypedNode. * @param node - Node to check. */ static isReturnTypedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.ConstructSignature: case ts.SyntaxKind.MethodSignature: return true; default: return false; } } /** * Gets if the node is a ScopeableNode. * @param node - Node to check. */ static isScopeableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.Parameter: return true; default: return false; } } /** * Gets if the node is a ScopedNode. * @param node - Node to check. */ static isScopedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.SetAccessor: return true; default: return false; } } /** * Gets if the node is a SetAccessorDeclaration. * @param node - Node to check. */ static isSetAccessorDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.SetAccessor: return true; default: return false; } } /** * Gets if the node is a SignaturedDeclaration. * @param node - Node to check. */ static isSignaturedDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.ConstructSignature: case ts.SyntaxKind.MethodSignature: return true; default: return false; } } /** * Gets if the node is a SourceFile. * @param node - Node to check. */ static isSourceFile(node) { switch (node.getKind()) { case ts.SyntaxKind.SourceFile: return true; default: return false; } } /** * Gets if the node is a StatementedNode. * @param node - Node to check. */ static isStatementedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.SourceFile: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.ModuleDeclaration: return true; default: return false; } } /** * Gets if the node is a StaticableNode. * @param node - Node to check. */ static isStaticableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.SetAccessor: return true; default: return false; } } /** * Gets if the node is a TextInsertableNode. * @param node - Node to check. */ static isTextInsertableNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.EnumDeclaration: case ts.SyntaxKind.SourceFile: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.ModuleDeclaration: return true; default: return false; } } /** * Gets if the node is a TypeAliasDeclaration. * @param node - Node to check. */ static isTypeAliasDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.TypeAliasDeclaration: return true; default: return false; } } /** * Gets if the node is a TypeArgumentedNode. * @param node - Node to check. */ static isTypeArgumentedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.CallExpression: return true; default: return false; } } /** * Gets if the node is a TypeParameterDeclaration. * @param node - Node to check. */ static isTypeParameterDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.TypeParameter: return true; default: return false; } } /** * Gets if the node is a TypeParameteredNode. * @param node - Node to check. */ static isTypeParameteredNode(node) { switch (node.getKind()) { case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.Constructor: case ts.SyntaxKind.GetAccessor: case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.SetAccessor: case ts.SyntaxKind.FunctionDeclaration: case ts.SyntaxKind.ConstructSignature: case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.MethodSignature: case ts.SyntaxKind.TypeAliasDeclaration: return true; default: return false; } } /** * Gets if the node is a TypeReferenceNode. * @param node - Node to check. */ static isTypeReferenceNode(node) { switch (node.getKind()) { case ts.SyntaxKind.TypeReference: return true; default: return false; } } /** * Gets if the node is a TypedNode. * @param node - Node to check. */ static isTypedNode(node) { switch (node.getKind()) { case ts.SyntaxKind.PropertyDeclaration: case ts.SyntaxKind.Parameter: case ts.SyntaxKind.PropertySignature: case ts.SyntaxKind.TypeAliasDeclaration: case ts.SyntaxKind.VariableDeclaration: return true; default: return false; } } /** * Gets if the node is a VariableDeclaration. * @param node - Node to check. */ static isVariableDeclaration(node) { switch (node.getKind()) { case ts.SyntaxKind.VariableDeclaration: return true; default: return false; } } /** * Gets if the node is a VariableDeclarationList. * @param node - Node to check. */ static isVariableDeclarationList(node) { switch (node.getKind()) { case ts.SyntaxKind.VariableDeclarationList: return true; default: return false; } } /** * Gets if the node is a VariableStatement. * @param node - Node to check. */ static isVariableStatement(node) { switch (node.getKind()) { case ts.SyntaxKind.VariableStatement: return true; default: return false; } } } exports.TypeGuards = TypeGuards; //# sourceMappingURL=TypeGuards.js.map