Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reusing parser result across different searches. #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions jmespath.js
Original file line number Diff line number Diff line change
Expand Up @@ -1649,19 +1649,26 @@
}

function search(data, expression) {
var parser = new Parser();
return searcher(expression)(data);
}

function searcher(expression){
// This needs to be improved. Both the interpreter and runtime depend on
// each other. The runtime needs the interpreter to support exprefs.
// There's likely a clean way to avoid the cyclic dependency.
var runtime = new Runtime();
var interpreter = new TreeInterpreter(runtime);
runtime._interpreter = interpreter;
var parser = new Parser();
var node = parser.parse(expression);
return interpreter.search(node, data);
return function(data){
return interpreter.search(node, data);
}
}

exports.tokenize = tokenize;
exports.compile = compile;
exports.search = search;
exports.searcher = searcher;
exports.strictDeepEqual = strictDeepEqual;
})(typeof exports === "undefined" ? this.jmespath = {} : exports);