MCPcopy
hub / github.com/eslint/eslint / preprocess

Function preprocess

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

* 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. * @retur

(analyzer, node)

Source from the content-addressed store, hash-verified

256 * @returns {void}
257 */
258function preprocess(analyzer, node) {
259 const codePath = analyzer.codePath;
260 const state = CodePath.getState(codePath);
261 const parent = node.parent;
262
263 switch (parent.type) {
264 // The `arguments.length == 0` case is in `postprocess` function.
265 case "CallExpression":
266 if (
267 parent.optional === true &&
268 parent.arguments.length >= 1 &&
269 parent.arguments[0] === node
270 ) {
271 state.makeOptionalRight();
272 }
273 break;
274 case "MemberExpression":
275 if (parent.optional === true && parent.property === node) {
276 state.makeOptionalRight();
277 }
278 break;
279
280 case "LogicalExpression":
281 if (
282 parent.right === node &&
283 isHandledLogicalOperator(parent.operator)
284 ) {
285 state.makeLogicalRight();
286 }
287 break;
288
289 case "AssignmentExpression":
290 if (
291 parent.right === node &&
292 isLogicalAssignmentOperator(parent.operator)
293 ) {
294 state.makeLogicalRight();
295 }
296 break;
297
298 case "ConditionalExpression":
299 case "IfStatement":
300 /*
301 * Fork if this node is at `consequent`/`alternate`.
302 * `popForkContext()` exists at `IfStatement:exit` and
303 * `ConditionalExpression:exit`.
304 */
305 if (parent.consequent === node) {
306 state.makeIfConsequent();
307 } else if (parent.alternate === node) {
308 state.makeIfAlternate();
309 }
310 break;
311
312 case "SwitchCase":
313 if (parent.consequent[0] === node) {
314 state.makeSwitchCaseBody(false, !parent.test);
315 }

Callers 1

enterNodeMethod · 0.70

Calls 15

isHandledLogicalOperatorFunction · 0.85
getStateMethod · 0.80
makeOptionalRightMethod · 0.80
makeLogicalRightMethod · 0.80
makeIfConsequentMethod · 0.80
makeIfAlternateMethod · 0.80
makeSwitchCaseBodyMethod · 0.80
makeCatchBlockMethod · 0.80
makeFinallyBlockMethod · 0.80
makeWhileTestMethod · 0.80
makeWhileBodyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…