@@ -177,8 +177,16 @@ class ProgramMap {
177177 /// The files in the given project
178178 final p.PathSet files;
179179
180+ /// A list of declarations to include
180181 final List <String > filterDeclSet;
181182
183+ /// The declarations as globs
184+ List <RegExp > get filterDeclSetPatterns => filterDeclSet.map ((decl) {
185+ final escapedDecl = RegExp .escape (decl);
186+ if (escapedDecl == decl) return RegExp ('^$decl \$ ' );
187+ return RegExp (decl);
188+ }).toList ();
189+
182190 final bool generateAll;
183191
184192 final bool strictUnsupported;
@@ -201,28 +209,42 @@ class ProgramMap {
201209 } else {
202210 final src = program.getSourceFile (file);
203211
204- final transformer =
205- _activeTransformers.putIfAbsent (file, () => Transformer (this , src));
212+ if (src == null && ! strictUnsupported) {
213+ // print warning
214+ print ('WARN: Could not find file $file ' );
215+ // try to transform by yourself
216+ final anonymousTransformer = _activeTransformers.putIfAbsent (
217+ file, () => Transformer (this , null , file: file));
218+
219+ // TODO: Replace with .transformAndReturn once #388 lands
220+ return anonymousTransformer.transformAndReturn (node);
221+ } else {
222+ final transformer =
223+ _activeTransformers.putIfAbsent (file, () => Transformer (this , src));
206224
207- if (! transformer.nodes.contains (node)) {
208- if (declName case final d?
209- when transformer.nodeMap.findByName (d).isEmpty) {
210- // find the source file decl
211- if (src == null ) return null ;
225+ if (! transformer.nodes.contains (node)) {
226+ if (declName case final d?
227+ when transformer.nodeMap.findByName (d).isEmpty) {
228+ // find the source file decl
229+ if (src == null ) return null ;
212230
213- final symbol = typeChecker.getSymbolAtLocation (src)! ;
214- final exports = symbol.exports? .toDart ?? {};
231+ final symbol = typeChecker.getSymbolAtLocation (src)! ;
232+ final exports = symbol.exports? .toDart ?? {};
215233
216- final targetSymbol = exports[d.toJS]! ;
234+ final targetSymbol = exports[d.toJS]! ;
217235
218- transformer.transform (targetSymbol.getDeclarations ()! .toDart.first);
219- } else {
220- transformer.transform (node);
236+ for (final decl in targetSymbol.getDeclarations ()? .toDart ??
237+ < TSDeclaration > []) {
238+ transformer.transform (decl);
239+ }
240+ } else {
241+ transformer.transform (node);
242+ }
221243 }
222- }
223244
224- nodeMap = transformer.processAndReturn ();
225- _activeTransformers[file] = transformer;
245+ nodeMap = transformer.processAndReturn ();
246+ _activeTransformers[file] = transformer;
247+ }
226248 }
227249
228250 final name = declName ?? (node as TSNamedDeclaration ).name? .text;
@@ -287,8 +309,14 @@ class ProgramMap {
287309 } else {
288310 final exportedSymbols = sourceSymbol.exports? .toDart;
289311
290- for (final MapEntry (value: symbol)
312+ for (final MapEntry (key : symbolName, value: symbol)
291313 in exportedSymbols? .entries ?? < MapEntry <JSString , TSSymbol >> []) {
314+ // if there are decls to filter by and it does not match any, skip
315+ if (! filterDeclSetPatterns
316+ .any ((f) => f.hasMatch (symbolName.toDart)) &&
317+ filterDeclSet.isNotEmpty) {
318+ continue ;
319+ }
292320 final decls = symbol.getDeclarations ()? .toDart ?? [];
293321 try {
294322 final aliasedSymbol = typeChecker.getAliasedSymbol (symbol);
0 commit comments