Skip to content

Commit

Permalink
Expose inImportRule() as the test-only fakeFromImport() function (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jul 22, 2022
1 parent cc5529b commit 3e7c9dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,10 +10,16 @@

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

### Dart API

* Add a top-level `fakeFromImport()` function for testing custom importers
that use `AsyncImporter.fromImport`.

### JS API

* Add a `charset` option that controls whether or not Sass emits a
`@charset`/BOM for non-ASCII stylesheets.

* Fix Sass npm package types for TS 4.7+ Node16 and NodeNext module resolution.

## 1.53.0
Expand Down
9 changes: 9 additions & 0 deletions lib/sass.dart
Expand Up @@ -5,6 +5,7 @@
/// We strongly recommend importing this library with the prefix `sass`.
library sass;

import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart';
import 'package:source_maps/source_maps.dart';

Expand All @@ -15,6 +16,7 @@ import 'src/compile_result.dart';
import 'src/exception.dart';
import 'src/import_cache.dart';
import 'src/importer.dart';
import 'src/importer/utils.dart';
import 'src/logger.dart';
import 'src/syntax.dart';
import 'src/util/nullable.dart';
Expand Down Expand Up @@ -474,3 +476,10 @@ Future<String> compileStringAsync(
result.sourceMap.andThen(sourceMap);
return result.css;
}

/// Runs [callback] in a context where [AsyncImporter.fromImport] returns
/// `true`.
///
/// This is only intended for use when testing custom importers.
@visibleForTesting
T fakeFromImport<T>(T callback()) => inImportRule(callback);
2 changes: 1 addition & 1 deletion lib/src/importer/utils.dart
Expand Up @@ -17,7 +17,7 @@ import '../io.dart';
/// removed, at which point we can delete this and have one consistent behavior.
bool get fromImport => Zone.current[#_inImportRule] as bool? ?? false;

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

0 comments on commit 3e7c9dd

Please sign in to comment.