feat(transformer): Support overloaded functions by attaching signatures on use #390
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add overloads feature flag that enables this feature.
Enabling it makes the transformer process function calls if their declaration
was previously marked for mocking (via getMethod).
From a type-perspective, typed methods shouldn't bother to consider their inputs
in order to determine the output in runtime. At transformation time, the type
checker resolves the matching overload and that information can be used to
attach to the function, by utilizing the "instance" (
this
) of it. Thetransformer changes transform functions in the following way.
As for constructor instantiation signatures in interfaces, those can be wrapped
by an intermediate function that will copy the mocked properties to preserve the
instantiation behavior.
These attached interfaces will determine the branching at runtime and to reduce
as much overhead as possible, all signatures of an overloaded function are
mapped to the resolved return type and stored in a jump table, i.e.:
It should be noted, that if spies are introduced using the method provider, then
this
will be occupied by the signature key.This is an alternative implementation of the feature(s) covered in #303 and #313