Skip to content

Commit 51e1bda

Browse files
committed
JS: Move isTypeOnly() check into a direct check, instead of an override
1 parent 9c4f85f commit 51e1bda

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

javascript/ql/lib/semmle/javascript/ES2015Modules.qll

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,16 @@ class ExportNamedDeclaration extends ExportDeclaration, @export_named_declaratio
543543
VarDecl getADecl() { result = this.getAnExportedDecl() }
544544

545545
override predicate exportsDirectlyAs(LexicalName v, string name) {
546-
exists(LexicalDecl vd | vd = this.getAnExportedDecl() |
547-
name = vd.getName() and v = vd.getALexicalName()
548-
)
549-
or
550-
exists(ExportSpecifier spec | spec = this.getASpecifier() and name = spec.getExportedName() |
551-
v = spec.getLocal().(LexicalAccess).getALexicalName()
552-
)
546+
(
547+
exists(LexicalDecl vd | vd = this.getAnExportedDecl() |
548+
name = vd.getName() and v = vd.getALexicalName()
549+
)
550+
or
551+
exists(ExportSpecifier spec | spec = this.getASpecifier() and name = spec.getExportedName() |
552+
v = spec.getLocal().(LexicalAccess).getALexicalName()
553+
)
554+
) and
555+
not (this.isTypeOnly() and v instanceof Variable)
553556
}
554557

555558
override DataFlow::Node getDirectSourceNode(string name) {
@@ -600,18 +603,6 @@ private class ExportNamespaceStep extends PreCallGraphStep {
600603
}
601604
}
602605

603-
/**
604-
* An export declaration with the `type` modifier.
605-
*/
606-
private class TypeOnlyExportDeclaration extends ExportNamedDeclaration {
607-
TypeOnlyExportDeclaration() { this.isTypeOnly() }
608-
609-
override predicate exportsDirectlyAs(LexicalName v, string name) {
610-
super.exportsDirectlyAs(v, name) and
611-
not v instanceof Variable
612-
}
613-
}
614-
615606
/**
616607
* An export specifier in an export declaration.
617608
*
@@ -834,7 +825,8 @@ class SelectiveReExportDeclaration extends ReExportDeclaration, ExportNamedDecla
834825
override predicate reExportsAs(LexicalName v, string name) {
835826
exists(ExportSpecifier spec | spec = this.getASpecifier() and name = spec.getExportedName() |
836827
this.getReExportedES2015Module().exportsAs(v, spec.getLocalName())
837-
)
828+
) and
829+
not (this.isTypeOnly() and v instanceof Variable)
838830
}
839831

840832
overlay[global]

0 commit comments

Comments
 (0)