| [9af201e] | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|---|
| 2 | // See LICENSE in the project root for license information.
|
|---|
| 3 | export function isArrayExpression(node) {
|
|---|
| 4 | return node.type === 'ArrayExpression';
|
|---|
| 5 | }
|
|---|
| 6 | export function isArrowFunctionExpression(node) {
|
|---|
| 7 | return node.type === 'ArrowFunctionExpression';
|
|---|
| 8 | }
|
|---|
| 9 | /** default parameters */
|
|---|
| 10 | export function isAssignmentPattern(node) {
|
|---|
| 11 | return node.type === 'AssignmentPattern';
|
|---|
| 12 | }
|
|---|
| 13 | export function isClassDeclaration(node) {
|
|---|
| 14 | return node.type === 'ClassDeclaration';
|
|---|
| 15 | }
|
|---|
| 16 | export function isClassExpression(node) {
|
|---|
| 17 | return node.type === 'ClassExpression';
|
|---|
| 18 | }
|
|---|
| 19 | export function isExportDefaultDeclaration(node) {
|
|---|
| 20 | return node.type === 'ExportDefaultDeclaration';
|
|---|
| 21 | }
|
|---|
| 22 | export function isExpression(node) {
|
|---|
| 23 | return node.type.includes('Expression');
|
|---|
| 24 | }
|
|---|
| 25 | export function isFunctionDeclaration(node) {
|
|---|
| 26 | return node.type === 'FunctionDeclaration';
|
|---|
| 27 | }
|
|---|
| 28 | export function isFunctionExpression(node) {
|
|---|
| 29 | return node.type === 'FunctionExpression';
|
|---|
| 30 | }
|
|---|
| 31 | export function isIdentifier(node) {
|
|---|
| 32 | return node.type === 'Identifier';
|
|---|
| 33 | }
|
|---|
| 34 | export function isLiteral(node) {
|
|---|
| 35 | return node.type === 'Literal';
|
|---|
| 36 | }
|
|---|
| 37 | export function isMethodDefinition(node) {
|
|---|
| 38 | return node.type === 'MethodDefinition';
|
|---|
| 39 | }
|
|---|
| 40 | export function isObjectExpression(node) {
|
|---|
| 41 | return node.type === 'ObjectExpression';
|
|---|
| 42 | }
|
|---|
| 43 | export function isPrivateIdentifier(node) {
|
|---|
| 44 | return node.type === 'PrivateIdentifier';
|
|---|
| 45 | }
|
|---|
| 46 | export function isProperty(node) {
|
|---|
| 47 | return node.type === 'Property';
|
|---|
| 48 | }
|
|---|
| 49 | export function isPropertyDefinition(node) {
|
|---|
| 50 | return node.type === 'PropertyDefinition';
|
|---|
| 51 | }
|
|---|
| 52 | export function isTSEnumDeclaration(node) {
|
|---|
| 53 | return node.type === 'TSEnumDeclaration';
|
|---|
| 54 | }
|
|---|
| 55 | export function isTSInterfaceDeclaration(node) {
|
|---|
| 56 | return node.type === 'TSInterfaceDeclaration';
|
|---|
| 57 | }
|
|---|
| 58 | export function isTSModuleDeclaration(node) {
|
|---|
| 59 | return node.type === 'TSModuleDeclaration';
|
|---|
| 60 | }
|
|---|
| 61 | export function isTSQualifiedName(node) {
|
|---|
| 62 | return node.type === 'TSQualifiedName';
|
|---|
| 63 | }
|
|---|
| 64 | export function isTSTypeAliasDeclaration(node) {
|
|---|
| 65 | return node.type === 'TSTypeAliasDeclaration';
|
|---|
| 66 | }
|
|---|
| 67 | export function isVariableDeclarator(node) {
|
|---|
| 68 | return node.type === 'VariableDeclarator';
|
|---|
| 69 | }
|
|---|
| 70 | // Compound Type Guards for @typescript-eslint/types ast-spec compound types
|
|---|
| 71 | export function isClassDeclarationWithName(node) {
|
|---|
| 72 | return isClassDeclaration(node) && node.id !== null;
|
|---|
| 73 | }
|
|---|
| 74 | export function isClassPropertyNameNonComputed(node) {
|
|---|
| 75 | return isPrivateIdentifier(node) || isPropertyNameNonComputed(node);
|
|---|
| 76 | }
|
|---|
| 77 | export function isFunctionDeclarationWithName(node) {
|
|---|
| 78 | return isFunctionDeclaration(node) && node.id !== null;
|
|---|
| 79 | }
|
|---|
| 80 | export function isNumberLiteral(node) {
|
|---|
| 81 | return isLiteral(node) && typeof node.value === 'number';
|
|---|
| 82 | }
|
|---|
| 83 | export function isPropertyNameNonComputed(node) {
|
|---|
| 84 | return isIdentifier(node) || isNumberLiteral(node) || isStringLiteral(node);
|
|---|
| 85 | }
|
|---|
| 86 | export function isStringLiteral(node) {
|
|---|
| 87 | return isLiteral(node) && typeof node.value === 'string';
|
|---|
| 88 | }
|
|---|
| 89 | export function isClassExpressionWithName(node) {
|
|---|
| 90 | return isClassExpression(node) && node.id !== null;
|
|---|
| 91 | }
|
|---|
| 92 | export function isFunctionExpressionWithName(node) {
|
|---|
| 93 | return isFunctionExpression(node) && node.id !== null;
|
|---|
| 94 | }
|
|---|
| 95 | export function isNormalAnonymousExpression(node) {
|
|---|
| 96 | const ANONYMOUS_EXPRESSION_GUARDS = [
|
|---|
| 97 | isArrowFunctionExpression,
|
|---|
| 98 | isClassExpression,
|
|---|
| 99 | isFunctionExpression,
|
|---|
| 100 | isObjectExpression
|
|---|
| 101 | ];
|
|---|
| 102 | return ANONYMOUS_EXPRESSION_GUARDS.some((guard) => guard(node));
|
|---|
| 103 | }
|
|---|
| 104 | export function isNormalAssignmentPattern(node) {
|
|---|
| 105 | return isAssignmentPattern(node) && isIdentifier(node.left);
|
|---|
| 106 | }
|
|---|
| 107 | export function isNormalClassPropertyDefinition(node) {
|
|---|
| 108 | return (isPropertyDefinition(node) &&
|
|---|
| 109 | (isIdentifier(node.key) || isPrivateIdentifier(node.key)) &&
|
|---|
| 110 | node.value !== null);
|
|---|
| 111 | }
|
|---|
| 112 | export function isNormalMethodDefinition(node) {
|
|---|
| 113 | return isMethodDefinition(node) && (isIdentifier(node.key) || isPrivateIdentifier(node.key));
|
|---|
| 114 | }
|
|---|
| 115 | export function isNormalObjectProperty(node) {
|
|---|
| 116 | return isProperty(node) && (isIdentifier(node.key) || isPrivateIdentifier(node.key));
|
|---|
| 117 | }
|
|---|
| 118 | export function isNormalVariableDeclarator(node) {
|
|---|
| 119 | return isVariableDeclarator(node) && isIdentifier(node.id) && node.init !== null;
|
|---|
| 120 | }
|
|---|
| 121 | export function isNormalAssignmentPatternWithAnonymousExpressionAssigned(node) {
|
|---|
| 122 | return isNormalAssignmentPattern(node) && isNormalAnonymousExpression(node.right);
|
|---|
| 123 | }
|
|---|
| 124 | export function isNormalVariableDeclaratorWithAnonymousExpressionAssigned(node) {
|
|---|
| 125 | return isNormalVariableDeclarator(node) && isNormalAnonymousExpression(node.init);
|
|---|
| 126 | }
|
|---|
| 127 | export function isNormalObjectPropertyWithAnonymousExpressionAssigned(node) {
|
|---|
| 128 | return isNormalObjectProperty(node) && isNormalAnonymousExpression(node.value);
|
|---|
| 129 | }
|
|---|
| 130 | export function isNormalClassPropertyDefinitionWithAnonymousExpressionAssigned(node) {
|
|---|
| 131 | return isNormalClassPropertyDefinition(node) && isNormalAnonymousExpression(node.value);
|
|---|
| 132 | }
|
|---|
| 133 | export function isNodeWithName(node) {
|
|---|
| 134 | return (isClassDeclarationWithName(node) ||
|
|---|
| 135 | isFunctionDeclarationWithName(node) ||
|
|---|
| 136 | isClassExpressionWithName(node) ||
|
|---|
| 137 | isFunctionExpressionWithName(node) ||
|
|---|
| 138 | isNormalVariableDeclaratorWithAnonymousExpressionAssigned(node) ||
|
|---|
| 139 | isNormalObjectPropertyWithAnonymousExpressionAssigned(node) ||
|
|---|
| 140 | isNormalClassPropertyDefinitionWithAnonymousExpressionAssigned(node) ||
|
|---|
| 141 | isNormalAssignmentPatternWithAnonymousExpressionAssigned(node) ||
|
|---|
| 142 | isNormalMethodDefinition(node) ||
|
|---|
| 143 | isTSEnumDeclaration(node) ||
|
|---|
| 144 | isTSInterfaceDeclaration(node) ||
|
|---|
| 145 | isTSTypeAliasDeclaration(node));
|
|---|
| 146 | }
|
|---|
| 147 | //# sourceMappingURL=ast-guards.js.map |
|---|