From bbaa91d6580336bafd3169bfbfe7e6106a6ef794 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 12 Jun 2019 14:06:23 +0100 Subject: [PATCH 1/2] Add a module-variables() function --- lib/src/async_environment.dart | 2 ++ lib/src/environment.dart | 5 ++++- lib/src/visitor/async_evaluate.dart | 13 +++++++++++++ lib/src/visitor/evaluate.dart | 15 ++++++++++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/src/async_environment.dart b/lib/src/async_environment.dart index 287105bd..e1dcfc49 100644 --- a/lib/src/async_environment.dart +++ b/lib/src/async_environment.dart @@ -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 get modules => UnmodifiableMapView(_modules); final Map _modules; /// The namespaceless modules used in the current scope. diff --git a/lib/src/environment.dart b/lib/src/environment.dart index e14d87c6..fbd48c50 100644 --- a/lib/src/environment.dart +++ b/lib/src/environment.dart @@ -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> get modules => UnmodifiableMapView(_modules); final Map> _modules; /// The namespaceless modules used in the current scope. diff --git a/lib/src/visitor/async_evaluate.dart b/lib/src/visitor/async_evaluate.dart index 4c237600..11f471f0 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -289,6 +289,19 @@ 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("get-function", r"$name, $css: false, $module: null", (arguments) { var name = arguments[0].assertString("name"); diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index 633d468b..7b5635ee 100644 --- a/lib/src/visitor/evaluate.dart +++ b/lib/src/visitor/evaluate.dart @@ -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: 6138883df6130d5bbf47a70704a5edc6e35741e0 // // ignore_for_file: unused_import @@ -297,6 +297,19 @@ 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("get-function", r"$name, $css: false, $module: null", (arguments) { var name = arguments[0].assertString("name"); From d89fef612b110bf34f545dacd6f4c9a020b0f5ff Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 12 Jun 2019 15:02:04 +0100 Subject: [PATCH 2/2] Add a module-functions() function --- lib/src/visitor/async_evaluate.dart | 13 +++++++++++++ lib/src/visitor/evaluate.dart | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/src/visitor/async_evaluate.dart b/lib/src/visitor/async_evaluate.dart index 11f471f0..313cffaf 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -302,6 +302,19 @@ class _EvaluateVisitor }); }), + 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"); diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index 7b5635ee..6f1896d7 100644 --- a/lib/src/visitor/evaluate.dart +++ b/lib/src/visitor/evaluate.dart @@ -5,7 +5,7 @@ // DO NOT EDIT. This file was generated from async_evaluate.dart. // See tool/grind/synchronize.dart for details. // -// Checksum: 6138883df6130d5bbf47a70704a5edc6e35741e0 +// Checksum: 83e5a1fae8bbf8a4862b04bbaaa33bb5de181af0 // // ignore_for_file: unused_import @@ -310,6 +310,19 @@ class _EvaluateVisitor }); }), + 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");