CodePath Class — react Architecture
Architecture documentation for the CodePath class in code-path.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 9d0ad6be_3800_8694_06ab_1b89f16d8205["CodePath"] 24bdcda8_0755_88a7_512a_340311fa700b["code-path.js"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|defined in| 24bdcda8_0755_88a7_512a_340311fa700b 4e41b91a_6c96_6629_b90b_d3a1e82bd201["constructor()"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|method| 4e41b91a_6c96_6629_b90b_d3a1e82bd201 5c2a7eb6_7bc9_3895_65b1_bdcd1a39ebf5["getState()"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|method| 5c2a7eb6_7bc9_3895_65b1_bdcd1a39ebf5 61d25e1a_5e9d_08e4_e2e0_37b47819f50a["initialSegment()"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|method| 61d25e1a_5e9d_08e4_e2e0_37b47819f50a 2f9bc71a_7cf3_2802_01b2_80a196b3777f["finalSegments()"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|method| 2f9bc71a_7cf3_2802_01b2_80a196b3777f f461b53a_d2ff_a8f0_1441_3f72a8a42d94["returnedSegments()"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|method| f461b53a_d2ff_a8f0_1441_3f72a8a42d94 49ba9308_f9f9_c941_a67c_4d10d3e299a0["thrownSegments()"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|method| 49ba9308_f9f9_c941_a67c_4d10d3e299a0 561de770_b7c5_b66e_9741_8e1ab0c285b3["currentSegments()"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|method| 561de770_b7c5_b66e_9741_8e1ab0c285b3 3130e823_1a1d_c8ab_f87c_5946541f48b5["traverseSegments()"] 9d0ad6be_3800_8694_06ab_1b89f16d8205 -->|method| 3130e823_1a1d_c8ab_f87c_5946541f48b5
Relationship Graph
Source Code
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js lines 19–237
class CodePath {
/**
* Creates a new instance.
* @param {Object} options Options for the function (see below).
* @param {string} options.id An identifier.
* @param {string} options.origin The type of code path origin.
* @param {CodePath|null} options.upper The code path of the upper function scope.
* @param {Function} options.onLooped A callback function to notify looping.
*/
constructor({id, origin, upper, onLooped}) {
/**
* The identifier of this code path.
* Rules use it to store additional information of each rule.
* @type {string}
*/
this.id = id;
/**
* The reason that this code path was started. May be "program",
* "function", "class-field-initializer", or "class-static-block".
* @type {string}
*/
this.origin = origin;
/**
* The code path of the upper function scope.
* @type {CodePath|null}
*/
this.upper = upper;
/**
* The code paths of nested function scopes.
* @type {CodePath[]}
*/
this.childCodePaths = [];
// Initializes internal state.
Object.defineProperty(this, 'internal', {
value: new CodePathState(new IdGenerator(`${id}_`), onLooped),
});
// Adds this into `childCodePaths` of `upper`.
if (upper) {
upper.childCodePaths.push(this);
}
}
/**
* Gets the state of a given code path.
* @param {CodePath} codePath A code path to get.
* @returns {CodePathState} The state of the code path.
*/
static getState(codePath) {
return codePath.internal;
}
/**
* The initial code path segment.
* @type {CodePathSegment}
*/
get initialSegment() {
return this.internal.initialSegment;
}
/**
* Final code path segments.
* This array is a mix of `returnedSegments` and `thrownSegments`.
* @type {CodePathSegment[]}
*/
get finalSegments() {
return this.internal.finalSegments;
}
/**
* Final code path segments which is with `return` statements.
* This array contains the last path segment if it's reachable.
* Since the reachable last path returns `undefined`.
* @type {CodePathSegment[]}
*/
get returnedSegments() {
return this.internal.returnedForkContext;
Source
Frequently Asked Questions
What is the CodePath class?
CodePath is a class in the react codebase, defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js.
Where is CodePath defined?
CodePath is defined in packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js at line 19.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free