Skip to content

Commit 7b63de3

Browse files
committed
Fixes for importing URIs that have 'part of' directives.
Change-Id: If5495106e44b55059558537ceafee43549235152 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112264 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent d204876 commit 7b63de3

File tree

1 file changed

+26
-5
lines changed
  • pkg/analyzer/lib/src/dart/analysis

1 file changed

+26
-5
lines changed

pkg/analyzer/lib/src/dart/analysis/ddc.dart

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ class DevCompilerResynthesizerBuilder {
134134
var inputLibraries = <summary2.LinkInputLibrary>[];
135135

136136
var sourceToUnit = _fileCrawler.sourceToUnit;
137-
for (var librarySource in _fileCrawler.librarySources) {
137+
var librarySourcesToLink = <Source>[]
138+
..addAll(_fileCrawler.librarySources)
139+
..addAll(_fileCrawler._invalidLibrarySources);
140+
for (var librarySource in librarySourcesToLink) {
138141
var libraryUriStr = '${librarySource.uri}';
139142
var unit = sourceToUnit[librarySource];
140143

@@ -267,6 +270,18 @@ class _SourceCrawler {
267270
/// we only visit a given source once.
268271
var _knownSources = Set<Uri>();
269272

273+
/// The set of URIs that expected to be libraries.
274+
///
275+
/// Some of the might turn out to have `part of` directive, and so reported
276+
/// later. However we still must be able to provide some element for them
277+
/// when requested via `import` or `export` directives.
278+
final Set<Uri> _expectedLibraryUris = Set<Uri>();
279+
280+
/// The list of sources with URIs that [_expectedLibraryUris], but turned
281+
/// out to be parts. We still add them into summaries, but don't resolve
282+
/// them as units.
283+
final List<Source> _invalidLibrarySources = [];
284+
270285
final Map<Source, UnlinkedUnitBuilder> sourceToUnlinkedUnit = {};
271286
final Map<String, UnlinkedUnitBuilder> uriToUnlinkedUnit = {};
272287
final Map<Source, CompilationUnit> sourceToUnit = {};
@@ -321,23 +336,27 @@ class _SourceCrawler {
321336
uriToUnlinkedUnit[uriStr] = unlinkedUnit;
322337
sourceToUnlinkedUnit[source] = unlinkedUnit;
323338

324-
void enqueueSource(String relativeUri) {
339+
void enqueueSource(String relativeUri, bool shouldBeLibrary) {
325340
var sourceUri = resolveRelativeUri(uri, Uri.parse(relativeUri));
326341
if (_knownSources.add(sourceUri)) {
327342
_pendingSource.add(sourceUri);
343+
if (shouldBeLibrary) {
344+
_expectedLibraryUris.add(sourceUri);
345+
}
328346
}
329347
}
330348

331349
// Add reachable imports/exports/parts, if any.
332350
var isPart = false;
333351
for (var directive in unit.directives) {
334352
if (directive is UriBasedDirective) {
335-
enqueueSource(directive.uri.stringValue);
336-
// Handle conditional imports.
337353
if (directive is NamespaceDirective) {
354+
enqueueSource(directive.uri.stringValue, true);
338355
for (var config in directive.configurations) {
339-
enqueueSource(config.uri.stringValue);
356+
enqueueSource(config.uri.stringValue, true);
340357
}
358+
} else {
359+
enqueueSource(directive.uri.stringValue, false);
341360
}
342361
} else if (directive is PartOfDirective) {
343362
isPart = true;
@@ -348,6 +367,8 @@ class _SourceCrawler {
348367
if (!isPart) {
349368
libraryUris.add(uriStr);
350369
librarySources.add(source);
370+
} else if (_expectedLibraryUris.contains(uri)) {
371+
_invalidLibrarySources.add(source);
351372
}
352373
}
353374
}

0 commit comments

Comments
 (0)