(node: ts.Node)
| 521 | |
| 522 | // Visit recursive function navigate constructor |
| 523 | const visit = (node: ts.Node) => { |
| 524 | // Check if current node is identifier (variable) |
| 525 | if (ts.isIdentifier(node)) { |
| 526 | // Using the type checker, verify that this identifier refers |
| 527 | // exactly to our destructured parameter and is not the node of the original declaration. |
| 528 | if (localTypeChecker.getSymbolAtLocation(node) === symbol && node !== element.name) { |
| 529 | // If the identifier is used as a shorthand property in an object literal (e.g., { myVar }), |
| 530 | // must replace the entire `ShorthandPropertyAssignment` node |
| 531 | // with a `PropertyAssignment` (e.g., myVar: this.myVar). |
| 532 | if (ts.isShorthandPropertyAssignment(node.parent)) { |
| 533 | tracker.replaceNode( |
| 534 | node.parent, |
| 535 | ts.factory.createPropertyAssignment( |
| 536 | node, |
| 537 | ts.factory.createPropertyAccessExpression(ts.factory.createThis(), propertyName), |
| 538 | ), |
| 539 | ); |
| 540 | } else { |
| 541 | // Otherwise, replace the identifier with `this.propertyName`. |
| 542 | tracker.replaceNode( |
| 543 | node, |
| 544 | ts.factory.createPropertyAccessExpression(ts.factory.createThis(), propertyName), |
| 545 | ); |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | ts.forEachChild(node, visit); |
| 550 | }; |
| 551 | |
| 552 | visit(constructorDecl.body); |
| 553 | } |
no test coverage detected