MCPcopy
hub / github.com/eslint/eslint / traverseSegments

Method traverseSegments

lib/linter/code-path-analysis/code-path.js:148–331  ·  view source on GitHub ↗

* Traverses all segments in this code path. * * codePath.traverseSegments((segment, controller) => { * // do something. * }); * * This method enumerates segments in order from the head. * * The `controller` argument has two methods: * * - `skip()` - skips the foll

(optionsOrCallback, callback)

Source from the content-addressed store, hash-verified

146 * @returns {void}
147 */
148 traverseSegments(optionsOrCallback, callback) {
149 // normalize the arguments into a callback and options
150 let resolvedOptions;
151 let resolvedCallback;
152
153 if (typeof optionsOrCallback === "function") {
154 resolvedCallback = optionsOrCallback;
155 resolvedOptions = {};
156 } else {
157 resolvedOptions = optionsOrCallback || {};
158 resolvedCallback = callback;
159 }
160
161 // determine where to start traversing from based on the options
162 const startSegment =
163 resolvedOptions.first || this.internal.initialSegment;
164 const lastSegment = resolvedOptions.last;
165
166 // set up initial location information
167 let record;
168 let index;
169 let end;
170 let segment = null;
171
172 // segments that have already been visited during traversal
173 const visited = new Set();
174
175 // tracks the traversal steps
176 const stack = [[startSegment, 0]];
177
178 // segments that have been skipped during traversal
179 const skipped = new Set();
180
181 // indicates if we exited early from the traversal
182 let broken = false;
183
184 /**
185 * Maintains traversal state.
186 */
187 const controller = {
188 /**
189 * Skip the following segments in this branch.
190 * @returns {void}
191 */
192 skip() {
193 skipped.add(segment);
194 },
195
196 /**
197 * Stop traversal completely - do not traverse to any
198 * other segments.
199 * @returns {void}
200 */
201 break() {
202 broken = true;
203 },
204 };
205

Callers

nothing calls this directly

Calls 2

skipMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected