From 6dbc48075b6feba902533bd41b69ac1a9df7f933 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Sat, 26 Aug 2023 14:00:43 -0700 Subject: [PATCH] [tests] bug repros --- ...or.todo-lambda-return-expression.expect.md | 28 +++++++++++++++ .../error.todo-lambda-return-expression.ts | 13 +++++++ ...-validate-identifiers-object-key.expect.md | 36 +++++++++++++++++++ ...or.todo-validate-identifiers-object-key.ts | 15 ++++++++ compiler/packages/snap/src/compiler-worker.ts | 1 + 5 files changed, 93 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-lambda-return-expression.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-lambda-return-expression.ts create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-validate-identifiers-object-key.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-validate-identifiers-object-key.ts diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-lambda-return-expression.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-lambda-return-expression.expect.md new file mode 100644 index 0000000000..42607b8aef --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-lambda-return-expression.expect.md @@ -0,0 +1,28 @@ + +## Input + +```javascript +import { invoke } from "shared-runtime"; + +function useFoo() { + const x = {}; + const result = invoke(() => x); + console.log(result); +} + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [], + isComponent: false, +}; + +``` + + +## Error + +``` +[ReactForget] Invariant: Expected value for identifier `16` to be initialized. (5:5) +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-lambda-return-expression.ts b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-lambda-return-expression.ts new file mode 100644 index 0000000000..d9e8b8eddb --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-lambda-return-expression.ts @@ -0,0 +1,13 @@ +import { invoke } from "shared-runtime"; + +function useFoo() { + const x = {}; + const result = invoke(() => x); + console.log(result); +} + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [], + isComponent: false, +}; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-validate-identifiers-object-key.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-validate-identifiers-object-key.expect.md new file mode 100644 index 0000000000..1f92566cea --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-validate-identifiers-object-key.expect.md @@ -0,0 +1,36 @@ + +## Input + +```javascript +function Foo() { + return { + "a.b": 1, + "a\b": 2, + "a/b": 3, + "a+b": 4, + "a b": 5, + }; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Foo, + params: [], + isComponent: false, +}; + +``` + + +## Error + +``` +Unexpected token, expected "," (2:13) + 1 | import { unstable_useMemoCache as useMemoCache } from "react";function Foo() {const $ = useMemoCache(1);let t0;if ($[0] === Symbol.for("react.memo_cache_sentinel")) { +> 2 | t0 = { a.b: 1, a: 2, a/b: 3, a+b: 4, a b: 5 };$[0] = t0;} else {t0 = $[0];}return t0;} + | ^ + 3 | + 4 | + 5 | +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-validate-identifiers-object-key.ts b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-validate-identifiers-object-key.ts new file mode 100644 index 0000000000..0d039fd122 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-validate-identifiers-object-key.ts @@ -0,0 +1,15 @@ +function Foo() { + return { + "a.b": 1, + "a\b": 2, + "a/b": 3, + "a+b": 4, + "a b": 5, + }; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Foo, + params: [], + isComponent: false, +}; diff --git a/compiler/packages/snap/src/compiler-worker.ts b/compiler/packages/snap/src/compiler-worker.ts index f125166e7a..0a54470795 100644 --- a/compiler/packages/snap/src/compiler-worker.ts +++ b/compiler/packages/snap/src/compiler-worker.ts @@ -88,6 +88,7 @@ export async function compile( runReactForgetBabelPlugin ).code; } catch (e) { + e.message = e.message.replace(/\u001b[^m]*m/g, ''); error = e; }