Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/ast.js

    rd565449 r0c6b92a  
    9393
    9494  /* TODO: properly warn on React.forwardRefs having typo properties
    95   if (nodeType === 'CallExpression') {
     95  if (astUtil.isCallExpression(ASTNode)) {
    9696    const callee = ASTNode.callee;
    9797    const pragma = pragmaUtil.getFromContext(context);
     
    149149 */
    150150function 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  ) {
    152156    return node.key;
    153157  }
     
    161165 * Get properties name
    162166 * @param {Object} node - Property.
    163  * @returns {String} Property name.
     167 * @returns {string} Property name.
    164168 */
    165169function getPropertyName(node) {
     
    211215 * @param {Object} context The node to check
    212216 * @param {ASTNode} node The node to check
    213  * @return {Boolean} true if it's the first node in its line
     217 * @return {boolean} true if it's the first node in its line
    214218 */
    215219function isNodeFirstInLine(context, node) {
     
    223227 * Checks if the node is a function or arrow function expression.
    224228 * @param {ASTNode} node The node to check
    225  * @return {Boolean} true if it's a function-like expression
     229 * @return {boolean} true if it's a function-like expression
    226230 */
    227231function isFunctionLikeExpression(node) {
     
    232236 * Checks if the node is a function.
    233237 * @param {ASTNode} node The node to check
    234  * @return {Boolean} true if it's a function
     238 * @return {boolean} true if it's a function
    235239 */
    236240function isFunction(node) {
     
    241245 * Checks if node is a function declaration or expression or arrow function.
    242246 * @param {ASTNode} node The node to check
    243  * @return {Boolean} true if it's a function-like
     247 * @return {boolean} true if it's a function-like
    244248 */
    245249function isFunctionLike(node) {
     
    250254 * Checks if the node is a class.
    251255 * @param {ASTNode} node The node to check
    252  * @return {Boolean} true if it's a class
     256 * @return {boolean} true if it's a class
    253257 */
    254258function isClass(node) {
     
    330334 * Checks if a node is being assigned a value: props.bar = 'bar'
    331335 * @param {ASTNode} node The AST node being checked.
    332  * @returns {Boolean}
     336 * @returns {boolean}
    333337 */
    334338function isAssignmentLHS(node) {
     
    340344}
    341345
     346function 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 */
     355function isCallExpression(node) {
     356  return node && node.type === 'CallExpression';
     357}
     358
    342359/**
    343360 * Extracts the expression node that is wrapped inside a TS type assertion
     
    347364 */
    348365function unwrapTSAsExpression(node) {
    349   if (node && node.type === 'TSAsExpression') return node.expression;
    350   return node;
     366  return isTSAsExpression(node) ? node.expression : node;
    351367}
    352368
    353369function isTSTypeReference(node) {
    354370  if (!node) return false;
    355   const nodeType = node.type;
    356   return nodeType === 'TSTypeReference';
     371
     372  return node.type === 'TSTypeReference';
    357373}
    358374
    359375function isTSTypeAnnotation(node) {
    360   if (!node) return false;
    361   const nodeType = node.type;
    362   return nodeType === 'TSTypeAnnotation';
     376  if (!node) { return false; }
     377
     378  return node.type === 'TSTypeAnnotation';
    363379}
    364380
    365381function isTSTypeLiteral(node) {
    366   if (!node) return false;
    367   const nodeType = node.type;
    368   return nodeType === 'TSTypeLiteral';
     382  if (!node) { return false; }
     383
     384  return node.type === 'TSTypeLiteral';
    369385}
    370386
    371387function isTSIntersectionType(node) {
    372   if (!node) return false;
    373   const nodeType = node.type;
    374   return nodeType === 'TSIntersectionType';
     388  if (!node) { return false; }
     389
     390  return node.type === 'TSIntersectionType';
    375391}
    376392
    377393function isTSInterfaceHeritage(node) {
    378   if (!node) return false;
    379   const nodeType = node.type;
    380   return nodeType === 'TSInterfaceHeritage';
     394  if (!node) { return false; }
     395
     396  return node.type === 'TSInterfaceHeritage';
    381397}
    382398
    383399function 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
     408function 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
     418function isTSTypeAliasDeclaration(node) {
     419  if (!node) { return false; }
     420
    386421  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';
    411425}
    412426
    413427function isTSParenthesizedType(node) {
    414   if (!node) return false;
    415   const nodeType = node.type;
    416   return nodeType === 'TSTypeAliasDeclaration';
     428  if (!node) { return false; }
     429
     430  return node.type === 'TSTypeAliasDeclaration';
    417431}
    418432
    419433function isTSFunctionType(node) {
    420   if (!node) return false;
    421   const nodeType = node.type;
    422   return nodeType === 'TSFunctionType';
     434  if (!node) { return false; }
     435
     436  return node.type === 'TSFunctionType';
    423437}
    424438
    425439function isTSTypeQuery(node) {
    426   if (!node) return false;
    427   const nodeType = node.type;
    428   return nodeType === 'TSTypeQuery';
     440  if (!node) { return false; }
     441
     442  return node.type === 'TSTypeQuery';
    429443}
    430444
    431445function isTSTypeParameterInstantiation(node) {
    432   if (!node) return false;
    433   const nodeType = node.type;
    434   return nodeType === 'TSTypeParameterInstantiation';
     446  if (!node) { return false; }
     447
     448  return node.type === 'TSTypeParameterInstantiation';
    435449}
    436450
    437451module.exports = {
    438   traverse,
    439452  findReturnStatement,
     453  getComponentProperties,
    440454  getFirstNodeInLine,
     455  getKeyValue,
    441456  getPropertyName,
    442457  getPropertyNameNode,
    443   getComponentProperties,
    444   getKeyValue,
    445   isParenthesized,
     458  inConstructor,
    446459  isAssignmentLHS,
     460  isCallExpression,
    447461  isClass,
    448462  isFunction,
     463  isFunctionLike,
    449464  isFunctionLikeExpression,
    450   isFunctionLike,
    451   inConstructor,
    452465  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,
    453482  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,
    467483};
Note: See TracChangeset for help on using the changeset viewer.