@@ -27,7 +27,7 @@ import { DependencyFactory } from "./dependency/DependencyFactory";
2727import { Export } from "./target/export/Export" ;
2828import { TargetFactory } from "./target/TargetFactory" ;
2929import { TypeModelFactory } from "./type/resolving/TypeModelFactory" ;
30- import { getAllFiles , readFile } from "./utils/fileSystem" ;
30+ import { readFile } from "./utils/fileSystem" ;
3131import { ExportFactory } from "./target/export/ExportFactory" ;
3232import { TypeExtractor } from "./type/discovery/TypeExtractor" ;
3333import { TypeModel } from "./type/resolving/TypeModel" ;
@@ -51,7 +51,9 @@ export class RootContext extends CoreRootContext<t.Node> {
5151
5252 protected _constantPoolFactory : ConstantPoolFactory ;
5353
54- protected _files : string [ ] ;
54+ protected _targetFiles : Set < string > ;
55+ protected _analysisFiles : Set < string > ;
56+
5557 // filepath -> id -> element
5658 protected _elementMap : Map < string , Map < string , Element > > ;
5759 // filepath -> id -> relation
@@ -67,6 +69,8 @@ export class RootContext extends CoreRootContext<t.Node> {
6769
6870 constructor (
6971 rootPath : string ,
72+ targetFiles : Set < string > ,
73+ analysisFiles : Set < string > ,
7074 abstractSyntaxTreeFactory : AbstractSyntaxTreeFactory ,
7175 controlFlowGraphFactory : ControlFlowGraphFactory ,
7276 targetFactory : TargetFactory ,
@@ -85,6 +89,8 @@ export class RootContext extends CoreRootContext<t.Node> {
8589 dependencyFactory
8690 ) ;
8791 RootContext . LOGGER = getLogger ( "RootContext" ) ;
92+ this . _targetFiles = targetFiles ;
93+ this . _analysisFiles = analysisFiles ;
8894 this . _exportFactory = exportFactory ;
8995 this . _typeExtractor = typeExtractor ;
9096 this . _typeResolver = typeResolver ;
@@ -95,21 +101,6 @@ export class RootContext extends CoreRootContext<t.Node> {
95101 return this . _rootPath ;
96102 }
97103
98- // TODO something with the types
99-
100- getFiles ( ) {
101- if ( ! this . _files ) {
102- this . _files = getAllFiles ( this . rootPath , ".js" ) . filter (
103- ( x ) =>
104- ! x . includes ( "/test/" ) &&
105- ! x . includes ( ".test.js" ) &&
106- ! x . includes ( "node_modules" )
107- ) ; // maybe we should also take those into account
108- }
109-
110- return this . _files ;
111- }
112-
113104 override getSource ( filePath : string ) {
114105 let absoluteTargetPath = this . resolvePath ( filePath ) ;
115106
@@ -172,7 +163,7 @@ export class RootContext extends CoreRootContext<t.Node> {
172163 if ( ! this . _exportMap ) {
173164 this . _exportMap = new Map ( ) ;
174165
175- for ( const filepath of this . getFiles ( ) ) {
166+ for ( const filepath of this . _analysisFiles ) {
176167 this . _exportMap . set ( filepath , this . getExports ( filepath ) ) ;
177168 }
178169 }
@@ -208,7 +199,7 @@ export class RootContext extends CoreRootContext<t.Node> {
208199 if ( ! this . _elementMap ) {
209200 this . _elementMap = new Map ( ) ;
210201
211- for ( const filepath of this . getFiles ( ) ) {
202+ for ( const filepath of this . _analysisFiles ) {
212203 this . _elementMap . set ( filepath , this . getElements ( filepath ) ) ;
213204 }
214205 }
@@ -244,7 +235,7 @@ export class RootContext extends CoreRootContext<t.Node> {
244235 if ( ! this . _relationMap ) {
245236 this . _relationMap = new Map ( ) ;
246237
247- for ( const filepath of this . getFiles ( ) ) {
238+ for ( const filepath of this . _analysisFiles ) {
248239 this . _relationMap . set ( filepath , this . getRelations ( filepath ) ) ;
249240 }
250241 }
@@ -280,7 +271,7 @@ export class RootContext extends CoreRootContext<t.Node> {
280271 if ( ! this . _objectMap ) {
281272 this . _objectMap = new Map ( ) ;
282273
283- for ( const filepath of this . getFiles ( ) ) {
274+ for ( const filepath of this . _analysisFiles ) {
284275 this . _objectMap . set ( filepath , this . getObjectTypes ( filepath ) ) ;
285276 }
286277 }
@@ -332,7 +323,7 @@ export class RootContext extends CoreRootContext<t.Node> {
332323 // TODO cache
333324 private _getContextConstantPool ( ) : ConstantPool {
334325 const constantPool = new ConstantPool ( ) ;
335- for ( const filepath of this . getFiles ( ) ) {
326+ for ( const filepath of this . _analysisFiles ) {
336327 const ast = this . getAbstractSyntaxTree ( filepath ) ;
337328 this . _constantPoolFactory . extract ( filepath , ast , constantPool ) ;
338329 }
0 commit comments