JS: Add DataFlow::Node.getLocation

This commit is contained in:
Tom Hvitved
2024-03-12 11:08:18 +01:00
parent 35a8e7cbf0
commit 16cef92106
22 changed files with 235 additions and 97 deletions

View File

@@ -23,31 +23,27 @@ private import semmle.javascript.internal.CachedStages
* ```
*/
class AstNode extends @ast_node, NodeInStmtContainer {
override Location getLocation() { hasLocation(this, result) }
override File getFile() {
result = this.getLocation().getFile() // Specialized for performance reasons
}
/** Gets the first token belonging to this element. */
Token getFirstToken() {
exists(Location l1, Location l2 |
exists(DbLocation l1, DbLocation l2, string filepath, int startline, int startcolumn |
l1 = this.getLocation() and
l2 = result.getLocation() and
l1.getFile() = l2.getFile() and
l1.getStartLine() = l2.getStartLine() and
l1.getStartColumn() = l2.getStartColumn()
l1.hasLocationInfo(filepath, startline, startcolumn, _, _) and
l2.hasLocationInfo(filepath, startline, startcolumn, _, _)
)
}
/** Gets the last token belonging to this element. */
Token getLastToken() {
exists(Location l1, Location l2 |
exists(DbLocation l1, DbLocation l2, string filepath, int endline, int endcolumn |
l1 = this.getLocation() and
l2 = result.getLocation() and
l1.getFile() = l2.getFile() and
l1.getEndLine() = l2.getEndLine() and
l1.getEndColumn() = l2.getEndColumn()
l1.hasLocationInfo(filepath, _, _, endline, endcolumn) and
l2.hasLocationInfo(filepath, _, _, endline, endcolumn)
) and
// exclude empty EOF token
not result instanceof EOFToken