mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
@@ -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>;
|
||||
|
||||
+7
-1
@@ -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 | }
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user