Skip to content

Commit 091b835

Browse files
committed
refactor: simplify replay fill positional typing
1 parent f6f2569 commit 091b835

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/replay/script.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,22 +282,21 @@ function parseReplayScriptLine(line: string): SessionAction | null {
282282
if (command === 'fill') {
283283
const parsed = parseReplaySeriesFlags(command, args);
284284
Object.assign(action.flags, parsed.flags);
285-
const target = parsed.positionals[0];
286-
const text = parsed.positionals[1];
287-
if (target === undefined || text === undefined) {
285+
if (!hasFillTargetAndText(parsed.positionals)) {
288286
action.positionals = parsed.positionals;
289287
return action;
290288
}
289+
const [target, text, ...textRest] = parsed.positionals;
291290
if (target.startsWith('@')) {
292-
if (parsed.positionals.length >= 3) {
293-
action.positionals = [target, parsed.positionals.slice(2).join(' ')];
294-
action.result = { refLabel: parsed.positionals[1] };
291+
if (textRest.length > 0) {
292+
action.positionals = [target, textRest.join(' ')];
293+
action.result = { refLabel: text };
295294
return action;
296295
}
297296
action.positionals = [target, text];
298297
return action;
299298
}
300-
action.positionals = [target, parsed.positionals.slice(1).join(' ')];
299+
action.positionals = [target, [text, ...textRest].join(' ')];
301300
return action;
302301
}
303302

@@ -375,6 +374,10 @@ function parseReplayScriptLine(line: string): SessionAction | null {
375374
return action;
376375
}
377376

377+
function hasFillTargetAndText(positionals: string[]): positionals is [string, string, ...string[]] {
378+
return positionals.length >= 2;
379+
}
380+
378381
function isNumericToken(token: string | undefined): token is string {
379382
if (!token) return false;
380383
return !Number.isNaN(Number(token));

0 commit comments

Comments
 (0)