@samitouri / QOS-React-2 / commits / a558b1536a

[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.

Lauren Tan committed Jun 16, 2023 at 12:18 UTC a558b1536a41768d50f4cd5f20ab01ac0eaf9824
2 files changed +27 -33
compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+26 -32
@@ -144,8 +144,9 @@ export function compileProgram(
144 }
145
146 const loweredFn = buildFunctionDeclaration(fn);
147 - if (loweredFn instanceof CompilerError) {
148 - const error = loweredFn;
147 + if (loweredFn instanceof CompilerErrorDetail) {
148 + const error = new CompilerError();
149 + error.pushErrorDetail(loweredFn);
150
151 const options = parsePluginOptions(pass.opts);
152 if (options.logger != null) {
@@ -345,48 +346,41 @@ function log(error: CompilerError, filename: string | null): void {
346 );
347 }
348
348 -function makeError(
349 - reason: string,
350 - loc: t.SourceLocation | null
351 -): CompilerError {
352 - const error = new CompilerError();
353 - error.pushErrorDetail(
354 - new CompilerErrorDetail({
355 - reason,
356 - description: null,
357 - severity: ErrorSeverity.InvalidInput,
358 - codeframe: null,
359 - loc,
360 - })
361 - );
362 - return error;
363 -}
364 -
349 function buildFunctionDeclaration(
350 fn: NodePath<t.ArrowFunctionExpression>
367 -): NodePath<t.FunctionDeclaration> | CompilerError {
351 +): NodePath<t.FunctionDeclaration> | CompilerErrorDetail {
352 if (!fn.parentPath.isVariableDeclarator()) {
369 - return makeError(
370 - "ArrowFunctionExpression must be declared in variable declaration",
371 - fn.node.loc ?? null
372 - );
353 + return new CompilerErrorDetail({
354 + reason:
355 + "ArrowFunctionExpression was not declared in a variable declaration",
356 + severity: ErrorSeverity.Todo,
357 + description: `Handle ${fn.parentPath.type}`,
358 + codeframe: null,
359 + loc: fn.node.loc ?? null,
360 + });
361 }
362 const variableDeclarator = fn.parentPath;
363
364 if (!variableDeclarator.parentPath.isVariableDeclaration()) {
377 - return makeError(
378 - "ArrowFunctionExpression must be a single declaration",
379 - fn.node.loc ?? null
380 - );
365 + return new CompilerErrorDetail({
366 + reason: "ArrowFunctionExpression was not a single declaration",
367 + severity: ErrorSeverity.Todo,
368 + description: `Handle ${variableDeclarator.parentPath.type}`,
369 + codeframe: null,
370 + loc: fn.node.loc ?? null,
371 + });
372 }
373 const variableDeclaration = variableDeclarator.parentPath;
374
375 const id = variableDeclarator.get("id");
376 if (!id.isIdentifier()) {
386 - return makeError(
387 - "ArrowFunctionExpression must have an id",
388 - fn.node.loc ?? null
389 - );
377 + return new CompilerErrorDetail({
378 + reason: "ArrowFunctionExpression was not an identifier",
379 + severity: ErrorSeverity.Todo,
380 + description: `Handle ${id.type}`,
381 + codeframe: null,
382 + loc: fn.node.loc ?? null,
383 + });
384 }
385
386 const rewrittenFn = variableDeclaration.replaceWith(
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error._todo.multi-arrow-expr-export-default-gating-test.expect.md
+1 -1
@@ -18,7 +18,7 @@ export default Renderer = (props) => (
18 ## Error
19
20 ```
21 -[ReactForget] InvalidInput: ArrowFunctionExpression must be declared in variable declaration (4:9)
21 +[ReactForget] Todo: ArrowFunctionExpression was not declared in a variable declaration. Handle AssignmentExpression (4:9)
22 ```
23
24
\ No newline at end of file