(positionals: string[])
| 23 | } |
| 24 | |
| 25 | export function readFillTargetFromPositionals(positionals: string[]): DecodedFillTarget { |
| 26 | const firstPositional = positionals[0]; |
| 27 | if (firstPositional?.startsWith('@')) { |
| 28 | const text = |
| 29 | positionals.length >= 3 ? positionals.slice(2).join(' ') : positionals.slice(1).join(' '); |
| 30 | return { |
| 31 | kind: 'ref', |
| 32 | target: { |
| 33 | ref: firstPositional, |
| 34 | label: positionals.length >= 3 ? optionalTrimmedText(positionals.slice(1, 2)) : undefined, |
| 35 | }, |
| 36 | text, |
| 37 | }; |
| 38 | } |
| 39 | const selectorArgs = splitSelectorFromArgs(positionals, { preferTrailingValue: true }); |
| 40 | if (selectorArgs) { |
| 41 | return { |
| 42 | kind: 'selector', |
| 43 | target: { selector: selectorArgs.selectorExpression }, |
| 44 | text: selectorArgs.rest.join(' '), |
| 45 | }; |
| 46 | } |
| 47 | return { |
| 48 | kind: 'point', |
| 49 | target: { x: Number(positionals[0]), y: Number(positionals[1]) }, |
| 50 | text: positionals.slice(2).join(' '), |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | function optionalTrimmedText(parts: string[]): string | undefined { |
| 55 | const text = parts.join(' ').trim(); |
no test coverage detected