From a558b1536a41768d50f4cd5f20ab01ac0eaf9824 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Fri, 16 Jun 2023 12:18:45 -0400 Subject: [PATCH] [babel-plugin] buildFunctionDeclaration errors are todos The existing errors thrown were marked as InvalidInput, which is now considered critical. This was causing an error in the sync since we had 2 occurrences of the errors being thrown. These are really todos and not invalid code. --- .../src/Entrypoint/Program.ts | 58 +++++++++---------- ...-expr-export-default-gating-test.expect.md | 2 +- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts b/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts index 14eb51b01b..e63751e53c 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts @@ -144,8 +144,9 @@ export function compileProgram( } const loweredFn = buildFunctionDeclaration(fn); - if (loweredFn instanceof CompilerError) { - const error = loweredFn; + if (loweredFn instanceof CompilerErrorDetail) { + const error = new CompilerError(); + error.pushErrorDetail(loweredFn); const options = parsePluginOptions(pass.opts); if (options.logger != null) { @@ -345,48 +346,41 @@ function log(error: CompilerError, filename: string | null): void { ); } -function makeError( - reason: string, - loc: t.SourceLocation | null -): CompilerError { - const error = new CompilerError(); - error.pushErrorDetail( - new CompilerErrorDetail({ - reason, - description: null, - severity: ErrorSeverity.InvalidInput, - codeframe: null, - loc, - }) - ); - return error; -} - function buildFunctionDeclaration( fn: NodePath -): NodePath | CompilerError { +): NodePath | CompilerErrorDetail { if (!fn.parentPath.isVariableDeclarator()) { - return makeError( - "ArrowFunctionExpression must be declared in variable declaration", - fn.node.loc ?? null - ); + return new CompilerErrorDetail({ + reason: + "ArrowFunctionExpression was not declared in a variable declaration", + severity: ErrorSeverity.Todo, + description: `Handle ${fn.parentPath.type}`, + codeframe: null, + loc: fn.node.loc ?? null, + }); } const variableDeclarator = fn.parentPath; if (!variableDeclarator.parentPath.isVariableDeclaration()) { - return makeError( - "ArrowFunctionExpression must be a single declaration", - fn.node.loc ?? null - ); + return new CompilerErrorDetail({ + reason: "ArrowFunctionExpression was not a single declaration", + severity: ErrorSeverity.Todo, + description: `Handle ${variableDeclarator.parentPath.type}`, + codeframe: null, + loc: fn.node.loc ?? null, + }); } const variableDeclaration = variableDeclarator.parentPath; const id = variableDeclarator.get("id"); if (!id.isIdentifier()) { - return makeError( - "ArrowFunctionExpression must have an id", - fn.node.loc ?? null - ); + return new CompilerErrorDetail({ + reason: "ArrowFunctionExpression was not an identifier", + severity: ErrorSeverity.Todo, + description: `Handle ${id.type}`, + codeframe: null, + loc: fn.node.loc ?? null, + }); } const rewrittenFn = variableDeclaration.replaceWith( diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error._todo.multi-arrow-expr-export-default-gating-test.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error._todo.multi-arrow-expr-export-default-gating-test.expect.md index fbac6be13b..0b746a2a3a 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error._todo.multi-arrow-expr-export-default-gating-test.expect.md +++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error._todo.multi-arrow-expr-export-default-gating-test.expect.md @@ -18,7 +18,7 @@ export default Renderer = (props) => ( ## Error ``` -[ReactForget] InvalidInput: ArrowFunctionExpression must be declared in variable declaration (4:9) +[ReactForget] Todo: ArrowFunctionExpression was not declared in a variable declaration. Handle AssignmentExpression (4:9) ``` \ No newline at end of file