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.
This commit is contained in:
Joe Savona
2024-03-19 16:39:05 -07:00
parent f2b0b656b2
commit 346f6c13a8
2 changed files with 26 additions and 1 deletions
@@ -2058,6 +2058,25 @@ function lowerExpression(
suggestions: null,
});
}
const fbtEnumLocations: Array<SourceLocation> = [];
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 <fbt> tags with multiple <fbt:enum> values`,
loc: fbtEnumLocations.at(-1) ?? GeneratedSource,
description: null,
suggestions: null,
});
}
}
let children: Array<Place>;
@@ -19,7 +19,13 @@ function Component({ a, b }) {
## Error
```
avalue1 not found in { bvalue1: 'bvalue1', bvalue2: 'bvalue2' }. Attempting to re-use incompatible enums
5 | <fbt desc="Description">
6 | <fbt:enum enum-range={["avalue1", "avalue1"]} value={a} />{" "}
> 7 | <fbt:enum enum-range={["bvalue1", "bvalue2"]} value={b} />
| ^^^^^^^^ [ReactForget] Todo: Support <fbt> tags with multiple <fbt:enum> values (7:7)
8 | </fbt>
9 | );
10 | }
```