( instruction: StateEditInstruction, previous: string | null )
| 424 | } |
| 425 | |
| 426 | async function plannedContentForInstruction( |
| 427 | instruction: StateEditInstruction, |
| 428 | previous: string | null |
| 429 | ): Promise<string> { |
| 430 | if (instruction.kind === "write") { |
| 431 | return instruction.content; |
| 432 | } |
| 433 | |
| 434 | if (instruction.kind === "writeJson") { |
| 435 | return stringifyJsonFileContent( |
| 436 | instruction.value, |
| 437 | instruction.path, |
| 438 | instruction.options?.spaces |
| 439 | ); |
| 440 | } |
| 441 | |
| 442 | if (previous === null) { |
| 443 | throw new Error(`ENOENT: no such file: ${instruction.path}`); |
| 444 | } |
| 445 | |
| 446 | return replaceTextContent( |
| 447 | previous, |
| 448 | instruction.search, |
| 449 | instruction.replacement, |
| 450 | instruction.options |
| 451 | ).content; |
| 452 | } |
| 453 | |
| 454 | function createTextMatcher(query: string, options: StateSearchOptions): RegExp { |
| 455 | if (query.length === 0) { |
no test coverage detected