MCPcopy
hub / github.com/eslint/eslint / processCodePathToEnter

Function processCodePathToEnter

lib/linter/code-path-analysis/code-path-analyzer.js:390–537  ·  view source on GitHub ↗

* Updates the code path due to the type of a given node in entering. * @param {CodePathAnalyzer} analyzer The instance. * @param {ASTNode} node The current AST node. * @returns {void}

(analyzer, node)

Source from the content-addressed store, hash-verified

388 * @returns {void}
389 */
390function processCodePathToEnter(analyzer, node) {
391 let codePath = analyzer.codePath;
392 let state = codePath && CodePath.getState(codePath);
393 const parent = node.parent;
394
395 /**
396 * Creates a new code path and trigger the onCodePathStart event
397 * based on the currently selected node.
398 * @param {string} origin The reason the code path was started.
399 * @returns {void}
400 */
401 function startCodePath(origin) {
402 if (codePath) {
403 // Emits onCodePathSegmentStart events if updated.
404 forwardCurrentToHead(analyzer, node);
405 debug.dumpState(node, state, false);
406 }
407
408 // Create the code path of this scope.
409 codePath = analyzer.codePath = new CodePath({
410 id: analyzer.idGenerator.next(),
411 origin,
412 upper: codePath,
413 onLooped: analyzer.onLooped,
414 });
415 state = CodePath.getState(codePath);
416
417 // Emits onCodePathStart events.
418 debug.dump(`onCodePathStart ${codePath.id}`);
419 analyzer.emit("onCodePathStart", [codePath, node]);
420 }
421
422 /*
423 * Special case: The right side of class field initializer is considered
424 * to be its own function, so we need to start a new code path in this
425 * case.
426 */
427 if (isPropertyDefinitionValue(node)) {
428 startCodePath("class-field-initializer");
429
430 /*
431 * Intentional fall through because `node` needs to also be
432 * processed by the code below. For example, if we have:
433 *
434 * class Foo {
435 * a = () => {}
436 * }
437 *
438 * In this case, we also need start a second code path.
439 */
440 }
441
442 switch (node.type) {
443 case "Program":
444 startCodePath("program");
445 break;
446
447 case "FunctionDeclaration":

Callers 1

enterNodeMethod · 0.85

Calls 15

startCodePathFunction · 0.85
isHandledLogicalOperatorFunction · 0.85
isForkingByTrueOrFalseFunction · 0.85
getLabelFunction · 0.85
forwardCurrentToHeadFunction · 0.85
getStateMethod · 0.80
pushChainContextMethod · 0.80
makeOptionalNodeMethod · 0.80
pushChoiceContextMethod · 0.80
pushSwitchContextMethod · 0.80
pushTryContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…