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');
|
|
|
|
|
2015-07-25 01:31:55 +00:00
|
|
|
export type ComponentInterface = ReactClass<any, any, any> | {
|
|
|
|
name?: string;
|
|
|
|
displayName?: string;
|
|
|
|
propTypes: Object;
|
|
|
|
};
|
|
|
|
|
2015-04-17 01:17:19 +00:00
|
|
|
function verifyPropTypes(
|
2015-07-25 01:31:55 +00:00
|
|
|
componentInterface: ComponentInterface,
|
2015-04-17 01:17:19 +00:00
|
|
|
viewConfig: Object,
|
2015-07-25 01:31:55 +00:00
|
|
|
nativePropsToIgnore?: ?Object
|
2015-04-17 01:17:19 +00:00
|
|
|
) {
|
|
|
|
if (!viewConfig) {
|
|
|
|
return; // This happens for UnimplementedView.
|
|
|
|
}
|
2015-07-25 01:31:55 +00:00
|
|
|
var componentName = componentInterface.name ||
|
|
|
|
componentInterface.displayName ||
|
|
|
|
'unknown';
|
|
|
|
if (!componentInterface.propTypes) {
|
2015-05-18 18:53:23 +00:00
|
|
|
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-07-25 01:31:55 +00:00
|
|
|
if (!componentInterface.propTypes[prop] &&
|
2015-04-17 01:17:19 +00:00
|
|
|
!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;
|