getHookNameForLocation-test.js — react Source File
Architecture documentation for getHookNameForLocation-test.js, a javascript file in the react codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 1ab77cff_6803_e7fc_0f93_59c0fdfeb26e["getHookNameForLocation-test.js"] d816dd9a_2650_2f50_e9eb_2cdf900b512f["generateHookMap.js"] 1ab77cff_6803_e7fc_0f93_59c0fdfeb26e --> d816dd9a_2650_2f50_e9eb_2cdf900b512f 5ab6cc34_8610_de9f_93dc_9e7a8742ce9b["getHookNameForLocation.js"] 1ab77cff_6803_e7fc_0f93_59c0fdfeb26e --> 5ab6cc34_8610_de9f_93dc_9e7a8742ce9b e39d8e56_d264_6a32_839e_aeea5b5a0b9b["getHookNameForLocation"] 1ab77cff_6803_e7fc_0f93_59c0fdfeb26e --> e39d8e56_d264_6a32_839e_aeea5b5a0b9b ba38a3cc_fa9d_cd5d_0746_ec93bcb397e1["parser"] 1ab77cff_6803_e7fc_0f93_59c0fdfeb26e --> ba38a3cc_fa9d_cd5d_0746_ec93bcb397e1 style 1ab77cff_6803_e7fc_0f93_59c0fdfeb26e 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
*/
import {parse} from '@babel/parser';
import {generateHookMap} from '../generateHookMap';
import {getHookNameForLocation} from '../getHookNameForLocation';
function expectHookMapToEqual(actual, expected) {
expect(actual.names).toEqual(expected.names);
const formattedMappings = [];
actual.mappings.forEach(lines => {
lines.forEach(segment => {
const name = actual.names[segment[2]];
if (name == null) {
throw new Error(`Expected to find name at position ${segment[2]}`);
}
formattedMappings.push(`${name} from ${segment[0]}:${segment[1]}`);
});
});
expect(formattedMappings).toEqual(expected.mappings);
}
describe('generateHookMap', () => {
it('should parse names for built-in hooks', () => {
const code = `
import {useState, useContext, useMemo, useReducer} from 'react';
export function Component() {
const a = useMemo(() => A);
const [b, setB] = useState(0);
// prettier-ignore
const c = useContext(A), d = useContext(B); // eslint-disable-line one-var
const [e, dispatch] = useReducer(reducer, initialState);
const f = useRef(null)
return a + b + c + d + e + f.current;
}`;
const parsed = parse(code, {
sourceType: 'module',
plugins: ['jsx', 'flow'],
});
const hookMap = generateHookMap(parsed);
expectHookMapToEqual(hookMap, {
names: ['<no-hook>', 'a', 'b', 'c', 'd', 'e', 'f'],
mappings: [
'<no-hook> from 1:0',
'a from 5:12',
'<no-hook> from 5:28',
'b from 6:20',
'<no-hook> from 6:31',
// ... (205 more lines)
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does getHookNameForLocation-test.js do?
getHookNameForLocation-test.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-test.js?
getHookNameForLocation-test.js defines 1 function(s): expectHookMapToEqual.
What does getHookNameForLocation-test.js depend on?
getHookNameForLocation-test.js imports 4 module(s): generateHookMap.js, getHookNameForLocation, getHookNameForLocation.js, parser.
Where is getHookNameForLocation-test.js in the architecture?
getHookNameForLocation-test.js is located at packages/react-devtools-shared/src/hooks/__tests__/getHookNameForLocation-test.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/hooks/__tests__).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free