Skip to content

Commit ecdf472

Browse files
authored
Merge pull request #340 from MizouziE/fix/remove-depracated-sass-if
fix: Remove Depracated Sass `if()` usages
2 parents eb736be + 4a2c26e commit ecdf472

File tree

8 files changed

+75
-25
lines changed

8 files changed

+75
-25
lines changed

sass/assert/_utils.scss

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
@include data.output-context($type);
2323

2424
$block: map.get(config.$output, $type);
25-
$start: if(
26-
$description or ($block == 'ASSERT'),
27-
'#{$block}: #{$description}',
28-
$block
29-
);
25+
$start: $block;
26+
27+
@if ($description or ($block == 'ASSERT')) {
28+
$start: '#{$block}: #{$description}';
29+
}
3030

3131
@include config.message(' #{$start} ', 'comments');
3232

@@ -127,7 +127,10 @@
127127
$not: (not not $assert);
128128
$list: ($assert != ());
129129
$string: ($assert != '');
130-
$truthy: if(($not and $list and $string), true, false);
131130

132-
@return $truthy;
131+
@if ($not and $list and $string) {
132+
@return true;
133+
}
134+
135+
@return false;
133136
}

sass/config/_throw.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ $catch-errors: false !default;
2323

2424
// Format an error prefix, with source if available
2525
@function _prefix($source) {
26-
@return if($source, 'ERROR [#{$source}]:', 'ERROR:');
26+
@if $source {
27+
@return 'ERROR [#{$source}]:';
28+
}
29+
30+
@return 'ERROR:';
2731
}
2832

2933
/// Use in place of `@error` statements inside functions.

sass/data/_details.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
/// @param {bool} $terminal [$terminal-output] -
3232
/// whether to use the terminal as an output stream
3333
@mixin fail-details($assert, $expected, $terminal: config.$terminal-output) {
34-
$location: if($terminal, ('comments', 'debug'), 'comments');
34+
$location: 'comments';
35+
36+
@if $terminal {
37+
$location: ('comments', 'debug');
38+
}
3539

3640
// Title Messages
3741
$assertion: data.context('assert');

sass/data/_results.scss

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
/// Set to `true` if the comparison is expected to fail
1414
/// @return {'pass' | 'fail'} The result of a test
1515
@function get-result($assert, $expected, $unequal: false) {
16-
$equal: $assert == $expected;
17-
$pass: if($unequal, not $equal, $equal);
16+
$is-equal: $assert == $expected;
17+
$assert-equal: not $unequal;
1818

19-
@return if($pass, 'pass', 'fail');
19+
@if ($assert-equal != $is-equal) {
20+
@return 'fail';
21+
}
22+
23+
@return 'pass';
2024
}
2125

2226
// Results
@@ -82,26 +86,41 @@ $test-result: null;
8286
/// Single or multi-line message for reporting
8387
@function results-message($linebreak: false, $results: $results) {
8488
$run: map.get($results, 'run');
89+
$items-label: 'Tests';
90+
91+
@if ($run == 1) {
92+
$items-label: 'Test';
93+
}
94+
8595
$pass: map.get($results, 'pass');
8696
$fail: map.get($results, 'fail');
8797
$output-to-css: map.get($results, 'output-to-css');
88-
$items: if($run == 1, 'Test', 'Tests');
89-
$items: '#{$run} #{$items}';
98+
$items: '#{$run} #{$items-label}';
9099
$passed: '#{$pass} Passed';
91100
$failed: '#{$fail} Failed';
92-
$compiled: if($output-to-css > 0, '#{$output-to-css} Output to CSS', null);
101+
$compiled: null;
102+
103+
@if ($output-to-css > 0) {
104+
$compiled: '#{$output-to-css} Output to CSS';
105+
}
93106

94107
// Linebreaks
95108
@if $linebreak {
96109
$message: ('#{$items}:', '- #{$passed}', '- #{$failed}');
97-
$message: if($compiled, list.append($message, '- #{$compiled}'), $message);
110+
111+
@if $compiled {
112+
$message: list.append($message, '- #{$compiled}');
113+
}
98114

99115
@return $message;
100116
}
101117

102118
// No Linebreaks
103119
$message: '#{$items}, #{$passed}, #{$failed}';
104-
$message: if($compiled, '#{$message}, #{$compiled}', $message);
120+
121+
@if $compiled {
122+
$message: '#{$message}, #{$compiled}';
123+
}
105124

106125
@return $message;
107126
}

sass/data/_stats.scss

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,23 @@ $stats: (
4343
$assertions: map.get($stats, 'assertions');
4444

4545
// Pluralize Labels
46-
$modules-label: if($modules == 1, 'Module', 'Modules');
47-
$tests-label: if($tests == 1, 'Test', 'Tests');
48-
$assertions-label: if($assertions == 1, 'Assertion', 'Assertions');
46+
$modules-label: 'Modules';
47+
48+
@if ($modules == 1) {
49+
$modules-label: 'Module';
50+
}
51+
52+
$tests-label: 'Tests';
53+
54+
@if ($tests == 1) {
55+
$tests-label: 'Test';
56+
}
57+
58+
$assertions-label: 'Assertions';
59+
60+
@if ($assertions == 1) {
61+
$assertions-label: 'Assertion';
62+
}
4963

5064
// Combine Results with Labels
5165
$modules: '#{$modules} #{$modules-label}';

sass/data/_utilities.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
$value: map.get($add, $key);
1717

1818
@if $value {
19-
$base-value: map.get($base, $key);
20-
$new-value: if($base-value, $base-value + $value, $value);
19+
$base-value: map.get($base, $key) or 0;
2120
$base: map.merge(
2221
$base,
2322
(
24-
$key: $new-value,
23+
$key: $base-value + $value,
2524
)
2625
);
2726
}

sass/module/_utils.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
/// @return {string} - Underline dashes of the same length as string param
4949
@function underline($string) {
5050
$underline: '';
51-
$string: if(meta.type-of($string) == 'string', $string, '#{$string}');
51+
52+
@if (meta.type_of($string) != 'string') {
53+
$string: '#{$string}';
54+
}
5255

5356
@for $i from 1 through string.length($string) {
5457
$underline: '#{$underline}-';

sass/report/_report.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@
5353
}
5454

5555
@if $fail-on-error and ($fail > 0) {
56-
$plural: if(($fail == 1), 'test', 'tests');
56+
$plural: 'tests';
57+
58+
@if ($fail == 1) {
59+
$plural: 'test';
60+
}
5761

5862
@include config.error('#{$fail} #{$plural} failed', 'report');
5963
}

0 commit comments

Comments
 (0)