* A code path.
| 20 | * A code path. |
| 21 | */ |
| 22 | class CodePath { |
| 23 | /** |
| 24 | * Creates a new instance. |
| 25 | * @param {Object} options Options for the function (see below). |
| 26 | * @param {string} options.id An identifier. |
| 27 | * @param {string} options.origin The type of code path origin. |
| 28 | * @param {CodePath|null} options.upper The code path of the upper function scope. |
| 29 | * @param {Function} options.onLooped A callback function to notify looping. |
| 30 | */ |
| 31 | constructor({ id, origin, upper, onLooped }) { |
| 32 | /** |
| 33 | * The identifier of this code path. |
| 34 | * Rules use it to store additional information of each rule. |
| 35 | * @type {string} |
| 36 | */ |
| 37 | this.id = id; |
| 38 | |
| 39 | /** |
| 40 | * The reason that this code path was started. May be "program", |
| 41 | * "function", "class-field-initializer", or "class-static-block". |
| 42 | * @type {string} |
| 43 | */ |
| 44 | this.origin = origin; |
| 45 | |
| 46 | /** |
| 47 | * The code path of the upper function scope. |
| 48 | * @type {CodePath|null} |
| 49 | */ |
| 50 | this.upper = upper; |
| 51 | |
| 52 | /** |
| 53 | * The code paths of nested function scopes. |
| 54 | * @type {CodePath[]} |
| 55 | */ |
| 56 | this.childCodePaths = []; |
| 57 | |
| 58 | // Initializes internal state. |
| 59 | Object.defineProperty(this, "internal", { |
| 60 | value: new CodePathState(new IdGenerator(`${id}_`), onLooped), |
| 61 | }); |
| 62 | |
| 63 | // Adds this into `childCodePaths` of `upper`. |
| 64 | if (upper) { |
| 65 | upper.childCodePaths.push(this); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Gets the state of a given code path. |
| 71 | * @param {CodePath} codePath A code path to get. |
| 72 | * @returns {CodePathState} The state of the code path. |
| 73 | */ |
| 74 | static getState(codePath) { |
| 75 | return codePath.internal; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * The initial code path segment. This is the segment that is at the head |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…