| 646 | const isNumberOrNumeric = (s: string | number) => typeof s === 'number' || /^[0-9]+$/.test(s); |
| 647 | |
| 648 | class Variable implements IVariable { |
| 649 | public id = getVariableId(); |
| 650 | |
| 651 | /** Gets the variable name in its parent scope or object. */ |
| 652 | public get name() { |
| 653 | return this.context.name; |
| 654 | } |
| 655 | |
| 656 | /** Gets the presentation hint set by the parent. */ |
| 657 | public get sortOrder() { |
| 658 | return this.context.sortOrder; |
| 659 | } |
| 660 | |
| 661 | constructor( |
| 662 | protected readonly context: VariableContext, |
| 663 | public readonly remoteObject: Cdp.Runtime.RemoteObject, |
| 664 | ) {} |
| 665 | |
| 666 | /** |
| 667 | * Gets the accessor though which this object can be read. |
| 668 | */ |
| 669 | public get accessor(): string { |
| 670 | const { parent, name, isCustomProperty } = this.context; |
| 671 | if (parent instanceof AccessorVariable) { |
| 672 | return parent.accessor; |
| 673 | } |
| 674 | |
| 675 | if (!(parent instanceof Variable)) { |
| 676 | return this.context.name; |
| 677 | } |
| 678 | |
| 679 | if (isCustomProperty) { |
| 680 | const prefix = `${parent.accessor}[Symbol.for(${ |
| 681 | JSON.stringify(DescriptionSymbols.Properties) |
| 682 | })]()`; |
| 683 | if (isNumberOrNumeric(name)) { |
| 684 | return `${prefix}[${name}]`; |
| 685 | } |
| 686 | if (identifierRe.test(name)) { |
| 687 | return `${prefix}.${name}`; |
| 688 | } |
| 689 | return `${prefix}[${JSON.stringify(name)}]`; |
| 690 | } |
| 691 | |
| 692 | // Maps and sets: |
| 693 | const grandparent = parent.context.parent; |
| 694 | if (grandparent instanceof Variable) { |
| 695 | if ((this.remoteObject.subtype as string) === 'internal#entry') { |
| 696 | return `[...${grandparent.accessor}.entries()][${+name}]`; |
| 697 | } |
| 698 | |
| 699 | if ((parent.remoteObject.subtype as string) === 'internal#entry') { |
| 700 | return `${parent.accessor}[${this.name === 'key' ? 0 : 1}]`; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | if (isNumberOrNumeric(name)) { |
| 705 | return `${parent.accessor}[${name}]`; |
nothing calls this directly
no outgoing calls
no test coverage detected