Skip to content

Commit 3a34590

Browse files
committed
Extract getHookSourceLocationKey helper
This is used in environments that don't use "react".
1 parent 9f08277 commit 3a34590

File tree

7 files changed

+29
-20
lines changed

7 files changed

+29
-20
lines changed

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {getMetaValueLabel, serializeHooksForCopy} from '../utils';
2020
import Store from '../../store';
2121
import styles from './InspectedElementHooksTree.css';
2222
import {meta} from '../../../hydration';
23-
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookNamesCache';
23+
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookSourceLocation';
2424
import HookNamesModuleLoaderContext from 'react-devtools-shared/src/devtools/views/Components/HookNamesModuleLoaderContext';
2525
import isArray from 'react-devtools-shared/src/isArray';
2626

packages/react-devtools-shared/src/devtools/views/Profiler/HookChangeSummary.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ import ButtonIcon from '../ButtonIcon';
2121
import {InspectedElementContext} from '../Components/InspectedElementContext';
2222
import {StoreContext} from '../context';
2323

24-
import {
25-
getAlreadyLoadedHookNames,
26-
getHookSourceLocationKey,
27-
} from 'react-devtools-shared/src/hookNamesCache';
24+
import {getAlreadyLoadedHookNames} from 'react-devtools-shared/src/hookNamesCache';
25+
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookSourceLocation';
2826
import Toggle from '../Toggle';
2927
import type {HooksNode} from 'react-debug-tools/src/ReactDebugHooks';
3028
import type {ChangeDescription} from './types';

packages/react-devtools-shared/src/hookNamesCache.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import type {
1818
import type {
1919
Element,
2020
HookNames,
21-
HookSourceLocationKey,
2221
} from 'react-devtools-shared/src/frontend/types';
23-
import type {HookSource} from 'react-debug-tools/src/ReactDebugHooks';
2422
import type {FetchFileWithCaching} from 'react-devtools-shared/src/devtools/views/Components/FetchFileWithCachingContext';
2523

2624
import * as React from 'react';
@@ -226,17 +224,6 @@ export function loadHookNames(
226224
return response;
227225
}
228226

229-
export function getHookSourceLocationKey({
230-
fileName,
231-
lineNumber,
232-
columnNumber,
233-
}: HookSource): HookSourceLocationKey {
234-
if (fileName == null || lineNumber == null || columnNumber == null) {
235-
throw Error('Hook source code location not found.');
236-
}
237-
return `${fileName}:${lineNumber}:${columnNumber}`;
238-
}
239-
240227
export function clearHookNamesCache(): void {
241228
map = new WeakMap();
242229
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
import type {HookSourceLocationKey} from 'react-devtools-shared/src/frontend/types';
11+
import type {HookSource} from 'react-debug-tools/src/ReactDebugHooks';
12+
13+
export function getHookSourceLocationKey({
14+
fileName,
15+
lineNumber,
16+
columnNumber,
17+
}: HookSource): HookSourceLocationKey {
18+
if (fileName == null || lineNumber == null || columnNumber == null) {
19+
throw Error('Hook source code location not found.');
20+
}
21+
return `${fileName}:${lineNumber}:${columnNumber}`;
22+
}

packages/react-devtools-shared/src/hooks/parseHookNames/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type {HooksNode, HooksTree} from 'react-debug-tools/src/ReactDebugHooks';
1212
import type {HookNames} from 'react-devtools-shared/src/frontend/types';
1313
import type {FetchFileWithCaching} from 'react-devtools-shared/src/devtools/views/Components/FetchFileWithCachingContext';
1414

15+
import 'react';
16+
1517
import {withAsyncPerfMeasurements} from 'react-devtools-shared/src/PerformanceLoggingUtils';
1618
import WorkerizedParseSourceAndMetadata from './parseSourceAndMetadata.worker';
1719
import typeof * as ParseSourceAndMetadataModule from './parseSourceAndMetadata';

packages/react-devtools-shared/src/hooks/parseHookNames/loadSourceAndMetadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
// and there is no need to convert runtime code to the original source.
4747

4848
import {__DEBUG__} from 'react-devtools-shared/src/constants';
49-
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookNamesCache';
49+
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookSourceLocation';
5050
import {sourceMapIncludesSource} from '../SourceMapUtils';
5151
import {
5252
withAsyncPerfMeasurements,

packages/react-devtools-shared/src/hooks/parseHookNames/parseSourceAndMetadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import LRU from 'lru-cache';
1515
import {getHookName} from '../astUtils';
1616
import {areSourceMapsAppliedToErrors} from '../ErrorTester';
1717
import {__DEBUG__} from 'react-devtools-shared/src/constants';
18-
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookNamesCache';
18+
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookSourceLocation';
1919
import {SourceMapMetadataConsumer} from '../SourceMapMetadataConsumer';
2020
import {
2121
withAsyncPerfMeasurements,

0 commit comments

Comments
 (0)