@@ -90,6 +90,10 @@ class References {
90
90
/// map to the [ReferenceSource] for the `sass:meta` module).
91
91
final Map <SassNode , ReferenceSource > sources;
92
92
93
+ /// The set of import-only files that do not directly depend on their regular
94
+ /// counterparts.
95
+ final Set <Uri > orphanImportOnlyFiles;
96
+
93
97
/// An iterable of all member declarations.
94
98
Iterable <MemberDeclaration > get allDeclarations =>
95
99
variables.values.followedBy (mixins.values).followedBy (functions.values);
@@ -149,7 +153,8 @@ class References {
149
153
getFunctionReferences,
150
154
Set <MemberDeclaration > globalDeclarations,
151
155
Map <MemberDeclaration , Set <Uri >> libraries,
152
- Map <SassNode , ReferenceSource > sources)
156
+ Map <SassNode , ReferenceSource > sources,
157
+ Set <Uri > orphanImportOnlyFiles)
153
158
: variables = UnmodifiableBidirectionalMapView (variables),
154
159
variableReassignments =
155
160
UnmodifiableBidirectionalMapView (variableReassignments),
@@ -162,7 +167,8 @@ class References {
162
167
globalDeclarations = UnmodifiableSetView (globalDeclarations),
163
168
libraries = UnmodifiableMapView (
164
169
mapMap (libraries, value: (_, urls) => UnmodifiableSetView (urls))),
165
- sources = UnmodifiableMapView (sources);
170
+ sources = UnmodifiableMapView (sources),
171
+ orphanImportOnlyFiles = UnmodifiableSetView (orphanImportOnlyFiles);
166
172
167
173
/// Constructs a new [References] object based on a [stylesheet] (imported by
168
174
/// [importer] ) and its dependencies.
@@ -188,6 +194,7 @@ class _ReferenceVisitor extends RecursiveAstVisitor {
188
194
final _globalDeclarations = < MemberDeclaration > {};
189
195
final _libraries = < MemberDeclaration , Set <Uri >> {};
190
196
final _sources = < SassNode , ReferenceSource > {};
197
+ final _orphanImportOnlyFiles = < Uri > {};
191
198
192
199
/// The current global scope.
193
200
///
@@ -243,6 +250,12 @@ class _ReferenceVisitor extends RecursiveAstVisitor {
243
250
/// stylesheet.
244
251
Importer _importer;
245
252
253
+ /// If the current stylesheet is an import-only file, this starts as true and
254
+ /// is changed to false if it forwards its regular counterpart.
255
+ ///
256
+ /// This is always false for regular files.
257
+ bool _isOrphanImportOnly;
258
+
246
259
/// Cache used to load stylesheets.
247
260
ImportCache importCache;
248
261
@@ -276,7 +289,8 @@ class _ReferenceVisitor extends RecursiveAstVisitor {
276
289
_getFunctionReferences,
277
290
_globalDeclarations,
278
291
_libraries,
279
- _sources);
292
+ _sources,
293
+ _orphanImportOnlyFiles);
280
294
}
281
295
282
296
/// Checks any remaining [_unresolvedReferences] to see if they match a
@@ -321,9 +335,13 @@ class _ReferenceVisitor extends RecursiveAstVisitor {
321
335
void visitStylesheet (Stylesheet node) {
322
336
var oldNamespaces = _namespaces;
323
337
var oldUrl = _currentUrl;
338
+ var oldOrphaned = _isOrphanImportOnly;
324
339
_namespaces = {};
325
340
_currentUrl = node.span.sourceUrl;
341
+ _isOrphanImportOnly = isImportOnlyFile (_currentUrl);
326
342
super .visitStylesheet (node);
343
+ if (_isOrphanImportOnly) _orphanImportOnlyFiles.add (_currentUrl);
344
+ _isOrphanImportOnly = oldOrphaned;
327
345
_namespaces = oldNamespaces;
328
346
_currentUrl = oldUrl;
329
347
}
@@ -436,6 +454,9 @@ class _ReferenceVisitor extends RecursiveAstVisitor {
436
454
void visitForwardRule (ForwardRule node) {
437
455
super .visitForwardRule (node);
438
456
var canonicalUrl = _loadUseOrForward (node.url, node);
457
+ if (_isOrphanImportOnly && _currentUrl == getImportOnlyUrl (canonicalUrl)) {
458
+ _isOrphanImportOnly = false ;
459
+ }
439
460
var moduleScope = _moduleScopes[canonicalUrl];
440
461
for (var declaration in moduleScope.variables.values) {
441
462
if (declaration.member is ! VariableDeclaration ) {
0 commit comments