(workInProgress, ctor, props)
| 12964 | } |
| 12965 | |
| 12966 | function constructClassInstance(workInProgress, ctor, props) { |
| 12967 | var isLegacyContextConsumer = false; |
| 12968 | var unmaskedContext = emptyContextObject; |
| 12969 | var context = emptyContextObject; |
| 12970 | var contextType = ctor.contextType; |
| 12971 | |
| 12972 | { |
| 12973 | if ('contextType' in ctor) { |
| 12974 | var isValid = // Allow null for conditional declaration |
| 12975 | contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer> |
| 12976 | |
| 12977 | if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) { |
| 12978 | didWarnAboutInvalidateContextType.add(ctor); |
| 12979 | var addendum = ''; |
| 12980 | |
| 12981 | if (contextType === undefined) { |
| 12982 | addendum = ' However, it is set to undefined. ' + 'This can be caused by a typo or by mixing up named and default imports. ' + 'This can also happen due to a circular dependency, so ' + 'try moving the createContext() call to a separate file.'; |
| 12983 | } else if (typeof contextType !== 'object') { |
| 12984 | addendum = ' However, it is set to a ' + typeof contextType + '.'; |
| 12985 | } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) { |
| 12986 | addendum = ' Did you accidentally pass the Context.Provider instead?'; |
| 12987 | } else if (contextType._context !== undefined) { |
| 12988 | // <Context.Consumer> |
| 12989 | addendum = ' Did you accidentally pass the Context.Consumer instead?'; |
| 12990 | } else { |
| 12991 | addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.'; |
| 12992 | } |
| 12993 | |
| 12994 | error('%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum); |
| 12995 | } |
| 12996 | } |
| 12997 | } |
| 12998 | |
| 12999 | if (typeof contextType === 'object' && contextType !== null) { |
| 13000 | context = readContext(contextType); |
| 13001 | } else { |
| 13002 | unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); |
| 13003 | var contextTypes = ctor.contextTypes; |
| 13004 | isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined; |
| 13005 | context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject; |
| 13006 | } // Instantiate twice to help detect side-effects. |
| 13007 | |
| 13008 | |
| 13009 | { |
| 13010 | if ( workInProgress.mode & StrictMode) { |
| 13011 | new ctor(props, context); // eslint-disable-line no-new |
| 13012 | } |
| 13013 | } |
| 13014 | |
| 13015 | var instance = new ctor(props, context); |
| 13016 | var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null; |
| 13017 | adoptClassInstance(workInProgress, instance); |
| 13018 | |
| 13019 | { |
| 13020 | if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) { |
| 13021 | var componentName = getComponentName(ctor) || 'Component'; |
| 13022 | |
| 13023 | if (!didWarnAboutUninitializedState.has(componentName)) { |
no test coverage detected