@@ -347,26 +347,6 @@ private predicate functionHasNameCandidate(
347347 nameFromExterns ( function , package , name , badness )
348348}
349349
350- private predicate functionHasPrimaryName (
351- DataFlow:: FunctionNode function , string package , string name , int badness
352- ) {
353- badness = min ( int b | functionHasNameCandidate ( function , _, _, b ) | b ) and
354- package = min ( string p | functionHasNameCandidate ( function , p , _, badness ) | p ) and
355- name =
356- min ( string n |
357- functionHasNameCandidate ( function , package , n , badness )
358- |
359- n order by n .length ( ) , n
360- )
361- }
362-
363- /**
364- * Holds if `(package, name)` is the primary name for the given `function`.
365- */
366- predicate functionHasPrimaryName ( DataFlow:: FunctionNode function , string package , string name ) {
367- functionHasPrimaryName ( function , package , name , _)
368- }
369-
370350private predicate sourceNodeHasNameCandidate (
371351 DataFlow:: SourceNode node , string package , string name , int badness
372352) {
@@ -387,6 +367,29 @@ private predicate sourceNodeHasPrimaryName(
387367 min ( string n | sourceNodeHasNameCandidate ( node , package , n , badness ) | n order by n .length ( ) , n )
388368}
389369
370+ /**
371+ * Holds if `node` is a function or a call that returns a function.
372+ */
373+ private predicate isFunctionSource ( DataFlow:: SourceNode node ) {
374+ node instanceof DataFlow:: FunctionNode
375+ or
376+ node instanceof DataFlow:: InvokeNode and
377+ exists ( node .getABoundFunctionValue ( _) ) and
378+ // `getASinkNode` steps through imports (but not other calls) so exclude calls that are imports (i.e. require calls)
379+ // as we want to get as close to the source as possible.
380+ not node instanceof DataFlow:: ModuleImportNode
381+ }
382+
383+ /**
384+ * Holds if `(package, name)` is the primary name for the given `function`.
385+ *
386+ * The `function` node may be an actual function expression, or a call site from which a function is returned.
387+ */
388+ predicate functionHasPrimaryName ( DataFlow:: SourceNode function , string package , string name ) {
389+ sourceNodeHasPrimaryName ( function , package , name , _) and
390+ isFunctionSource ( function )
391+ }
392+
390393private predicate sinkHasSourceName ( API:: Node sink , string package , string name , int badness ) {
391394 exists ( DataFlow:: SourceNode source |
392395 sink = getASinkNode ( source ) and
0 commit comments