Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/eslint-plugin-react/lib/util/ast.js
rd565449 r0c6b92a 93 93 94 94 /* TODO: properly warn on React.forwardRefs having typo properties 95 if ( nodeType === 'CallExpression') {95 if (astUtil.isCallExpression(ASTNode)) { 96 96 const callee = ASTNode.callee; 97 97 const pragma = pragmaUtil.getFromContext(context); … … 149 149 */ 150 150 function getPropertyNameNode(node) { 151 if (node.key || ['MethodDefinition', 'Property'].indexOf(node.type) !== -1) { 151 if ( 152 node.key 153 || node.type === 'MethodDefinition' 154 || node.type === 'Property' 155 ) { 152 156 return node.key; 153 157 } … … 161 165 * Get properties name 162 166 * @param {Object} node - Property. 163 * @returns { String} Property name.167 * @returns {string} Property name. 164 168 */ 165 169 function getPropertyName(node) { … … 211 215 * @param {Object} context The node to check 212 216 * @param {ASTNode} node The node to check 213 * @return { Boolean} true if it's the first node in its line217 * @return {boolean} true if it's the first node in its line 214 218 */ 215 219 function isNodeFirstInLine(context, node) { … … 223 227 * Checks if the node is a function or arrow function expression. 224 228 * @param {ASTNode} node The node to check 225 * @return { Boolean} true if it's a function-like expression229 * @return {boolean} true if it's a function-like expression 226 230 */ 227 231 function isFunctionLikeExpression(node) { … … 232 236 * Checks if the node is a function. 233 237 * @param {ASTNode} node The node to check 234 * @return { Boolean} true if it's a function238 * @return {boolean} true if it's a function 235 239 */ 236 240 function isFunction(node) { … … 241 245 * Checks if node is a function declaration or expression or arrow function. 242 246 * @param {ASTNode} node The node to check 243 * @return { Boolean} true if it's a function-like247 * @return {boolean} true if it's a function-like 244 248 */ 245 249 function isFunctionLike(node) { … … 250 254 * Checks if the node is a class. 251 255 * @param {ASTNode} node The node to check 252 * @return { Boolean} true if it's a class256 * @return {boolean} true if it's a class 253 257 */ 254 258 function isClass(node) { … … 330 334 * Checks if a node is being assigned a value: props.bar = 'bar' 331 335 * @param {ASTNode} node The AST node being checked. 332 * @returns { Boolean}336 * @returns {boolean} 333 337 */ 334 338 function isAssignmentLHS(node) { … … 340 344 } 341 345 346 function isTSAsExpression(node) { 347 return node && node.type === 'TSAsExpression'; 348 } 349 350 /** 351 * Matcher used to check whether given node is a `CallExpression` 352 * @param {ASTNode} node The AST node 353 * @returns {boolean} True if node is a `CallExpression`, false if not 354 */ 355 function isCallExpression(node) { 356 return node && node.type === 'CallExpression'; 357 } 358 342 359 /** 343 360 * Extracts the expression node that is wrapped inside a TS type assertion … … 347 364 */ 348 365 function unwrapTSAsExpression(node) { 349 if (node && node.type === 'TSAsExpression') return node.expression; 350 return node; 366 return isTSAsExpression(node) ? node.expression : node; 351 367 } 352 368 353 369 function isTSTypeReference(node) { 354 370 if (!node) return false; 355 const nodeType = node.type; 356 return node Type === 'TSTypeReference';371 372 return node.type === 'TSTypeReference'; 357 373 } 358 374 359 375 function isTSTypeAnnotation(node) { 360 if (!node) return false;361 const nodeType = node.type; 362 return node Type === 'TSTypeAnnotation';376 if (!node) { return false; } 377 378 return node.type === 'TSTypeAnnotation'; 363 379 } 364 380 365 381 function isTSTypeLiteral(node) { 366 if (!node) return false;367 const nodeType = node.type; 368 return node Type === 'TSTypeLiteral';382 if (!node) { return false; } 383 384 return node.type === 'TSTypeLiteral'; 369 385 } 370 386 371 387 function isTSIntersectionType(node) { 372 if (!node) return false;373 const nodeType = node.type; 374 return node Type === 'TSIntersectionType';388 if (!node) { return false; } 389 390 return node.type === 'TSIntersectionType'; 375 391 } 376 392 377 393 function isTSInterfaceHeritage(node) { 378 if (!node) return false;379 const nodeType = node.type; 380 return node Type === 'TSInterfaceHeritage';394 if (!node) { return false; } 395 396 return node.type === 'TSInterfaceHeritage'; 381 397 } 382 398 383 399 function isTSInterfaceDeclaration(node) { 384 if (!node) return false; 385 let nodeType = node.type; 400 if (!node) { return false; } 401 402 return (node.type === 'ExportNamedDeclaration' && node.declaration 403 ? node.declaration.type 404 : node.type 405 ) === 'TSInterfaceDeclaration'; 406 } 407 408 function isTSTypeDeclaration(node) { 409 if (!node) { return false; } 410 411 const nodeToCheck = node.type === 'ExportNamedDeclaration' && node.declaration 412 ? node.declaration 413 : node; 414 415 return nodeToCheck.type === 'VariableDeclaration' && nodeToCheck.kind === 'type'; 416 } 417 418 function isTSTypeAliasDeclaration(node) { 419 if (!node) { return false; } 420 386 421 if (node.type === 'ExportNamedDeclaration' && node.declaration) { 387 nodeType = node.declaration.type; 388 } 389 return nodeType === 'TSInterfaceDeclaration'; 390 } 391 392 function isTSTypeDeclaration(node) { 393 if (!node) return false; 394 let nodeType = node.type; 395 let nodeKind = node.kind; 396 if (node.type === 'ExportNamedDeclaration' && node.declaration) { 397 nodeType = node.declaration.type; 398 nodeKind = node.declaration.kind; 399 } 400 return nodeType === 'VariableDeclaration' && nodeKind === 'type'; 401 } 402 403 function isTSTypeAliasDeclaration(node) { 404 if (!node) return false; 405 let nodeType = node.type; 406 if (node.type === 'ExportNamedDeclaration' && node.declaration) { 407 nodeType = node.declaration.type; 408 return nodeType === 'TSTypeAliasDeclaration' && node.exportKind === 'type'; 409 } 410 return nodeType === 'TSTypeAliasDeclaration'; 422 return node.declaration.type === 'TSTypeAliasDeclaration' && node.exportKind === 'type'; 423 } 424 return node.type === 'TSTypeAliasDeclaration'; 411 425 } 412 426 413 427 function isTSParenthesizedType(node) { 414 if (!node) return false;415 const nodeType = node.type; 416 return node Type === 'TSTypeAliasDeclaration';428 if (!node) { return false; } 429 430 return node.type === 'TSTypeAliasDeclaration'; 417 431 } 418 432 419 433 function isTSFunctionType(node) { 420 if (!node) return false;421 const nodeType = node.type; 422 return node Type === 'TSFunctionType';434 if (!node) { return false; } 435 436 return node.type === 'TSFunctionType'; 423 437 } 424 438 425 439 function isTSTypeQuery(node) { 426 if (!node) return false;427 const nodeType = node.type; 428 return node Type === 'TSTypeQuery';440 if (!node) { return false; } 441 442 return node.type === 'TSTypeQuery'; 429 443 } 430 444 431 445 function isTSTypeParameterInstantiation(node) { 432 if (!node) return false;433 const nodeType = node.type; 434 return node Type === 'TSTypeParameterInstantiation';446 if (!node) { return false; } 447 448 return node.type === 'TSTypeParameterInstantiation'; 435 449 } 436 450 437 451 module.exports = { 438 traverse,439 452 findReturnStatement, 453 getComponentProperties, 440 454 getFirstNodeInLine, 455 getKeyValue, 441 456 getPropertyName, 442 457 getPropertyNameNode, 443 getComponentProperties, 444 getKeyValue, 445 isParenthesized, 458 inConstructor, 446 459 isAssignmentLHS, 460 isCallExpression, 447 461 isClass, 448 462 isFunction, 463 isFunctionLike, 449 464 isFunctionLikeExpression, 450 isFunctionLike,451 inConstructor,452 465 isNodeFirstInLine, 466 isParenthesized, 467 isTSAsExpression, 468 isTSFunctionType, 469 isTSInterfaceDeclaration, 470 isTSInterfaceHeritage, 471 isTSIntersectionType, 472 isTSParenthesizedType, 473 isTSTypeAliasDeclaration, 474 isTSTypeAnnotation, 475 isTSTypeDeclaration, 476 isTSTypeLiteral, 477 isTSTypeParameterInstantiation, 478 isTSTypeQuery, 479 isTSTypeReference, 480 traverse, 481 traverseReturns, 453 482 unwrapTSAsExpression, 454 traverseReturns,455 isTSTypeReference,456 isTSTypeAnnotation,457 isTSTypeLiteral,458 isTSIntersectionType,459 isTSInterfaceHeritage,460 isTSInterfaceDeclaration,461 isTSTypeAliasDeclaration,462 isTSParenthesizedType,463 isTSFunctionType,464 isTSTypeQuery,465 isTSTypeParameterInstantiation,466 isTSTypeDeclaration,467 483 };
Note:
See TracChangeset
for help on using the changeset viewer.