UNPKG

4.32 kBJavaScriptView Raw
1/**
2 * Copyright 2013-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 *
9 */
10
11'use strict';
12
13var DOMProperty = require('./DOMProperty');
14var EventPluginRegistry = require('./EventPluginRegistry');
15var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
16
17var warning = require('fbjs/lib/warning');
18
19if (process.env.NODE_ENV !== 'production') {
20 var reactProps = {
21 children: true,
22 dangerouslySetInnerHTML: true,
23 key: true,
24 ref: true,
25
26 autoFocus: true,
27 defaultValue: true,
28 valueLink: true,
29 defaultChecked: true,
30 checkedLink: true,
31 innerHTML: true,
32 suppressContentEditableWarning: true,
33 onFocusIn: true,
34 onFocusOut: true
35 };
36 var warnedProperties = {};
37
38 var validateProperty = function (tagName, name, debugID) {
39 if (DOMProperty.properties.hasOwnProperty(name) || DOMProperty.isCustomAttribute(name)) {
40 return true;
41 }
42 if (reactProps.hasOwnProperty(name) && reactProps[name] || warnedProperties.hasOwnProperty(name) && warnedProperties[name]) {
43 return true;
44 }
45 if (EventPluginRegistry.registrationNameModules.hasOwnProperty(name)) {
46 return true;
47 }
48 warnedProperties[name] = true;
49 var lowerCasedName = name.toLowerCase();
50
51 // data-* attributes should be lowercase; suggest the lowercase version
52 var standardName = DOMProperty.isCustomAttribute(lowerCasedName) ? lowerCasedName : DOMProperty.getPossibleStandardName.hasOwnProperty(lowerCasedName) ? DOMProperty.getPossibleStandardName[lowerCasedName] : null;
53
54 var registrationName = EventPluginRegistry.possibleRegistrationNames.hasOwnProperty(lowerCasedName) ? EventPluginRegistry.possibleRegistrationNames[lowerCasedName] : null;
55
56 if (standardName != null) {
57 process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown DOM property %s. Did you mean %s?%s', name, standardName, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
58 return true;
59 } else if (registrationName != null) {
60 process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown event handler property %s. Did you mean `%s`?%s', name, registrationName, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
61 return true;
62 } else {
63 // We were unable to guess which prop the user intended.
64 // It is likely that the user was just blindly spreading/forwarding props
65 // Components should be careful to only render valid props/attributes.
66 // Warning will be invoked in warnUnknownProperties to allow grouping.
67 return false;
68 }
69 };
70}
71
72var warnUnknownProperties = function (debugID, element) {
73 var unknownProps = [];
74 for (var key in element.props) {
75 var isValid = validateProperty(element.type, key, debugID);
76 if (!isValid) {
77 unknownProps.push(key);
78 }
79 }
80
81 var unknownPropString = unknownProps.map(function (prop) {
82 return '`' + prop + '`';
83 }).join(', ');
84
85 if (unknownProps.length === 1) {
86 process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown prop %s on <%s> tag. Remove this prop from the element. ' + 'For details, see https://fb.me/react-unknown-prop%s', unknownPropString, element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
87 } else if (unknownProps.length > 1) {
88 process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown props %s on <%s> tag. Remove these props from the element. ' + 'For details, see https://fb.me/react-unknown-prop%s', unknownPropString, element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
89 }
90};
91
92function handleElement(debugID, element) {
93 if (element == null || typeof element.type !== 'string') {
94 return;
95 }
96 if (element.type.indexOf('-') >= 0 || element.props.is) {
97 return;
98 }
99 warnUnknownProperties(debugID, element);
100}
101
102var ReactDOMUnknownPropertyHook = {
103 onBeforeMountComponent: function (debugID, element) {
104 handleElement(debugID, element);
105 },
106 onBeforeUpdateComponent: function (debugID, element) {
107 handleElement(debugID, element);
108 }
109};
110
111module.exports = ReactDOMUnknownPropertyHook;
\No newline at end of file