@samitouri / QOS-React / commits / c17bf38035

Get a few more Fiber tests passing (#8149)

* Get a few more Fiber tests passing * Fix Flow and wrap in __DEV__

Dan Abramov committed Oct 30, 2016 at 00:43 UTC c17bf38035b48e7aa56f5c12ec2bf9b93a85883f
6 files changed +53 -8
src/isomorphic/classic/element/ReactElementValidator.js
+3 -2
@@ -25,12 +25,13 @@ var ReactElement = require('ReactElement');
25 var checkReactTypeSpec = require('checkReactTypeSpec');
26
27 var canDefineProperty = require('canDefineProperty');
28 +var getComponentName = require('getComponentName');
29 var getIteratorFn = require('getIteratorFn');
30 var warning = require('warning');
31
32 function getDeclarationErrorAddendum() {
33 if (ReactCurrentOwner.current) {
33 - var name = ReactCurrentOwner.current.getName();
34 + var name = getComponentName(ReactCurrentOwner.current);
35 if (name) {
36 return ' Check the render method of `' + name + '`.';
37 }
@@ -94,7 +95,7 @@ function validateExplicitKey(element, parentType) {
95 element._owner !== ReactCurrentOwner.current) {
96 // Give the component that originally created this child.
97 childOwner =
97 - ` It was passed a child from ${element._owner.getName()}.`;
98 + ` It was passed a child from ${getComponentName(element._owner)}.`;
99 }
100
101 warning(
src/isomorphic/hooks/ReactComponentTreeHook.js
+2 -1
@@ -14,6 +14,7 @@
14
15 var ReactCurrentOwner = require('ReactCurrentOwner');
16
17 +var getComponentName = require('getComponentName');
18 var invariant = require('invariant');
19 var warning = require('warning');
20
@@ -310,7 +311,7 @@ var ReactComponentTreeHook = {
311 info += describeComponentFrame(
312 name,
313 topElement._source,
313 - owner && owner.getName()
314 + owner && getComponentName(owner)
315 );
316 }
317
src/renderers/dom/shared/CSSPropertyOperations.js
+2 -1
@@ -17,6 +17,7 @@ var ReactInstrumentation = require('ReactInstrumentation');
17
18 var camelizeStyleName = require('camelizeStyleName');
19 var dangerousStyleValue = require('dangerousStyleValue');
20 +var getComponentName = require('getComponentName');
21 var hyphenateStyleName = require('hyphenateStyleName');
22 var memoizeStringOnly = require('memoizeStringOnly');
23 var warning = require('warning');
@@ -114,7 +115,7 @@ if (__DEV__) {
115
116 var checkRenderMessage = function(owner) {
117 if (owner) {
117 - var name = owner.getName();
118 + var name = getComponentName(owner);
119 if (name) {
120 return ' Check the render method of `' + name + '`.';
121 }
src/renderers/dom/shared/utils/LinkedValueUtils.js
+2 -1
@@ -13,6 +13,7 @@
13
14 var React = require('React');
15
16 +var getComponentName = require('getComponentName');
17 var invariant = require('invariant');
18 var warning = require('warning');
19
@@ -88,7 +89,7 @@ var propTypes = {
89 var loggedTypeFailures = {};
90 function getDeclarationErrorAddendum(owner) {
91 if (owner) {
91 - var name = owner.getName();
92 + var name = getComponentName(owner);
93 if (name) {
94 return ' Check the render method of `' + name + '`.';
95 }
src/renderers/dom/shared/validateDOMNesting.js
+4 -3
@@ -12,6 +12,7 @@
12 'use strict';
13
14 var emptyFunction = require('emptyFunction');
15 +var getComponentName = require('getComponentName');
16 var warning = require('warning');
17
18 var validateDOMNesting = emptyFunction;
@@ -371,16 +372,16 @@ if (__DEV__) {
372
373 var UNKNOWN = '(unknown)';
374 var childOwnerNames = childOwners.slice(deepestCommon + 1).map(
374 - (inst) => inst.getName() || UNKNOWN
375 + (inst) => getComponentName(inst) || UNKNOWN
376 );
377 var ancestorOwnerNames = ancestorOwners.slice(deepestCommon + 1).map(
377 - (inst) => inst.getName() || UNKNOWN
378 + (inst) => getComponentName(inst) || UNKNOWN
379 );
380 var ownerInfo = [].concat(
381 // If the parent and child instances have a common owner ancestor, start
382 // with that -- otherwise we just start with the parent's owners.
383 deepestCommon !== -1 ?
383 - childOwners[deepestCommon].getName() || UNKNOWN :
384 + getComponentName(childOwners[deepestCommon]) || UNKNOWN :
385 [],
386 ancestorOwnerNames,
387 ancestorTag,
src/shared/utils/getComponentName.js new
+40
@@ -0,0 +1,40 @@
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 + * @flow
10 + * @providesModule getComponentName
11 + */
12 +
13 +'use strict';
14 +
15 +import type { ReactInstance } from 'ReactInstanceType';
16 +import type { Fiber } from 'ReactFiber';
17 +
18 +function getComponentName(instanceOrFiber : ReactInstance | Fiber) : string | null {
19 + if (__DEV__) {
20 + if (typeof instanceOrFiber.getName === 'function') {
21 + // Stack reconciler
22 + const instance = ((instanceOrFiber : any) : ReactInstance);
23 + return instance.getName() || 'Component';
24 + }
25 + if (typeof instanceOrFiber.tag === 'number') {
26 + // Fiber reconciler
27 + const fiber = ((instanceOrFiber : any) : Fiber);
28 + const {type} = fiber;
29 + if (typeof type === 'string') {
30 + return type;
31 + }
32 + if (typeof type === 'function') {
33 + return type.displayName || type.name || null;
34 + }
35 + }
36 + }
37 + return null;
38 +}
39 +
40 +module.exports = getComponentName;