react-test-renderer 15.5.0 → 15.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/lib/ReactShallowRenderer.js +6 -0
  2. package/lib/shallow/ARIADOMPropertyConfig.js +73 -0
  3. package/lib/shallow/AutoFocusUtils.js +23 -0
  4. package/lib/shallow/BeforeInputEventPlugin.js +384 -0
  5. package/lib/shallow/CSSProperty.js +147 -0
  6. package/lib/shallow/CSSPropertyOperations.js +208 -0
  7. package/lib/shallow/CallbackQueue.js +118 -0
  8. package/lib/shallow/ChangeEventPlugin.js +345 -0
  9. package/lib/shallow/DOMChildrenOperations.js +224 -0
  10. package/lib/shallow/DOMLazyTree.js +117 -0
  11. package/lib/shallow/DOMNamespaces.js +19 -0
  12. package/lib/shallow/DOMProperty.js +209 -0
  13. package/lib/shallow/DOMPropertyOperations.js +236 -0
  14. package/lib/shallow/Danger.js +47 -0
  15. package/lib/shallow/DefaultEventPluginOrder.js +25 -0
  16. package/lib/shallow/EnterLeaveEventPlugin.js +99 -0
  17. package/lib/shallow/EventConstants.js +91 -0
  18. package/lib/shallow/EventPluginHub.js +277 -0
  19. package/lib/shallow/EventPluginRegistry.js +254 -0
  20. package/lib/shallow/EventPluginUtils.js +225 -0
  21. package/lib/shallow/EventPropagators.js +133 -0
  22. package/lib/shallow/FallbackCompositionState.js +94 -0
  23. package/lib/shallow/HTMLDOMPropertyConfig.js +235 -0
  24. package/lib/shallow/KeyEscapeUtils.js +58 -0
  25. package/lib/shallow/LinkedValueUtils.js +137 -0
  26. package/lib/shallow/PluginModuleType.js +12 -0
  27. package/lib/shallow/PooledClass.js +111 -0
  28. package/lib/shallow/ReactBrowserEventEmitter.js +327 -0
  29. package/lib/shallow/ReactChildFiber.js +243 -0
  30. package/lib/shallow/ReactChildReconciler.js +153 -0
  31. package/lib/shallow/ReactComponentBrowserEnvironment.js +29 -0
  32. package/lib/shallow/ReactComponentEnvironment.js +45 -0
  33. package/lib/shallow/ReactCompositeComponent.js +901 -0
  34. package/lib/shallow/ReactCoroutine.js +80 -0
  35. package/lib/shallow/ReactDOM.js +110 -0
  36. package/lib/shallow/ReactDOMComponent.js +1000 -0
  37. package/lib/shallow/ReactDOMComponentFlags.js +17 -0
  38. package/lib/shallow/ReactDOMComponentTree.js +194 -0
  39. package/lib/shallow/ReactDOMContainerInfo.js +32 -0
  40. package/lib/shallow/ReactDOMEmptyComponent.js +59 -0
  41. package/lib/shallow/ReactDOMFeatureFlags.js +18 -0
  42. package/lib/shallow/ReactDOMFiber.js +97 -0
  43. package/lib/shallow/ReactDOMIDOperations.js +33 -0
  44. package/lib/shallow/ReactDOMInput.js +284 -0
  45. package/lib/shallow/ReactDOMInvalidARIAHook.js +92 -0
  46. package/lib/shallow/ReactDOMNullInputValuePropHook.js +42 -0
  47. package/lib/shallow/ReactDOMOption.js +122 -0
  48. package/lib/shallow/ReactDOMSelect.js +199 -0
  49. package/lib/shallow/ReactDOMSelection.js +211 -0
  50. package/lib/shallow/ReactDOMServer.js +25 -0
  51. package/lib/shallow/ReactDOMTextComponent.js +163 -0
  52. package/lib/shallow/ReactDOMTextarea.js +159 -0
  53. package/lib/shallow/ReactDOMTreeTraversal.js +135 -0
  54. package/lib/shallow/ReactDOMUnknownPropertyHook.js +111 -0
  55. package/lib/shallow/ReactDebugTool.js +358 -0
  56. package/lib/shallow/ReactDefaultBatchingStrategy.js +67 -0
  57. package/lib/shallow/ReactDefaultInjection.js +85 -0
  58. package/lib/shallow/ReactElementSymbol.js +19 -0
  59. package/lib/shallow/ReactEmptyComponent.js +29 -0
  60. package/lib/shallow/ReactErrorUtils.js +75 -0
  61. package/lib/shallow/ReactEventEmitterMixin.js +32 -0
  62. package/lib/shallow/ReactEventListener.js +154 -0
  63. package/lib/shallow/ReactFeatureFlags.js +21 -0
  64. package/lib/shallow/ReactFiber.js +190 -0
  65. package/lib/shallow/ReactFiberBeginWork.js +380 -0
  66. package/lib/shallow/ReactFiberCommitWork.js +78 -0
  67. package/lib/shallow/ReactFiberCompleteWork.js +208 -0
  68. package/lib/shallow/ReactFiberReconciler.js +64 -0
  69. package/lib/shallow/ReactFiberRoot.js +29 -0
  70. package/lib/shallow/ReactFiberScheduler.js +331 -0
  71. package/lib/shallow/ReactFiberUpdateQueue.js +77 -0
  72. package/lib/shallow/ReactHostComponent.js +67 -0
  73. package/lib/shallow/ReactHostOperationHistoryHook.js +33 -0
  74. package/lib/shallow/ReactInjection.js +33 -0
  75. package/lib/shallow/ReactInputSelection.js +123 -0
  76. package/lib/shallow/ReactInstanceMap.js +47 -0
  77. package/lib/shallow/ReactInstanceType.js +12 -0
  78. package/lib/shallow/ReactInstrumentation.js +23 -0
  79. package/lib/shallow/ReactInvalidSetStateWarningHook.js +36 -0
  80. package/lib/shallow/ReactMarkupChecksum.js +49 -0
  81. package/lib/shallow/ReactMount.js +537 -0
  82. package/lib/shallow/ReactMultiChild.js +449 -0
  83. package/lib/shallow/ReactMultiChildUpdateTypes.js +18 -0
  84. package/lib/shallow/ReactNodeTypes.js +39 -0
  85. package/lib/shallow/ReactOwner.js +93 -0
  86. package/lib/shallow/ReactPerf.js +500 -0
  87. package/lib/shallow/ReactPriorityLevel.js +20 -0
  88. package/lib/shallow/ReactPropTypeLocationNames.js +24 -0
  89. package/lib/shallow/ReactPropTypeLocations.js +12 -0
  90. package/lib/shallow/ReactPropTypesSecret.js +16 -0
  91. package/lib/shallow/ReactReconcileTransaction.js +177 -0
  92. package/lib/shallow/ReactReconciler.js +167 -0
  93. package/lib/shallow/ReactRef.js +88 -0
  94. package/lib/shallow/ReactReifiedYield.js +30 -0
  95. package/lib/shallow/ReactServerBatchingStrategy.js +21 -0
  96. package/lib/shallow/ReactServerRendering.js +89 -0
  97. package/lib/shallow/ReactServerRenderingTransaction.js +89 -0
  98. package/lib/shallow/ReactServerUpdateQueue.js +138 -0
  99. package/lib/shallow/ReactShallowRenderer.js +150 -0
  100. package/lib/shallow/ReactSimpleEmptyComponent.js +36 -0
  101. package/lib/shallow/ReactSyntheticEventType.js +14 -0
  102. package/lib/shallow/ReactTestEmptyComponent.js +36 -0
  103. package/lib/shallow/ReactTestMount.js +131 -0
  104. package/lib/shallow/ReactTestReconcileTransaction.js +128 -0
  105. package/lib/shallow/ReactTestRenderer.js +139 -0
  106. package/lib/shallow/ReactTestTextComponent.js +40 -0
  107. package/lib/shallow/ReactTypeOfWork.js +23 -0
  108. package/lib/shallow/ReactTypes.js +12 -0
  109. package/lib/shallow/ReactUpdateQueue.js +235 -0
  110. package/lib/shallow/ReactUpdates.js +250 -0
  111. package/lib/shallow/ReactVersion.js +13 -0
  112. package/lib/shallow/ResponderEventPlugin.js +507 -0
  113. package/lib/shallow/ResponderSyntheticEvent.js +38 -0
  114. package/lib/shallow/ResponderTouchHistoryStore.js +183 -0
  115. package/lib/shallow/SVGDOMPropertyConfig.js +301 -0
  116. package/lib/shallow/SelectEventPlugin.js +190 -0
  117. package/lib/shallow/SimpleEventPlugin.js +227 -0
  118. package/lib/shallow/SyntheticAnimationEvent.js +38 -0
  119. package/lib/shallow/SyntheticClipboardEvent.js +37 -0
  120. package/lib/shallow/SyntheticCompositionEvent.js +35 -0
  121. package/lib/shallow/SyntheticDragEvent.js +35 -0
  122. package/lib/shallow/SyntheticEvent.js +267 -0
  123. package/lib/shallow/SyntheticFocusEvent.js +35 -0
  124. package/lib/shallow/SyntheticInputEvent.js +36 -0
  125. package/lib/shallow/SyntheticKeyboardEvent.js +83 -0
  126. package/lib/shallow/SyntheticMouseEvent.js +71 -0
  127. package/lib/shallow/SyntheticTouchEvent.js +44 -0
  128. package/lib/shallow/SyntheticTransitionEvent.js +38 -0
  129. package/lib/shallow/SyntheticUIEvent.js +58 -0
  130. package/lib/shallow/SyntheticWheelEvent.js +53 -0
  131. package/lib/shallow/TapEventPlugin.js +115 -0
  132. package/lib/shallow/TouchHistoryMath.js +98 -0
  133. package/lib/shallow/Transaction.js +224 -0
  134. package/lib/shallow/ViewportMetrics.js +26 -0
  135. package/lib/shallow/accumulate.js +45 -0
  136. package/lib/shallow/accumulateInto.js +57 -0
  137. package/lib/shallow/adler32.js +43 -0
  138. package/lib/shallow/canDefineProperty.js +25 -0
  139. package/lib/shallow/checkReactTypeSpec.js +86 -0
  140. package/lib/shallow/createMicrosoftUnsafeLocalFunction.js +31 -0
  141. package/lib/shallow/dangerousStyleValue.js +78 -0
  142. package/lib/shallow/deprecated.js +56 -0
  143. package/lib/shallow/escapeTextContentForBrowser.js +122 -0
  144. package/lib/shallow/findDOMNode.js +59 -0
  145. package/lib/shallow/flattenChildren.js +75 -0
  146. package/lib/shallow/forEachAccumulated.js +30 -0
  147. package/lib/shallow/getEventCharCode.js +49 -0
  148. package/lib/shallow/getEventKey.js +101 -0
  149. package/lib/shallow/getEventModifierState.js +42 -0
  150. package/lib/shallow/getEventTarget.js +34 -0
  151. package/lib/shallow/getHostComponentFromComposite.js +29 -0
  152. package/lib/shallow/getIteratorFn.js +40 -0
  153. package/lib/shallow/getNodeForCharacterOffset.js +73 -0
  154. package/lib/shallow/getTextContentAccessor.js +32 -0
  155. package/lib/shallow/getVendorPrefixedEventName.js +100 -0
  156. package/lib/shallow/instantiateReactComponent.js +128 -0
  157. package/lib/shallow/isEventSupported.js +59 -0
  158. package/lib/shallow/isTextInputElement.js +50 -0
  159. package/lib/shallow/quoteAttributeValueForBrowser.js +25 -0
  160. package/lib/shallow/reactProdInvariant.js +38 -0
  161. package/lib/shallow/renderSubtreeIntoContainer.js +15 -0
  162. package/lib/shallow/setInnerHTML.js +97 -0
  163. package/lib/shallow/setTextContent.js +51 -0
  164. package/lib/shallow/shouldUpdateReactComponent.js +41 -0
  165. package/lib/shallow/traverseAllChildren.js +175 -0
  166. package/lib/shallow/validateDOMNesting.js +376 -0
  167. package/package.json +1 -1
  168. package/shallow.js +1 -1
