Skip to content

Commit 7090124

Browse files
committed
JS: Implement type inference through export * as ns
1 parent a252a41 commit 7090124

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

javascript/ql/src/semmle/javascript/ES2015Modules.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,18 @@ class ReExportDefaultSpecifier extends ExportDefaultSpecifier {
545545
}
546546

547547
/**
548-
* A namespace export specifier.
548+
* A namespace export specifier, that is `*` or `* as x` occuring in an export declaration.
549549
*
550-
* Example:
550+
* Examples:
551551
*
552552
* ```
553553
* export
554554
* * // namespace export specifier
555555
* from 'a';
556+
*
557+
* export
558+
* * as x // namespace export specifier
559+
* from 'a';
556560
* ```
557561
*/
558562
class ExportNamespaceSpecifier extends ExportSpecifier, @exportnamespacespecifier { }
@@ -564,6 +568,7 @@ class ExportNamespaceSpecifier extends ExportSpecifier, @exportnamespacespecifie
564568
*
565569
* ```
566570
* export * from 'a'; // bulk re-export declaration
571+
* export * as x from 'a'; // namespace re-export declaration
567572
* export { x } from 'a'; // named re-export declaration
568573
* export x from 'a'; // default re-export declaration
569574
* ```

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,16 @@ private class AnalyzedClosureGlobalAccessPath extends AnalyzedNode, AnalyzedProp
399399
)
400400
}
401401
}
402+
403+
/**
404+
* A namespace export declaration analyzed as a property write.
405+
*/
406+
private class AnalyzedExportNamespaceSpecifier extends AnalyzedPropertyWrite, DataFlow::ValueNode {
407+
override ExportNamespaceSpecifier astNode;
408+
409+
override predicate writesValue(AbstractValue baseVal, string propName, AbstractValue value) {
410+
baseVal = TAbstractExportsObject(getTopLevel()) and
411+
propName = astNode.getExportedName() and
412+
value = TAbstractExportsObject(astNode.getExportDeclaration().(ReExportDeclaration).getReExportedModule())
413+
}
414+
}

javascript/ql/test/library-tests/CallGraphs/AnnotatedTest/Test.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ spuriousCallee
22
missingCallee
33
| constructor-field.ts:40:5:40:14 | f3.build() | constructor-field.ts:13:3:13:12 | build() {} |
44
| constructor-field.ts:71:1:71:11 | bf3.build() | constructor-field.ts:13:3:13:12 | build() {} |
5-
| reExportLibClient.js:4:1:4:6 | ns.f() | lib.js:3:2:3:14 | function() {} |
65
badAnnotation

0 commit comments

Comments
 (0)