I'd like to reuse the capture from a first pattern to filter the second pattern.
The first sub-pattern extracts the name of an import, and the second sub-pattern is supposed to find the arguments of the calls to the second pattern, whichever nesting level.
You can test the query on https://tree-sitter.github.io/tree-sitter/playground if you find a solution.
The funcName
captures only match badRoute
, rootRoute
, asyncRoute
.
The funcName
capture also match req
and res
on line 7, but it shouldn't.
import express from "express";
import { autometrics } from "@autometrics/autometrics";
const badRouteMetrics = autometrics(badRoute); // Should match
badRoute
as funcNameapp.get("/", autometrics(rootRoute)); // Should match
rootRoute
as funcNameapp.get("/bad", (req, res) => badRouteMetrics(req, res)); // Should not match anything
app.get("/async", autometrics(asyncRoute)); // Should match
asyncRoute
as funcName