From 9be05f6f383a9439323422bb06f251b9b576df87 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Sat, 7 May 2022 13:22:53 +0100 Subject: [PATCH] Use consistent parse tree node property for params --- core/modules/filters/unknown.js | 2 +- core/modules/parsers/wikiparser/rules/functiondef.js | 2 +- core/modules/widgets/importvariables.js | 1 - core/modules/widgets/setvariable.js | 2 +- core/modules/widgets/transclude.js | 2 +- core/modules/widgets/widget.js | 4 +--- editions/test/tiddlers/tests/test-wikitext-parser.js | 8 ++++---- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/core/modules/filters/unknown.js b/core/modules/filters/unknown.js index 93b42c706..7e962b30f 100644 --- a/core/modules/filters/unknown.js +++ b/core/modules/filters/unknown.js @@ -22,7 +22,7 @@ exports.unknown = function(source,operator,options) { customDefinition = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(customDefinitionTitle); if(customDefinition && customDefinition.srcVariable) { var variables = Object.create(null); - $tw.utils.each(customDefinition.srcVariable.variableParams,function(param,index) { + $tw.utils.each(customDefinition.srcVariable.params,function(param,index) { var value = operator.operands[index]; if(value === undefined) { value = param["default"] || ""; diff --git a/core/modules/parsers/wikiparser/rules/functiondef.js b/core/modules/parsers/wikiparser/rules/functiondef.js index 1c6430bbd..59d66f9c0 100644 --- a/core/modules/parsers/wikiparser/rules/functiondef.js +++ b/core/modules/parsers/wikiparser/rules/functiondef.js @@ -84,7 +84,7 @@ exports.parse = function() { value: {type: "string", value: text} }, children: [], - variableParams: params, + params: params, isFunctionDefinition: true }]; }; diff --git a/core/modules/widgets/importvariables.js b/core/modules/widgets/importvariables.js index b4f0f7c9e..bae920d67 100644 --- a/core/modules/widgets/importvariables.js +++ b/core/modules/widgets/importvariables.js @@ -55,7 +55,6 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) { type: "set", attributes: parseTreeNode.attributes, params: parseTreeNode.params, - variableParams: parseTreeNode.variableParams, isMacroDefinition: parseTreeNode.isMacroDefinition, isFunctionDefinition: parseTreeNode.isFunctionDefinition }; diff --git a/core/modules/widgets/setvariable.js b/core/modules/widgets/setvariable.js index 8a35ffada..e176cd21d 100755 --- a/core/modules/widgets/setvariable.js +++ b/core/modules/widgets/setvariable.js @@ -51,7 +51,7 @@ SetWidget.prototype.execute = function() { if(this.parseTreeNode.isMacroDefinition) { this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,!!this.parseTreeNode.isMacroDefinition); } else if(this.parseTreeNode.isFunctionDefinition) { - this.setVariable(this.setName,this.getValue(),undefined,undefined,{isFunctionDefinition: this.parseTreeNode.isFunctionDefinition,variableParams: this.parseTreeNode.variableParams}); + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: this.parseTreeNode.isFunctionDefinition}); } else { this.setVariable(this.setName,this.getValue()); } diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index 787e6a26d..5ccfa5921 100755 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -184,7 +184,7 @@ TranscludeWidget.prototype.getTransclusionTarget = function() { } ] } - $tw.utils.each(variableInfo.variableParams,function(param) { + $tw.utils.each(variableInfo.params,function(param) { $tw.utils.addAttributeToParseTreeNode(parser.tree[0],param.name,param["default"]) }); } diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 6c201177c..6a9a9d1d2 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -90,7 +90,6 @@ params: array of {name:, default:} for each parameter isMacroDefinition: true if the variable is set via a \define macro pragma (and hence should have variable substitution performed) options includes: isFunctionDefinition: true if the variable is set via a \function pragma (and hence should not have variable substitution performed) - variableParams: array of {name:, default:} for each function parameter */ Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,options) { options = options || {}; @@ -98,8 +97,7 @@ Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,opti value: value, params: params, isMacroDefinition: !!isMacroDefinition, - isFunctionDefinition: !!options.isFunctionDefinition, - variableParams: options.variableParams + isFunctionDefinition: !!options.isFunctionDefinition }; }; diff --git a/editions/test/tiddlers/tests/test-wikitext-parser.js b/editions/test/tiddlers/tests/test-wikitext-parser.js index 6c3d15ac6..bfaf00093 100644 --- a/editions/test/tiddlers/tests/test-wikitext-parser.js +++ b/editions/test/tiddlers/tests/test-wikitext-parser.js @@ -122,7 +122,7 @@ describe("WikiText parser tests", function() { it("should parse function definitions with no parameters", function() { expect(parse("\\function myMacro\nnothing\n\\end\n")).toEqual( - [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], variableParams : [ ], isFunctionDefinition : true } ] + [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isFunctionDefinition : true } ] ); }); @@ -130,7 +130,7 @@ describe("WikiText parser tests", function() { it("should parse single line function definitions with no parameters", function() { expect(parse("\\function myMacro nothing\n")).toEqual( - [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], variableParams : [ ], isFunctionDefinition : true } ] + [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isFunctionDefinition : true } ] ); }); @@ -138,7 +138,7 @@ describe("WikiText parser tests", function() { it("should parse function definitions with parameters", function() { expect(parse("\\function myMacro(one,two,three,four:elephant)\nnothing\n\\end\n")).toEqual( - [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], variableParams : [ { name: 'one' }, { name: 'two' }, { name: 'three' }, { name: 'four', default: 'elephant' } ], isFunctionDefinition : true } ] + [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ { name: 'one' }, { name: 'two' }, { name: 'three' }, { name: 'four', default: 'elephant' } ], isFunctionDefinition : true } ] ); }); @@ -146,7 +146,7 @@ describe("WikiText parser tests", function() { it("should parse function definitions", function() { expect(parse("\\function myMacro(one:'Jaguar')\n<$text text=<>/>\n\\end\n\n")).toEqual( - [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : '<$text text=<>/>' } }, children : [ ], variableParams : [ { name: 'one', "default": 'Jaguar' } ], isFunctionDefinition : true } ] + [ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : '<$text text=<>/>' } }, children : [ ], params : [ { name: 'one', "default": 'Jaguar' } ], isFunctionDefinition : true } ] ); });