Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Apr 12, 2024
1 parent c467ae7 commit 9fd6296
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/src/embedded/importer/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class FileImporter extends ImporterBase {
..url = url.toString()
..fromImport = fromImport;
var containingUrl = canonicalizeContext.containingUrlWithoutMarking;
if (containingUrl != null) {
if (containingUrl case var containingUrl?) {
request.containingUrl = containingUrl.toString();
}
var response = dispatcher.sendFileImportRequest(request);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/embedded/importer/host.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class HostImporter extends ImporterBase {
..url = url.toString()
..fromImport = fromImport;
var containingUrl = canonicalizeContext.containingUrlWithoutMarking;
if (containingUrl != null) {
if (containingUrl case var containingUrl?) {
request.containingUrl = containingUrl.toString();
}
var response = dispatcher.sendCanonicalizeRequest(request);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/importer/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ abstract class AsyncImporter {
///
/// Subclasses should only access this from within calls to [canonicalize].
/// Outside of that context, its value is undefined and subject to change.
///
/// @nodoc
@internal
@protected
@nonVirtual
CanonicalizeContext get canonicalizeContext => utils.canonicalizeContext;
Expand Down
14 changes: 12 additions & 2 deletions lib/src/importer/canonicalize_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@

import 'package:meta/meta.dart';

class CanonicalizeContext {
/// Contextual information used by importers' `canonicalize` method.
@internal
final class CanonicalizeContext {
/// Whether the Sass compiler is currently evaluating an `@import` rule.
final bool fromImport;

/// The URL of the stylesheet that contains the current load.
Uri? get containingUrl {
_wasContainingUrlAccessed = true;
return _containingUrl;
}

final Uri? _containingUrl;

/// Returns the same value as [containingUrl], but doesn't mark it accessed.
Uri? get containingUrlWithoutMarking => _containingUrl;

/// Whether [containingUrl] has been accessed.
///
/// This is used to determine whether canonicalize result is cacheable.
///
/// @nodoc
@internal
bool get wasContainingUrlAccessed => _wasContainingUrlAccessed;
bool _wasContainingUrlAccessed = false;
var _wasContainingUrlAccessed = false;

CanonicalizeContext(this._containingUrl, this.fromImport);
}

0 comments on commit 9fd6296

Please sign in to comment.