Skip to content

Commit 799a8b9

Browse files
committed
Fix flow errors
1 parent 93abed0 commit 799a8b9

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/handlers/defaultPropsHandler.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ function getDefaultValuesFromProps(
9494
// Don't evaluate property if component is functional and the node is not an AssignmentPattern
9595
.filter(propertyPath => !isStatelessComponent || types.AssignmentPattern.check(propertyPath.get('value').node))
9696
.forEach(function(propertyPath) {
97-
var propDescriptor = documentation.getPropDescriptor(
97+
const propDescriptor = documentation.getPropDescriptor(
9898
getPropertyName(propertyPath)
9999
);
100-
var value = isStatelessComponent ? propertyPath.get('value', 'right') : propertyPath.get('value');
101-
var defaultValue = getDefaultValue(value, isStatelessComponent);
100+
const defaultValue = getDefaultValue(
101+
isStatelessComponent ?
102+
propertyPath.get('value', 'right') :
103+
propertyPath.get('value')
104+
);
102105
if (defaultValue) {
103106
propDescriptor.defaultValue = defaultValue;
104107
}

src/utils/resolveToValue.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,17 @@ export default function resolveToValue(path: NodePath): NodePath {
121121
} else if (types.MemberExpression.check(node)) {
122122
const resolved = resolveToValue(getMemberExpressionRoot(path));
123123
if (types.ObjectExpression.check(resolved.node)) {
124-
const memberParts = toArray(path).slice(1);
125-
const init = memberParts.reduce((propertyPath, propertyName) => {
124+
let propertyPath = resolved;
125+
for (const propertyName of toArray(path).slice(1)) {
126+
if (propertyPath && types.ObjectExpression.check(propertyPath.node)) {
127+
propertyPath = getPropertyValuePath(propertyPath, propertyName);
128+
}
129+
if (!propertyPath) {
130+
return path;
131+
}
126132
propertyPath = resolveToValue(propertyPath);
127-
return types.ObjectExpression.check(propertyPath.node) ?
128-
getPropertyValuePath(propertyPath, propertyName) :
129-
null;
130-
}, resolved);
131-
return init ? resolveToValue(init) : path;
133+
}
134+
return propertyPath;
132135
}
133136
} else if (
134137
types.ImportDefaultSpecifier.check(node) ||

0 commit comments

Comments
 (0)