-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative method using transformers #5
Comments
It's near-impossible to detect all usages of a function X that uses In theory it could still be possible to build an "index" of caller information keyed by stackframes, sort of like a reduced version of the program's AST. This would require indexing a project's entire tree including dependencies. Even if this index could be built in a reasonable time & size, it would still be problematic to actually use it at runtime, because (as far as I know) it's impossible to emit extra files using a transformer. |
The scope (therefore size) of the index could be limited by specifying the modules that should be index. However, because this index is created at compile-time, any usage from code not known at compile-time will fail. Therefore libraries won't effectively be able to use this method, |
Perhaps it's possible to store caller information on the function object itself, and then retrieve it using this principle. However, this method still has two major remaining issues:
// JS source + definitions
function execute<T>(x: T, func: (x: T) => any) {
func(x);
}
// TS source
function foo<T>(x: T) {
const callSite = getCallSite();
// Use "reified" generic information on T, see ts-reified-generics
}
// It's very clear that in this line 'foo' has T = string, but this can't be detected
execute("bar", foo); |
It might be a good idea to investigate using transformers as an alternative method for getting runtime caller information.
This would avoid the need to keep around TS source code and replaces source-maps & stack analysis, which has shown to have finnicky edge-cases (#2).
However, I predict there will be some logistical issues when implementing this within the limits of the compiler API. More investigation is needed to see if this is actually a suitable alternative.
Concept approachFirst pass
getCallSite
.Second pass
Issues & limitations
Program
instance at both passes, but that's a big performance hit.arguments
could break, which could be a very big problem for functions that do funky overloads.Unfortunately it's not possible to pre-store caller information by stackframe, because (without source map) it's impossible to know what the new location information will be.It might be possible to know what a "caller stackframe" will look like when using anafter
transformation.More investigation is needed.
The text was updated successfully, but these errors were encountered: