Skip to content

Commit 4aa6d5f

Browse files
authored
Support parseSelectors in ImportCache (#2701)
1 parent eae38c5 commit 4aa6d5f

File tree

9 files changed

+52
-20
lines changed

9 files changed

+52
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.95.1
2+
3+
* No user-visible changes.
4+
15
## 1.95.0
26

37
* Add support for the [CSS-style `if()` function]. In addition to supporting the

lib/src/ast/sass/statement/style_rule.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class StyleRule extends ParentStatement<List<Statement>> {
1919
/// The selector to which the declaration will be applied.
2020
///
2121
/// This is only parsed after the interpolation has been resolved. This is
22-
/// null if and only if [interpolatedSelector] is not null.
22+
/// null if and only if [parsedSelector] is not null.
2323
final Interpolation? selector;
2424

2525
/// Like [selector], but with as much of the selector parsed as possible.
@@ -31,14 +31,12 @@ final class StyleRule extends ParentStatement<List<Statement>> {
3131

3232
final FileSpan span;
3333

34-
/// Constructs a style rule with [selector] set and [interpolatedSelector]
35-
/// null.
34+
/// Constructs a style rule with [selector] set and [parsedSelector] null.
3635
StyleRule(this.selector, Iterable<Statement> children, this.span)
3736
: parsedSelector = null,
3837
super(List.unmodifiable(children));
3938

40-
/// Constructs a style rule with [interpolatedSelector] set and [selector]
41-
/// null.
39+
/// Constructs a style rule with [parsedSelector] set and [selector].
4240
StyleRule.withParsedSelector(
4341
this.parsedSelector, Iterable<Statement> children, this.span)
4442
: selector = null,

lib/src/async_import_cache.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ final class AsyncImportCache {
3535
/// The importers to use when loading new Sass files.
3636
final List<AsyncImporter> _importers;
3737

38+
/// Whether to parse [StyleRule.parsedSelector]s rather than
39+
/// [StyleRule.selector]s when loading new Sass files.
40+
final bool _parseSelectors;
41+
3842
/// The canonicalized URLs for each non-canonical URL.
3943
///
4044
/// The `forImport` in each key is true when this canonicalization is for an
@@ -94,15 +98,21 @@ final class AsyncImportCache {
9498
Iterable<AsyncImporter>? importers,
9599
Iterable<String>? loadPaths,
96100
PackageConfig? packageConfig,
97-
}) : _importers = _toImporters(importers, loadPaths, packageConfig);
101+
bool parseSelectors = false,
102+
}) : _importers = _toImporters(importers, loadPaths, packageConfig),
103+
_parseSelectors = parseSelectors;
98104

99105
/// Creates an import cache without any globally-available importers.
100-
AsyncImportCache.none() : _importers = const [];
106+
AsyncImportCache.none({bool parseSelectors = false})
107+
: _importers = const [],
108+
_parseSelectors = parseSelectors;
101109

102110
/// Creates an import cache without any globally-available importers, and only
103111
/// the passed in importers.
104-
AsyncImportCache.only(Iterable<AsyncImporter> importers)
105-
: _importers = List.unmodifiable(importers);
112+
AsyncImportCache.only(Iterable<AsyncImporter> importers,
113+
{bool parseSelectors = false})
114+
: _importers = List.unmodifiable(importers),
115+
_parseSelectors = parseSelectors;
106116

107117
/// Converts the user's [importers], [loadPaths], and [packageConfig]
108118
/// options into a single list of importers.
@@ -333,6 +343,7 @@ final class AsyncImportCache {
333343
url: originalUrl == null
334344
? canonicalUrl
335345
: originalUrl.resolveUri(canonicalUrl),
346+
parseSelectors: _parseSelectors,
336347
);
337348
});
338349
}

