support throttle like calls as partial calls

This commit is contained in:
Erik Krogh Kristensen
2020-10-16 10:41:15 +02:00
parent a92a701c35
commit b3d5f9c4dd
5 changed files with 92 additions and 0 deletions

View File

@@ -1379,6 +1379,48 @@ module PartialInvokeNode {
}
}
/**
* A partial call that behaves like a throttle call, like `require("call-limit")(fs, limit)` or `_.memoize`.
* Seen as a partial invocation that binds no arguments.
*/
private class ThrottleLikePartialCall extends PartialInvokeNode::Range, DataFlow::CallNode {
int callbackIndex;
ThrottleLikePartialCall() {
callbackIndex = 0 and
(
this = LodashUnderscore::member(["throttle", "debounce", "once", "memoize"]).getACall()
or
this =
DataFlow::moduleImport(["call-limit", "lodash.debounce", "lodash.throttle", "debounce"])
.getACall()
)
or
callbackIndex = 1 and
(
this = LodashUnderscore::member(["after", "before"]).getACall()
or
// not jQuery: https://github.com/cowboy/jquery-throttle-debounce
this = DataFlow::globalVarRef("$").getAMemberCall(["throttle", "debounce"])
)
or
callbackIndex = -1 and
this = DataFlow::moduleMember("throttle-debounce", ["debounce", "throttle"]).getACall()
}
override DataFlow::SourceNode getBoundFunction(DataFlow::Node callback, int boundArgs) {
(
callbackIndex >= 0 and
callback = getArgument(callbackIndex)
or
callbackIndex = -1 and
callback = getLastArgument()
) and
boundArgs = 0 and
result = this
}
}
/**
* A partial call through `ramda.partial`.
*/