From 52e650bbe640660c1cca967c4bdf6661feec3d22 Mon Sep 17 00:00:00 2001 From: Han Yeong-woo Date: Thu, 4 Apr 2024 11:05:47 +0900 Subject: [PATCH 1/2] Don't crash when encounter unknown node like `as` Fix #133 --- src/rules/reactivity.ts | 1 + test/fixture/valid/as-expression/main.tsx | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/fixture/valid/as-expression/main.tsx diff --git a/src/rules/reactivity.ts b/src/rules/reactivity.ts index 624ecd3..b309891 100644 --- a/src/rules/reactivity.ts +++ b/src/rules/reactivity.ts @@ -843,6 +843,7 @@ export default createRule({ this.skip(); // poor-man's `findInScope`: don't enter child scopes } }, + fallback: "iteration", // Don't crash when encounter unknown node. }); }; diff --git a/test/fixture/valid/as-expression/main.tsx b/test/fixture/valid/as-expression/main.tsx new file mode 100644 index 0000000..7322333 --- /dev/null +++ b/test/fixture/valid/as-expression/main.tsx @@ -0,0 +1,11 @@ +// @ts-nocheck +import { createSignal } from "solid-js"; +import { render } from "solid-js/web"; + +function App() { + const [a] = createSignal("a" as string); + + return
{a()}
; +} + +render(() => , document.getElementById("app")); From a3f07a2cacdc93e5ebcc48939f925c881776056e Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Sat, 13 Apr 2024 15:28:55 -0400 Subject: [PATCH 2/2] Make new fixture a unit test, add a few more. --- docs/reactivity.md | 8 ++++++++ test/fixture/valid/as-expression/main.tsx | 11 ----------- test/rules/reactivity.test.ts | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) delete mode 100644 test/fixture/valid/as-expression/main.tsx diff --git a/docs/reactivity.md b/docs/reactivity.md index 9fdee08..13964ff 100644 --- a/docs/reactivity.md +++ b/docs/reactivity.md @@ -645,6 +645,10 @@ function createFoo(v) {} const [bar, setBar] = createSignal(); createFoo([bar]); +function createFoo(v) {} +const [bar, setBar] = createSignal(); +createFoo({ onBar: () => bar() } as object); + const [bar, setBar] = createSignal(); X.createFoo(() => bar()); @@ -812,6 +816,10 @@ const m = createMemo(() => 5)! as Accessor; const m = createMemo(() => 5) satisfies Accessor; +const [s] = createSignal("a" as string); + +createFoo("a" as string); + function Component(props) { return (
diff --git a/test/fixture/valid/as-expression/main.tsx b/test/fixture/valid/as-expression/main.tsx deleted file mode 100644 index 7322333..0000000 --- a/test/fixture/valid/as-expression/main.tsx +++ /dev/null @@ -1,11 +0,0 @@ -// @ts-nocheck -import { createSignal } from "solid-js"; -import { render } from "solid-js/web"; - -function App() { - const [a] = createSignal("a" as string); - - return
{a()}
; -} - -render(() => , document.getElementById("app")); diff --git a/test/rules/reactivity.test.ts b/test/rules/reactivity.test.ts index d0c25f1..9f4087e 100644 --- a/test/rules/reactivity.test.ts +++ b/test/rules/reactivity.test.ts @@ -158,9 +158,12 @@ export const cases = run("reactivity", rule, { `function createFoo(v) {} const [bar, setBar] = createSignal(); createFoo([bar]);`, - // `function createFoo(v) {} - // const [bar, setBar] = createSignal(); - // createFoo((() => () => bar())());`, + { + code: `function createFoo(v) {} + const [bar, setBar] = createSignal(); + createFoo({ onBar: () => bar() } as object);`, + ...tsOnlyTest, + }, `const [bar, setBar] = createSignal(); X.createFoo(() => bar());`, `const [bar, setBar] = createSignal(); @@ -308,6 +311,14 @@ export const cases = run("reactivity", rule, { code: `const m = createMemo(() => 5) satisfies Accessor;`, ...tsOnlyTest, }, + { + code: `const [s] = createSignal('a' as string)`, + ...tsOnlyTest, + }, + { + code: `createFoo('a' as string)`, + ...tsOnlyTest, + }, // functions in JSXExpressionContainers `function Component(props) { return (