Skip to content

Commit a152500

Browse files
authored
Merge pull request #3626 from obsidian-tasks-group/issue-3625-return-string
docs: String "return" in function returns "undefined" (#3625)
2 parents 4275b11 + 0fd53fa commit a152500

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

docs/Scripting/Expressions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ As of Tasks 4.4.0, it is also possible to use more complex constructs in express
8686
- `if` statements
8787
- functions
8888

89+
Note in the examples below that if `return` appears anywhere in the expression, you must write your own `return` statement, to prevent the result being `undefined`.
90+
8991
As of Tasks 5.0.0, it is also possible to make longer expressions more readable using [[Line Continuations|line continuations]].
9092

9193
<!-- placeholder to force blank line before included text --><!-- include: Expression.test.Expression_returns_and_functions.approved.md -->
@@ -97,6 +99,12 @@ return 42
9799
const x = 1 + 1; return x * x
98100
=> 4
99101
102+
'any text that contains the word return'
103+
=> undefined
104+
105+
return 'any text that contains the word return'
106+
=> 'any text that contains the word return'
107+
100108
if (1 === 1) { return "yes"; } else { return "no" }
101109
=> 'yes'
102110

tests/Scripting/Expression.test.Expression_returns_and_functions.approved.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ return 42
77
const x = 1 + 1; return x * x
88
=> 4
99
10+
'any text that contains the word return'
11+
=> undefined
12+
13+
return 'any text that contains the word return'
14+
=> 'any text that contains the word return'
15+
1016
if (1 === 1) { return "yes"; } else { return "no" }
1117
=> 'yes'
1218

tests/Scripting/Expression.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ describe('Expression', () => {
151151
const expressions = [
152152
'return 42',
153153
'const x = 1 + 1; return x * x',
154+
155+
// Presence of 'return', even if in a string, makes Tasks plugin think it does not need to add 'return':
156+
"'any text that contains the word return'",
157+
// So if the text 'return' appears anywhere in the expression, an explicit 'return' instruction must be supplied:
158+
"return 'any text that contains the word return'",
159+
154160
'if (1 === 1) { return "yes"; } else { return "no" }',
155161
`function f(value) { \\
156162
if (value === 1 ) { \\

0 commit comments

Comments
 (0)