CodePathAnalyzer Class — react Architecture
Architecture documentation for the CodePathAnalyzer class in code-path-analyzer.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 879ae635_0722_8285_b0bd_4d1ab153e2e3["CodePathAnalyzer"] 09a1c78a_21af_9be8_1cc6_22cf0ceb9f8f["code-path-analyzer.js"] 879ae635_0722_8285_b0bd_4d1ab153e2e3 -->|defined in| 09a1c78a_21af_9be8_1cc6_22cf0ceb9f8f fc5e339c_6ee4_dc85_568f_c6dc36018b3a["constructor()"] 879ae635_0722_8285_b0bd_4d1ab153e2e3 -->|method| fc5e339c_6ee4_dc85_568f_c6dc36018b3a d082f1e7_4eef_c1db_f99e_4cfec174190f["enterNode()"] 879ae635_0722_8285_b0bd_4d1ab153e2e3 -->|method| d082f1e7_4eef_c1db_f99e_4cfec174190f dc411858_ea9d_ab2f_49db_a3428829fbde["leaveNode()"] 879ae635_0722_8285_b0bd_4d1ab153e2e3 -->|method| dc411858_ea9d_ab2f_49db_a3428829fbde 8e39d07b_62da_46d9_c8be_5d6ecb9a2323["onLooped()"] 879ae635_0722_8285_b0bd_4d1ab153e2e3 -->|method| 8e39d07b_62da_46d9_c8be_5d6ecb9a2323
Relationship Graph
Source Code
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js lines 723–800
class CodePathAnalyzer {
/**
* @param {EventGenerator} eventGenerator An event generator to wrap.
*/
constructor(emitters) {
this.emitter = {
emit(event, ...args) {
emitters[event]?.(...args);
},
};
this.codePath = null;
this.idGenerator = new IdGenerator('s');
this.currentNode = null;
this.onLooped = this.onLooped.bind(this);
}
/**
* Does the process to enter a given AST node.
* This updates state of analysis and calls `enterNode` of the wrapped.
* @param {ASTNode} node A node which is entering.
* @returns {void}
*/
enterNode(node) {
this.currentNode = node;
// Updates the code path due to node's position in its parent node.
if (node.parent) {
preprocess(this, node);
}
/*
* Updates the code path.
* And emits onCodePathStart/onCodePathSegmentStart events.
*/
processCodePathToEnter(this, node);
this.currentNode = null;
}
/**
* Does the process to leave a given AST node.
* This updates state of analysis and calls `leaveNode` of the wrapped.
* @param {ASTNode} node A node which is leaving.
* @returns {void}
*/
leaveNode(node) {
this.currentNode = node;
/*
* Updates the code path.
* And emits onCodePathStart/onCodePathSegmentStart events.
*/
processCodePathToExit(this, node);
// Emits the last onCodePathStart/onCodePathSegmentStart events.
postprocess(this, node);
this.currentNode = null;
}
/**
* This is called on a code path looped.
* Then this raises a looped event.
* @param {CodePathSegment} fromSegment A segment of prev.
* @param {CodePathSegment} toSegment A segment of next.
* @returns {void}
*/
onLooped(fromSegment, toSegment) {
if (fromSegment.reachable && toSegment.reachable) {
this.emitter.emit(
'onCodePathSegmentLoop',
fromSegment,
toSegment,
this.currentNode,
);
}
}
}
Domain
Source
Frequently Asked Questions
What is the CodePathAnalyzer class?
CodePathAnalyzer is a class in the react codebase, defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js.
Where is CodePathAnalyzer defined?
CodePathAnalyzer is defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js at line 723.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free