mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-04-29 02:01:29 +00:00
Minor improvement to filter code (#9054)
This commit is contained in:
@@ -248,8 +248,7 @@ exports.compileFilter = function(filterString) {
|
||||
// Create a function for the chain of operators in the operation
|
||||
var operationSubFunction = function(source,widget) {
|
||||
var accumulator = source,
|
||||
results = [],
|
||||
currTiddlerTitle = widget && widget.getVariable("currentTiddler");
|
||||
results = [];
|
||||
$tw.utils.each(operation.operators,function(operator) {
|
||||
var operands = [],
|
||||
operatorFunction;
|
||||
@@ -265,6 +264,7 @@ exports.compileFilter = function(filterString) {
|
||||
}
|
||||
$tw.utils.each(operator.operands,function(operand) {
|
||||
if(operand.indirect) {
|
||||
var currTiddlerTitle = widget && widget.getVariable("currentTiddler");
|
||||
operand.value = self.getTextReference(operand.text,"",currTiddlerTitle);
|
||||
} else if(operand.variable) {
|
||||
var varTree = $tw.utils.parseFilterVariable(operand.text);
|
||||
|
||||
@@ -1139,6 +1139,15 @@ Tests the filtering mechanism.
|
||||
// Non string properties should get toStringed.
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user