-
Notifications
You must be signed in to change notification settings - Fork 360
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
- Loading branch information
Showing
14 changed files
with
149 additions
and
63 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,49 @@ | ||
// 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 '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. | ||
/// | ||
/// @nodoc | ||
@internal | ||
bool get wasContainingUrlAccessed => _wasContainingUrlAccessed; | ||
var _wasContainingUrlAccessed = false; | ||
|
||
/// Runs [callback] in a context with specificed [fromImport]. | ||
/// | ||
/// @nodoc | ||
@internal | ||
T withFromImport<T>(bool fromImport, T callback()) { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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 'package:js/js.dart'; | ||
|
||
import '../../importer/canonicalize_context.dart'; | ||
import '../url.dart'; | ||
import '../../util/nullable.dart'; | ||
import '../utils.dart'; | ||
|
||
@JSExport() | ||
class JSExportCanonicalizeContext { | ||
final CanonicalizeContext _canonicalizeContext; | ||
|
||
bool get fromImport => _canonicalizeContext.fromImport; | ||
JSUrl? get containingUrl => | ||
_canonicalizeContext.containingUrl.andThen(dartToJSUrl); | ||
|
||
JSExportCanonicalizeContext(this._canonicalizeContext); | ||
} |
Oops, something went wrong.