(str: string)
| 49 | ) {} |
| 50 | |
| 51 | static fromString(str: string): BazelLabel { |
| 52 | let repo: string | undefined; |
| 53 | if (str.startsWith('@')) { |
| 54 | const slashSlashIndex = str.indexOf('//'); |
| 55 | if (slashSlashIndex <= 0) { |
| 56 | throw new Error(`Expected // after repo name (got ${str})`); |
| 57 | } |
| 58 | |
| 59 | repo = str.slice(1, slashSlashIndex); |
| 60 | str = str.slice(slashSlashIndex); |
| 61 | } |
| 62 | if (str.endsWith('/')) { |
| 63 | str = str.slice(0, -1); |
| 64 | } |
| 65 | |
| 66 | const separatorIndex = str.indexOf(':'); |
| 67 | if (separatorIndex >= 0) { |
| 68 | const target = str.slice(0, separatorIndex); |
| 69 | const name = str.slice(separatorIndex + 1); |
| 70 | return new BazelLabel(repo, target, name); |
| 71 | } else { |
| 72 | return new BazelLabel(repo, str, undefined); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | get apparentRepo(): string | undefined { |
| 77 | if (!this.repo) return undefined; |
no test coverage detected