diff --git a/lib/src/model.dart b/lib/src/model.dart index 9868133800..44c71997ce 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -6516,7 +6516,9 @@ class PackageBuilder { } } var sourceKind = await driver.getSourceKind(filePath); - if (sourceKind == SourceKind.LIBRARY) { + // Allow dart source files with inappropriate suffixes (#1897). Those + // do not show up as SourceKind.LIBRARY. + if (sourceKind != SourceKind.PART) { // Loading libraryElements from part files works, but is painfully slow // and creates many duplicates. return await driver.currentSession.getResolvedLibrary(source.fullName); diff --git a/test/model_test.dart b/test/model_test.dart index da2befc720..c7452b9cab 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -675,6 +675,10 @@ void main() { expect(anonLib.isDeprecated, isFalse); }); + test('can be reexported even if the file suffix is not .dart', () { + expect(fakeLibrary.allClasses.map((c) => c.name), contains('MyClassFromADartFile')); + }); + test('that is deprecated has a deprecated css class in linkedName', () { expect(isDeprecated.linkedName, contains('class="deprecated"')); }); diff --git a/testing/test_package/lib/fake.dart b/testing/test_package/lib/fake.dart index 03b0a69ee0..4af1f2ad87 100644 --- a/testing/test_package/lib/fake.dart +++ b/testing/test_package/lib/fake.dart @@ -58,6 +58,7 @@ import 'example.dart'; import 'mylibpub.dart' as renamedLib; import 'mylibpub.dart' as renamedLib2; import 'two_exports.dart' show BaseClass; +export 'src/notadotdartfile'; // ignore: uri_does_not_exist export 'package:test_package_imported/categoryExporting.dart' diff --git a/testing/test_package/lib/src/notadotdartfile b/testing/test_package/lib/src/notadotdartfile new file mode 100644 index 0000000000..7f9a1a3fe0 --- /dev/null +++ b/testing/test_package/lib/src/notadotdartfile @@ -0,0 +1,4 @@ +/// Test importing with an invalid dart file extension. (#1897) +library test_package.notadotdartfile; + +class MyClassFromADartFile {} \ No newline at end of file