From 346f6c13a838a3c99dac3a3c01d67f32da28e366 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Tue, 19 Mar 2024 16:39:05 -0700 Subject: [PATCH] Todo for fbt with multiple fbt:enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I need to do more debugging to figure out exactly why the example earlier fails — but whatever it is, it's clearly a matter of the fbt plugin relying on some specifics of source locations. Here we just detect multiple instances of `` within a given `` tag and throw a todo. --- .../src/HIR/BuildHIR.ts | 19 +++++++++++++++++++ ...rror.todo-fbt-unknown-enum-value.expect.md | 8 +++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts index c68fc05ba0..74ab0b41eb 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts @@ -2058,6 +2058,25 @@ function lowerExpression( suggestions: null, }); } + const fbtEnumLocations: Array = []; + expr.traverse({ + JSXNamespacedName(path) { + if ( + path.node.namespace.name === "fbt" && + path.node.name.name === "enum" + ) { + fbtEnumLocations.push(path.node.loc ?? GeneratedSource); + } + }, + }); + if (fbtEnumLocations.length > 1) { + CompilerError.throwTodo({ + reason: `Support tags with multiple values`, + loc: fbtEnumLocations.at(-1) ?? GeneratedSource, + description: null, + suggestions: null, + }); + } } let children: Array; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-unknown-enum-value.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-unknown-enum-value.expect.md index fefa98b7b0..bbd261aeef 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-unknown-enum-value.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-unknown-enum-value.expect.md @@ -19,7 +19,13 @@ function Component({ a, b }) { ## Error ``` -avalue1 not found in { bvalue1: 'bvalue1', bvalue2: 'bvalue2' }. Attempting to re-use incompatible enums + 5 | + 6 | {" "} +> 7 | + | ^^^^^^^^ [ReactForget] Todo: Support tags with multiple values (7:7) + 8 | + 9 | ); + 10 | } ``` \ No newline at end of file