@@ -48,11 +48,11 @@ interface TrackedScope {
48
48
/**
49
49
* The reactive variable should be one of these types:
50
50
* - "function": synchronous function or signal variable
51
- * - "event-handler ": synchronous or asynchronous function like a timer or
52
- * event handler that isn't really a tracked scope but acts like one
51
+ * - "called-function ": synchronous or asynchronous function like a timer or
52
+ * event handler that isn't really a tracked scope but allows reactivity
53
53
* - "expression": some value containing reactivity somewhere
54
54
*/
55
- expect : "function" | "event-handler " | "expression" ;
55
+ expect : "function" | "called-function " | "expression" ;
56
56
}
57
57
58
58
class ScopeStackItem {
@@ -271,7 +271,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
271
271
const matchTrackedScope = ( trackedScope : TrackedScope , node : T . Node ) : boolean => {
272
272
switch ( trackedScope . expect ) {
273
273
case "function" :
274
- case "event-handler " :
274
+ case "called-function " :
275
275
return node === trackedScope . node ;
276
276
case "expression" :
277
277
return Boolean (
@@ -638,7 +638,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
638
638
) => {
639
639
const pushTrackedScope = ( node : T . Node , expect : TrackedScope [ "expect" ] ) => {
640
640
currentScope ( ) . trackedScopes . push ( { node, expect } ) ;
641
- if ( expect !== "event-handler " && isFunctionNode ( node ) && node . async ) {
641
+ if ( expect !== "called-function " && isFunctionNode ( node ) && node . async ) {
642
642
// From the docs: "[Solid's] approach only tracks synchronously. If you
643
643
// have a setTimeout or use an async function in your Effect the code
644
644
// that executes async after the fact won't be tracked."
@@ -662,7 +662,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
662
662
const expect =
663
663
node . parent ?. type === "JSXAttribute" &&
664
664
sourceCode . getText ( node . parent . name ) . match ( / ^ o n [: A -Z ] / )
665
- ? "function"
665
+ ? "called- function"
666
666
: "expression" ;
667
667
pushTrackedScope ( node . expression , expect ) ;
668
668
} else if ( node . type === "CallExpression" && node . callee . type === "Identifier" ) {
@@ -673,7 +673,6 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
673
673
"createMemo" ,
674
674
"children" ,
675
675
"createEffect" ,
676
- "onMount" ,
677
676
"createRenderEffect" ,
678
677
"createDeferred" ,
679
678
"createComputed" ,
@@ -686,17 +685,19 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
686
685
pushTrackedScope ( arg0 , "function" ) ;
687
686
} else if (
688
687
[
688
+ "onMount" ,
689
689
"setInterval" ,
690
690
"setTimeout" ,
691
691
"setImmediate" ,
692
692
"requestAnimationFrame" ,
693
693
"requestIdleCallback" ,
694
694
] . includes ( callee . name )
695
695
) {
696
+ // onMount can be async.
696
697
// Timers are NOT tracked scopes. However, they don't need to react
697
698
// to updates to reactive variables; it's okay to poll the current
698
699
// value. Consider them event-handler tracked scopes for our purposes.
699
- pushTrackedScope ( arg0 , "event-handler " ) ;
700
+ pushTrackedScope ( arg0 , "called-function " ) ;
700
701
} else if ( callee . name === "createMutable" && arg0 ) {
701
702
pushTrackedScope ( arg0 , "expression" ) ;
702
703
} else if ( callee . name === "on" ) {
@@ -712,7 +713,8 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
712
713
}
713
714
}
714
715
if ( node . arguments [ 1 ] ) {
715
- pushTrackedScope ( node . arguments [ 1 ] , "function" ) ;
716
+ // Since dependencies are known, function can be async
717
+ pushTrackedScope ( node . arguments [ 1 ] , "called-function" ) ;
716
718
}
717
719
} else if ( callee . name === "runWithOwner" ) {
718
720
// runWithOwner(owner, fn) only creates a tracked scope if `owner =
@@ -791,7 +793,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
791
793
// where event handlers are manually attached to refs, detect these
792
794
// scenarios and mark the right hand sides as tracked scopes expecting
793
795
// functions.
794
- pushTrackedScope ( node . right , "event-handler " ) ;
796
+ pushTrackedScope ( node . right , "called-function " ) ;
795
797
}
796
798
}
797
799
} ;
0 commit comments