1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-09-02 10:58:01 +00:00

Use consistent parse tree node property for params

This commit is contained in:
jeremy@jermolene.com
2022-05-07 13:22:53 +01:00
parent 2fe2d20ddf
commit 9be05f6f38
7 changed files with 9 additions and 12 deletions

View File

@@ -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"] || "";

View File

@@ -84,7 +84,7 @@ exports.parse = function() {
value: {type: "string", value: text}
},
children: [],
variableParams: params,
params: params,
isFunctionDefinition: true
}];
};

View File

@@ -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
};

View File

@@ -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());
}

View File

@@ -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"])
});
}

View File

@@ -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
};
};

View File

@@ -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=<<one>>/>\n\\end\n\n")).toEqual(
[ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : '<$text text=<<one>>/>' } }, children : [ ], variableParams : [ { name: 'one', "default": 'Jaguar' } ], isFunctionDefinition : true } ]
[ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : '<$text text=<<one>>/>' } }, children : [ ], params : [ { name: 'one', "default": 'Jaguar' } ], isFunctionDefinition : true } ]
);
});