getHookNameForLocation.js — react Source File
Architecture documentation for getHookNameForLocation.js, a javascript file in the react codebase. 2 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR 5ab6cc34_8610_de9f_93dc_9e7a8742ce9b["getHookNameForLocation.js"] d816dd9a_2650_2f50_e9eb_2cdf900b512f["generateHookMap.js"] 5ab6cc34_8610_de9f_93dc_9e7a8742ce9b --> d816dd9a_2650_2f50_e9eb_2cdf900b512f 22acaf1d_d624_cc04_9046_5e8603f3a58d["astUtils.js"] 5ab6cc34_8610_de9f_93dc_9e7a8742ce9b --> 22acaf1d_d624_cc04_9046_5e8603f3a58d 5751162b_425a_76d9_4373_4cf5cde09b49["SourceMapMetadataConsumer.js"] 5751162b_425a_76d9_4373_4cf5cde09b49 --> 5ab6cc34_8610_de9f_93dc_9e7a8742ce9b 1ab77cff_6803_e7fc_0f93_59c0fdfeb26e["getHookNameForLocation-test.js"] 1ab77cff_6803_e7fc_0f93_59c0fdfeb26e --> 5ab6cc34_8610_de9f_93dc_9e7a8742ce9b style 5ab6cc34_8610_de9f_93dc_9e7a8742ce9b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
*/
import type {
HookMap,
HookMapEntry,
HookMapLine,
HookMapMappings,
} from './generateHookMap';
import type {Position} from './astUtils';
import {NO_HOOK_NAME} from './astUtils';
/**
* Finds the Hook name assigned to a given location in the source code,
* and a HookMap extracted from an extended source map.
* The given location must correspond to the location in the *original*
* source code (i.e. *not* the generated one).
*
* Note that all locations in the source code are guaranteed to map
* to a name, including a sentinel value that represents a missing
* Hook name: '<no-hook>'.
*
* For more details on the format of the HookMap, see generateHookMap
* and the tests for that function and this function.
*/
export function getHookNameForLocation(
location: Position,
hookMap: HookMap,
): string | null {
const {names, mappings} = hookMap;
// The HookMap mappings are grouped by lines, so first we look up
// which line of mappings covers the target location.
// Note that we expect to find a line since all the locations in the
// source code are guaranteed to map to a name, including a '<no-hook>'
// name.
const foundLine = binSearch(location, mappings, compareLinePositions);
if (foundLine == null) {
throw new Error(
`Expected to find a line in the HookMap that covers the target location at line: ${location.line}, column: ${location.column}`,
);
}
let foundEntry;
const foundLineNumber = getLineNumberFromLine(foundLine);
// The line found in the mappings will never be larger than the target
// line, and vice-versa, so if the target line doesn't match the found
// line, we immediately know that it must correspond to the last mapping
// entry for that line.
if (foundLineNumber !== location.line) {
foundEntry = foundLine[foundLine.length - 1];
} else {
foundEntry = binSearch(location, foundLine, compareColumnPositions);
}
// ... (215 more lines)
Domain
Subdomains
Functions
Dependencies
Imported By
Source
Frequently Asked Questions
What does getHookNameForLocation.js do?
getHookNameForLocation.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in getHookNameForLocation.js?
getHookNameForLocation.js defines 1 function(s): getHookNameForLocation.
What does getHookNameForLocation.js depend on?
getHookNameForLocation.js imports 2 module(s): astUtils.js, generateHookMap.js.
What files import getHookNameForLocation.js?
getHookNameForLocation.js is imported by 2 file(s): SourceMapMetadataConsumer.js, getHookNameForLocation-test.js.
Where is getHookNameForLocation.js in the architecture?
getHookNameForLocation.js is located at packages/react-devtools-shared/src/hooks/getHookNameForLocation.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/hooks).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free