mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
TypeScript: fix alerts in ambient code
This commit is contained in:
@@ -15,5 +15,6 @@ private import semmle.javascript.dataflow.InferredTypes
|
||||
|
||||
from InvokeExpr invk, DataFlow::AnalyzedNode callee
|
||||
where callee.asExpr() = invk.getCallee() and
|
||||
forex (InferredType tp | tp = callee.getAType() | tp != TTFunction() and tp != TTClass())
|
||||
forex (InferredType tp | tp = callee.getAType() | tp != TTFunction() and tp != TTClass()) and
|
||||
not invk.isAmbient()
|
||||
select invk, "Callee is not a function: it has type " + callee.ppTypes() + "."
|
||||
@@ -31,5 +31,6 @@ predicate namespaceOrConstEnumAccess(VarAccess e) {
|
||||
from PropAccess pacc, DataFlow::AnalyzedNode base
|
||||
where base.asExpr() = pacc.getBase() and
|
||||
forex (InferredType tp | tp = base.getAType() | tp = TTNull() or tp = TTUndefined()) and
|
||||
not namespaceOrConstEnumAccess(pacc.getBase())
|
||||
not namespaceOrConstEnumAccess(pacc.getBase()) and
|
||||
not pacc.isAmbient()
|
||||
select pacc, "The base expression of this property access is always " + base.ppTypes() + "."
|
||||
|
||||
@@ -208,6 +208,11 @@ class TopLevel extends @toplevel, StmtContainer {
|
||||
override string toString() {
|
||||
result = "<toplevel>"
|
||||
}
|
||||
|
||||
override predicate isAmbient() {
|
||||
getFile().getFileType().isTypeScript() and
|
||||
getFile().getBaseName().matches("%.d.ts")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user