Skip to content

Commit 77e01f5

Browse files
imorlandclaude
andauthored
fix(theme): return Less_Tree_Keyword for boolean custom Less functions (#4405)
Boolean return values from `addCustomLessFunction` were wrapped in `Less_Tree_Quoted`, producing a quoted string ('true'/'false') instead of a Less keyword (true/false). Quoted strings do not match in mixin guards, making it impossible to use boolean-returning functions with `.mixin(false) {}` patterns. Switch to `Less_Tree_Keyword` so booleans behave as proper Less keywords. CSS custom property output is unchanged; only mixin guard matching is fixed. Fixes #4383 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9854202 commit 77e01f5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

framework/core/src/Extend/Theme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function addCustomLessFunction(string $functionName, callable $callable):
8484
$return = $callable(...$argVals);
8585

8686
if (is_bool($return)) {
87-
return new \Less_Tree_Quoted('', $return ? 'true' : 'false');
87+
return new \Less_Tree_Keyword($return ? 'true' : 'false');
8888
}
8989

9090
if (is_string($return)) {

framework/core/tests/fixtures/less/custom_function.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
--x: is-flarum("not flarum") * 10;
66
--y: is-gt(1, 2);
77
}
8+
.mixin(@val) {}
9+
.mixin(false) {
10+
color: red;
11+
}
12+
.dummy_func_test3 {
13+
.mixin(is-gt(1, 2));
14+
}

framework/core/tests/integration/extenders/ThemeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public function theme_extender_can_add_custom_function()
131131

132132
$this->assertStringContainsString('.dummy_func_test{color:green}', $contents);
133133
$this->assertStringContainsString('.dummy_func_test2{--x:1000;--y:false}', $contents);
134+
// Boolean return values must be Less keywords (not quoted strings) so that mixin guards match correctly.
135+
$this->assertStringContainsString('.dummy_func_test3{color:red}', $contents);
134136
}
135137

136138
/**

0 commit comments

Comments
 (0)