From f0f84513f8efe533b6ee670a6f1a0c074387b2ec Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 13 Aug 2025 12:01:46 +0200 Subject: Make use of SASS modules --- src/bem/_validators.scss | 165 ++++++++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 81 deletions(-) (limited to 'src/bem/_validators.scss') diff --git a/src/bem/_validators.scss b/src/bem/_validators.scss index 042e15e..bc3c9b7 100644 --- a/src/bem/_validators.scss +++ b/src/bem/_validators.scss @@ -16,6 +16,9 @@ /// @access public //// +@use 'sass:list'; +@use 'sass:map'; +@use 'sass:meta'; @use './vars'; @use '../functions'; @use '../contexts'; @@ -46,7 +49,7 @@ $validators: (); /// @param {string} $func-names - Other function names. /// @mixin add($func-name, $func-names...) { - $noop: add($func-name, $func-names...); + $noop: add($func-name, $func-names...); } /// @@ -55,11 +58,11 @@ $validators: (); /// @see {mixin} add /// @function add($func-name, $func-names...) { - @each $fn-name in join($func-name, $func-names) { - $fn: get-function($fn-name); - $validators: map-merge($validators, ($fn-name: $fn)); - } - @return null; + @each $fn-name in list.join($func-name, $func-names) { + $fn: meta.get-function($fn-name); + $validators: map.merge($validators, ($fn-name: $fn)); + } + @return null; } /// @@ -69,7 +72,7 @@ $validators: (); /// @param {string} $func-names - Other function names. /// @mixin remove($func-name, $func-names...) { - $noop: remove($func-name, $func-names...); + $noop: remove($func-name, $func-names...); } /// @@ -78,20 +81,20 @@ $validators: (); /// @see {mixin} remove /// @function remove($func-name, $func-names...) { - $validators: map-remove($validators, $func-name, $func-names...); - @return null; + $validators: map.remove($validators, $func-name, $func-names...); + @return null; } /// /// @access private /// @mixin validate($type, $args, $selector, $context) { - @each $id, $fn in $validators { - $result: call($fn, $type, $args, $selector, $context); - @if not nth($result, 1) { - @error 'A BEM validator rejected this mixin usage due to the following reason: #{nth($result, 2)}'; - } - } + @each $id, $fn in $validators { + $result: meta.call($fn, $type, $args, $selector, $context); + @if not list.nth($result, 1) { + @error 'A BEM validator rejected this mixin usage due to the following reason: #{nth($result, 2)}'; + } + } } // @@ -105,76 +108,76 @@ $validators: (); /// namespace used. /// @function enforce-namespace-order($type, $args, $selector, $context) { - @if not global-variable-exists(namespace-order, vars) { - vars.$namespace-order: map-keys(vars.$namespaces); - } - @if not global-variable-exists(cur-namespace-index, vars) { - vars.$cur-namespace-index: 1; - } - - @if $type == 'block' { - $block-type: map-get($args, 'type'); - - @if $block-type != null { - $ns-index: index(vars.$namespace-order, $block-type); - - @if $ns-index != null { - @if $ns-index < vars.$cur-namespace-index { - @return false 'Namespace "#{$block-type}" comes before current namespace #{nth(vars.$namespace-order, vars.$cur-namespace-index)}'; - } - - vars.$cur-namespace-index: $ns-index; - } - } - } - - @return true ''; + @if not meta.global-variable-exists(namespace-order, vars) { + vars.$namespace-order: map.keys(vars.$namespaces); + } + @if not meta.global-variable-exists(cur-namespace-index, vars) { + vars.$cur-namespace-index: 1; + } + + @if $type == 'block' { + $block-type: map.get($args, 'type'); + + @if $block-type != null { + $ns-index: list.index(vars.$namespace-order, $block-type); + + @if $ns-index != null { + @if $ns-index < vars.$cur-namespace-index { + @return false 'Namespace "#{$block-type}" comes before current namespace #{nth(vars.$namespace-order, vars.$cur-namespace-index)}'; + } + + vars.$cur-namespace-index: $ns-index; + } + } + } + + @return true ''; } /// /// A validator that makes all BEM entities immutable. /// @function immutable-entities($type, $args, $selector, $context) { - @if not global-variable-exists(generated-selectors, vars) { - vars.$generated-selectors: (); - } - - $block-name: null; - $block-type: null; - $block-id: null; - - @if $type == 'block' { - $block-name: map-get($args, 'name'); - $block-type: map-get($args, 'type'); - } @else { - $block-context: contexts.get(vars.$context-id, 'block'); - $block-name: map-get(nth($block-context, 2), 'name'); - $block-type: map-get(nth($block-context, 2), 'type'); - } - - @if $block-type != null { - $block-id: $block-name + '_' + $block-type; - } @else { - $block-id: $block-name; - } - - @if $type == 'block' { - @if map-has-key(vars.$generated-selectors, $block-id) { - @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; - } - - vars.$generated-selectors: map-merge(vars.$generated-selectors, ($block-id: ())); - } @else { - $selectors: map-get(vars.$generated-selectors, $block-id); - - @if index($selectors, $selector) { - @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; - } - - $selectors: append($selectors, $selector); - - vars.$generated-selectors: map-merge(vars.$generated-selectors, ($block-id: $selectors)); - } - - @return true ''; + @if not meta.global-variable-exists(generated-selectors, vars) { + vars.$generated-selectors: (); + } + + $block-name: null; + $block-type: null; + $block-id: null; + + @if $type == 'block' { + $block-name: map.get($args, 'name'); + $block-type: map.get($args, 'type'); + } @else { + $block-context: contexts.get(vars.$context-id, 'block'); + $block-name: map.get(list.nth($block-context, 2), 'name'); + $block-type: map.get(list.nth($block-context, 2), 'type'); + } + + @if $block-type != null { + $block-id: $block-name + '_' + $block-type; + } @else { + $block-id: $block-name; + } + + @if $type == 'block' { + @if map.has-key(vars.$generated-selectors, $block-id) { + @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; + } + + vars.$generated-selectors: map.merge(vars.$generated-selectors, ($block-id: ())); + } @else { + $selectors: map.get(vars.$generated-selectors, $block-id); + + @if list.index($selectors, $selector) { + @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; + } + + $selectors: list.append($selectors, $selector); + + vars.$generated-selectors: map.merge(vars.$generated-selectors, ($block-id: $selectors)); + } + + @return true ''; } -- cgit v1.2.3-70-g09d2