Skip to content

Commit 3e7c9dd

Browse files
authored
Expose inImportRule() as the test-only fakeFromImport() function (#1750)
1 parent cc5529b commit 3e7c9dd

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010

1111
* Deprecate passing non-`deg` units to `color.hwb()`'s `$hue` argument.
1212

13+
### Dart API
14+
15+
* Add a top-level `fakeFromImport()` function for testing custom importers
16+
that use `AsyncImporter.fromImport`.
17+
1318
### JS API
1419

1520
* Add a `charset` option that controls whether or not Sass emits a
1621
`@charset`/BOM for non-ASCII stylesheets.
22+
1723
* Fix Sass npm package types for TS 4.7+ Node16 and NodeNext module resolution.
1824

1925
## 1.53.0

lib/sass.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/// We strongly recommend importing this library with the prefix `sass`.
66
library sass;
77

8+
import 'package:meta/meta.dart';
89
import 'package:package_config/package_config_types.dart';
910
import 'package:source_maps/source_maps.dart';
1011

@@ -15,6 +16,7 @@ import 'src/compile_result.dart';
1516
import 'src/exception.dart';
1617
import 'src/import_cache.dart';
1718
import 'src/importer.dart';
19+
import 'src/importer/utils.dart';
1820
import 'src/logger.dart';
1921
import 'src/syntax.dart';
2022
import 'src/util/nullable.dart';
@@ -474,3 +476,10 @@ Future<String> compileStringAsync(
474476
result.sourceMap.andThen(sourceMap);
475477
return result.css;
476478
}
479+
480+
/// Runs [callback] in a context where [AsyncImporter.fromImport] returns
481+
/// `true`.
482+
///
483+
/// This is only intended for use when testing custom importers.
484+
@visibleForTesting
485+
T fakeFromImport<T>(T callback()) => inImportRule(callback);

lib/src/importer/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import '../io.dart';
1717
/// removed, at which point we can delete this and have one consistent behavior.
1818
bool get fromImport => Zone.current[#_inImportRule] as bool? ?? false;
1919

20-
/// Runs [callback] in a context where [inImportRule] returns `true` and
20+
/// Runs [callback] in a context where [fromImport] returns `true` and
2121
/// [resolveImportPath] uses `@import` semantics rather than `@use` semantics.
2222
T inImportRule<T>(T callback()) =>
2323
runZoned(callback, zoneValues: {#_inImportRule: true});

0 commit comments

Comments
 (0)