Skip to content

Commit 7bd53e7

Browse files
committed
TypeScript: fix alerts in ambient code
1 parent af3f855 commit 7bd53e7

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

javascript/ql/src/Expressions/SuspiciousInvocation.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ private import semmle.javascript.dataflow.InferredTypes
1515

1616
from InvokeExpr invk, DataFlow::AnalyzedNode callee
1717
where callee.asExpr() = invk.getCallee() and
18-
forex (InferredType tp | tp = callee.getAType() | tp != TTFunction() and tp != TTClass())
18+
forex (InferredType tp | tp = callee.getAType() | tp != TTFunction() and tp != TTClass()) and
19+
not invk.isAmbient()
1920
select invk, "Callee is not a function: it has type " + callee.ppTypes() + "."

javascript/ql/src/Expressions/SuspiciousPropAccess.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ predicate namespaceOrConstEnumAccess(VarAccess e) {
3131
from PropAccess pacc, DataFlow::AnalyzedNode base
3232
where base.asExpr() = pacc.getBase() and
3333
forex (InferredType tp | tp = base.getAType() | tp = TTNull() or tp = TTUndefined()) and
34-
not namespaceOrConstEnumAccess(pacc.getBase())
34+
not namespaceOrConstEnumAccess(pacc.getBase()) and
35+
not pacc.isAmbient()
3536
select pacc, "The base expression of this property access is always " + base.ppTypes() + "."

javascript/ql/src/semmle/javascript/AST.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ class TopLevel extends @toplevel, StmtContainer {
208208
override string toString() {
209209
result = "<toplevel>"
210210
}
211+
212+
override predicate isAmbient() {
213+
getFile().getFileType().isTypeScript() and
214+
getFile().getBaseName().matches("%.d.ts")
215+
}
211216
}
212217

213218
/**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class Subclass extends BaseClass {} // OK - ambient context
2+
3+
export class BaseClass {}

0 commit comments

Comments
 (0)