* The constructor (or class) a function assigned to `Ctor.prototype.m` or * `Ctor.m` is a method of, with the method's name, when `Ctor` is a function * or class declared in the scope the assignment is written in (#2966) — the * classic way to give a constructor its methods, and its static
(assignment: SyntaxNode, value: SyntaxNode)
| 2498 | * Mirrored in the kernel (tsjs/extractors.rs constructor_member). |
| 2499 | */ |
| 2500 | private constructorMember(assignment: SyntaxNode, value: SyntaxNode): { owner: Node; name: string; isStatic: boolean } | null { |
| 2501 | if (!this.ownsObjectLiterals()) return null; |
| 2502 | const right = getChildByField(assignment, 'right'); |
| 2503 | if (!right || right.startIndex !== value.startIndex || right.endIndex !== value.endIndex) return null; |
| 2504 | const left = getChildByField(assignment, 'left'); |
| 2505 | if (left?.type !== 'member_expression') return null; |
| 2506 | const property = getChildByField(left, 'property'); |
| 2507 | if (property?.type !== 'property_identifier') return null; |
| 2508 | const name = getNodeText(property, this.source); |
| 2509 | if (name === 'prototype') return null; |
| 2510 | let object = getChildByField(left, 'object'); |
| 2511 | let isStatic = true; |
| 2512 | if (object?.type === 'member_expression') { |
| 2513 | const link = getChildByField(object, 'property'); |
| 2514 | if (link?.type !== 'property_identifier' || getNodeText(link, this.source) !== 'prototype') return null; |
| 2515 | object = getChildByField(object, 'object'); |
| 2516 | isStatic = false; |
| 2517 | } |
| 2518 | if (object?.type !== 'identifier') return null; |
| 2519 | const scopeId = this.nodeStack[this.nodeStack.length - 1]; |
| 2520 | const owner = scopeId ? this.scopeDeclarations.get(`${scopeId}\0${getNodeText(object, this.source)}`) : undefined; |
| 2521 | return owner ? { owner, name, isStatic } : null; |
| 2522 | } |
| 2523 | |
| 2524 | /** |
| 2525 | * Extract a function assigned to `Ctor.prototype.m` / `Ctor.m` as method `m` |
no test coverage detected