@@ -95,9 +95,8 @@ class Transformer {
9595 state . operator = this . #getOperator( state )
9696
9797 esquery . traverse ( ast , esquery . parse ( query ) , ( ...args ) => {
98- if ( this . #visit( state , ...args ) ) {
99- injectionCount ++
100- }
98+ injectionCount ++
99+ this . #visit( state , ...args )
101100 } )
102101 }
103102
@@ -138,12 +137,11 @@ class Transformer {
138137 *
139138 * @param {object } state - Merged config + runtime state for this traversal.
140139 * @param {...unknown } args - `(node, parent, ancestry)` from esquery traverse.
141- * @returns {boolean } True if injection should be counted, false otherwise.
142140 */
143141 #visit ( state , ...args ) {
144142 const transform = this . #customTransforms[ state . operator ] ?? transforms [ state . operator ]
145143 const { index = 0 } = state . functionQuery
146- const [ node , , ancestry ] = args
144+ const [ node ] = args
147145 const type = node . init ?. type || node . type
148146
149147 // Class nodes are visited for traceInstanceMethod (missing method patching),
@@ -153,41 +151,14 @@ class Transformer {
153151 // nested class like `let Server = (() => { class Server {} })()`) is only
154152 // matched because `[id.name="Server"]` is broad. It is not a function node
155153 // and should not be instrumented or counted toward the function index.
156- if ( node . type === 'VariableDeclarator' ) return false
154+ if ( node . type === 'VariableDeclarator' ) return
157155
158156 state . functionIndex = ++ state . functionIndex || 0
159157
160- if ( index !== null && index !== state . functionIndex ) return false
161- } else {
162- // For class nodes, validate that the method exists before instrumenting
163- const { methodName } = state . functionQuery
164- if ( methodName ) {
165- // Handle both ClassDeclaration/ClassExpression and VariableDeclarator with ClassExpression init
166- const classNode = node . type === 'VariableDeclarator' ? node . init : node
167- const classBody = classNode . body
168- const methodExists = classBody . body . some ( ( { key } ) => key ?. name === methodName )
169-
170- if ( ! methodExists ) {
171- // Method doesn't exist on the class. Check if any subclass has it.
172- const className = classNode . id ?. name || node . id ?. name
173- const program = ancestry [ ancestry . length - 1 ]
174-
175- if ( className ) {
176- const hasMethodInSubclass = esquery . query (
177- program ,
178- `ClassDeclaration[superClass.name="${ className } "] > ClassBody > MethodDefinition[key.name="${ methodName } "]`
179- ) . length > 0
180-
181- if ( ! hasMethodInSubclass ) {
182- throw new Error ( `Method '${ methodName } ' not found on class '${ className } ' or any of its subclasses` )
183- }
184- }
185- }
186- }
158+ if ( index !== null && index !== state . functionIndex ) return
187159 }
188160
189161 transform ( state , ...args )
190- return true
191162 }
192163
193164 /**
0 commit comments