Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47673c6

Browse files
committed
TS: Disable export analysis for type-only exports
1 parent 16c909b commit 47673c6

6 files changed

Lines changed: 25 additions & 1 deletion

File tree

javascript/ql/src/semmle/javascript/dataflow/internal/InterModuleTypeInference.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,16 @@ private class AnalyzedClosureGlobalAccessPath extends AnalyzedNode, AnalyzedProp
405405
*/
406406
private class AnalyzedExportNamespaceSpecifier extends AnalyzedPropertyWrite, DataFlow::ValueNode {
407407
override ExportNamespaceSpecifier astNode;
408+
ReExportDeclaration decl;
409+
410+
AnalyzedExportNamespaceSpecifier() {
411+
decl = astNode.getExportDeclaration() and
412+
not decl.isTypeOnly()
413+
}
408414

409415
override predicate writesValue(AbstractValue baseVal, string propName, AbstractValue value) {
410416
baseVal = TAbstractExportsObject(getTopLevel()) and
411417
propName = astNode.getExportedName() and
412-
value = TAbstractExportsObject(astNode.getExportDeclaration().(ReExportDeclaration).getReExportedModule())
418+
value = TAbstractExportsObject(decl.getReExportedModule())
413419
}
414420
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function f() {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { ns } from "./importType";
2+
3+
ns.f(); // Calls local method in 'importType'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type * as ns from "./exportFunction";
2+
3+
export var ns = { f() {} };
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
getAVarReference
22
| Foo | tst.ts:5:5:5:7 | Foo |
3+
| f | exportFunction.ts:1:17:1:17 | f |
4+
| ns | importFunction.ts:1:10:1:11 | ns |
5+
| ns | importFunction.ts:3:1:3:2 | ns |
6+
| ns | importType.ts:3:12:3:13 | ns |
37
getAnExportAccess
48
| Foo | tst.ts:3:15:3:17 | Foo |
59
getATypeDecl
610
| Foo | tst.ts:1:15:1:17 | Foo |
11+
| ns | importFunction.ts:1:10:1:11 | ns |
712
| types | tst.ts:7:18:7:22 | types |
13+
calls
14+
| importFunction.ts:3:1:3:6 | ns.f() | importType.ts:3:19:3:24 | f() {} |

javascript/ql/test/library-tests/TypeScript/TypeOnlyImportExport/test.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ query VarRef getAnExportAccess(LocalTypeName t) {
1111
query TypeDecl getATypeDecl(LocalTypeName t) {
1212
result = t.getADeclaration()
1313
}
14+
15+
query Function calls(DataFlow::InvokeNode invoke) {
16+
result = invoke.getACallee()
17+
}

0 commit comments

Comments
 (0)