Skip to content

Commit

Permalink
Check package names when finding import aliases.
Browse files Browse the repository at this point in the history
Closes #2985.
  • Loading branch information
simolus3 committed May 3, 2024
1 parent 6ba049e commit c54fdff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions drift_dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.18.0-dev

- Add support for the `geopoly` extension in drift files.
- Improve finding the correct import alias in generated code for part files.

## 2.17.0

Expand Down
14 changes: 14 additions & 0 deletions drift_dev/lib/src/writer/import_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ class ImportManagerForPartFiles extends ImportManager {
return null;
}

/// Heuristic to determine whether a source uri [wanted] likely exports the
/// [target] element.
///
/// We can't compare the [target] definition with the [wanted] url directly,
/// as many parts use URLs relying on re-exports. For instance, this should
/// return true for a wanted URI of `package:drift/drift.dart` when the
/// element is actually defined in `package:drift/src/runtime/table.dart`.
static bool _matchingUrl(Uri wanted, Element target) {
final targetUri = target.librarySource?.uri;
if (targetUri == null || targetUri.scheme != wanted.scheme) {
return false;
}

if (targetUri.scheme == 'package') {
// Match if the two elements are coming from the same package
final targetPackage = targetUri.pathSegments.first;
final wantedPackage = wanted.pathSegments.first;
return targetPackage == wantedPackage;
}

return true;
}
}
Expand Down

0 comments on commit c54fdff

Please sign in to comment.