@samitouri / QOS-React-2 / commits / 346f6c13a8

Todo for fbt with multiple fbt:enum

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 `<fbt:enum>` within a given `<fbt>` tag and throw a todo.

Joe Savona committed Mar 19, 2024 at 16:39 UTC 346f6c13a838a3c99dac3a3c01d67f32da28e366
2 files changed +26 -1
compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts
+19
@@ -2058,6 +2058,25 @@ function lowerExpression(
2058 suggestions: null,
2059 });
2060 }
2061 + const fbtEnumLocations: Array<SourceLocation> = [];
2062 + expr.traverse({
2063 + JSXNamespacedName(path) {
2064 + if (
2065 + path.node.namespace.name === "fbt" &&
2066 + path.node.name.name === "enum"
2067 + ) {
2068 + fbtEnumLocations.push(path.node.loc ?? GeneratedSource);
2069 + }
2070 + },
2071 + });
2072 + if (fbtEnumLocations.length > 1) {
2073 + CompilerError.throwTodo({
2074 + reason: `Support <fbt> tags with multiple <fbt:enum> values`,
2075 + loc: fbtEnumLocations.at(-1) ?? GeneratedSource,
2076 + description: null,
2077 + suggestions: null,
2078 + });
2079 + }
2080 }
2081
2082 let children: Array<Place>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-unknown-enum-value.expect.md
+7 -1
@@ -19,7 +19,13 @@ function Component({ a, b }) {
19 ## Error
20
21 ```
22 -avalue1 not found in { bvalue1: 'bvalue1', bvalue2: 'bvalue2' }. Attempting to re-use incompatible enums
22 + 5 | <fbt desc="Description">
23 + 6 | <fbt:enum enum-range={["avalue1", "avalue1"]} value={a} />{" "}
24 +> 7 | <fbt:enum enum-range={["bvalue1", "bvalue2"]} value={b} />
25 + | ^^^^^^^^ [ReactForget] Todo: Support <fbt> tags with multiple <fbt:enum> values (7:7)
26 + 8 | </fbt>
27 + 9 | );
28 + 10 | }
29 ```
30
31
\ No newline at end of file