Skip to content

Commit 2291544

Browse files
committed
[fix] [email protected] propType warnings
1 parent 6416166 commit 2291544

File tree

4 files changed

+55
-53
lines changed

4 files changed

+55
-53
lines changed

docs/components/View.md

-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ from `style`.
168168
+ `right`
169169
+ `top`
170170
+ `transform`
171-
+ `transformMatrix`
172171
+ `userSelect`
173172
+ `visibility`
174173
+ `width`

src/apis/StyleSheet/StyleSheetValidation.js

+27-17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
/**
23
* Copyright (c) 2016-present, Nicolas Gallagher.
34
* Copyright (c) 2015-present, Facebook, Inc.
@@ -8,50 +9,59 @@
89

910
import { PropTypes } from 'react'
1011
import ImageStylePropTypes from '../../components/Image/ImageStylePropTypes'
12+
import ReactPropTypeLocations from 'react/lib/ReactPropTypeLocations'
13+
import ReactPropTypesSecret from 'react/lib/ReactPropTypesSecret'
1114
import TextStylePropTypes from '../../components/Text/TextStylePropTypes'
1215
import ViewStylePropTypes from '../../components/View/ViewStylePropTypes'
1316
import warning from 'fbjs/lib/warning'
1417

15-
const allStylePropTypes = {}
16-
1718
class StyleSheetValidation {
1819
static validateStyleProp(prop, style, caller) {
1920
if (process.env.NODE_ENV !== 'production') {
2021
if (allStylePropTypes[prop] === undefined) {
21-
const message1 = `"${prop}" is not a valid style property on Web.`
22-
const message2 = '\nValid style props: ' + JSON.stringify(Object.keys(allStylePropTypes).sort(), null, ' ')
23-
styleError(message1, style, caller, message2)
24-
} else {
25-
const error = allStylePropTypes[prop](style, prop, caller, 'prop')
26-
if (error) {
27-
styleError(error.message, style, caller)
28-
}
22+
var message1 = '"' + prop + '" is not a valid style property.';
23+
var message2 = '\nValid style props: ' +
24+
JSON.stringify(Object.keys(allStylePropTypes).sort(), null, ' ');
25+
styleError(message1, style, caller, message2);
26+
}
27+
var error = allStylePropTypes[prop](
28+
style,
29+
prop,
30+
caller,
31+
ReactPropTypeLocations.prop,
32+
null,
33+
ReactPropTypesSecret
34+
);
35+
if (error) {
36+
styleError(error.message, style, caller);
2937
}
3038
}
3139
}
3240

3341
static validateStyle(name, styles) {
3442
if (process.env.NODE_ENV !== 'production') {
35-
for (const prop in styles[name]) {
36-
StyleSheetValidation.validateStyleProp(prop, styles[name], 'StyleSheet ' + name)
43+
for (var prop in styles[name]) {
44+
StyleSheetValidation.validateStyleProp(prop, styles[name], 'StyleSheet ' + name);
3745
}
3846
}
3947
}
4048

4149
static addValidStylePropTypes(stylePropTypes) {
42-
for (const key in stylePropTypes) {
43-
allStylePropTypes[key] = stylePropTypes[key]
50+
for (var key in stylePropTypes) {
51+
allStylePropTypes[key] = stylePropTypes[key];
4452
}
4553
}
4654
}
4755

48-
const styleError = (message1, style, caller, message2) => {
56+
var styleError = function(message1, style, caller?, message2?) {
4957
warning(
5058
false,
5159
message1 + '\n' + (caller || '<<unknown>>') + ': ' +
5260
JSON.stringify(style, null, ' ') + (message2 || '')
53-
)
54-
}
61+
);
62+
};
63+
64+
var allStylePropTypes = {};
5565

5666
StyleSheetValidation.addValidStylePropTypes(ImageStylePropTypes)
5767
StyleSheetValidation.addValidStylePropTypes(TextStylePropTypes)

src/propTypes/TransformPropTypes.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,8 @@
88
import { PropTypes } from 'react'
99

1010
const { arrayOf, number, oneOfType, shape, string } = PropTypes
11-
const ArrayOfNumberPropType = arrayOf(number)
1211
const numberOrString = oneOfType([ number, string ])
1312

14-
const TransformMatrixPropType = function (
15-
props : Object,
16-
propName : string,
17-
componentName : string
18-
) : ?Error {
19-
if (props.transform && props.transformMatrix) {
20-
return new Error(
21-
'transformMatrix and transform styles cannot be used on the same ' +
22-
'component'
23-
)
24-
}
25-
return ArrayOfNumberPropType(props, propName, componentName)
26-
}
27-
2813
const TransformPropTypes = {
2914
transform: arrayOf(
3015
oneOfType([
@@ -43,8 +28,7 @@ const TransformPropTypes = {
4328
shape({ translateZ: numberOrString }),
4429
shape({ translate3d: string })
4530
])
46-
),
47-
transformMatrix: TransformMatrixPropType
31+
)
4832
}
4933

5034
module.exports = TransformPropTypes
+27-18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable */
2+
13
/**
24
* Copyright (c) 2015-present, Facebook, Inc.
35
* All rights reserved.
@@ -10,61 +12,68 @@
1012
*/
1113

