mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2025-12-15 15:10:30 -08:00
Minor improvement to filter code (#9054)
This commit is contained in:
parent
05db1bcb2c
commit
8837a0f405
2 changed files with 11 additions and 2 deletions
|
|
@ -248,8 +248,7 @@ exports.compileFilter = function(filterString) {
|
||||||
// Create a function for the chain of operators in the operation
|
// Create a function for the chain of operators in the operation
|
||||||
var operationSubFunction = function(source,widget) {
|
var operationSubFunction = function(source,widget) {
|
||||||
var accumulator = source,
|
var accumulator = source,
|
||||||
results = [],
|
results = [];
|
||||||
currTiddlerTitle = widget && widget.getVariable("currentTiddler");
|
|
||||||
$tw.utils.each(operation.operators,function(operator) {
|
$tw.utils.each(operation.operators,function(operator) {
|
||||||
var operands = [],
|
var operands = [],
|
||||||
operatorFunction;
|
operatorFunction;
|
||||||
|
|
@ -265,6 +264,7 @@ exports.compileFilter = function(filterString) {
|
||||||
}
|
}
|
||||||
$tw.utils.each(operator.operands,function(operand) {
|
$tw.utils.each(operator.operands,function(operand) {
|
||||||
if(operand.indirect) {
|
if(operand.indirect) {
|
||||||
|
var currTiddlerTitle = widget && widget.getVariable("currentTiddler");
|
||||||
operand.value = self.getTextReference(operand.text,"",currTiddlerTitle);
|
operand.value = self.getTextReference(operand.text,"",currTiddlerTitle);
|
||||||
} else if(operand.variable) {
|
} else if(operand.variable) {
|
||||||
var varTree = $tw.utils.parseFilterVariable(operand.text);
|
var varTree = $tw.utils.parseFilterVariable(operand.text);
|
||||||
|
|
|
||||||
|
|
@ -1139,6 +1139,15 @@ Tests the filtering mechanism.
|
||||||
// Non string properties should get toStringed.
|
// Non string properties should get toStringed.
|
||||||
expect(wiki.filterTiddlers("[[$:/core/modules/commands/init.js]moduleproperty[info]]").join(" ")).toBe('{"name":"init","synchronous":true}');
|
expect(wiki.filterTiddlers("[[$:/core/modules/commands/init.js]moduleproperty[info]]").join(" ")).toBe('{"name":"init","synchronous":true}');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should minimize unnecessary variable lookup", function() {
|
||||||
|
var widget = wiki.makeWidget();
|
||||||
|
var getVar = spyOn(widget, "getVariableInfo").and.callThrough();
|
||||||
|
expect(wiki.filterTiddlers("[all[]prefix[anything]]", widget).length).toBe(0);
|
||||||
|
// We didn't use any indirect operands or variables.
|
||||||
|
// No variable lookup should have occurred.
|
||||||
|
expect(getVar).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue