|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | /**
|
|---|
| 2 | * @fileoverview Utility functions for type annotation detection.
|
|---|
| 3 | * @author Yannick Croissant
|
|---|
| 4 | * @author Vitor Balocco
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | 'use strict';
|
|---|
| 8 |
|
|---|
| 9 | const 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 | */
|
|---|
| 17 | function 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 |
|
|---|
| 32 | module.exports = {
|
|---|
| 33 | isAnnotatedFunctionPropsDeclaration,
|
|---|
| 34 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.