Skip to content

Commit 6c6ea4d

Browse files
committed
Fix some flow errors
There are still some errors left which I'm not sure are worth fixing :-/
1 parent 5d09e61 commit 6c6ea4d

12 files changed

+29
-25
lines changed

flow/react-docgen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ declare class Documentation {
3232

3333
type Handler = (documentation: Documentation, path: NodePath) => void;
3434
type Resolver =
35-
(node: ASTNode, recast: Recast) => (NodePath|Array<NodePath>|void);
35+
(node: ASTNode, recast: Recast) => (?NodePath|?Array<NodePath>);

flow/recast.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*
99
*/
1010

11+
/*eslint no-unused-vars: 0*/
12+
1113
/**
1214
* A minimal set of declarations to make flow work with the recast API.
1315
*/
@@ -16,17 +18,21 @@ type ASTNode = Object;
1618

1719
declare class Scope {
1820
lookup(name: string): ?Scope;
19-
getBindings(): Object<string, Array<NodePath>>;
21+
getBindings(): {[key: string]: NodePath};
22+
node: NodePath;
2023
}
2124

2225
declare class NodePath {
26+
value: (ASTNode|Array<ASTNode>);
2327
node: ASTNode;
2428
parent: NodePath;
29+
parentPath: NodePath;
2530
scope: Scope;
2631

27-
get(...x: (string|number)): NodePath;
28-
each(f: (p: NodePath) => void): void;
32+
get(...x: Array<string|number>): NodePath;
33+
each(f: (p: NodePath) => any): any;
2934
map<T>(f: (p: NodePath) => T): Array<T>;
35+
filter(f: (p: NodePath) => bool): Array<NodePath>;
3036
}
3137

3238
type Recast = {

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import parse from './parse';
1515
import * as resolver from './resolver';
1616
import * as utils from './utils';
1717

18-
const defaultResolver = resolver.findExportedComponentDefinition;
19-
const defaultHandlers = [
18+
var defaultResolver = resolver.findExportedComponentDefinition;
19+
var defaultHandlers = [
2020
handlers.propTypeHandler,
2121
handlers.propDocBlockHandler,
2222
handlers.defaultPropsHandler,

src/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Documentation from './Documentation';
1515
import babylon from './babylon';
1616
import recast from 'recast';
1717

18-
const ERROR_MISSING_DEFINITION = 'No suitable component definition found.';
18+
var ERROR_MISSING_DEFINITION = 'No suitable component definition found.';
1919

2020
function executeHandlers(handlers, componentDefinitions) {
2121
return componentDefinitions.map(componentDefinition => {

src/utils/docblock.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* Helper functions to work with docblock comments.
1414
*/
1515

16-
import recast from 'recast';
17-
18-
const DOCLET_PATTERN = /^@(\w+)(?:$|\s((?:[^](?!^@\w))*))/gmi;
16+
var DOCLET_PATTERN = /^@(\w+)(?:$|\s((?:[^](?!^@\w))*))/gmi;
1917

2018
function parseDocblock(str) {
2119
var lines = str.split('\n');

src/utils/getClassMemberValuePath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var {types: {namedTypes: types}} = recast;
1818
export default function getClassMemberValuePath(
1919
classDefinition: NodePath,
2020
memberName: string
21-
) {
21+
): ?NodePath {
2222
// Fortunately it seems like that all members of a class body, be it
2323
// ClassProperty or MethodDefinition, have the same structure: They have a
2424
// "key" and a "value"

src/utils/getMemberValuePath.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import recast from 'recast';
1616

1717
var {types: {namedTypes: types}} = recast;
1818

19-
const SYNONYMS = {
19+
var SYNONYMS = {
2020
getDefaultProps: 'defaultProps',
2121
defaultProps: 'getDefaultProps',
2222
};
2323

24-
const LOOKUP_METHOD = {
24+
var LOOKUP_METHOD = {
2525
[types.ObjectExpression.name]: getPropertyValuePath,
2626
[types.ClassDeclaration.name]: getClassMemberValuePath,
2727
[types.ClassExpression.name]: getClassMemberValuePath,

src/utils/getMembers.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var {types: {namedTypes: types}} = recast;
3838
* {path: NodePath<42>, arguments: null, computed: false}
3939
* ]
4040
*/
41-
export default function getMembers(path: NodePath): Array<MemberExpression> {
41+
export default function getMembers(path: NodePath): Array<MemberDescriptor> {
4242
var result = [];
4343
var argumentsPath = null;
4444
loop: while(true) { // eslint-disable-line no-constant-condition
@@ -62,5 +62,3 @@ export default function getMembers(path: NodePath): Array<MemberExpression> {
6262
}
6363
return result.reverse();
6464
}
65-
66-
module.exports = getMembers;

src/utils/getPropType.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ export default function getPropType(path: NodePath): PropTypeDescriptor {
128128
} else if (types.Identifier.check(node) && !member.computed) {
129129
name = node.name;
130130
}
131-
if (simplePropTypes.hasOwnProperty(name)) {
132-
descriptor = {name};
133-
return true;
134-
} else if (propTypes.hasOwnProperty(name) && member.argumentsPath) {
135-
descriptor = propTypes[name](member.argumentsPath.get(0));
136-
return true;
131+
if (name) {
132+
if (simplePropTypes.hasOwnProperty(name)) {
133+
descriptor = {name};
134+
return true;
135+
} else if (propTypes.hasOwnProperty(name) && member.argumentsPath) {
136+
descriptor = propTypes[name](member.argumentsPath.get(0));
137+
return true;
138+
}
137139
}
138140
});
139141
if (!descriptor) {

src/utils/isReactCreateClassCall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ export default function isReactCreateClassCall(path: NodePath): boolean {
3030
return false;
3131
}
3232
var module = resolveToModule(path.get('callee', 'object'));
33-
return module && isReactModuleName(module);
33+
return Boolean(module && isReactModuleName(module));
3434
}

0 commit comments

Comments
 (0)