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