Merge pull request #721 from sass/new-functions

Add module-variables() and module-functions()
This commit is contained in:
Natalie Weizenbaum 2019-06-18 13:30:49 -07:00 committed by GitHub
commit 339ebe89f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 2 deletions

View File

@ -3,6 +3,7 @@
// https://opensource.org/licenses/MIT.
import 'dart:async';
import 'dart:collection';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
@ -28,6 +29,7 @@ import 'visitor/clone_css.dart';
/// mixins.
class AsyncEnvironment {
/// The modules used in the current scope, indexed by their namespaces.
Map<String, Module> get modules => UnmodifiableMapView(_modules);
final Map<String, Module> _modules;
/// The namespaceless modules used in the current scope.

View File

@ -5,10 +5,12 @@
// DO NOT EDIT. This file was generated from async_environment.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 9037d898096d2eb998be8f01a65739ee34bec024
// Checksum: 02d98a8b9466b9a25d2ef91fb803d87921749700
//
// ignore_for_file: unused_import
import 'dart:collection';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:source_span/source_span.dart';
@ -33,6 +35,7 @@ import 'visitor/clone_css.dart';
/// mixins.
class Environment {
/// The modules used in the current scope, indexed by their namespaces.
Map<String, Module<Callable>> get modules => UnmodifiableMapView(_modules);
final Map<String, Module<Callable>> _modules;
/// The namespaceless modules used in the current scope.

View File

@ -289,6 +289,32 @@ class _EvaluateVisitor
return SassBoolean(_environment.content != null);
}),
BuiltInCallable("module-variables", r"$module", (arguments) {
var namespace = arguments[0].assertString("module");
var module = _environment.modules[namespace.text];
if (module == null) {
throw 'There is no module with namespace "${namespace.text}".';
}
return SassMap({
for (var entry in module.variables.entries)
SassString(entry.key): entry.value
});
}),
BuiltInCallable("module-functions", r"$module", (arguments) {
var namespace = arguments[0].assertString("module");
var module = _environment.modules[namespace.text];
if (module == null) {
throw 'There is no module with namespace "${namespace.text}".';
}
return SassMap({
for (var entry in module.functions.entries)
SassString(entry.key): SassFunction(entry.value)
});
}),
BuiltInCallable("get-function", r"$name, $css: false, $module: null",
(arguments) {
var name = arguments[0].assertString("name");

View File

@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: f6dcd674164d13633df1359d5a4cfc215f3a3469
// Checksum: 83e5a1fae8bbf8a4862b04bbaaa33bb5de181af0
//
// ignore_for_file: unused_import
@ -297,6 +297,32 @@ class _EvaluateVisitor
return SassBoolean(_environment.content != null);
}),
BuiltInCallable("module-variables", r"$module", (arguments) {
var namespace = arguments[0].assertString("module");
var module = _environment.modules[namespace.text];
if (module == null) {
throw 'There is no module with namespace "${namespace.text}".';
}
return SassMap({
for (var entry in module.variables.entries)
SassString(entry.key): entry.value
});
}),
BuiltInCallable("module-functions", r"$module", (arguments) {
var namespace = arguments[0].assertString("module");
var module = _environment.modules[namespace.text];
if (module == null) {
throw 'There is no module with namespace "${namespace.text}".';
}
return SassMap({
for (var entry in module.functions.entries)
SassString(entry.key): SassFunction(entry.value)
});
}),
BuiltInCallable("get-function", r"$name, $css: false, $module: null",
(arguments) {
var name = arguments[0].assertString("name");