|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow |
| 8 | + */ |
| 9 | + |
| 10 | +// Do not add / import anything to this file. |
| 11 | +// This function is used from multiple places, including hook. |
| 12 | + |
| 13 | +import type {WorkTagMap} from 'react-devtools-shared/src/backend/types'; |
| 14 | + |
| 15 | +import {gt, gte} from 'react-devtools-shared/src/backend/utils'; |
| 16 | + |
| 17 | +export default function getWorkTagMap(version: string): WorkTagMap { |
| 18 | + let ReactTypeOfWork: WorkTagMap = ((null: any): WorkTagMap); |
| 19 | + |
| 20 | + // ********************************************************** |
| 21 | + // The section below is copied from files in React repo, see ReactWorkTags.js. |
| 22 | + // Keep it in sync, and add version guards if it changes. |
| 23 | + if (gt(version, '17.0.1')) { |
| 24 | + ReactTypeOfWork = { |
| 25 | + CacheComponent: 24, // Experimental |
| 26 | + ClassComponent: 1, |
| 27 | + ContextConsumer: 9, |
| 28 | + ContextProvider: 10, |
| 29 | + CoroutineComponent: -1, // Removed |
| 30 | + CoroutineHandlerPhase: -1, // Removed |
| 31 | + DehydratedSuspenseComponent: 18, // Behind a flag |
| 32 | + ForwardRef: 11, |
| 33 | + Fragment: 7, |
| 34 | + FunctionComponent: 0, |
| 35 | + HostComponent: 5, |
| 36 | + HostPortal: 4, |
| 37 | + HostRoot: 3, |
| 38 | + HostHoistable: 26, // In reality, 18.2+. But doesn't hurt to include it here |
| 39 | + HostSingleton: 27, // Same as above |
| 40 | + HostText: 6, |
| 41 | + IncompleteClassComponent: 17, |
| 42 | + IncompleteFunctionComponent: 28, |
| 43 | + IndeterminateComponent: 2, // removed in 19.0.0 |
| 44 | + LazyComponent: 16, |
| 45 | + LegacyHiddenComponent: 23, |
| 46 | + MemoComponent: 14, |
| 47 | + Mode: 8, |
| 48 | + OffscreenComponent: 22, // Experimental |
| 49 | + Profiler: 12, |
| 50 | + ScopeComponent: 21, // Experimental |
| 51 | + SimpleMemoComponent: 15, |
| 52 | + SuspenseComponent: 13, |
| 53 | + SuspenseListComponent: 19, // Experimental |
| 54 | + TracingMarkerComponent: 25, // Experimental - This is technically in 18 but we don't |
| 55 | + // want to fork again so we're adding it here instead |
| 56 | + YieldComponent: -1, // Removed |
| 57 | + Throw: 29, |
| 58 | + }; |
| 59 | + } else if (gte(version, '17.0.0-alpha')) { |
| 60 | + ReactTypeOfWork = { |
| 61 | + CacheComponent: -1, // Doesn't exist yet |
| 62 | + ClassComponent: 1, |
| 63 | + ContextConsumer: 9, |
| 64 | + ContextProvider: 10, |
| 65 | + CoroutineComponent: -1, // Removed |
| 66 | + CoroutineHandlerPhase: -1, // Removed |
| 67 | + DehydratedSuspenseComponent: 18, // Behind a flag |
| 68 | + ForwardRef: 11, |
| 69 | + Fragment: 7, |
| 70 | + FunctionComponent: 0, |
| 71 | + HostComponent: 5, |
| 72 | + HostPortal: 4, |
| 73 | + HostRoot: 3, |
| 74 | + HostHoistable: -1, // Doesn't exist yet |
| 75 | + HostSingleton: -1, // Doesn't exist yet |
| 76 | + HostText: 6, |
| 77 | + IncompleteClassComponent: 17, |
| 78 | + IncompleteFunctionComponent: -1, // Doesn't exist yet |
| 79 | + IndeterminateComponent: 2, |
| 80 | + LazyComponent: 16, |
| 81 | + LegacyHiddenComponent: 24, |
| 82 | + MemoComponent: 14, |
| 83 | + Mode: 8, |
| 84 | + OffscreenComponent: 23, // Experimental |
| 85 | + Profiler: 12, |
| 86 | + ScopeComponent: 21, // Experimental |
| 87 | + SimpleMemoComponent: 15, |
| 88 | + SuspenseComponent: 13, |
| 89 | + SuspenseListComponent: 19, // Experimental |
| 90 | + TracingMarkerComponent: -1, // Doesn't exist yet |
| 91 | + YieldComponent: -1, // Removed |
| 92 | + Throw: -1, // Doesn't exist yet |
| 93 | + }; |
| 94 | + } else if (gte(version, '16.6.0-beta.0')) { |
| 95 | + ReactTypeOfWork = { |
| 96 | + CacheComponent: -1, // Doesn't exist yet |
| 97 | + ClassComponent: 1, |
| 98 | + ContextConsumer: 9, |
| 99 | + ContextProvider: 10, |
| 100 | + CoroutineComponent: -1, // Removed |
| 101 | + CoroutineHandlerPhase: -1, // Removed |
| 102 | + DehydratedSuspenseComponent: 18, // Behind a flag |
| 103 | + ForwardRef: 11, |
| 104 | + Fragment: 7, |
| 105 | + FunctionComponent: 0, |
| 106 | + HostComponent: 5, |
| 107 | + HostPortal: 4, |
| 108 | + HostRoot: 3, |
| 109 | + HostHoistable: -1, // Doesn't exist yet |
| 110 | + HostSingleton: -1, // Doesn't exist yet |
| 111 | + HostText: 6, |
| 112 | + IncompleteClassComponent: 17, |
| 113 | + IncompleteFunctionComponent: -1, // Doesn't exist yet |
| 114 | + IndeterminateComponent: 2, |
| 115 | + LazyComponent: 16, |
| 116 | + LegacyHiddenComponent: -1, |
| 117 | + MemoComponent: 14, |
| 118 | + Mode: 8, |
| 119 | + OffscreenComponent: -1, // Experimental |
| 120 | + Profiler: 12, |
| 121 | + ScopeComponent: -1, // Experimental |
| 122 | + SimpleMemoComponent: 15, |
| 123 | + SuspenseComponent: 13, |
| 124 | + SuspenseListComponent: 19, // Experimental |
| 125 | + TracingMarkerComponent: -1, // Doesn't exist yet |
| 126 | + YieldComponent: -1, // Removed |
| 127 | + Throw: -1, // Doesn't exist yet |
| 128 | + }; |
| 129 | + } else if (gte(version, '16.4.3-alpha')) { |
| 130 | + ReactTypeOfWork = { |
| 131 | + CacheComponent: -1, // Doesn't exist yet |
| 132 | + ClassComponent: 2, |
| 133 | + ContextConsumer: 11, |
| 134 | + ContextProvider: 12, |
| 135 | + CoroutineComponent: -1, // Removed |
| 136 | + CoroutineHandlerPhase: -1, // Removed |
| 137 | + DehydratedSuspenseComponent: -1, // Doesn't exist yet |
| 138 | + ForwardRef: 13, |
| 139 | + Fragment: 9, |
| 140 | + FunctionComponent: 0, |
| 141 | + HostComponent: 7, |
| 142 | + HostPortal: 6, |
| 143 | + HostRoot: 5, |
| 144 | + HostHoistable: -1, // Doesn't exist yet |
| 145 | + HostSingleton: -1, // Doesn't exist yet |
| 146 | + HostText: 8, |
| 147 | + IncompleteClassComponent: -1, // Doesn't exist yet |
| 148 | + IncompleteFunctionComponent: -1, // Doesn't exist yet |
| 149 | + IndeterminateComponent: 4, |
| 150 | + LazyComponent: -1, // Doesn't exist yet |
| 151 | + LegacyHiddenComponent: -1, |
| 152 | + MemoComponent: -1, // Doesn't exist yet |
| 153 | + Mode: 10, |
| 154 | + OffscreenComponent: -1, // Experimental |
| 155 | + Profiler: 15, |
| 156 | + ScopeComponent: -1, // Experimental |
| 157 | + SimpleMemoComponent: -1, // Doesn't exist yet |
| 158 | + SuspenseComponent: 16, |
| 159 | + SuspenseListComponent: -1, // Doesn't exist yet |
| 160 | + TracingMarkerComponent: -1, // Doesn't exist yet |
| 161 | + YieldComponent: -1, // Removed |
| 162 | + Throw: -1, // Doesn't exist yet |
| 163 | + }; |
| 164 | + } else { |
| 165 | + ReactTypeOfWork = { |
| 166 | + CacheComponent: -1, // Doesn't exist yet |
| 167 | + ClassComponent: 2, |
| 168 | + ContextConsumer: 12, |
| 169 | + ContextProvider: 13, |
| 170 | + CoroutineComponent: 7, |
| 171 | + CoroutineHandlerPhase: 8, |
| 172 | + DehydratedSuspenseComponent: -1, // Doesn't exist yet |
| 173 | + ForwardRef: 14, |
| 174 | + Fragment: 10, |
| 175 | + FunctionComponent: 1, |
| 176 | + HostComponent: 5, |
| 177 | + HostPortal: 4, |
| 178 | + HostRoot: 3, |
| 179 | + HostHoistable: -1, // Doesn't exist yet |
| 180 | + HostSingleton: -1, // Doesn't exist yet |
| 181 | + HostText: 6, |
| 182 | + IncompleteClassComponent: -1, // Doesn't exist yet |
| 183 | + IncompleteFunctionComponent: -1, // Doesn't exist yet |
| 184 | + IndeterminateComponent: 0, |
| 185 | + LazyComponent: -1, // Doesn't exist yet |
| 186 | + LegacyHiddenComponent: -1, |
| 187 | + MemoComponent: -1, // Doesn't exist yet |
| 188 | + Mode: 11, |
| 189 | + OffscreenComponent: -1, // Experimental |
| 190 | + Profiler: 15, |
| 191 | + ScopeComponent: -1, // Experimental |
| 192 | + SimpleMemoComponent: -1, // Doesn't exist yet |
| 193 | + SuspenseComponent: 16, |
| 194 | + SuspenseListComponent: -1, // Doesn't exist yet |
| 195 | + TracingMarkerComponent: -1, // Doesn't exist yet |
| 196 | + YieldComponent: 9, |
| 197 | + Throw: -1, // Doesn't exist yet |
| 198 | + }; |
| 199 | + } |
| 200 | + // ********************************************************** |
| 201 | + // End of copied code. |
| 202 | + // ********************************************************** |
| 203 | + |
| 204 | + return ReactTypeOfWork; |
| 205 | +} |
0 commit comments