Skip to content

Commit

Permalink
refactor: remove explicit type casts form STEPS as they just make it …
Browse files Browse the repository at this point in the history
…harder to read
  • Loading branch information
EagleoutIce committed Aug 28, 2023
1 parent 422e570 commit 2b4e4a9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const STEPS_PER_FILE = {
printer: {
[StepOutputFormat.internal]: internalPrinter
}
} satisfies IStep<typeof retrieveXmlFromRCode> as IStep<typeof retrieveXmlFromRCode>,
} satisfies IStep<typeof retrieveXmlFromRCode>,
'normalize': {
step: 'normalize',
description: 'Normalize the AST to flowR\'s AST (first step of the normalization)',
Expand All @@ -62,7 +62,7 @@ export const STEPS_PER_FILE = {
printer: {
[StepOutputFormat.internal]: internalPrinter
}
} satisfies IStep<typeof normalize> as IStep<typeof normalize>,
} satisfies IStep<typeof normalize>,
'dataflow': {
step: 'dataflow',
description: 'Construct the dataflow graph',
Expand All @@ -71,10 +71,9 @@ export const STEPS_PER_FILE = {
printer: {
[StepOutputFormat.internal]: internalPrinter
}
} satisfies IStep<typeof produceDataFlowGraph> as IStep<typeof produceDataFlowGraph>
} satisfies IStep<typeof produceDataFlowGraph>
} as const


export const STEPS_PER_SLICE = {
'slice': {
step: 'slice',
Expand All @@ -84,7 +83,7 @@ export const STEPS_PER_SLICE = {
printer: {
[StepOutputFormat.internal]: internalPrinter
}
} satisfies IStep<typeof staticSlicing> as IStep<typeof staticSlicing>,
} satisfies IStep<typeof staticSlicing>,
'reconstruct': {
step: 'reconstruct',
description: 'Reconstruct R code from the static slice',
Expand All @@ -93,7 +92,7 @@ export const STEPS_PER_SLICE = {
printer: {
[StepOutputFormat.internal]: internalPrinter
}
} satisfies IStep<typeof reconstructToCode> as IStep<typeof reconstructToCode>
} satisfies IStep<typeof reconstructToCode>
} as const

export const STEPS = { ...STEPS_PER_FILE, ...STEPS_PER_SLICE } as const
Expand All @@ -106,6 +105,7 @@ export type SubStepProcessor<name extends SubStepName> = SubStep<name>['processo
export type SubStepResult<name extends SubStepName> = Awaited<ReturnType<SubStepProcessor<name>>>

export function executeSingleSubStep<Name extends SubStepName, Processor extends SubStepProcessor<Name>>(subStep: Name, ...input: Parameters<Processor>): ReturnType<Processor> {
// @ts-expect-error - this is safe, as we know that the function arguments are correct by 'satisfies', this saves an explicit cast with 'as'
return STEPS[subStep].processor(...input as unknown as never[]) as ReturnType<Processor>
}

0 comments on commit 2b4e4a9

Please sign in to comment.