lib/src/import_cache.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_import_cache.dart.
66
// See tool/grind/synchronize.dart for details.
77
//
8-
// Checksum: a0b4e091d7a729fbadceabdb1f51ab2631e2df4a
8+
// Checksum: bcdb7643d7bd5740fdb4586869f1b4cd362cf902
99
//
1010
// ignore_for_file: unused_import
1111

@@ -38,6 +38,10 @@ final class ImportCache {
3838
/// The importers to use when loading new Sass files.
3939
final List<Importer> _importers;
4040

41+
/// Whether to parse [StyleRule.parsedSelector]s rather than
42+
/// [StyleRule.selector]s when loading new Sass files.
43+
final bool _parseSelectors;
44+
4145
/// The canonicalized URLs for each non-canonical URL.
4246
///
4347
/// The `forImport` in each key is true when this canonicalization is for an
@@ -95,15 +99,20 @@ final class ImportCache {
9599
Iterable<Importer>? importers,
96100
Iterable<String>? loadPaths,
97101
PackageConfig? packageConfig,
98-
}) : _importers = _toImporters(importers, loadPaths, packageConfig);
102+
bool parseSelectors = false,
103+
}) : _importers = _toImporters(importers, loadPaths, packageConfig),
104+
_parseSelectors = parseSelectors;
99105

100106
/// Creates an import cache without any globally-available importers.
101-
ImportCache.none() : _importers = const [];
107+
ImportCache.none({bool parseSelectors = false})
108+
: _importers = const [],
109+
_parseSelectors = parseSelectors;
102110

103111
/// Creates an import cache without any globally-available importers, and only
104112
/// the passed in importers.
105-
ImportCache.only(Iterable<Importer> importers)
106-
: _importers = List.unmodifiable(importers);
113+
ImportCache.only(Iterable<Importer> importers, {bool parseSelectors = false})
114+
: _importers = List.unmodifiable(importers),
115+
_parseSelectors = parseSelectors;
107116

108117
/// Converts the user's [importers], [loadPaths], and [packageConfig]
109118
/// options into a single list of importers.
@@ -331,6 +340,7 @@ final class ImportCache {
331340
url: originalUrl == null
332341
? canonicalUrl
333342
: originalUrl.resolveUri(canonicalUrl),
343+
parseSelectors: _parseSelectors,
334344
);
335345
});
336346
}

pkg/sass-parser/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.38
2+
3+
* No user-visible changes.
4+
15
## 0.4.37
26

37
* Add support for the CSS `if()` expression and its Sass extensions.

pkg/sass-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-parser",
3-
"version": "0.4.37",
3+
"version": "0.4.38",
44
"description": "A PostCSS-compatible wrapper of the official Sass parser",
55
"repository": "sass/dart-sass",
66
"author": "Google Inc.",

pkg/sass_api/CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 17.1.0
2+
3+
* Add support for passing `parseSelectors: true` to `ImportCache` and
4+
`AsyncImportCache`.
5+
16
## 17.0.0
27

38
* Rename the old `IfExpression` class to `LegacyIfExpression`.
@@ -17,8 +22,8 @@
1722

1823
## 16.0.3
1924

20-
* Add several members of `RecursiveAstVisitor` which were mising in the previous
21-
release.
25+
* Add several members of `RecursiveAstVisitor` which were missing in the
26+
previous release.
2227

2328
## 16.0.2
2429

pkg/sass_api/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: sass_api
22
# Note: Every time we add a new Sass AST node, we need to bump the *major*
33
# version because it's a breaking change for anyone who's implementing the
44
# visitor interface(s).
5-
version: 17.0.0
5+
version: 17.1.0
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

99
environment:
1010
sdk: ">=3.6.0 <4.0.0"
1111

1212
dependencies:
13-
sass: 1.95.0
13+
sass: 1.95.1
1414

1515
dev_dependencies:
1616
dartdoc: ">=8.0.14 <10.0.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.95.0
2+
version: 1.95.1
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

0 commit comments

Comments
 (0)