disable import resolution on type-only import specifiers

This commit is contained in:
Erik Krogh Kristensen
2021-11-23 12:53:06 +01:00
parent d946802057
commit d1a7feebc4
3 changed files with 9 additions and 2 deletions

View File

@@ -42,7 +42,7 @@ private predicate defn(ControlFlowNode def, Expr lhs, AST::ValueNode rhs) {
lhs = i.getIdentifier() and rhs = i.getImportedEntity()
)
or
exists(ImportSpecifier i | def = i | lhs = i.getLocal() and rhs = i)
exists(ImportSpecifier i | def = i and not i.isTypeOnly() | lhs = i.getLocal() and rhs = i)
or
exists(EnumMember member | def = member.getIdentifier() |
lhs = def and rhs = member.getInitializer()

View File

@@ -881,6 +881,7 @@ module DataFlow {
ImportSpecifierAsPropRead() {
astNode = imprt.getASpecifier() and
not astNode.isTypeOnly() and
exists(astNode.getImportedName())
}

View File

@@ -15,7 +15,11 @@ private import AbstractPropertiesImpl
private class AnalyzedImportSpecifier extends AnalyzedVarDef, @import_specifier {
ImportDeclaration id;
AnalyzedImportSpecifier() { this = id.getASpecifier() and exists(id.resolveImportedPath()) }
AnalyzedImportSpecifier() {
this = id.getASpecifier() and
exists(id.resolveImportedPath()) and
not this.(ImportSpecifier).isTypeOnly()
}
override DataFlow::AnalyzedNode getRhs() { result.(AnalyzedImport).getImportSpecifier() = this }
@@ -135,10 +139,12 @@ private predicate incompleteExport(ES2015Module m, string y) {
*/
private class AnalyzedImport extends AnalyzedPropertyRead, DataFlow::ValueNode {
Module imported;
override ImportSpecifier astNode;
AnalyzedImport() {
exists(ImportDeclaration id |
astNode = id.getASpecifier() and
not astNode.isTypeOnly() and
imported = id.getImportedModule()
)
}