-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement access tracking for containingUrl (#2220)
Co-authored-by: Natalie Weizenbaum <nweiz@google.com>
- Loading branch information
Showing
15 changed files
with
141 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2024 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
/// Contextual information used by importers' `canonicalize` method. | ||
@internal | ||
final class CanonicalizeContext { | ||
/// Whether the Sass compiler is currently evaluating an `@import` rule. | ||
bool get fromImport => _fromImport; | ||
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. | ||
bool get wasContainingUrlAccessed => _wasContainingUrlAccessed; | ||
var _wasContainingUrlAccessed = false; | ||
|
||
/// Runs [callback] in a context with specificed [fromImport]. | ||
T withFromImport<T>(bool fromImport, T callback()) { | ||
assert(Zone.current[#_canonicalizeContext] == this); | ||
|
||
var oldFromImport = _fromImport; | ||
_fromImport = fromImport; | ||
try { | ||
return callback(); | ||
} finally { | ||
_fromImport = oldFromImport; | ||
} | ||
} | ||
|
||
CanonicalizeContext(this._containingUrl, this._fromImport); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2014 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import '../../importer/canonicalize_context.dart'; | ||
import '../../util/nullable.dart'; | ||
import '../reflection.dart'; | ||
import '../utils.dart'; | ||
|
||
/// Adds JS members to Dart's `CanonicalizeContext` class. | ||
void updateCanonicalizeContextPrototype() => | ||
getJSClass(CanonicalizeContext(null, false)).defineGetters({ | ||
'fromImport': (CanonicalizeContext self) => self.fromImport, | ||
'containingUrl': (CanonicalizeContext self) => | ||
self.containingUrl.andThen(dartToJSUrl), | ||
}); |
Oops, something went wrong.