From 32293022225c47bcaa642a7919da5ded2f477900 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 22 Mar 2024 08:53:30 -0700 Subject: [PATCH] Repro for "expect trees to be >=2 elements long" invariant These cases have a switch with only a default, so we create a "conditional" child dependency tree and no other trees which hits the invariant. --- ...or.todo-switch-with-only-default.expect.md | 21 +++++++++++++++++++ .../error.todo-switch-with-only-default.js | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-switch-with-only-default.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-switch-with-only-default.js diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-switch-with-only-default.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-switch-with-only-default.expect.md new file mode 100644 index 0000000000..a0c950647b --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-switch-with-only-default.expect.md @@ -0,0 +1,21 @@ + +## Input + +```javascript +function Component({ kind, ...props }) { + switch (kind) { + default: + return ; + } +} + +``` + + +## Error + +``` +[ReactForget] Invariant: Expected trees to be at least 2 elements long. +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-switch-with-only-default.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-switch-with-only-default.js new file mode 100644 index 0000000000..4b6cc8b258 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-switch-with-only-default.js @@ -0,0 +1,6 @@ +function Component({ kind, ...props }) { + switch (kind) { + default: + return ; + } +}