code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
tap(payload) { domEventSequences.pointerdown(payload); domEventSequences.pointerup(payload); }
Gesture abstractions. Helpers for event sequences expected in a gesture. target.tap({ pointerType: 'touch' })
tap
javascript
facebook/react
packages/dom-event-testing-library/index.js
https://github.com/facebook/react/blob/master/packages/dom-event-testing-library/index.js
MIT
function addTouch(touch) { const identifier = touch.identifier; const target = touch.target; if (!activeTouches.has(target)) { activeTouches.set(target, new Map()); } if (activeTouches.get(target).get(identifier)) { // Do not allow existing touches to be overwritten console.error( 'Touch wit...
Touch events state machine. Keeps track of the active pointers and allows them to be reflected in touch events.
addTouch
javascript
facebook/react
packages/dom-event-testing-library/touchStore.js
https://github.com/facebook/react/blob/master/packages/dom-event-testing-library/touchStore.js
MIT
function updateTouch(touch) { const identifier = touch.identifier; const target = touch.target; if (activeTouches.get(target) != null) { activeTouches.get(target).set(identifier, touch); } else { console.error( 'Touch with identifier %s does not exist. Cannot record touch move without a touch star...
Touch events state machine. Keeps track of the active pointers and allows them to be reflected in touch events.
updateTouch
javascript
facebook/react
packages/dom-event-testing-library/touchStore.js
https://github.com/facebook/react/blob/master/packages/dom-event-testing-library/touchStore.js
MIT
function removeTouch(touch) { const identifier = touch.identifier; const target = touch.target; if (activeTouches.get(target) != null) { if (activeTouches.get(target).has(identifier)) { activeTouches.get(target).delete(identifier); } else { console.error( 'Touch with identifier %s does...
Touch events state machine. Keeps track of the active pointers and allows them to be reflected in touch events.
removeTouch
javascript
facebook/react
packages/dom-event-testing-library/touchStore.js
https://github.com/facebook/react/blob/master/packages/dom-event-testing-library/touchStore.js
MIT
function getTouches() { const touches = []; activeTouches.forEach((_, target) => { touches.push(...getTargetTouches(target)); }); return touches; }
Touch events state machine. Keeps track of the active pointers and allows them to be reflected in touch events.
getTouches
javascript
facebook/react
packages/dom-event-testing-library/touchStore.js
https://github.com/facebook/react/blob/master/packages/dom-event-testing-library/touchStore.js
MIT
function getTargetTouches(target) { if (activeTouches.get(target) != null) { return Array.from(activeTouches.get(target).values()); } return []; }
Touch events state machine. Keeps track of the active pointers and allows them to be reflected in touch events.
getTargetTouches
javascript
facebook/react
packages/dom-event-testing-library/touchStore.js
https://github.com/facebook/react/blob/master/packages/dom-event-testing-library/touchStore.js
MIT
function isCaseNode(node) { return Boolean(node.test); }
Checks whether or not a given node is a `case` node (not `default` node). @param {ASTNode} node A `SwitchCase` node to check. @returns {boolean} `true` if the node is a `case` node (not `default` node).
isCaseNode
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function isPropertyDefinitionValue(node) { const parent = node.parent; return ( parent && parent.type === 'PropertyDefinition' && parent.value === node ); }
Checks if a given node appears as the value of a PropertyDefinition node. @param {ASTNode} node THe node to check. @returns {boolean} `true` if the node is a PropertyDefinition value, false if not.
isPropertyDefinitionValue
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function isHandledLogicalOperator(operator) { return operator === '&&' || operator === '||' || operator === '??'; }
Checks whether the given logical operator is taken into account for the code path analysis. @param {string} operator The operator found in the LogicalExpression node @returns {boolean} `true` if the operator is "&&" or "||" or "??"
isHandledLogicalOperator
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function isLogicalAssignmentOperator(operator) { return operator === '&&=' || operator === '||=' || operator === '??='; }
Checks whether the given assignment operator is a logical assignment operator. Logical assignments are taken into account for the code path analysis because of their short-circuiting semantics. @param {string} operator The operator found in the AssignmentExpression node @returns {boolean} `true` if the operator is "&&=...
isLogicalAssignmentOperator
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function getLabel(node) { if (node.parent.type === 'LabeledStatement') { return node.parent.label.name; } return null; }
Gets the label if the parent node of a given node is a LabeledStatement. @param {ASTNode} node A node to get. @returns {string|null} The label or `null`.
getLabel
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function isForkingByTrueOrFalse(node) { const parent = node.parent; switch (parent.type) { case 'ConditionalExpression': case 'IfStatement': case 'WhileStatement': case 'DoWhileStatement': case 'ForStatement': return parent.test === node; case 'LogicalExpression': return isHand...
Checks whether or not a given logical expression node goes different path between the `true` case and the `false` case. @param {ASTNode} node A node to check. @returns {boolean} `true` if the node is a test of a choice statement.
isForkingByTrueOrFalse
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function getBooleanValueIfSimpleConstant(node) { if (node.type === 'Literal') { return Boolean(node.value); } return void 0; }
Gets the boolean value of a given literal node. This is used to detect infinity loops (e.g. `while (true) {}`). Statements preceded by an infinity loop are unreachable if the loop didn't have any `break` statement. @param {ASTNode} node A node to get. @returns {boolean|undefined} a boolean value if the node is a Liter...
getBooleanValueIfSimpleConstant
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function isIdentifierReference(node) { const parent = node.parent; switch (parent.type) { case 'LabeledStatement': case 'BreakStatement': case 'ContinueStatement': case 'ArrayPattern': case 'RestElement': case 'ImportSpecifier': case 'ImportDefaultSpecifier': case 'ImportNamespaceSp...
Checks that a given identifier node is a reference or not. This is used to detect the first throwable node in a `try` block. @param {ASTNode} node An Identifier node to check. @returns {boolean} `true` if the node is a reference.
isIdentifierReference
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function forwardCurrentToHead(analyzer, node) { const codePath = analyzer.codePath; const state = CodePath.getState(codePath); const currentSegments = state.currentSegments; const headSegments = state.headSegments; const end = Math.max(currentSegments.length, headSegments.length); let i, currentSegment, hea...
Updates the current segment with the head segment. This is similar to local branches and tracking branches of git. To separate the current and the head is in order to not make useless segments. In this process, both "onCodePathSegmentStart" and "onCodePathSegmentEnd" events are fired. @param {CodePathAnalyzer} analyz...
forwardCurrentToHead
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function leaveFromCurrentSegment(analyzer, node) { const state = CodePath.getState(analyzer.codePath); const currentSegments = state.currentSegments; for (let i = 0; i < currentSegments.length; ++i) { const currentSegment = currentSegments[i]; if (currentSegment.reachable) { analyzer.emitter.emit('...
Updates the current segment with empty. This is called at the last of functions or the program. @param {CodePathAnalyzer} analyzer The instance. @param {ASTNode} node The current AST node. @returns {void}
leaveFromCurrentSegment
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function preprocess(analyzer, node) { const codePath = analyzer.codePath; const state = CodePath.getState(codePath); const parent = node.parent; switch (parent.type) { // The `arguments.length == 0` case is in `postprocess` function. case 'CallExpression': if ( parent.optional === true &&...
Updates the code path due to the position of a given node in the parent node thereof. For example, if the node is `parent.consequent`, this creates a fork from the current path. @param {CodePathAnalyzer} analyzer The instance. @param {ASTNode} node The current AST node. @returns {void}
preprocess
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function processCodePathToEnter(analyzer, node) { let codePath = analyzer.codePath; let state = codePath && CodePath.getState(codePath); const parent = node.parent; /** * Creates a new code path and trigger the onCodePathStart event * based on the currently selected node. * @param {string} origin The ...
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}
processCodePathToEnter
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function startCodePath(origin) { if (codePath) { // Emits onCodePathSegmentStart events if updated. forwardCurrentToHead(analyzer, node); } // Create the code path of this scope. codePath = analyzer.codePath = new CodePath({ id: analyzer.idGenerator.next(), origin, upper: ...
Creates a new code path and trigger the onCodePathStart event based on the currently selected node. @param {string} origin The reason the code path was started. @returns {void}
startCodePath
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function processCodePathToExit(analyzer, node) { const codePath = analyzer.codePath; const state = CodePath.getState(codePath); let dontForward = false; switch (node.type) { case 'ChainExpression': state.popChainContext(); break; case 'IfStatement': case 'ConditionalExpression': ...
Updates the code path due to the type of a given node in leaving. @param {CodePathAnalyzer} analyzer The instance. @param {ASTNode} node The current AST node. @returns {void}
processCodePathToExit
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function postprocess(analyzer, node) { /** * Ends the code path for the current node. * @returns {void} */ function endCodePath() { let codePath = analyzer.codePath; // Mark the current path as the final node. CodePath.getState(codePath).makeFinal(); // Emits onCodePathSegmentEnd event of...
Updates the code path to finalize the current code path. @param {CodePathAnalyzer} analyzer The instance. @param {ASTNode} node The current AST node. @returns {void}
postprocess
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function endCodePath() { let codePath = analyzer.codePath; // Mark the current path as the final node. CodePath.getState(codePath).makeFinal(); // Emits onCodePathSegmentEnd event of the current segments. leaveFromCurrentSegment(analyzer, node); // Emits onCodePathEnd event of this code path....
Ends the code path for the current node. @returns {void}
endCodePath
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
constructor(emitters) { this.emitter = { emit(event, ...args) { emitters[event]?.(...args); }, }; this.codePath = null; this.idGenerator = new IdGenerator('s'); this.currentNode = null; this.onLooped = this.onLooped.bind(this); }
@param {EventGenerator} eventGenerator An event generator to wrap.
constructor
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
enterNode(node) { this.currentNode = node; // Updates the code path due to node's position in its parent node. if (node.parent) { preprocess(this, node); } /* * Updates the code path. * And emits onCodePathStart/onCodePathSegmentStart events. */ processCodePathToEnter(this...
Does the process to enter a given AST node. This updates state of analysis and calls `enterNode` of the wrapped. @param {ASTNode} node A node which is entering. @returns {void}
enterNode
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
leaveNode(node) { this.currentNode = node; /* * Updates the code path. * And emits onCodePathStart/onCodePathSegmentStart events. */ processCodePathToExit(this, node); // Emits the last onCodePathStart/onCodePathSegmentStart events. postprocess(this, node); this.currentNode = n...
Does the process to leave a given AST node. This updates state of analysis and calls `leaveNode` of the wrapped. @param {ASTNode} node A node which is leaving. @returns {void}
leaveNode
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
onLooped(fromSegment, toSegment) { if (fromSegment.reachable && toSegment.reachable) { this.emitter.emit( 'onCodePathSegmentLoop', fromSegment, toSegment, this.currentNode, ); } }
This is called on a code path looped. Then this raises a looped event. @param {CodePathSegment} fromSegment A segment of prev. @param {CodePathSegment} toSegment A segment of next. @returns {void}
onLooped
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-analyzer.js
MIT
function isReachable(segment) { return segment.reachable; }
Checks whether or not a given segment is reachable. @param {CodePathSegment} segment A segment to check. @returns {boolean} `true` if the segment is reachable.
isReachable
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
constructor(id, allPrevSegments, reachable) { /** * The identifier of this code path. * Rules use it to store additional information of each rule. * @type {string} */ this.id = id; /** * An array of the next segments. * @type {CodePathSegment[]} */ this.nextSegments =...
@param {string} id An identifier. @param {CodePathSegment[]} allPrevSegments An array of the previous segments. This array includes unreachable segments. @param {boolean} reachable A flag which shows this is reachable.
constructor
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
isLoopedPrevSegment(segment) { return this.internal.loopedPrevSegments.includes(segment); }
Checks a given previous segment is coming from the end of a loop. @param {CodePathSegment} segment A previous segment to check. @returns {boolean} `true` if the segment is coming from the end of a loop.
isLoopedPrevSegment
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
static newRoot(id) { return new CodePathSegment(id, [], true); }
Creates the root segment. @param {string} id An identifier. @returns {CodePathSegment} The created segment.
newRoot
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
static newNext(id, allPrevSegments) { return new CodePathSegment( id, CodePathSegment.flattenUnusedSegments(allPrevSegments), allPrevSegments.some(isReachable), ); }
Creates a segment that follows given segments. @param {string} id An identifier. @param {CodePathSegment[]} allPrevSegments An array of the previous segments. @returns {CodePathSegment} The created segment.
newNext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
static newUnreachable(id, allPrevSegments) { const segment = new CodePathSegment( id, CodePathSegment.flattenUnusedSegments(allPrevSegments), false, ); /* * In `if (a) return a; foo();` case, the unreachable segment preceded by * the return statement is not used but must not be ...
Creates an unreachable segment that follows given segments. @param {string} id An identifier. @param {CodePathSegment[]} allPrevSegments An array of the previous segments. @returns {CodePathSegment} The created segment.
newUnreachable
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
static newDisconnected(id, allPrevSegments) { return new CodePathSegment(id, [], allPrevSegments.some(isReachable)); }
Creates a segment that follows given segments. This factory method does not connect with `allPrevSegments`. But this inherits `reachable` flag. @param {string} id An identifier. @param {CodePathSegment[]} allPrevSegments An array of the previous segments. @returns {CodePathSegment} The created segment.
newDisconnected
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
static markUsed(segment) { if (segment.internal.used) { return; } segment.internal.used = true; let i; if (segment.reachable) { for (i = 0; i < segment.allPrevSegments.length; ++i) { const prevSegment = segment.allPrevSegments[i]; prevSegment.allNextSegments.push(segme...
Makes a given segment being used. And this function registers the segment into the previous segments as a next. @param {CodePathSegment} segment A segment to mark. @returns {void}
markUsed
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
static flattenUnusedSegments(segments) { const done = Object.create(null); const retv = []; for (let i = 0; i < segments.length; ++i) { const segment = segments[i]; // Ignores duplicated. if (done[segment.id]) { continue; } // Use previous segments if unused. i...
Replaces unused segments with the previous segments of each unused segment. @param {CodePathSegment[]} segments An array of segments to replace. @returns {CodePathSegment[]} The replaced array.
flattenUnusedSegments
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-segment.js
MIT
function addToReturnedOrThrown(dest, others, all, segments) { for (let i = 0; i < segments.length; ++i) { const segment = segments[i]; dest.push(segment); if (!others.includes(segment)) { all.push(segment); } } }
Adds given segments into the `dest` array. If the `others` array does not includes the given segments, adds to the `all` array as well. This adds only reachable and used segments. @param {CodePathSegment[]} dest A destination array (`returnedSegments` or `thrownSegments`). @param {CodePathSegment[]} others Another des...
addToReturnedOrThrown
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
function getContinueContext(state, label) { if (!label) { return state.loopContext; } let context = state.loopContext; while (context) { if (context.label === label) { return context; } context = context.upper; } /* c8 ignore next */ return null; }
Gets a loop-context for a `continue` statement. @param {CodePathState} state A state to get. @param {string} label The label of a `continue` statement. @returns {LoopContext} A loop-context for a `continue` statement.
getContinueContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
function getBreakContext(state, label) { let context = state.breakContext; while (context) { if (label ? context.label === label : context.breakable) { return context; } context = context.upper; } /* c8 ignore next */ return null; }
Gets a context for a `break` statement. @param {CodePathState} state A state to get. @param {string} label The label of a `break` statement. @returns {LoopContext|SwitchContext} A context for a `break` statement.
getBreakContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
function getReturnContext(state) { let context = state.tryContext; while (context) { if (context.hasFinalizer && context.position !== 'finally') { return context; } context = context.upper; } return state; }
Gets a context for a `return` statement. @param {CodePathState} state A state to get. @returns {TryContext|CodePathState} A context for a `return` statement.
getReturnContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
function getThrowContext(state) { let context = state.tryContext; while (context) { if ( context.position === 'try' || (context.hasFinalizer && context.position === 'catch') ) { return context; } context = context.upper; } return state; }
Gets a context for a `throw` statement. @param {CodePathState} state A state to get. @returns {TryContext|CodePathState} A context for a `throw` statement.
getThrowContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
function remove(xs, x) { xs.splice(xs.indexOf(x), 1); }
Removes a given element from a given array. @param {any[]} xs An array to remove the specific element. @param {any} x An element to be removed. @returns {void}
remove
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
function removeConnection(prevSegments, nextSegments) { for (let i = 0; i < prevSegments.length; ++i) { const prevSegment = prevSegments[i]; const nextSegment = nextSegments[i]; remove(prevSegment.nextSegments, nextSegment); remove(prevSegment.allNextSegments, nextSegment); remove(nextSegment.pre...
Disconnect given segments. This is used in a process for switch statements. If there is the "default" chunk before other cases, the order is different between node's and running's. @param {CodePathSegment[]} prevSegments Forward segments to disconnect. @param {CodePathSegment[]} nextSegments Backward segments to disco...
removeConnection
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) { const fromSegments = CodePathSegment.flattenUnusedSegments( unflattenedFromSegments, ); const toSegments = CodePathSegment.flattenUnusedSegments( unflattenedToSegments, ); const end = Math.min(fromSegments.length, toSegments...
Creates looping path. @param {CodePathState} state The instance. @param {CodePathSegment[]} unflattenedFromSegments Segments which are source. @param {CodePathSegment[]} unflattenedToSegments Segments which are destination. @returns {void}
makeLooped
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
function finalizeTestSegmentsOfFor(context, choiceContext, head) { if (!choiceContext.processed) { choiceContext.trueForkContext.add(head); choiceContext.falseForkContext.add(head); choiceContext.qqForkContext.add(head); } if (context.test !== true) { context.brokenForkContext.addAll(choiceContex...
Finalizes segments of `test` chunk of a ForStatement. - Adds `false` paths to paths which are leaving from the loop. - Sets `true` paths to paths which go to the body. @param {LoopContext} context A loop context to modify. @param {ChoiceContext} choiceContext A choice context of this loop. @param {CodePathSegment[]} h...
finalizeTestSegmentsOfFor
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
constructor(idGenerator, onLooped) { this.idGenerator = idGenerator; this.notifyLooped = onLooped; this.forkContext = ForkContext.newRoot(idGenerator); this.choiceContext = null; this.switchContext = null; this.tryContext = null; this.loopContext = null; this.breakContext = null; thi...
@param {IdGenerator} idGenerator An id generator to generate id for code path segments. @param {Function} onLooped A callback function to notify looping.
constructor
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
get parentForkContext() { const current = this.forkContext; return current && current.upper; }
The parent forking context. This is used for the root of new forks. @type {ForkContext}
parentForkContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
pushForkContext(forkLeavingPath) { this.forkContext = ForkContext.newEmpty(this.forkContext, forkLeavingPath); return this.forkContext; }
Creates and stacks new forking context. @param {boolean} forkLeavingPath A flag which shows being in a "finally" block. @returns {ForkContext} The created context.
pushForkContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
popForkContext() { const lastContext = this.forkContext; this.forkContext = lastContext.upper; this.forkContext.replaceHead(lastContext.makeNext(0, -1)); return lastContext; }
Pops and merges the last forking context. @returns {ForkContext} The last context.
popForkContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
pushChoiceContext(kind, isForkingAsResult) { this.choiceContext = { upper: this.choiceContext, kind, isForkingAsResult, trueForkContext: ForkContext.newEmpty(this.forkContext), falseForkContext: ForkContext.newEmpty(this.forkContext), qqForkContext: ForkContext.newEmpty(this.fork...
Creates a context for ConditionalExpression, LogicalExpression, AssignmentExpression (logical assignments only), IfStatement, WhileStatement, DoWhileStatement, or ForStatement. LogicalExpressions have cases that it goes different paths between the `true` case and the `false` case. For Example: if (a || b) { ...
pushChoiceContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
popChoiceContext() { const context = this.choiceContext; this.choiceContext = context.upper; const forkContext = this.forkContext; const headSegments = forkContext.head; switch (context.kind) { case '&&': case '||': case '??': /* * If any result were not transfe...
Pops the last choice context and finalizes it. @throws {Error} (Unreachable.) @returns {ChoiceContext} The popped context.
popChoiceContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeLogicalRight() { const context = this.choiceContext; const forkContext = this.forkContext; if (context.processed) { /* * This got segments already from the child choice context. * Creates the next path from own true/false fork context. */ let prevForkContext; swi...
Makes a code path segment of the right-hand operand of a logical expression. @throws {Error} (Unreachable.) @returns {void}
makeLogicalRight
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeIfConsequent() { const context = this.choiceContext; const forkContext = this.forkContext; /* * If any result were not transferred from child contexts, * this sets the head segments to both cases. * The head segments are the path of the test expression. */ if (!context.processed...
Makes a code path segment of the `if` block. @returns {void}
makeIfConsequent
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeIfAlternate() { const context = this.choiceContext; const forkContext = this.forkContext; /* * The head segments are the path of the `if` block. * Updates the `true` path with the end of the `if` block. */ context.trueForkContext.clear(); context.trueForkContext.add(forkContext.h...
Makes a code path segment of the `else` block. @returns {void}
makeIfAlternate
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
pushChainContext() { this.chainContext = { upper: this.chainContext, countChoiceContexts: 0, }; }
Push a new `ChainExpression` context to the stack. This method is called on entering to each `ChainExpression` node. This context is used to count forking in the optional chain then merge them on the exiting from the `ChainExpression` node. @returns {void}
pushChainContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
popChainContext() { const context = this.chainContext; this.chainContext = context.upper; // pop all choice contexts of this. for (let i = context.countChoiceContexts; i > 0; --i) { this.popChoiceContext(); } }
Pop a `ChainExpression` context from the stack. This method is called on exiting from each `ChainExpression` node. This merges all forks of the last optional chaining. @returns {void}
popChainContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeOptionalNode() { if (this.chainContext) { this.chainContext.countChoiceContexts += 1; this.pushChoiceContext('??', false); } }
Create a choice context for optional access. This method is called on entering to each `(Call|Member)Expression[optional=true]` node. This creates a choice context as similar to `LogicalExpression[operator="??"]` node. @returns {void}
makeOptionalNode
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeOptionalRight() { if (this.chainContext) { this.makeLogicalRight(); } }
Create a fork. This method is called on entering to the `arguments|property` property of each `(Call|Member)Expression` node. @returns {void}
makeOptionalRight
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
pushSwitchContext(hasCase, label) { this.switchContext = { upper: this.switchContext, hasCase, defaultSegments: null, defaultBodySegments: null, foundDefault: false, lastIsDefault: false, countForks: 0, }; this.pushBreakContext(true, label); }
Creates a context object of SwitchStatement and stacks it. @param {boolean} hasCase `true` if the switch statement has one or more case parts. @param {string|null} label The label text. @returns {void}
pushSwitchContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
popSwitchContext() { const context = this.switchContext; this.switchContext = context.upper; const forkContext = this.forkContext; const brokenForkContext = this.popBreakContext().brokenForkContext; if (context.countForks === 0) { /* * When there is only one `default` chunk and there...
Pops the last context of SwitchStatement and finalizes it. - Disposes all forking stack for `case` and `default`. - Creates the next code path segment from `context.brokenForkContext`. - If the last `SwitchCase` node is not a `default` part, creates a path to the `default` body. @returns {void}
popSwitchContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeSwitchCaseBody(isEmpty, isDefault) { const context = this.switchContext; if (!context.hasCase) { return; } /* * Merge forks. * The parent fork context has two segments. * Those are from the current case and the body of the previous case. */ const parentForkContext = t...
Makes a code path segment for a `SwitchCase` node. @param {boolean} isEmpty `true` if the body is empty. @param {boolean} isDefault `true` if the body is the default case. @returns {void}
makeSwitchCaseBody
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
pushTryContext(hasFinalizer) { this.tryContext = { upper: this.tryContext, position: 'try', hasFinalizer, returnedForkContext: hasFinalizer ? ForkContext.newEmpty(this.forkContext) : null, thrownForkContext: ForkContext.newEmpty(this.forkContext), lastOfTryIsRea...
Creates a context object of TryStatement and stacks it. @param {boolean} hasFinalizer `true` if the try statement has a `finally` block. @returns {void}
pushTryContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
popTryContext() { const context = this.tryContext; this.tryContext = context.upper; if (context.position === 'catch') { // Merges two paths from the `try` block and `catch` block merely. this.popForkContext(); return; } /* * The following process is executed only when there...
Pops the last context of TryStatement and finalizes it. @returns {void}
popTryContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeCatchBlock() { const context = this.tryContext; const forkContext = this.forkContext; const thrown = context.thrownForkContext; // Update state. context.position = 'catch'; context.thrownForkContext = ForkContext.newEmpty(forkContext); context.lastOfTryIsReachable = forkContext.reachabl...
Makes a code path segment for a `catch` block. @returns {void}
makeCatchBlock
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeFinallyBlock() { const context = this.tryContext; let forkContext = this.forkContext; const returned = context.returnedForkContext; const thrown = context.thrownForkContext; const headOfLeavingSegments = forkContext.head; // Update state. if (context.position === 'catch') { // Mer...
Makes a code path segment for a `finally` block. In the `finally` block, parallel paths are created. The parallel paths are used as leaving-paths. The leaving-paths are paths from `return` statements and `throw` statements in a `try` block or a `catch` block. @returns {void}
makeFinallyBlock
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeFirstThrowablePathInTryBlock() { const forkContext = this.forkContext; if (!forkContext.reachable) { return; } const context = getThrowContext(this); if ( context === this || context.position !== 'try' || !context.thrownForkContext.empty ) { return; } ...
Makes a code path segment from the first throwable node to the `catch` block or the `finally` block. @returns {void}
makeFirstThrowablePathInTryBlock
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
pushLoopContext(type, label) { const forkContext = this.forkContext; const breakContext = this.pushBreakContext(true, label); switch (type) { case 'WhileStatement': this.pushChoiceContext('loop', false); this.loopContext = { upper: this.loopContext, type, ...
Creates a context object of a loop statement and stacks it. @param {string} type The type of the node which was triggered. One of `WhileStatement`, `DoWhileStatement`, `ForStatement`, `ForInStatement`, and `ForStatement`. @param {string|null} label A label of the node which was triggered. @throws {Error} (Unreachab...
pushLoopContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
popLoopContext() { const context = this.loopContext; this.loopContext = context.upper; const forkContext = this.forkContext; const brokenForkContext = this.popBreakContext().brokenForkContext; // Creates a looped path. switch (context.type) { case 'WhileStatement': case 'ForStatem...
Pops the last context of a loop statement and finalizes it. @throws {Error} (Unreachable - unknown type.) @returns {void}
popLoopContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeWhileTest(test) { const context = this.loopContext; const forkContext = this.forkContext; const testSegments = forkContext.makeNext(0, -1); // Update state. context.test = test; context.continueDestSegments = testSegments; forkContext.replaceHead(testSegments); }
Makes a code path segment for the test part of a WhileStatement. @param {boolean|undefined} test The test value (only when constant). @returns {void}
makeWhileTest
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeWhileBody() { const context = this.loopContext; const choiceContext = this.choiceContext; const forkContext = this.forkContext; if (!choiceContext.processed) { choiceContext.trueForkContext.add(forkContext.head); choiceContext.falseForkContext.add(forkContext.head); } // Update...
Makes a code path segment for the body part of a WhileStatement. @returns {void}
makeWhileBody
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeDoWhileBody() { const context = this.loopContext; const forkContext = this.forkContext; const bodySegments = forkContext.makeNext(-1, -1); // Update state. context.entrySegments = bodySegments; forkContext.replaceHead(bodySegments); }
Makes a code path segment for the body part of a DoWhileStatement. @returns {void}
makeDoWhileBody
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeDoWhileTest(test) { const context = this.loopContext; const forkContext = this.forkContext; context.test = test; // Creates paths of `continue` statements. if (!context.continueForkContext.empty) { context.continueForkContext.add(forkContext.head); const testSegments = context.cont...
Makes a code path segment for the test part of a DoWhileStatement. @param {boolean|undefined} test The test value (only when constant). @returns {void}
makeDoWhileTest
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeForTest(test) { const context = this.loopContext; const forkContext = this.forkContext; const endOfInitSegments = forkContext.head; const testSegments = forkContext.makeNext(-1, -1); // Update state. context.test = test; context.endOfInitSegments = endOfInitSegments; context.continu...
Makes a code path segment for the test part of a ForStatement. @param {boolean|undefined} test The test value (only when constant). @returns {void}
makeForTest
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeForUpdate() { const context = this.loopContext; const choiceContext = this.choiceContext; const forkContext = this.forkContext; // Make the next paths of the test. if (context.testSegments) { finalizeTestSegmentsOfFor(context, choiceContext, forkContext.head); } else { context.e...
Makes a code path segment for the update part of a ForStatement. @returns {void}
makeForUpdate
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeForBody() { const context = this.loopContext; const choiceContext = this.choiceContext; const forkContext = this.forkContext; // Update state. if (context.updateSegments) { context.endOfUpdateSegments = forkContext.head; // `update` -> `test` if (context.testSegments) { ...
Makes a code path segment for the body part of a ForStatement. @returns {void}
makeForBody
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeForInOfLeft() { const context = this.loopContext; const forkContext = this.forkContext; const leftSegments = forkContext.makeDisconnected(-1, -1); // Update state. context.prevSegments = forkContext.head; context.leftSegments = context.continueDestSegments = leftSegments; forkContext.re...
Makes a code path segment for the left part of a ForInStatement and a ForOfStatement. @returns {void}
makeForInOfLeft
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeForInOfRight() { const context = this.loopContext; const forkContext = this.forkContext; const temp = ForkContext.newEmpty(forkContext); temp.add(context.prevSegments); const rightSegments = temp.makeNext(-1, -1); // Update state. context.endOfLeftSegments = forkContext.head; forkC...
Makes a code path segment for the right part of a ForInStatement and a ForOfStatement. @returns {void}
makeForInOfRight
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeForInOfBody() { const context = this.loopContext; const forkContext = this.forkContext; const temp = ForkContext.newEmpty(forkContext); temp.add(context.endOfLeftSegments); const bodySegments = temp.makeNext(-1, -1); // Make a path: `right` -> `left`. makeLooped(this, forkContext.head,...
Makes a code path segment for the body part of a ForInStatement and a ForOfStatement. @returns {void}
makeForInOfBody
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
pushBreakContext(breakable, label) { this.breakContext = { upper: this.breakContext, breakable, label, brokenForkContext: ForkContext.newEmpty(this.forkContext), }; return this.breakContext; }
Creates new context for BreakStatement. @param {boolean} breakable The flag to indicate it can break by an unlabeled BreakStatement. @param {string|null} label The label of this context. @returns {Object} The new context.
pushBreakContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
popBreakContext() { const context = this.breakContext; const forkContext = this.forkContext; this.breakContext = context.upper; // Process this context here for other than switches and loops. if (!context.breakable) { const brokenForkContext = context.brokenForkContext; if (!brokenFor...
Removes the top item of the break context stack. @returns {Object} The removed context.
popBreakContext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeBreak(label) { const forkContext = this.forkContext; if (!forkContext.reachable) { return; } const context = getBreakContext(this, label); if (context) { context.brokenForkContext.add(forkContext.head); } /* c8 ignore next */ forkContext.replaceHead(forkContext.makeUn...
Makes a path for a `break` statement. It registers the head segment to a context of `break`. It makes new unreachable segment, then it set the head with the segment. @param {string} label A label of the break statement. @returns {void}
makeBreak
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeContinue(label) { const forkContext = this.forkContext; if (!forkContext.reachable) { return; } const context = getContinueContext(this, label); if (context) { if (context.continueDestSegments) { makeLooped(this, forkContext.head, context.continueDestSegments); //...
Makes a path for a `continue` statement. It makes a looping path. It makes new unreachable segment, then it set the head with the segment. @param {string} label A label of the continue statement. @returns {void}
makeContinue
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeReturn() { const forkContext = this.forkContext; if (forkContext.reachable) { getReturnContext(this).returnedForkContext.add(forkContext.head); forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); } }
Makes a path for a `return` statement. It registers the head segment to a context of `return`. It makes new unreachable segment, then it set the head with the segment. @returns {void}
makeReturn
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeThrow() { const forkContext = this.forkContext; if (forkContext.reachable) { getThrowContext(this).thrownForkContext.add(forkContext.head); forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); } }
Makes a path for a `throw` statement. It registers the head segment to a context of `throw`. It makes new unreachable segment, then it set the head with the segment. @returns {void}
makeThrow
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
makeFinal() { const segments = this.currentSegments; if (segments.length > 0 && segments[0].reachable) { this.returnedForkContext.add(segments); } }
Makes the final path. @returns {void}
makeFinal
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path-state.js
MIT
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-in...
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 funct...
constructor
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
MIT
static getState(codePath) { return codePath.internal; }
Gets the state of a given code path. @param {CodePath} codePath A code path to get. @returns {CodePathState} The state of the code path.
getState
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
MIT
get initialSegment() { return this.internal.initialSegment; }
The initial code path segment. @type {CodePathSegment}
initialSegment
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
MIT
get finalSegments() { return this.internal.finalSegments; }
Final code path segments. This array is a mix of `returnedSegments` and `thrownSegments`. @type {CodePathSegment[]}
finalSegments
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
MIT
get returnedSegments() { return this.internal.returnedForkContext; }
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[]}
returnedSegments
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
MIT
get thrownSegments() { return this.internal.thrownForkContext; }
Final code path segments which is with `throw` statements. @type {CodePathSegment[]}
thrownSegments
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
MIT
get currentSegments() { return this.internal.currentSegments; }
Current code path segments. @type {CodePathSegment[]}
currentSegments
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
MIT
function isVisited(prevSegment) { return ( visited[prevSegment.id] || segment.isLoopedPrevSegment(prevSegment) ); }
Checks a given previous segment has been visited. @param {CodePathSegment} prevSegment A previous segment to check. @returns {boolean} `true` if the segment has been visited.
isVisited
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/code-path.js
MIT
function isReachable(segment) { return segment.reachable; }
Gets whether or not a given segment is reachable. @param {CodePathSegment} segment A segment to get. @returns {boolean} `true` if the segment is reachable.
isReachable
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
MIT
function makeSegments(context, begin, end, create) { const list = context.segmentsList; const normalizedBegin = begin >= 0 ? begin : list.length + begin; const normalizedEnd = end >= 0 ? end : list.length + end; const segments = []; for (let i = 0; i < context.count; ++i) { const allPrevSegments = []; ...
Creates new segments from the specific range of `context.segmentsList`. When `context.segmentsList` is `[[a, b], [c, d], [e, f]]`, `begin` is `0`, and `end` is `-1`, this creates `[g, h]`. This `g` is from `a`, `c`, and `e`. This `h` is from `b`, `d`, and `f`. @param {ForkContext} context An instance. @param {number} ...
makeSegments
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
MIT
function mergeExtraSegments(context, segments) { let currentSegments = segments; while (currentSegments.length > context.count) { const merged = []; for ( let i = 0, length = (currentSegments.length / 2) | 0; i < length; ++i ) { merged.push( CodePathSegment.newNext(cont...
`segments` becomes doubly in a `finally` block. Then if a code path exits by a control statement (such as `break`, `continue`) from the `finally` block, the destination's segments may be half of the source segments. In that case, this merges segments. @param {ForkContext} context An instance. @param {CodePathSegment[]}...
mergeExtraSegments
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
MIT
constructor(idGenerator, upper, count) { this.idGenerator = idGenerator; this.upper = upper; this.count = count; this.segmentsList = []; }
@param {IdGenerator} idGenerator An identifier generator for segments. @param {ForkContext|null} upper An upper fork context. @param {number} count A number of parallel segments.
constructor
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
MIT
get empty() { return this.segmentsList.length === 0; }
A flag which shows empty. @type {boolean}
empty
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
MIT
get reachable() { const segments = this.head; return segments.length > 0 && segments.some(isReachable); }
A flag which shows reachable. @type {boolean}
reachable
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
MIT
makeNext(begin, end) { return makeSegments(this, begin, end, CodePathSegment.newNext); }
Creates new segments from this context. @param {number} begin The first index of previous segments. @param {number} end The last index of previous segments. @returns {CodePathSegment[]} New segments.
makeNext
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
MIT
makeUnreachable(begin, end) { return makeSegments(this, begin, end, CodePathSegment.newUnreachable); }
Creates new segments from this context. The new segments is always unreachable. @param {number} begin The first index of previous segments. @param {number} end The last index of previous segments. @returns {CodePathSegment[]} New segments.
makeUnreachable
javascript
facebook/react
packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/code-path-analysis/fork-context.js
MIT