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