Skip to content

Commit 41e9008

Browse files
committed
Fix weirdness with parsing undefined as an identifier.
1 parent 5bdce80 commit 41e9008

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

docs/no-react-deps.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ createEffect((prev) => {
8080
return (prev || 0) + 1;
8181
});
8282

83+
createEffect((prev) => {
84+
console.log(signal());
85+
return prev ? prev + 1 : 1;
86+
}, undefined);
87+
8388
const value = createMemo(() => computeExpensiveValue(a(), b()));
8489

8590
const sum = createMemo((prev) => input() + prev, 0);

docs/reactivity.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ createEffect(() => {
537537
runWithOwner(owner, () => console.log(signal()));
538538
});
539539

540+
const [signal] = createSignal();
541+
createEffect(() => {
542+
runWithOwner(undefined, () => console.log(signal()));
543+
});
544+
540545
const [signal] = createSignal();
541546
createEffect(() => {
542547
[1, 2].forEach(() => console.log(signal()));

src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export function trace(node: T.Node, initialScope: TSESLint.Scope.Scope): T.Node
5050
if (!variable) return node;
5151

5252
const def = variable.defs[0];
53-
switch (def.type) {
53+
54+
// def is `undefined` for Identifier `undefined`
55+
switch (def?.type) {
5456
case "FunctionName":
5557
case "ClassName":
5658
case "ImportBinding":

test/rules/no-react-deps.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export const cases = run("no-react-deps", rule, {
1414
console.log(signal());
1515
return (prev || 0) + 1;
1616
});`,
17+
`createEffect((prev) => {
18+
console.log(signal());
19+
return prev ? prev + 1 : 1;
20+
}, undefined);`,
1721
`const value = createMemo(() => computeExpensiveValue(a(), b()));`,
1822
`const sum = createMemo((prev) => input() + prev, 0);`,
1923
`const args = [() => { console.log(signal()); }, [signal()]];

test/rules/reactivity.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export const cases = run("reactivity", rule, {
9595
const owner = getOwner();
9696
runWithOwner(owner, () => console.log(signal()));
9797
});`,
98+
`const [signal] = createSignal();
99+
createEffect(() => {
100+
runWithOwner(undefined, () => console.log(signal()));
101+
});`,
98102
// Sync callbacks
99103
`const [signal] = createSignal();
100104
createEffect(() => {

0 commit comments

Comments
 (0)