2015-04-17 01:17:19 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @providesModule verifyPropTypes
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-05-08 16:45:43 +00:00
|
|
|
var ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
2015-04-17 01:17:19 +00:00
|
|
|
var View = require('View');
|
|
|
|
|
|
|
|
function verifyPropTypes(
|
|
|
|
component: Function,
|
|
|
|
viewConfig: Object,
|
|
|
|
nativePropsToIgnore?: Object
|
|
|
|
) {
|
|
|
|
if (!viewConfig) {
|
|
|
|
return; // This happens for UnimplementedView.
|
|
|
|
}
|
2015-05-18 18:53:23 +00:00
|
|
|
var componentName = component.name || component.displayName;
|
|
|
|
if (!component.propTypes) {
|
|
|
|
throw new Error(
|
|
|
|
'`' + componentName + '` has no propTypes defined`'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-27 02:25:11 +00:00
|
|
|
var nativeProps = viewConfig.NativeProps;
|
2015-04-22 04:07:17 +00:00
|
|
|
for (var prop in nativeProps) {
|
2015-04-17 01:17:19 +00:00
|
|
|
if (!component.propTypes[prop] &&
|
|
|
|
!View.propTypes[prop] &&
|
2015-05-08 16:45:43 +00:00
|
|
|
!ReactNativeStyleAttributes[prop] &&
|
2015-04-17 01:17:19 +00:00
|
|
|
(!nativePropsToIgnore || !nativePropsToIgnore[prop])) {
|
|
|
|
throw new Error(
|
2015-05-18 18:53:23 +00:00
|
|
|
'`' + componentName + '` has no propType for native prop `' +
|
2015-04-17 01:17:19 +00:00
|
|
|
viewConfig.uiViewClassName + '.' + prop + '` of native type `' +
|
2015-05-18 18:53:23 +00:00
|
|
|
nativeProps[prop] + '`'
|
2015-04-17 01:17:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = verifyPropTypes;
|