Fixes functions to use variables set by filter runs (#7906)

* fix: functions should use variables set by filter runs

* refactor: code clean up

* chore: added more tests
This commit is contained in:
Saq Imtiaz 2024-01-24 12:33:50 +01:00 committed by GitHub
parent fb85e91f82
commit aa4aeb187c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 1 deletions

View File

@ -153,7 +153,7 @@ Widget.prototype.getVariableInfo = function(name,options) {
} else if(variable.isFunctionDefinition) {
// Function evaluations
params = self.resolveVariableParameters(variable.params,actualParams);
var variables = Object.create(null);
var variables = options.variables || Object.create(null);
// Apply default parameter values
$tw.utils.each(variable.params,function(param,index) {
if(param["default"]) {

View File

@ -0,0 +1,24 @@
title: Functions/FunctionFilterrunVariables
description: Functions in filter runs that set variables
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Idiosyncrasy
caption: Idiosyncrasy Caption Field
+
title: Output
\whitespace trim
\procedure demo-subfilter() [<currentTiddler>]
\function .demo-function() [<currentTiddler>]
<$let currentTiddler="Idiosyncrasy">
<$text text={{{ [<currentTiddler>get[caption]!is[blank]else<currentTiddler>] :map[subfilter<demo-subfilter>] }}}/>,
<$text text={{{ [<currentTiddler>get[caption]!is[blank]else<currentTiddler>] :map[.demo-function[]] }}}/>
</$let>
+
title: ExpectedResult
<p>Idiosyncrasy Caption Field,Idiosyncrasy Caption Field</p>

View File

@ -0,0 +1,20 @@
title: Functions/FunctionFilterrunVariables2
description: Functions in filter runs that set variables
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Apple
cost: 5
+
title: Output
\whitespace trim
\function .doublecost() [<currentTiddler>get[cost]multiply[2]]
<$text text={{{ [[Apple]] :map[.doublecost[]] }}}/>
+
title: ExpectedResult
10