1214
import invariant from 'fbjs/lib/invariant'
15+
import merge from '../modules/merge'
1316
import ReactPropTypeLocationNames from 'react/lib/ReactPropTypeLocationNames'
17+
import ReactPropTypesSecret from 'react/lib/ReactPropTypesSecret'
1418

15-
module.exports = function createStrictShapeTypeChecker(shapeTypes) {
19+
function createStrictShapeTypeChecker(
20+
shapeTypes: {[key: string]: ReactPropsCheckType}
21+
): ReactPropsChainableTypeChecker {
1622
function checkType(isRequired, props, propName, componentName, location?) {
1723
if (!props[propName]) {
1824
if (isRequired) {
1925
invariant(
2026
false,
2127
`Required object \`${propName}\` was not specified in ` +
2228
`\`${componentName}\`.`
23-
)
29+
);
2430
}
25-
return
31+
return;
2632
}
27-
const propValue = props[propName]
28-
const propType = typeof propValue
29-
const locationName = location && ReactPropTypeLocationNames[location] || '(unknown)'
33+
var propValue = props[propName];
34+
var propType = typeof propValue;
35+
var locationName =
36+
location && ReactPropTypeLocationNames[location] || '(unknown)';
3037
if (propType !== 'object') {
3138
invariant(
3239
false,
3340
`Invalid ${locationName} \`${propName}\` of type \`${propType}\` ` +
3441
`supplied to \`${componentName}\`, expected \`object\`.`
35-
)
42+
);
3643
}
3744
// We need to check all keys in case some are required but missing from
3845
// props.
39-
const allKeys = { ...props[propName], ...shapeTypes }
40-
for (const key in allKeys) {
41-
const checker = shapeTypes[key]
46+
var allKeys = merge(props[propName], shapeTypes);
47+
for (var key in allKeys) {
48+
var checker = shapeTypes[key];
4249
if (!checker) {
4350
invariant(
4451
false,
4552
`Invalid props.${propName} key \`${key}\` supplied to \`${componentName}\`.` +
4653
`\nBad object: ` + JSON.stringify(props[propName], null, ' ') +
4754
`\nValid keys: ` + JSON.stringify(Object.keys(shapeTypes), null, ' ')
48-
)
55+
);
4956
}
50-
const error = checker(propValue, key, componentName, location)
57+
var error = checker(propValue, key, componentName, location, null, ReactPropTypesSecret);
5158
if (error) {
5259
invariant(
5360
false,
54-
error.message + `\nBad object: ` + JSON.stringify(props[propName], null, ' ')
55-
)
61+
error.message +
62+
`\nBad object: ` + JSON.stringify(props[propName], null, ' ')
63+
);
5664
}
5765
}
5866
}
59-
6067
function chainedCheckType(
6168
props: {[key: string]: any},
6269
propName: string,
6370
componentName: string,
6471
location?: string
6572
): ?Error {
66-
return checkType(false, props, propName, componentName, location)
73+
return checkType(false, props, propName, componentName, location);
6774
}
68-
chainedCheckType.isRequired = checkType.bind(null, true)
69-
return chainedCheckType
75+
chainedCheckType.isRequired = checkType.bind(null, true);
76+
return chainedCheckType;
7077
}
78+
79+
module.exports = createStrictShapeTypeChecker;

0 commit comments

Comments
 (0)