To start, please be aware that I am setting up this hypothetical problem intentionally, because it's a real world problem which I am faced with solving, and am not sure it's even possible.
Let's say I have a JavaScript package, called road-fetcher, with an exported function called find, which I can pass a lat/lng coordinate into, and get back the nearest road to that point.
So:
import { find } from 'road-fetcher'
find(36.585940, -95.304241) // output: 'US Route 66'
Let's suppose that a user consuming my road-fetcher app ends up using this find function 200-300x in their web app (all in predictable, non Math.random ways).
Internally, my road-fetcher package is making network requests to my external API. That works fine, but if we keep doing this at runtime, we incur bandwidth and latency costs (whether in browser or server) on each client, that we needn't necessarily. Moreover, maybe all 200 calls are on the same page. Instead, it'd be ideal to generate initial values at build time, and perhaps set some long TTL to revalidate values later on.
It's commonplace to process JavaScript with Webpack, and I'm wondering if it would be possible to statically analyse a user's usage of the find function to find all the permutations.
Ideally I'd want to compile a total list of function calls with their args and then make a network request based on this, during the build step, but even being able to compile a list of all function call args and store that somewhere in the filesystem (not sure, within node_modules, or cwd), to facilitate a single cache-warm step would be sufficient as well.
Having an initial look at the Webpack docs, it seems like evaluateCallExpressionMember may be a starting point, but I'm pretty out of my depth here.
I appreciate this is a contrived example, but it does represent a very real problem which I am trying to simplify here to clearly isolate the issue at hand.