mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-09-07 05:18:03 +00:00
Use consistent parse tree node property for params
This commit is contained in:
@@ -22,7 +22,7 @@ exports.unknown = function(source,operator,options) {
|
|||||||
customDefinition = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(customDefinitionTitle);
|
customDefinition = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(customDefinitionTitle);
|
||||||
if(customDefinition && customDefinition.srcVariable) {
|
if(customDefinition && customDefinition.srcVariable) {
|
||||||
var variables = Object.create(null);
|
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];
|
var value = operator.operands[index];
|
||||||
if(value === undefined) {
|
if(value === undefined) {
|
||||||
value = param["default"] || "";
|
value = param["default"] || "";
|
||||||
|
@@ -84,7 +84,7 @@ exports.parse = function() {
|
|||||||
value: {type: "string", value: text}
|
value: {type: "string", value: text}
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
variableParams: params,
|
params: params,
|
||||||
isFunctionDefinition: true
|
isFunctionDefinition: true
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
@@ -55,7 +55,6 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
|||||||
type: "set",
|
type: "set",
|
||||||
attributes: parseTreeNode.attributes,
|
attributes: parseTreeNode.attributes,
|
||||||
params: parseTreeNode.params,
|
params: parseTreeNode.params,
|
||||||
variableParams: parseTreeNode.variableParams,
|
|
||||||
isMacroDefinition: parseTreeNode.isMacroDefinition,
|
isMacroDefinition: parseTreeNode.isMacroDefinition,
|
||||||
isFunctionDefinition: parseTreeNode.isFunctionDefinition
|
isFunctionDefinition: parseTreeNode.isFunctionDefinition
|
||||||
};
|
};
|
||||||
|
@@ -51,7 +51,7 @@ SetWidget.prototype.execute = function() {
|
|||||||
if(this.parseTreeNode.isMacroDefinition) {
|
if(this.parseTreeNode.isMacroDefinition) {
|
||||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,!!this.parseTreeNode.isMacroDefinition);
|
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,!!this.parseTreeNode.isMacroDefinition);
|
||||||
} else if(this.parseTreeNode.isFunctionDefinition) {
|
} 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 {
|
} else {
|
||||||
this.setVariable(this.setName,this.getValue());
|
this.setVariable(this.setName,this.getValue());
|
||||||
}
|
}
|
||||||
|
@@ -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"])
|
$tw.utils.addAttributeToParseTreeNode(parser.tree[0],param.name,param["default"])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -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)
|
isMacroDefinition: true if the variable is set via a \define macro pragma (and hence should have variable substitution performed)
|
||||||
options includes:
|
options includes:
|
||||||
isFunctionDefinition: true if the variable is set via a \function pragma (and hence should not have variable substitution performed)
|
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) {
|
Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@@ -98,8 +97,7 @@ Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,opti
|
|||||||
value: value,
|
value: value,
|
||||||
params: params,
|
params: params,
|
||||||
isMacroDefinition: !!isMacroDefinition,
|
isMacroDefinition: !!isMacroDefinition,
|
||||||
isFunctionDefinition: !!options.isFunctionDefinition,
|
isFunctionDefinition: !!options.isFunctionDefinition
|
||||||
variableParams: options.variableParams
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -122,7 +122,7 @@ describe("WikiText parser tests", function() {
|
|||||||
it("should parse function definitions with no parameters", function() {
|
it("should parse function definitions with no parameters", function() {
|
||||||
expect(parse("\\function myMacro\nnothing\n\\end\n")).toEqual(
|
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() {
|
it("should parse single line function definitions with no parameters", function() {
|
||||||
expect(parse("\\function myMacro nothing\n")).toEqual(
|
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() {
|
it("should parse function definitions with parameters", function() {
|
||||||
expect(parse("\\function myMacro(one,two,three,four:elephant)\nnothing\n\\end\n")).toEqual(
|
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() {
|
it("should parse function definitions", function() {
|
||||||
expect(parse("\\function myMacro(one:'Jaguar')\n<$text text=<<one>>/>\n\\end\n\n")).toEqual(
|
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 } ]
|
||||||
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user