From fcfe516a2e08322b184ae82db37f38645f131337 Mon Sep 17 00:00:00 2001 From: Pete Hunt Date: Wed, 27 Nov 2013 11:57:34 -0800 Subject: [PATCH] Less verbose ReactPropTypeLocations logging Since we use keyMirror() and invariant() messages are only shown in __DEV__, we don't have to do manual constant->string translation. Also fixes a few undefined keys that just happened to work before. --- src/core/ReactPropTypeLocations.js | 2 +- src/core/ReactPropTypes.js | 32 +++++++++++++----------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/core/ReactPropTypeLocations.js b/src/core/ReactPropTypeLocations.js index d0868d9993..bb0bbbaa70 100644 --- a/src/core/ReactPropTypeLocations.js +++ b/src/core/ReactPropTypeLocations.js @@ -21,7 +21,7 @@ var keyMirror = require('keyMirror'); var ReactPropTypeLocations = keyMirror({ - props: null, + prop: null, context: null, childContext: null }); diff --git a/src/core/ReactPropTypes.js b/src/core/ReactPropTypes.js index ebe261687f..cf243edd86 100644 --- a/src/core/ReactPropTypes.js +++ b/src/core/ReactPropTypes.js @@ -18,11 +18,19 @@ "use strict"; -var ReactPropTypeLocations = require('ReactPropTypeLocations'); - var createObjectFrom = require('createObjectFrom'); var invariant = require('invariant'); +var ReactPropTypeLocationNames = {}; + +if (__DEV__) { + ReactPropTypeLocationNames = { + prop: 'prop', + context: 'context', + childContext: 'child context' + }; +} + /** * Collection of methods that allow declaration and validation of props that are * supplied to React components. Example usage: @@ -97,10 +105,7 @@ function createPrimitiveTypeChecker(expectedType) { invariant( propType === expectedType, 'Invalid %s `%s` of type `%s` supplied to `%s`, expected `%s`.', - (location === ReactPropTypeLocations.prop ? 'prop' : - (location === ReactPropTypeLocations.context ? 'context' : - (location === ReactPropTypeLocations.childContext ? 'child context' : - ''))), + ReactPropTypeLocationNames[location], propName, propType, componentName, @@ -116,10 +121,7 @@ function createEnumTypeChecker(expectedValues) { invariant( expectedEnum[propValue], 'Invalid %s `%s` supplied to `%s`, expected one of %s.', - (location === ReactPropTypeLocations.prop ? 'prop' : - (location === ReactPropTypeLocations.context ? 'context' : - (location === ReactPropTypeLocations.childContext ? 'child context' : - ''))), + ReactPropTypeLocationNames[location], propName, componentName, JSON.stringify(Object.keys(expectedEnum)) @@ -133,10 +135,7 @@ function createInstanceTypeChecker(expectedClass) { invariant( propValue instanceof expectedClass, 'Invalid %s `%s` supplied to `%s`, expected instance of `%s`.', - (location === ReactPropTypeLocations.prop ? 'prop' : - (location === ReactPropTypeLocations.context ? 'context' : - (location === ReactPropTypeLocations.childContext ? 'child context' : - ''))), + ReactPropTypeLocationNames[location], propName, componentName, expectedClass.name || ANONYMOUS @@ -156,10 +155,7 @@ function createChainableTypeChecker(validate) { invariant( !isRequired, 'Required %s `%s` was not specified in `%s`.', - (location === ReactPropTypeLocations.prop ? - 'prop' : (location === ReactPropTypeLocations.context ? - 'context' : (location === ReactPropTypeLocations.childContext ? - 'child context' : ''))), + ReactPropTypeLocationNames[location], propName, componentName || ANONYMOUS );