JS: More robust hasUnderlyingType

This commit is contained in:
Asger Feldthaus
2021-05-10 13:17:25 +02:00
parent 097b6e5e33
commit 3e5dc1efb7
5 changed files with 14 additions and 2 deletions

View File

@@ -725,7 +725,7 @@ class TypeAccess extends @typeaccess, TypeExpr, TypeRef {
spec.getImportedName() = exportedName and
this = spec.getLocal().(TypeDecl).getLocalTypeName().getAnAccess()
or
spec instanceof ImportNamespaceSpecifier and
(spec instanceof ImportNamespaceSpecifier or spec instanceof ImportDefaultSpecifier) and
this =
spec.getLocal().(LocalNamespaceDecl).getLocalNamespaceName().getAMemberAccess(exportedName)
)

View File

@@ -239,7 +239,6 @@ module DataFlow {
private TypeAnnotation getFallbackTypeAnnotation() {
exists(BindingPattern pattern |
this = valueNode(pattern) and
not ast_node_type(pattern, _) and
result = pattern.getTypeAnnotation()
)
or

View File

@@ -1,2 +1,6 @@
underlyingTypeNode
| foo | Bar | foo.ts:3:1:5:1 | use (instance (member Bar (member exports (module foo)))) |
| foo | Bar | foo.ts:3:12:3:12 | use (instance (member Bar (member exports (module foo)))) |
#select
| tst.ts:8:14:8:16 | arg | Base in global scope |
| tst.ts:8:14:8:16 | arg | Sub in global scope |

View File

@@ -3,3 +3,7 @@ import javascript
from Expr e, TypeName typeName
where e.getType().hasUnderlyingTypeName(typeName)
select e, typeName
query API::Node underlyingTypeNode(string mod, string name) {
result = API::Node::ofType(mod, name)
}

View File

@@ -0,0 +1,5 @@
import foo from "foo";
function f(x: foo.Bar) {
return x;
}