fix exception when ES6 class with no propTypes defined before calling requireNativeComponent

Summary:
Closes https://github.com/facebook/react-native/pull/1260
Github Author: Luke <kejinlu@gmail.com>

Test Plan: Created `class Foo extends React.Component` and made sure error messages were good.
This commit is contained in:
Luke 2015-05-18 11:53:23 -07:00
parent 03905e69f4
commit de27f1db54

View File

@ -22,6 +22,13 @@ function verifyPropTypes(
if (!viewConfig) {
return; // This happens for UnimplementedView.
}
var componentName = component.name || component.displayName;
if (!component.propTypes) {
throw new Error(
'`' + componentName + '` has no propTypes defined`'
);
}
var nativeProps = viewConfig.nativeProps;
for (var prop in nativeProps) {
if (!component.propTypes[prop] &&
@ -29,9 +36,9 @@ function verifyPropTypes(
!ReactNativeStyleAttributes[prop] &&
(!nativePropsToIgnore || !nativePropsToIgnore[prop])) {
throw new Error(
'`' + component.displayName + '` has no propType for native prop `' +
'`' + componentName + '` has no propType for native prop `' +
viewConfig.uiViewClassName + '.' + prop + '` of native type `' +
nativeProps[prop].type + '`'
nativeProps[prop] + '`'
);
}
}