Skip to content

Commit 6783456

Browse files
committed
JS: Add discard predicates
1 parent ba585b8 commit 6783456

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

javascript/ql/lib/javascript.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,4 @@ import semmle.javascript.linters.JSLint
146146
import semmle.javascript.linters.Linting
147147
import semmle.javascript.security.dataflow.RemoteFlowSources
148148
import semmle.javascript.frameworks.UnderscoreDotString
149+
private import semmle.javascript.internal.Overlay
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
private import javascript
2+
3+
/** Holds if the database is an overlay. */
4+
overlay[local]
5+
private predicate isOverlay() { databaseMetadata("isOverlay", "true") }
6+
7+
overlay[local]
8+
private string getFileFromEntity(@locatable node) {
9+
exists(@location loc, @file file |
10+
hasLocation(node, loc) and
11+
locations_default(loc, file, _, _, _, _) and
12+
files(file, result)
13+
)
14+
}
15+
16+
/** Holds if `file` was changed or deleted in the overlay. */
17+
overlay[local]
18+
private predicate discardFile(string file) { isOverlay() and overlayChangedFiles(file) }
19+
20+
/** Holds if `node` is in the `file` and is part of the overlay base database. */
21+
overlay[local]
22+
private predicate discardableEntity(string file, @locatable node) {
23+
not isOverlay() and file = getFileFromEntity(node)
24+
}
25+
26+
/** Holds if `node` 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. */
27+
overlay[discard_entity]
28+
private predicate discardEntity(@locatable node) {
29+
exists(string file | discardableEntity(file, node) and discardFile(file))
30+
}

0 commit comments

Comments
 (0)