Skip to content

Commit

Permalink
Merge pull request #134 from nix6839/fix-#133
Browse files Browse the repository at this point in the history
Don't crash when encounter unknown node like `as`
  • Loading branch information
joshwilsonvu authored Apr 13, 2024
2 parents b65cf30 + a3f07a2 commit 6a89e2c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -812,6 +816,10 @@ const m = createMemo(() => 5)! as Accessor<number>;

const m = createMemo(() => 5) satisfies Accessor<number>;

const [s] = createSignal("a" as string);

createFoo("a" as string);

function Component(props) {
return (
<div>
Expand Down
1 change: 1 addition & 0 deletions src/rules/reactivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ export default createRule<Options, MessageIds>({
this.skip(); // poor-man's `findInScope`: don't enter child scopes
}
},
fallback: "iteration", // Don't crash when encounter unknown node.
});
};

Expand Down
17 changes: 14 additions & 3 deletions test/rules/reactivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -308,6 +311,14 @@ export const cases = run("reactivity", rule, {
code: `const m = createMemo(() => 5) satisfies Accessor<number>;`,
...tsOnlyTest,
},
{
code: `const [s] = createSignal('a' as string)`,
...tsOnlyTest,
},
{
code: `createFoo('a' as string)`,
...tsOnlyTest,
},
// functions in JSXExpressionContainers
`function Component(props) {
return (
Expand Down

0 comments on commit 6a89e2c

Please sign in to comment.