@@ -177,8 +177,16 @@ class ProgramMap {
177
177
/// The files in the given project
178
178
final p.PathSet files;
179
179
180
+ /// A list of declarations to include
180
181
final List <String > filterDeclSet;
181
182
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
+
182
190
final bool generateAll;
183
191
184
192
final bool strictUnsupported;
@@ -201,28 +209,42 @@ class ProgramMap {
201
209
} else {
202
210
final src = program.getSourceFile (file);
203
211
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));
206
224
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 ;
212
230
213
- final symbol = typeChecker.getSymbolAtLocation (src)! ;
214
- final exports = symbol.exports? .toDart ?? {};
231
+ final symbol = typeChecker.getSymbolAtLocation (src)! ;
232
+ final exports = symbol.exports? .toDart ?? {};
215
233
216
- final targetSymbol = exports[d.toJS]! ;
234
+ final targetSymbol = exports[d.toJS]! ;
217
235
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
+ }
221
243
}
222
- }
223
244
224
- nodeMap = transformer.processAndReturn ();
225
- _activeTransformers[file] = transformer;
245
+ nodeMap = transformer.processAndReturn ();
246
+ _activeTransformers[file] = transformer;
247
+ }
226
248
}
227
249
228
250
final name = declName ?? (node as TSNamedDeclaration ).name? .text;
@@ -287,8 +309,14 @@ class ProgramMap {
287
309
} else {
288
310
final exportedSymbols = sourceSymbol.exports? .toDart;
289
311
290
- for (final MapEntry (value: symbol)
312
+ for (final MapEntry (key : symbolName, value: symbol)
291
313
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
+ }
292
320
final decls = symbol.getDeclarations ()? .toDart ?? [];
293
321
try {
294
322
final aliasedSymbol = typeChecker.getAliasedSymbol (symbol);
0 commit comments