@@ -0,0 +1,159 @@
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
+
13
+ var _prodInvariant = require('./reactProdInvariant'),
14
+ _assign = require('object-assign');
15
+
16
+ var LinkedValueUtils = require('./LinkedValueUtils');
17
+ var ReactDOMComponentTree = require('./ReactDOMComponentTree');
18
+ var ReactUpdates = require('./ReactUpdates');
19
+
20
+ var invariant = require('fbjs/lib/invariant');
21
+ var warning = require('fbjs/lib/warning');
22
+
23
+ var didWarnValueLink = false;
24
+ var didWarnValDefaultVal = false;
25
+
26
+ function forceUpdateIfMounted() {
27
+ if (this._rootNodeID) {
28
+ // DOM component is still mounted; update
29
+ ReactDOMTextarea.updateWrapper(this);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Implements a <textarea> host component that allows setting `value`, and
35
+ * `defaultValue`. This differs from the traditional DOM API because value is
36
+ * usually set as PCDATA children.
37
+ *
38
+ * If `value` is not supplied (or null/undefined), user actions that affect the
39
+ * value will trigger updates to the element.
40
+ *
41
+ * If `value` is supplied (and not null/undefined), the rendered element will
42
+ * not trigger updates to the element. Instead, the `value` prop must change in
43
+ * order for the rendered element to be updated.
44
+ *
45
+ * The rendered element will be initialized with an empty value, the prop
46
+ * `defaultValue` if specified, or the children content (deprecated).
47
+ */
48
+ var ReactDOMTextarea = {
49
+ getHostProps: function (inst, props) {
50
+ !(props.dangerouslySetInnerHTML == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, '`dangerouslySetInnerHTML` does not make sense on <textarea>.') : _prodInvariant('91') : void 0;
51
+
52
+ // Always set children to the same thing. In IE9, the selection range will
53
+ // get reset if `textContent` is mutated. We could add a check in setTextContent
54
+ // to only set the value if/when the value differs from the node value (which would
55
+ // completely solve this IE9 bug), but Sebastian+Ben seemed to like this solution.
56
+ // The value can be a boolean or object so that's why it's forced to be a string.
57
+ var hostProps = _assign({}, props, {
58
+ value: undefined,
59
+ defaultValue: undefined,
60
+ children: '' + inst._wrapperState.initialValue,
61
+ onChange: inst._wrapperState.onChange
62
+ });
63
+
64
+ return hostProps;
65
+ },
66
+
67
+ mountWrapper: function (inst, props) {
68
+ if (process.env.NODE_ENV !== 'production') {
69
+ LinkedValueUtils.checkPropTypes('textarea', props, inst._currentElement._owner);
70
+ if (props.valueLink !== undefined && !didWarnValueLink) {
71
+ process.env.NODE_ENV !== 'production' ? warning(false, '`valueLink` prop on `textarea` is deprecated; set `value` and `onChange` instead.') : void 0;
72
+ didWarnValueLink = true;
73
+ }
74
+ if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValDefaultVal) {
75
+ process.env.NODE_ENV !== 'production' ? warning(false, 'Textarea elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled textarea ' + 'and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components') : void 0;
76
+ didWarnValDefaultVal = true;
77
+ }
78
+ }
79
+
80
+ var value = LinkedValueUtils.getValue(props);
81
+ var initialValue = value;
82
+
83
+ // Only bother fetching default value if we're going to use it
84
+ if (value == null) {
85
+ var defaultValue = props.defaultValue;
86
+ // TODO (yungsters): Remove support for children content in <textarea>.
87
+ var children = props.children;
88
+ if (children != null) {
89
+ if (process.env.NODE_ENV !== 'production') {
90
+ process.env.NODE_ENV !== 'production' ? warning(false, 'Use the `defaultValue` or `value` props instead of setting ' + 'children on <textarea>.') : void 0;
91
+ }
92
+ !(defaultValue == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'If you supply `defaultValue` on a <textarea>, do not pass children.') : _prodInvariant('92') : void 0;
93
+ if (Array.isArray(children)) {
94
+ !(children.length <= 1) ? process.env.NODE_ENV !== 'production' ? invariant(false, '<textarea> can only have at most one child.') : _prodInvariant('93') : void 0;
95
+ children = children[0];
96
+ }
97
+
98
+ defaultValue = '' + children;
99
+ }
100
+ if (defaultValue == null) {
101
+ defaultValue = '';
102
+ }
103
+ initialValue = defaultValue;
104
+ }
105
+
106
+ inst._wrapperState = {
107
+ initialValue: '' + initialValue,
108
+ listeners: null,
109
+ onChange: _handleChange.bind(inst)
110
+ };
111
+ },
112
+
113
+ updateWrapper: function (inst) {
114
+ var props = inst._currentElement.props;
115
+
116
+ var node = ReactDOMComponentTree.getNodeFromInstance(inst);
117
+ var value = LinkedValueUtils.getValue(props);
118
+ if (value != null) {
119
+ // Cast `value` to a string to ensure the value is set correctly. While
120
+ // browsers typically do this as necessary, jsdom doesn't.
121
+ var newValue = '' + value;
122
+
123
+ // To avoid side effects (such as losing text selection), only set value if changed
124
+ if (newValue !== node.value) {
125
+ node.value = newValue;
126
+ }
127
+ if (props.defaultValue == null) {
128
+ node.defaultValue = newValue;
129
+ }
130
+ }
131
+ if (props.defaultValue != null) {
132
+ node.defaultValue = props.defaultValue;
133
+ }
134
+ },
135
+
136
+ postMountWrapper: function (inst) {
137
+ // This is in postMount because we need access to the DOM node, which is not
138
+ // available until after the component has mounted.
139
+ var node = ReactDOMComponentTree.getNodeFromInstance(inst);
140
+ var textContent = node.textContent;
141
+
142
+ // Only set node.value if textContent is equal to the expected
143
+ // initial value. In IE10/IE11 there is a bug where the placeholder attribute
144
+ // will populate textContent as well.
145
+ // https://developer.microsoft.com/microsoft-edge/platform/issues/101525/
146
+ if (textContent === inst._wrapperState.initialValue) {
147
+ node.value = textContent;
148
+ }
149
+ }
150
+ };
151
+
152
+ function _handleChange(event) {
153
+ var props = this._currentElement.props;
154
+ var returnValue = LinkedValueUtils.executeOnChange(props, event);
155
+ ReactUpdates.asap(forceUpdateIfMounted, this);
156
+ return returnValue;
157
+ }
158
+
159
+ module.exports = ReactDOMTextarea;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Copyright 2015-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
+
13
+ var _prodInvariant = require('./reactProdInvariant');
14
+
15
+ var invariant = require('fbjs/lib/invariant');
16
+
17
+ /**
18
+ * Return the lowest common ancestor of A and B, or null if they are in
19
+ * different trees.
20
+ */
21
+ function getLowestCommonAncestor(instA, instB) {
22
+ !('_hostNode' in instA) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getNodeFromInstance: Invalid argument.') : _prodInvariant('33') : void 0;
23
+ !('_hostNode' in instB) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getNodeFromInstance: Invalid argument.') : _prodInvariant('33') : void 0;
24
+
25
+ var depthA = 0;
26
+ for (var tempA = instA; tempA; tempA = tempA._hostParent) {
27
+ depthA++;
28
+ }
29
+ var depthB = 0;
30
+ for (var tempB = instB; tempB; tempB = tempB._hostParent) {
31
+ depthB++;
32
+ }
33
+
34
+ // If A is deeper, crawl up.
35
+ while (depthA - depthB > 0) {
36
+ instA = instA._hostParent;
37
+ depthA--;
38
+ }
39
+
40
+ // If B is deeper, crawl up.
41
+ while (depthB - depthA > 0) {
42
+ instB = instB._hostParent;
43
+ depthB--;
44
+ }
45
+
46
+ // Walk in lockstep until we find a match.
47
+ var depth = depthA;
48
+ while (depth--) {
49
+ if (instA === instB) {
50
+ return instA;
51
+ }
52
+ instA = instA._hostParent;
53
+ instB = instB._hostParent;
54
+ }
55
+ return null;
56
+ }
57
+
58
+ /**
59
+ * Return if A is an ancestor of B.
60
+ */
61
+ function isAncestor(instA, instB) {
62
+ !('_hostNode' in instA) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'isAncestor: Invalid argument.') : _prodInvariant('35') : void 0;
63
+ !('_hostNode' in instB) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'isAncestor: Invalid argument.') : _prodInvariant('35') : void 0;
64
+
65
+ while (instB) {
66
+ if (instB === instA) {
67
+ return true;
68
+ }
69
+ instB = instB._hostParent;
70
+ }
71
+ return false;
72
+ }
73
+
74
+ /**
75
+ * Return the parent instance of the passed-in instance.
76
+ */
77
+ function getParentInstance(inst) {
78
+ !('_hostNode' in inst) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getParentInstance: Invalid argument.') : _prodInvariant('36') : void 0;
79
+
80
+ return inst._hostParent;
81
+ }
82
+
83
+ /**
84
+ * Simulates the traversal of a two-phase, capture/bubble event dispatch.
85
+ */
86
+ function traverseTwoPhase(inst, fn, arg) {
87
+ var path = [];
88
+ while (inst) {
89
+ path.push(inst);
90
+ inst = inst._hostParent;
91
+ }
92
+ var i;
93
+ for (i = path.length; i-- > 0;) {
94
+ fn(path[i], 'captured', arg);
95
+ }
96
+ for (i = 0; i < path.length; i++) {
97
+ fn(path[i], 'bubbled', arg);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Traverses the ID hierarchy and invokes the supplied `cb` on any IDs that
103
+ * should would receive a `mouseEnter` or `mouseLeave` event.
104
+ *
105
+ * Does not invoke the callback on the nearest common ancestor because nothing
106
+ * "entered" or "left" that element.
107
+ */
108
+ function traverseEnterLeave(from, to, fn, argFrom, argTo) {
109
+ var common = from && to ? getLowestCommonAncestor(from, to) : null;
110
+ var pathFrom = [];
111
+ while (from && from !== common) {
112
+ pathFrom.push(from);
113
+ from = from._hostParent;
114
+ }
115
+ var pathTo = [];
116
+ while (to && to !== common) {
117
+ pathTo.push(to);
118
+ to = to._hostParent;
119
+ }
120
+ var i;
121
+ for (i = 0; i < pathFrom.length; i++) {
122
+ fn(pathFrom[i], 'bubbled', argFrom);
123
+ }
124
+ for (i = pathTo.length; i-- > 0;) {
125
+ fn(pathTo[i], 'captured', argTo);
126
+ }
127
+ }
128
+
129
+ module.exports = {
130
+ isAncestor: isAncestor,
131
+ getLowestCommonAncestor: getLowestCommonAncestor,
132
+ getParentInstance: getParentInstance,
133
+ traverseTwoPhase: traverseTwoPhase,
134
+ traverseEnterLeave: traverseEnterLeave
135
+ };
@@ -0,0 +1,111 @@
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
+
13
+ var DOMProperty = require('./DOMProperty');
14
+ var EventPluginRegistry = require('./EventPluginRegistry');
15
+ var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
16
+
17
+ var warning = require('fbjs/lib/warning');
18
+
19
+ if (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
+
72
+ var 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
+
92
+ function 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
+
102
+ var ReactDOMUnknownPropertyHook = {
103
+ onBeforeMountComponent: function (debugID, element) {
104
+ handleElement(debugID, element);
105
+ },
106
+ onBeforeUpdateComponent: function (debugID, element) {
107
+ handleElement(debugID, element);
108
+ }
109
+ };
110
+
111
+ module.exports = ReactDOMUnknownPropertyHook;