feat: remove 'original' and __file (#59446)

This commit is contained in:
Oliver Eyton-Williams
2025-03-26 22:34:06 +01:00
committed by GitHub
parent d91f57b12b
commit 350424701f
10 changed files with 5 additions and 25 deletions
@@ -341,8 +341,7 @@ function* updatePython(challengeData) {
interruptCodeExecution();
const code = {
contents: buildData.sources.index,
editableContents: buildData.sources.editableContents,
original: buildData.sources.original
editableContents: buildData.sources.editableContents
};
runPythonCode(code);
@@ -74,22 +74,18 @@ const applyFunction =
const composeFunctions = (...fns: ApplyFunctionProps[]) =>
fns.map(applyFunction).reduce((f, g) => x => f(x).then(g));
// TODO: split this into at least two functions. One to create 'original' i.e.
// the source and another to create the contents.
function buildSourceMap(challengeFiles: ChallengeFile[]): Source | undefined {
// TODO: rename sources.index to sources.contents.
const source: Source | undefined = challengeFiles?.reduce(
(sources, challengeFile) => {
sources.index += challengeFile.source || '';
sources.contents = sources.index;
sources.original[challengeFile.history[0]] = challengeFile.source ?? null;
sources.editableContents += challengeFile.editableContents || '';
return sources;
},
{
index: '',
editableContents: '',
original: {}
editableContents: ''
} as Source
);
return source;
@@ -181,8 +177,7 @@ function getWorkerTestRunner(
) {
const code = {
contents: sources.index,
editableContents: sources.editableContents,
original: sources.original
editableContents: sources.editableContents
};
interface TestWorkerExecutor extends WorkerExecutor {
@@ -13,7 +13,6 @@ export interface Source {
index: string;
contents?: string;
editableContents: string;
original: { [key: string]: string | null };
}
interface Hooks {
@@ -8,7 +8,6 @@ let listener: ((event: MessageEvent) => void) | null = null;
type Code = {
contents: string;
editableContents: string;
original: string;
};
// We need to keep track of the last code message so we can re-run it if the
// worker is reset.
@@ -102,7 +101,6 @@ export function interruptCodeExecution(): void {
export function runPythonCode(code: {
contents: string;
editableContents: string;
original: string;
}): void {
lastCodeMessage = code;
getPythonWorker().postMessage({ type: 'run', code });
+1 -2
View File
@@ -570,8 +570,7 @@ async function createTestRunner(
const code = {
contents: sources.index,
editableContents: sources.editableContents,
original: sources.original
editableContents: sources.editableContents
};
const buildFunction = buildFunctions[challenge.challengeType];
@@ -11,13 +11,7 @@ frameDocument.__initTestFrame = initTestFrame;
async function initTestFrame(e: InitTestFrameArg = { code: {} }) {
const code = (e.code.contents || '').slice();
const __file = (id?: string) => {
if (id && e.code.original) {
return e.code.original[id];
} else {
return code;
}
};
const editableContents = (e.code.editableContents || '').slice();
// __testEditable allows test authors to run tests against a transitory dom
// element built using only the code in the editable region.
-1
View File
@@ -18,7 +18,6 @@ export interface InitTestFrameArg {
code: {
contents?: string;
editableContents?: string;
original?: { [id: string]: string | null };
};
getUserInput?: (fileName: string) => string;
loadEnzyme?: () => void;
@@ -16,7 +16,6 @@ interface PythonRunEvent extends MessageEvent {
code: {
contents: string;
editableContents: string;
original: { [id: string]: string };
};
firstTest: unknown;
testString: string;
@@ -21,7 +21,6 @@ interface PythonRunEvent extends MessageEvent {
code: {
contents: string;
editableContents: string;
original: { [id: string]: string };
};
};
}
@@ -103,7 +103,6 @@ interface TestEvaluatorEvent extends MessageEvent {
code: {
contents: string;
editableContents: string;
original: { [id: string]: string };
};
firstTest: unknown;
testString: string;