mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 14:32:24 +00:00
Let a part have its own LibraryCycle if requested.
Change-Id: Ic724342040f951cfc670a6daa3e6be08e33d2fc2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213531 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
7015c192ab
commit
532214b033
2 changed files with 31 additions and 7 deletions
|
@ -259,13 +259,6 @@ class FileState {
|
|||
/// Return the [LibraryCycle] this file belongs to, even if it consists of
|
||||
/// just this file. If the library cycle is not known yet, compute it.
|
||||
LibraryCycle get libraryCycle {
|
||||
if (isPart) {
|
||||
final library = this.library;
|
||||
if (library != null && !identical(library, this)) {
|
||||
return library.libraryCycle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_libraryCycle == null) {
|
||||
computeLibraryCycle(_fsState._saltForElements, this);
|
||||
}
|
||||
|
|
|
@ -498,6 +498,7 @@ class D implements C {}
|
|||
// It's a cycle.
|
||||
_assertLibraryCycle(fa, [fa, fb], []);
|
||||
_assertLibraryCycle(fb, [fa, fb], []);
|
||||
expect(fa.libraryCycle, same(fb.libraryCycle));
|
||||
|
||||
// Update a.dart so that it does not import b.dart anymore.
|
||||
newFile(pa);
|
||||
|
@ -520,6 +521,36 @@ part 'a.dart';
|
|||
_assertLibraryCycle(fa, [fa], []);
|
||||
}
|
||||
|
||||
test_libraryCycle_part() {
|
||||
var a_path = convertPath('/aaa/lib/a.dart');
|
||||
var b_path = convertPath('/aaa/lib/b.dart');
|
||||
|
||||
newFile(a_path, content: r'''
|
||||
part 'b.dart';
|
||||
''');
|
||||
newFile(b_path, content: r'''
|
||||
part of 'a.dart';
|
||||
''');
|
||||
|
||||
var a_file = fileSystemState.getFileForPath(a_path);
|
||||
var b_file = fileSystemState.getFileForPath(b_path);
|
||||
_assertFilesWithoutLibraryCycle([a_file, b_file]);
|
||||
|
||||
// Compute the library cycle for 'a.dart', the library.
|
||||
var a_libraryCycle = a_file.libraryCycle;
|
||||
_assertFilesWithoutLibraryCycle([b_file]);
|
||||
|
||||
// The part 'b.dart' has its own library cycle.
|
||||
// If the user chooses to import a part, it is a compile-time error.
|
||||
// We could handle this in different ways:
|
||||
// 1. Completely ignore an import of a file with a `part of` directive.
|
||||
// 2. Treat such file as a library anyway.
|
||||
// By giving a part its own library cycle we support (2).
|
||||
var b_libraryCycle = b_file.libraryCycle;
|
||||
expect(b_libraryCycle, isNot(same(a_libraryCycle)));
|
||||
_assertFilesWithoutLibraryCycle([]);
|
||||
}
|
||||
|
||||
test_referencedNames() {
|
||||
String path = convertPath('/aaa/lib/a.dart');
|
||||
newFile(path, content: r'''
|
||||
|
|
Loading…
Reference in a new issue