* Returns the used name. * @param {ExportInfoName | ExportInfoName[]} name the export name * @param {RuntimeSpec} runtime check usage for this runtime only * @returns {UsedName} the used name
(name, runtime)
| 801 | * @returns {UsedName} the used name |
| 802 | */ |
| 803 | getUsedName(name, runtime) { |
| 804 | if (Array.isArray(name)) { |
| 805 | if (name.length === 0) { |
| 806 | if (!this.isUsed(runtime)) return false; |
| 807 | return name; |
| 808 | } |
| 809 | // Walk the nested path once, collecting used names into a single array |
| 810 | // instead of slicing/spreading at every level. |
| 811 | /** @type {ExportsInfo} */ |
| 812 | let exportsInfo = this; |
| 813 | /** @type {ExportInfoName[] | undefined} */ |
| 814 | let result; |
| 815 | const last = name.length - 1; |
| 816 | for (let i = 0; ; i++) { |
| 817 | const info = exportsInfo.getReadOnlyExportInfo(name[i]); |
| 818 | const x = info.getUsedName(name[i], runtime); |
| 819 | if (x === false) return false; |
| 820 | if (x instanceof InlinedUsedName) { |
| 821 | // The inlined value replaces the prefix; trailing ids become its suffix |
| 822 | if (i === last) return x; |
| 823 | return new InlinedUsedName(x.value, [ |
| 824 | ...x.suffix, |
| 825 | ...name.slice(i + 1) |
| 826 | ]); |
| 827 | } |
| 828 | if (i === last) { |
| 829 | if (result === undefined) return x === name[i] ? name : [x]; |
| 830 | result.push(x); |
| 831 | return result; |
| 832 | } |
| 833 | if (result === undefined) result = []; |
| 834 | result.push(x); |
| 835 | // Descend only while the parent is reached purely via property access |
| 836 | if ( |
| 837 | info.exportsInfo && |
| 838 | info.getUsed(runtime) === UsageState.OnlyPropertiesUsed |
| 839 | ) { |
| 840 | exportsInfo = info.exportsInfo; |
| 841 | continue; |
| 842 | } |
| 843 | // Cannot descend further: keep the remaining ids unchanged |
| 844 | for (let j = i + 1; j <= last; j++) result.push(name[j]); |
| 845 | return result; |
| 846 | } |
| 847 | } |
| 848 | const info = this.getReadOnlyExportInfo(name); |
| 849 | return info.getUsedName(name, runtime); |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Checks whether `getUsedName(name, runtime)` would return an `InlinedUsedName`, |
nothing calls this directly
no test coverage detected