Emit direct imports in preprocess step

This commit is contained in:
Simon Binder 2023-08-13 11:10:31 +02:00
parent 7f6e22b892
commit f8635469d4
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 11 additions and 2 deletions

View File

@ -118,6 +118,10 @@ class DriftPreprocessor {
}
}
}
} else {
// If there aren't any expressions to resolve we don't need to crawl and
// just use the direct imports.
seenFiles.addAll(queue);
}
final importedDartFiles =

View File

@ -24,14 +24,19 @@ var expr_0 = const MyConverter();
''');
});
test('does not emit Dart file if no Dart expressions are used', () async {
test('only includes direct imports if no Dart expressions are used',
() async {
final backend = TestBackend.inTest({
'a|lib/main.drift': '''
import 'foo.dart';
import '2.drift';
CREATE TABLE foo (
bar INTEGER NOT NULL
);
''',
'a|lib/2.drift': '''
import 'bar.dart';
''',
});
@ -39,7 +44,7 @@ CREATE TABLE foo (
backend, Uri.parse('package:a/main.drift'));
expect(result.result.declaredTablesAndViews, ['foo']);
expect(result.temporaryDartFile, isEmpty);
expect(result.temporaryDartFile, "import 'package:a/foo.dart';\n");
});
test('finds nested dart imports', () async {