Adjust code to handle more availability of function.name (#7670)
Paul O’Shannessy committed
Sep 20, 2016 at 14:23 UTC
00ac1797d75cea4b42d46c0161ee77acec5125f3
1 file changed
+11
-2
src/isomorphic/classic/class/ReactClass.js
+11
-2
@@ -24,6 +24,12 @@ import type { ReactPropTypeLocations } from 'ReactPropTypeLocations';
24
25
var MIXINS_KEY = 'mixins';
26
27
+// Helper function to allow the creation of anonymous functions which do not
28
+// have .name set to the name of the variable being assigned to.
29
+function identity(fn) {
30
+ return fn;
31
+}
32
+
33
/**
34
* Policies that describe methods in `ReactClassInterface`.
35
*/
@@ -762,7 +768,10 @@ var ReactClass = {
768
* @public
769
*/
770
createClass: function(spec) {
765
- var Constructor = function(props, context, updater) {
771
+ // To keep our warnings more understandable, we'll use a little hack here to
772
+ // ensure that Constructor.name !== 'Constructor'. This makes sure we don't
773
+ // unnecessarily identify a class without displayName as 'Constructor'.
774
+ var Constructor = identity(function(props, context, updater) {
775
// This constructor gets overridden by mocks. The argument is used
776
// by mocks to assert on what gets mounted.
777
@@ -806,7 +815,7 @@ var ReactClass = {
815
);
816
817
this.state = initialState;
809
- };
818
+ });
819
Constructor.prototype = new ReactClassComponent();
820
Constructor.prototype.constructor = Constructor;
821
Constructor.prototype.__reactAutoBindPairs = [];