@@ -102,6 +102,9 @@ class LibraryBuilder with MacroApplicationsContainer {
102102 /// The `export` directives that export this library.
103103 final List <Export > exports = [];
104104
105+ /// The identifier of the reference used for unnamed fragments.
106+ int _nextUnnamedId = 0 ;
107+
105108 /// The fields that were speculatively created as [ConstFieldElementImpl] ,
106109 /// but we want to clear [ConstVariableElement.constantInitializer] for it
107110 /// if the class will not end up with a `const` constructor. We don't know
@@ -1074,8 +1077,8 @@ class LibraryBuilder with MacroApplicationsContainer {
10741077 }) {
10751078 var importPrefix = state.unlinked.prefix.mapOrNull ((unlinked) {
10761079 var prefix = _buildLibraryImportPrefix (
1077- name: unlinked.name,
10781080 nameOffset: unlinked.nameOffset,
1081+ name: unlinked.name,
10791082 containerLibrary: containerLibrary,
10801083 containerUnit: containerUnit,
10811084 );
@@ -1093,8 +1096,7 @@ class LibraryBuilder with MacroApplicationsContainer {
10931096 var prefixFragment = state.unlinked.prefix.mapOrNull ((unlinked) {
10941097 return _buildLibraryImportPrefixFragment (
10951098 libraryFragment: containerUnit,
1096- name: unlinked.name,
1097- nameOffset: unlinked.nameOffset,
1099+ unlinkedName: unlinked.name,
10981100 isDeferred: unlinked.deferredOffset != null ,
10991101 );
11001102 });
@@ -1171,20 +1173,21 @@ class LibraryBuilder with MacroApplicationsContainer {
11711173 }
11721174
11731175 PrefixElementImpl _buildLibraryImportPrefix ({
1174- required String name,
11751176 required int nameOffset,
1177+ required UnlinkedLibraryImportPrefixName ? name,
11761178 required LibraryOrAugmentationElementImpl containerLibrary,
11771179 required CompilationUnitElementImpl containerUnit,
11781180 }) {
11791181 // TODO(scheglov): Make reference required.
11801182 var containerRef = containerUnit.reference! ;
1181- var reference = containerRef.getChild ('@prefix' ).getChild (name);
1183+ var refName = name? .name ?? '${_nextUnnamedId ++}' ;
1184+ var reference = containerRef.getChild ('@prefix' ).getChild (refName);
11821185 var existing = reference.element;
11831186 if (existing is PrefixElementImpl ) {
11841187 return existing;
11851188 } else {
11861189 var result = PrefixElementImpl (
1187- name,
1190+ name? .name ?? '' ,
11881191 nameOffset,
11891192 reference: reference,
11901193 );
@@ -1196,23 +1199,28 @@ class LibraryBuilder with MacroApplicationsContainer {
11961199
11971200 PrefixFragmentImpl _buildLibraryImportPrefixFragment ({
11981201 required CompilationUnitElementImpl libraryFragment,
1199- required String name,
1200- required int nameOffset,
1202+ required UnlinkedLibraryImportPrefixName ? unlinkedName,
12011203 required bool isDeferred,
12021204 }) {
1205+ FragmentNameImpl ? fragmentName;
1206+ if (unlinkedName != null ) {
1207+ fragmentName = FragmentNameImpl (
1208+ name: unlinkedName.name,
1209+ nameOffset: unlinkedName.nameOffset,
1210+ );
1211+ }
1212+
12031213 var fragment = PrefixFragmentImpl (
12041214 enclosingFragment: libraryFragment,
1205- name: name,
1206- name2: FragmentNameImpl (
1207- name: name,
1208- nameOffset: nameOffset,
1209- ),
1210- nameOffset: nameOffset,
1215+ name: unlinkedName? .name ?? '' ,
1216+ nameOffset: unlinkedName? .nameOffset ?? - 1 ,
1217+ name2: fragmentName,
12111218 isDeferred: isDeferred,
12121219 );
12131220
12141221 var containerRef = libraryFragment.reference! ;
1215- var reference = containerRef.getChild ('@prefix2' ).getChild (name);
1222+ var refName = unlinkedName? .name ?? '${_nextUnnamedId ++}' ;
1223+ var reference = containerRef.getChild ('@prefix2' ).getChild (refName);
12161224 var element = reference.element2 as PrefixElementImpl2 ? ;
12171225
12181226 if (element == null ) {
0 commit comments