* A TS/JS receiver that subscripts the enclosing class's object: an element * of a field, `this. [k]` → `this. []`, or a field named by a * string key, `this['svc']` → `this.svc`. Null for any other subscript. * Mirrored in the kernel's this_subscript_of.
(node: SyntaxNode, source: string)
| 762 | * Mirrored in the kernel's this_subscript_of. |
| 763 | */ |
| 764 | function tsThisSubscriptReceiver(node: SyntaxNode, source: string): string | null { |
| 765 | if (node.type !== 'subscript_expression') return null; |
| 766 | const objectNode = getChildByField(node, 'object'); |
| 767 | if (!objectNode) return null; |
| 768 | const object = peelTsJsReceiver(objectNode); |
| 769 | if (object.type === 'this') { |
| 770 | const key = quotedIdentifier(getChildByField(node, 'index'), source); |
| 771 | return key ? `this.${key}` : null; |
| 772 | } |
| 773 | if (object.type !== 'member_expression' || getChildByField(object, 'object')?.type !== 'this') return null; |
| 774 | const property = getChildByField(object, 'property'); |
| 775 | if (!property || !THIS_FIELD_PROPERTY_TYPES.has(property.type)) return null; |
| 776 | return `this.${getNodeText(property, source)}[]`; |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * Whether a TS/JS receiver still collapses to the bare method name: `this` / |
no test coverage detected