Remove indirection in checking propTypes (#9358)

* Remove indirection in checking propTypes

* Silence flow errors
This commit is contained in:
Dan Abramov
2017-04-07 15:23:28 +01:00
committed by GitHub
parent 2fe477131b
commit fcbb2ae930
5 changed files with 33 additions and 37 deletions
@@ -21,13 +21,12 @@
var ReactCurrentOwner = require('ReactCurrentOwner');
var ReactElement = require('ReactElement');
var checkReactTypeSpec = require('checkReactTypeSpec');
var canDefineProperty = require('canDefineProperty');
var getComponentName = require('getComponentName');
var getIteratorFn = require('getIteratorFn');
if (__DEV__) {
var checkPropTypes = require('checkPropTypes');
var warning = require('fbjs/lib/warning');
var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame');
var {
@@ -193,7 +192,13 @@ function validatePropTypes(element) {
: componentClass.propTypes;
if (propTypes) {
checkReactTypeSpec(propTypes, element.props, 'prop', name);
checkPropTypes(
propTypes,
element.props,
'prop',
name,
ReactDebugCurrentFrame.getStackAddendum,
);
}
if (typeof componentClass.getDefaultProps === 'function') {
warning(
@@ -13,7 +13,6 @@
var PropTypes;
var checkPropTypes;
var checkReactTypeSpec;
var React;
var ReactDOM;
@@ -22,7 +21,6 @@ var MyComponent;
function resetWarningCache() {
jest.resetModules();
checkReactTypeSpec = require('checkReactTypeSpec');
checkPropTypes = require('checkPropTypes');
}
@@ -33,7 +31,7 @@ function getPropTypeWarningMessage(propTypes, object, componentName) {
console.error.calls.reset();
}
resetWarningCache();
checkReactTypeSpec(propTypes, object, 'prop', 'testComponent');
checkPropTypes(propTypes, object, 'prop', 'testComponent');
const callCount = console.error.calls.count();
if (callCount > 1) {
throw new Error('Too many warnings.');
@@ -15,6 +15,7 @@
import type {Fiber} from 'ReactFiber';
import type {StackCursor} from 'ReactFiberStack';
var React = require('react');
var emptyObject = require('fbjs/lib/emptyObject');
var getComponentName = require('getComponentName');
var invariant = require('fbjs/lib/invariant');
@@ -33,7 +34,6 @@ const {
} = require('ReactFiberStack');
if (__DEV__) {
var checkReactTypeSpec = require('checkReactTypeSpec');
var ReactDebugCurrentFrame = require('react/lib/ReactDebugCurrentFrame');
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
var {
@@ -105,7 +105,14 @@ exports.getMaskedContext = function(
if (__DEV__) {
const name = getComponentName(workInProgress) || 'Unknown';
ReactDebugCurrentFrame.current = workInProgress;
checkReactTypeSpec(contextTypes, context, 'context', name);
// $FlowFixMe - We know this export exists now, need to wait for Flow update
React.checkPropTypes(
contextTypes,
context,
'context',
name,
ReactDebugCurrentFrame.getStackAddendum,
);
ReactDebugCurrentFrame.current = null;
}
@@ -212,7 +219,14 @@ function processChildContext(
// TODO: remove this hack when we delete unstable_renderSubtree in Fiber.
const workInProgress = isReconciling ? fiber : null;
ReactDebugCurrentFrame.current = workInProgress;
checkReactTypeSpec(childContextTypes, childContext, 'child context', name);
// $FlowFixMe - We know this export exists now, need to wait for Flow update
React.checkPropTypes(
childContextTypes,
childContext,
'child context',
name,
ReactDebugCurrentFrame.getStackAddendum,
);
ReactDebugCurrentFrame.current = null;
}
@@ -23,7 +23,6 @@ var ReactNodeTypes = require('ReactNodeTypes');
var ReactReconciler = require('ReactReconciler');
if (__DEV__) {
var checkReactTypeSpec = require('checkReactTypeSpec');
var ReactDebugCurrentFrame = require('react/lib/ReactDebugCurrentFrame');
var warningAboutMissingGetChildContext = {};
}
@@ -730,7 +729,13 @@ var ReactCompositeComponent = {
_checkContextTypes: function(typeSpecs, values, location: string) {
if (__DEV__) {
ReactDebugCurrentFrame.current = this._debugID;
checkReactTypeSpec(typeSpecs, values, location, this.getName());
React.checkPropTypes(
typeSpecs,
values,
location,
this.getName(),
ReactDebugCurrentFrame.getStackAddendum,
);
ReactDebugCurrentFrame.current = null;
}
},
-26
View File
@@ -1,26 +0,0 @@
/**
* Copyright 2013-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 checkReactTypeSpec
*/
'use strict';
var checkPropTypes = require('react/lib/checkPropTypes');
var {getStackAddendum} = require('react/lib/ReactDebugCurrentFrame');
function checkReactTypeSpec(
typeSpecs,
values,
location: string,
componentName,
) {
checkPropTypes(typeSpecs, values, location, componentName, getStackAddendum);
}
module.exports = checkReactTypeSpec;