From 4a793bb86e6aa8c27b7dcba5783a2f8dbb5b68d0 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Thu, 2 Nov 2023 11:01:29 -0400 Subject: [PATCH] [hoisting] Add more repros for hoisting bugs --- .../compiler/error.bug-hoisting.expect.md | 26 +++++++++++++++++++ .../fixtures/compiler/error.bug-hoisting.js | 11 ++++++++ .../compiler/error.bug-hoisting2.expect.md | 24 +++++++++++++++++ .../fixtures/compiler/error.bug-hoisting2.js | 9 +++++++ 4 files changed, 70 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.js create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting2.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting2.js diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.expect.md new file mode 100644 index 0000000000..11e60e79d6 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.expect.md @@ -0,0 +1,26 @@ + +## Input + +```javascript +function Component(props) { + const wat = () => { + const pathname = "wat"; + pathname; + }; + + const pathname = props.wat; + const deeplinkItemId = pathname ? itemID : null; + + return ; +} + +``` + + +## Error + +``` +[ReactForget] Invariant: Expected value kind to be initialized at '8:25:8:33' (8:8) +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.js new file mode 100644 index 0000000000..b0f46df363 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.js @@ -0,0 +1,11 @@ +function Component(props) { + const wat = () => { + const pathname = "wat"; + pathname; + }; + + const pathname = props.wat; + const deeplinkItemId = pathname ? itemID : null; + + return ; +} diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting2.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting2.expect.md new file mode 100644 index 0000000000..6a568c660e --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting2.expect.md @@ -0,0 +1,24 @@ + +## Input + +```javascript +function Component() { + useRunOnceDuringRender(() => { + const handler = () => { + return () => { + detachHandler(handler); + }; + }; + }); +} + +``` + + +## Error + +``` +[ReactForget] Todo: EnterSSA: Expected identifier to be defined before being used. Identifier handler$1 is undefined (3:7) +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting2.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting2.js new file mode 100644 index 0000000000..84cc237b35 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting2.js @@ -0,0 +1,9 @@ +function Component() { + useRunOnceDuringRender(() => { + const handler = () => { + return () => { + detachHandler(handler); + }; + }; + }); +}