Skip to content

Commit c8cf6ad

Browse files
authored
Allow libraries without a '.dart' ending (#1900)
* Fix library files without a .dart ending bug * Explain more in comment
1 parent 4cf94b8 commit c8cf6ad

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

lib/src/model.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6516,7 +6516,9 @@ class PackageBuilder {
65166516
}
65176517
}
65186518
var sourceKind = await driver.getSourceKind(filePath);
6519-
if (sourceKind == SourceKind.LIBRARY) {
6519+
// Allow dart source files with inappropriate suffixes (#1897). Those
6520+
// do not show up as SourceKind.LIBRARY.
6521+
if (sourceKind != SourceKind.PART) {
65206522
// Loading libraryElements from part files works, but is painfully slow
65216523
// and creates many duplicates.
65226524
return await driver.currentSession.getResolvedLibrary(source.fullName);

test/model_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,10 @@ void main() {
675675
expect(anonLib.isDeprecated, isFalse);
676676
});
677677

678+
test('can be reexported even if the file suffix is not .dart', () {
679+
expect(fakeLibrary.allClasses.map((c) => c.name), contains('MyClassFromADartFile'));
680+
});
681+
678682
test('that is deprecated has a deprecated css class in linkedName', () {
679683
expect(isDeprecated.linkedName, contains('class="deprecated"'));
680684
});

testing/test_package/lib/fake.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import 'example.dart';
5858
import 'mylibpub.dart' as renamedLib;
5959
import 'mylibpub.dart' as renamedLib2;
6060
import 'two_exports.dart' show BaseClass;
61+
export 'src/notadotdartfile';
6162

6263
// ignore: uri_does_not_exist
6364
export 'package:test_package_imported/categoryExporting.dart'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// Test importing with an invalid dart file extension. (#1897)
2+
library test_package.notadotdartfile;
3+
4+
class MyClassFromADartFile {}

0 commit comments

Comments
 (0)