@@ -521,16 +521,32 @@ func evaluateJsonnet(imports string, snippets ...string) (string, error) {
521521 has_(o[ks[0]], ks[1:]);
522522 has_(o, std.split(f, '.')),
523523 RecurseReplace(any, from, to)::
524+ local apply_(maybeFunc, current) = if std.isFunction(maybeFunc) then maybeFunc(current) else maybeFunc;
525+ local is_match_(maybeFunc, current) = if std.isFunction(maybeFunc) then maybeFunc(current) else maybeFunc == current;
524526 local recurseReplace_(any, from, to) = (
525527 {
526- object: function(x) { [k]: recurseReplace_(x[k], from, to) for k in std.objectFields(x) },
527- array: function(x) [recurseReplace_(e, from, to) for e in x],
528- string: function(x) std.native('ReplacePattern')(x, from, to),
529- #string: function(x) std.strReplace(x, from, to),
530- number: function(x) x,
531- boolean: function(x) x,
532- 'function': function(x) x,
533- 'null': function(x) x,
528+ object: function(x) { [k]: recurseReplace_(x[k], from, to) for k in std.objectFields(x) },
529+ array: function(x) [recurseReplace_(e, from, to) for e in x],
530+ string: function(x) std.native('ReplacePattern')(x, from, to),
531+ number: function(x) if is_match_(from, x) then apply_(to, x) else x,
532+ boolean: function(x) if is_match_(from, x) then apply_(to, x) else x,
533+ 'function': function(x) if is_match_(from, x) then apply_(to, x) else x,
534+ 'null': function(x) if is_match_(from, x) then apply_(to, x) else x,
535+ }[std.type(any)](any)
536+ );
537+ recurseReplace_(any, from, to),
538+ Recurse(any, from, to)::
539+ local apply_(maybeFunc, current) = if std.isFunction(maybeFunc) then maybeFunc(current) else maybeFunc;
540+ local is_match_(maybeFunc, current) = if std.isFunction(maybeFunc) then maybeFunc(current) else maybeFunc == current;
541+ local recurseReplace_(any, from, to) = (
542+ {
543+ object: function(x) { [k]: recurseReplace_(x[k], from, to) for k in std.objectFields(x) },
544+ array: function(x) [recurseReplace_(e, from, to) for e in x],
545+ string: function(x) if is_match_(from, x) then apply_(to, x) else x,
546+ number: function(x) if is_match_(from, x) then apply_(to, x) else x,
547+ boolean: function(x) if is_match_(from, x) then apply_(to, x) else x,
548+ 'function': function(x) if is_match_(from, x) then apply_(to, x) else x,
549+ 'null': function(x) if is_match_(from, x) then apply_(to, x) else x,
534550 }[std.type(any)](any)
535551 );
536552 recurseReplace_(any, from, to),
0 commit comments