@@ -785,6 +785,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
785
785
| T . VariableDeclarator
786
786
| T . AssignmentExpression
787
787
| T . TaggedTemplateExpression
788
+ | T . NewExpression
788
789
) => {
789
790
const pushTrackedScope = ( node : T . Node , expect : TrackedScope [ "expect" ] ) => {
790
791
currentScope ( ) . trackedScopes . push ( { node, expect } ) ;
@@ -848,7 +849,7 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
848
849
} else if ( node . type === "JSXSpreadAttribute" ) {
849
850
// allow <div {...props.nestedProps} />; {...props} is already ignored
850
851
pushTrackedScope ( node . argument , "expression" ) ;
851
- } else if ( node . type === "CallExpression" ) {
852
+ } else if ( node . type === "CallExpression" || node . type === "NewExpression" ) {
852
853
if ( node . callee . type === "Identifier" ) {
853
854
const {
854
855
callee,
@@ -878,16 +879,24 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
878
879
} else if (
879
880
matchImport ( [ "onMount" , "onCleanup" , "onError" ] , callee . name ) ||
880
881
[
882
+ // Timers
881
883
"setInterval" ,
882
884
"setTimeout" ,
883
885
"setImmediate" ,
884
886
"requestAnimationFrame" ,
885
887
"requestIdleCallback" ,
888
+ // Observers from Standard Web APIs
889
+ "IntersectionObserver" ,
890
+ "MutationObserver" ,
891
+ "PerformanceObserver" ,
892
+ "ReportingObserver" ,
893
+ "ResizeObserver" ,
886
894
] . includes ( callee . name )
887
895
) {
888
- // on* and timers are NOT tracked scopes. However, they don't need to react
889
- // to updates to reactive variables; it's okay to poll the current
890
- // value. Consider them called-function tracked scopes for our purposes.
896
+ // on*, timers, and observers are NOT tracked scopes. However, they
897
+ // don't need to react to updates to reactive variables; it's okay
898
+ // to poll the current value. Consider them called-function tracked
899
+ // scopes for our purposes.
891
900
pushTrackedScope ( arg0 , "called-function" ) ;
892
901
} else if ( matchImport ( "on" , callee . name ) ) {
893
902
// on accepts a signal or an array of signals as its first argument,
@@ -1072,6 +1081,9 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
1072
1081
checkForReactiveAssignment ( null , node ) ;
1073
1082
}
1074
1083
} ,
1084
+ NewExpression ( node : T . NewExpression ) {
1085
+ checkForTrackedScopes ( node ) ;
1086
+ } ,
1075
1087
VariableDeclarator ( node : T . VariableDeclarator ) {
1076
1088
if ( node . init ) {
1077
1089
checkForReactiveAssignment ( node . id , node . init ) ;
0 commit comments