importCanonical method

Stylesheet? importCanonical(
  1. Importer importer,
  2. Uri canonicalUrl, {
  3. Uri? originalUrl,
  4. bool quiet = false,
})

Tries to load the canonicalized canonicalUrl using importer.

If importer can import canonicalUrl, returns the imported Stylesheet. Otherwise returns null.

If passed, the originalUrl represents the URL that was canonicalized into canonicalUrl. It's used to resolve a relative canonical URL, which importers may return for legacy reasons.

If quiet is true, this will disable logging warnings when parsing the newly imported stylesheet.

Caches the result of the import and uses cached results if possible.

Implementation

Stylesheet? importCanonical(Importer importer, Uri canonicalUrl,
    {Uri? originalUrl, bool quiet = false}) {
  return _importCache.putIfAbsent(canonicalUrl, () {
    var result = importer.load(canonicalUrl);
    if (result == null) return null;

    _resultsCache[canonicalUrl] = result;
    return Stylesheet.parse(result.contents, result.syntax,
        // For backwards-compatibility, relative canonical URLs are resolved
        // relative to [originalUrl].
        url: originalUrl == null
            ? canonicalUrl
            : originalUrl.resolveUri(canonicalUrl),
        logger: quiet ? Logger.quiet : _logger);
  });
}