From a405b7b3e05969795428cada93d119560d919b37 Mon Sep 17 00:00:00 2001 From: Asger F Date: Mon, 17 Nov 2025 10:47:37 +0100 Subject: [PATCH] JS: Add discard predicates for locations --- .../semmle/javascript/internal/Overlay.qll | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/javascript/ql/lib/semmle/javascript/internal/Overlay.qll b/javascript/ql/lib/semmle/javascript/internal/Overlay.qll index a20ac1868e6..43a4a07df47 100644 --- a/javascript/ql/lib/semmle/javascript/internal/Overlay.qll +++ b/javascript/ql/lib/semmle/javascript/internal/Overlay.qll @@ -28,3 +28,23 @@ overlay[discard_entity] private predicate discardEntity(@locatable node) { exists(string file | discardableEntity(file, node) and discardFile(file)) } + +overlay[local] +private string getFileFromLocation(@location loc) { + exists(@file file | + locations_default(loc, file, _, _, _, _) and + files(file, result) + ) +} + +/** Holds if `loc` is in the `file` and is part of the overlay base database. */ +overlay[local] +private predicate discardableLocation(string file, @location node) { + not isOverlay() and file = getFileFromLocation(node) +} + +/** Holds if `loc` should be discarded, because it is part of the overlay base and is in a file that was also extracted as part of the overlay database. */ +overlay[discard_entity] +private predicate discardLocation(@location loc) { + exists(string file | discardableLocation(file, loc) and discardFile(file)) +}