Merge pull request #151 from asger-semmle/ts-ambient-toplevel

Approved by xiemaisi
This commit is contained in:
semmle-qlci
2018-09-05 10:52:08 +01:00
committed by GitHub
5 changed files with 14 additions and 2 deletions

View File

@@ -85,6 +85,8 @@
- [xss](https://github.com/leizongmin/js-xss)
- [xtend](https://github.com/Raynos/xtend)
* Handling of ambient TypeScript code has been improved. As a result, fewer false positives will be reported in `.d.ts` files.
## New queries
| **Query** | **Tags** | **Purpose** |

View File

@@ -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() + "."

View File

@@ -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() + "."

View File

@@ -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")
}
}
/**

View File

@@ -0,0 +1,3 @@
export class Subclass extends BaseClass {} // OK - ambient context
export class BaseClass {}