checkNodeLocation() — react Function Reference
Architecture documentation for the checkNodeLocation() function in astUtils.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 084c323b_7361_94be_de61_55a1aff4c014["checkNodeLocation()"] 22acaf1d_d624_cc04_9046_5e8603f3a58d["astUtils.js"] 084c323b_7361_94be_de61_55a1aff4c014 -->|defined in| 22acaf1d_d624_cc04_9046_5e8603f3a58d ae74fc61_22de_3ac9_6314_d002de1a11ab["getHookName()"] ae74fc61_22de_3ac9_6314_d002de1a11ab -->|calls| 084c323b_7361_94be_de61_55a1aff4c014 style 084c323b_7361_94be_de61_55a1aff4c014 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-devtools-shared/src/hooks/astUtils.js lines 45–98
function checkNodeLocation(
path: NodePath,
line: number,
column?: number | null = null,
): boolean {
const {start, end} = path.node.loc;
if (line !== start.line) {
return false;
}
if (column !== null) {
// Column numbers are represented differently between tools/engines.
// Error.prototype.stack columns are 1-based (like most IDEs) but ASTs are 0-based.
//
// In practice this will probably never matter,
// because this code matches the 1-based Error stack location for the hook Identifier (e.g. useState)
// with the larger 0-based VariableDeclarator (e.g. [foo, setFoo] = useState())
// so the ranges should always overlap.
//
// For more info see https://github.com/facebook/react/pull/21833#discussion_r666831276
column -= 1;
if (
(line === start.line && column < start.column) ||
(line === end.line && column > end.column)
) {
return false;
}
}
return true;
}
// Checks whether hookNode is a member of targetHookNode
function filterMemberNodesOfTargetHook(
targetHookNode: NodePath,
hookNode: NodePath,
): boolean {
const targetHookName = targetHookNode.node.id.name;
return (
targetHookName != null &&
(targetHookName ===
(hookNode.node.init.object && hookNode.node.init.object.name) ||
targetHookName === hookNode.node.init.name)
);
}
// Checks whether hook is the first member node of a state variable declaration node
function filterMemberWithHookVariableName(hook: NodePath): boolean {
return (
hook.node.init.property.type === AST_NODE_TYPES.NUMERIC_LITERAL &&
hook.node.init.property.value === 0
);
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does checkNodeLocation() do?
checkNodeLocation() is a function in the react codebase, defined in packages/react-devtools-shared/src/hooks/astUtils.js.
Where is checkNodeLocation() defined?
checkNodeLocation() is defined in packages/react-devtools-shared/src/hooks/astUtils.js at line 45.
What calls checkNodeLocation()?
checkNodeLocation() is called by 1 function(s): getHookName.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free