Skip to content

Commit

Permalink
[compiler] Fix snap types
Browse files Browse the repository at this point in the history
ghstack-source-id: 3174790e7abd5b0bcb8cf5a819d096adb99fa5f8
Pull Request resolved: #29217
  • Loading branch information
poteto committed May 22, 2024
1 parent ea68ad7 commit b31de51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 10 additions & 5 deletions compiler/packages/snap/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ function getEvaluatorPresets(
);
return presets;
}
function format(inputCode: string, language: "typescript" | "flow"): string {
return prettier.format(inputCode, {
async function format(
inputCode: string,
language: "typescript" | "flow",
): Promise<string> {
return await prettier.format(inputCode, {
semi: true,
parser: language === "typescript" ? "babel-ts" : "flow",
});
Expand All @@ -287,13 +290,15 @@ export type TransformResult = {
} | null;
};

export function transformFixtureInput(
export async function transformFixtureInput(
input: string,
fixturePath: string,
parseConfigPragmaFn: typeof ParseConfigPragma,
plugin: BabelCore.PluginObj,
includeEvaluator: boolean,
): { kind: "ok"; value: TransformResult } | { kind: "err"; msg: string } {
): Promise<
{ kind: "ok"; value: TransformResult } | { kind: "err"; msg: string }
> {
// Extract the first line to quickly check for custom test directives
const firstLine = input.substring(0, input.indexOf("\n"));

Expand Down Expand Up @@ -400,7 +405,7 @@ export function transformFixtureInput(
return {
kind: "ok",
value: {
forgetOutput: format(forgetOutput, language),
forgetOutput: await format(forgetOutput, language),
evaluatorCode,
},
};
Expand Down
10 changes: 5 additions & 5 deletions compiler/packages/snap/src/runner-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ export function clearRequireCache() {
});
}

function compile(
async function compile(
input: string,
fixturePath: string,
compilerVersion: number,
shouldLog: boolean,
includeEvaluator: boolean,
): {
): Promise<{
error: string | null;
compileResult: TransformResult | null;
} {
}> {
const seenConsoleErrors: Array<string> = [];
console.error = (...messages: Array<string>) => {
seenConsoleErrors.push(...messages);
Expand All @@ -68,7 +68,7 @@ function compile(
// only try logging if we filtered out all but one fixture,
// since console log order is non-deterministic
toggleLogging(shouldLog);
const result = transformFixtureInput(
const result = await transformFixtureInput(
input,
fixturePath,
parseConfigPragma,
Expand Down Expand Up @@ -147,7 +147,7 @@ export async function transformFixture(
unexpectedError: null,
};
}
const { compileResult, error } = compile(
const { compileResult, error } = await compile(
input,
fixture.fixturePath,
compilerVersion,
Expand Down

0 comments on commit b31de51

Please sign in to comment.