Gracefully handle empty "xstyle" prop values (#23190)

This commit is contained in:
Brian Vaughn
2022-01-26 13:54:44 -05:00
committed by GitHub
parent 529dc3ce84
commit 934f72221d
2 changed files with 27 additions and 0 deletions

View File

@@ -33,6 +33,29 @@ describe('Stylex plugin utils', () => {
});
});
it('should gracefully handle empty values', () => {
expect(getStyleXData(null)).toMatchInlineSnapshot(`
Object {
"resolvedStyles": Object {},
"sources": Array [],
}
`);
expect(getStyleXData(undefined)).toMatchInlineSnapshot(`
Object {
"resolvedStyles": Object {},
"sources": Array [],
}
`);
expect(getStyleXData('')).toMatchInlineSnapshot(`
Object {
"resolvedStyles": Object {},
"sources": Array [],
}
`);
});
it('should support simple style objects', () => {
defineStyles(`
.foo {

View File

@@ -29,6 +29,10 @@ export function crawlData(
sources: Set<string>,
resolvedStyles: Object,
): void {
if (data == null) {
return;
}
if (isArray(data)) {
data.forEach(entry => {
if (isArray(entry)) {