зеркало из https://github.com/github/codeql.git
JS: Remove Import->SourceNode dependency from lazy cache
This commit is contained in:
Родитель
8f930fc3e6
Коммит
3804d3fcfd
|
@ -6,8 +6,11 @@ import javascript
|
|||
|
||||
module LazyCache {
|
||||
/**
|
||||
* DEPRECATED. DO NOT USE.
|
||||
*
|
||||
* A lazy-cache object, usually created through an expression of form `require('lazy-cache')(require)`.
|
||||
*/
|
||||
deprecated
|
||||
class LazyCacheObject extends DataFlow::SourceNode {
|
||||
LazyCacheObject() {
|
||||
// Use `require` directly instead of `moduleImport` to avoid recursion.
|
||||
|
@ -19,13 +22,26 @@ module LazyCache {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A variable containing a lazy-cache object.
|
||||
*/
|
||||
class LazyCacheVariable extends LocalVariable {
|
||||
LazyCacheVariable() {
|
||||
// To avoid recursion, this should not depend on `SourceNode`.
|
||||
exists(Require req |
|
||||
req.getArgument(0).getStringValue() = "lazy-cache" and
|
||||
getAnAssignedExpr().(CallExpr).getCallee() = req
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An import through `lazy-cache`.
|
||||
*/
|
||||
class LazyCacheImport extends CallExpr, Import {
|
||||
LazyCacheObject cache;
|
||||
LazyCacheVariable cache;
|
||||
|
||||
LazyCacheImport() { this = cache.getACall().asExpr() }
|
||||
LazyCacheImport() { getCallee() = cache.getAnAccess() }
|
||||
|
||||
/** Gets the name of the package as it's exposed on the lazy-cache object. */
|
||||
string getLocalAlias() {
|
||||
|
@ -39,10 +55,23 @@ module LazyCache {
|
|||
|
||||
override PathExpr getImportedPath() { result = getArgument(0) }
|
||||
|
||||
private LazyCacheVariable getVariable() {
|
||||
result = cache
|
||||
}
|
||||
|
||||
pragma[noopt]
|
||||
override DataFlow::Node getImportedModuleNode() {
|
||||
this instanceof LazyCacheImport and
|
||||
result = this.flow()
|
||||
or
|
||||
result = cache.getAPropertyRead(getLocalAlias())
|
||||
exists(LazyCacheVariable variable, Expr base, PropAccess access, string localName |
|
||||
variable = getVariable() and
|
||||
base = variable.getAnAccess() and
|
||||
access.getBase() = base and
|
||||
localName = getLocalAlias() and
|
||||
access.getPropertyName() = localName and
|
||||
result = access.flow()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче