* 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)
| 256 | * @returns {void} |
| 257 | */ |
| 258 | function 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 | } |
no test coverage detected
searching dependent graphs…