source: imaps-frontend/node_modules/eslint-plugin-react/lib/util/annotations.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[d565449]1/**
2 * @fileoverview Utility functions for type annotation detection.
3 * @author Yannick Croissant
4 * @author Vitor Balocco
5 */
6
7'use strict';
8
9const getFirstTokens = require('./eslint').getFirstTokens;
10
11/**
12 * Checks if we are declaring a `props` argument with a flow type annotation.
13 * @param {ASTNode} node The AST node being checked.
14 * @param {Object} context
15 * @returns {Boolean} True if the node is a type annotated props declaration, false if not.
16 */
17function isAnnotatedFunctionPropsDeclaration(node, context) {
18 if (!node || !node.params || !node.params.length) {
19 return false;
20 }
21
22 const typeNode = node.params[0].type === 'AssignmentPattern' ? node.params[0].left : node.params[0];
23
24 const tokens = getFirstTokens(context, typeNode, 2);
25 const isAnnotated = typeNode.typeAnnotation;
26 const isDestructuredProps = typeNode.type === 'ObjectPattern';
27 const isProps = tokens[0].value === 'props' || (tokens[1] && tokens[1].value === 'props');
28
29 return (isAnnotated && (isDestructuredProps || isProps));
30}
31
32module.exports = {
33 isAnnotatedFunctionPropsDeclaration,
34};
Note: See TracBrowser for help on using the repository browser.