function add_dynamic_nested_refs (localRefsHash, localRefs, ref_type, args_object, arg_name) {
      var arg_expression = args_object[arg_name];
      var bracket_count = 0;
      var outer_string = '';
      var object_lookup_string = '';

      for (var j = arg_expression.length - 1; j >= 0; j--) {
        var arg_expression_char = arg_expression[j];
        if (bracket_count === 0) {
          if (arg_expression_char === ']') {
            bracket_count++;
          } else {
            outer_string = arg_expression_char + outer_string;
          }
        } else {
          if (arg_expression_char === ']') {
            bracket_count++;
          } else if (arg_expression_char === '[') {
            bracket_count--;
            if (bracket_count === 0) {
              var parsed_index = esprima.parse(object_lookup_string);
              if (parsed_index.body[0].expression.type === "Literal") {
                var constant_ref_name = '$$dynamic_nested_constant_'+constant_count++;
                var parsed_literal = parsed_index.body[0].expression.value;

                var constant_ref = {
                  type: 'constants',
                  value: parsed_literal,
                  name: constant_ref_name
                };
                localRefs.push(constant_ref);
                localRefsHash[constant_ref_name] = constant_ref;
                object_lookup_string = constant_ref_name;
                break;
              } else {
                break;
              }
            }
          }

          object_lookup_string = arg_expression_char + object_lookup_string;
        }
      }

      if (!object_lookup_string) {
        return;
      }

      var dynamic_nested_source = arg_expression.slice(0, j);
      var dynamic_nested_field = object_lookup_string;
      var nested_off_of_dynamic_nested = outer_string;

      var dynamic_nested_name = 'dynamic_nested_' + sanitize_ref_name(dynamic_nested_source) + '_' + sanitize_ref_name(dynamic_nested_field);
      if (!localRefsHash[dynamic_nested_name]) {
        var dynamic_nested_ref = { name: dynamic_nested_name, type: 'dynamic_nesteds', value: { args: { source: dynamic_nested_source, field: dynamic_nested_field } } };

        localRefsHash[dynamic_nested_name] = dynamic_nested_ref;
        localRefs.push(dynamic_nested_ref);
      }

      args_object[arg_name] = dynamic_nested_name + nested_off_of_dynamic_nested;
    }
// Note that this injects into the localRefs array and the algorithm relies on the for loop that calls this eventually running into the refs added here.  The reason we do this is to support insane expressions like "foo[bar.a[blah.d]].c[id]" by breaking it into parts and letting each part get pulled out
Note that this injects into the localRefs array and the algorithm relies on the for loop that calls this eventually running into the refs added here.  The reason we do this is to support insane expressions like "foo[bar.a[blah.d]].c[id]" by breaking it into parts and letting each part get pulled out
Note that this injects into the localRefs array and the algorithm relies on the for loop that calls this eventually running into the refs added here . The reason we do this is to support insane expressions like " foo [ bar . a [ blah . d ]] . c [ id ] " by breaking it into parts and letting each part get pulled out
function add_dynamic_nested_refs (localRefsHash, localRefs, ref_type, args_object, arg_name) {
      var arg_expression = args_object[arg_name];
      var bracket_count = 0;
      var outer_string = '';
      var object_lookup_string = '';
      for (var j = arg_expression.length - 1; j >= 0; j--) {
        var arg_expression_char = arg_expression[j];
        if (bracket_count === 0) {
          if (arg_expression_char === ']') {
            bracket_count++;
          } else {
            outer_string = arg_expression_char + outer_string;
          }
        } else {
          if (arg_expression_char === ']') {
            bracket_count++;
          } else if (arg_expression_char === '[') {
            bracket_count--;
            if (bracket_count === 0) {
              var parsed_index = esprima.parse(object_lookup_string);
              if (parsed_index.body[0].expression.type === "Literal") {
                var constant_ref_name = '$$dynamic_nested_constant_'+constant_count++;
                var parsed_literal = parsed_index.body[0].expression.value;
                var constant_ref = {
                  type: 'constants',
                  value: parsed_literal,
                  name: constant_ref_name
                };
                localRefs.push(constant_ref);
                localRefsHash[constant_ref_name] = constant_ref;
                object_lookup_string = constant_ref_name;
                break;
              } else {
                break;
              }
            }
          }
          object_lookup_string = arg_expression_char + object_lookup_string;
        }
      }
      if (!object_lookup_string) {
        return;
      }
      var dynamic_nested_source = arg_expression.slice(0, j);
      var dynamic_nested_field = object_lookup_string;
      var nested_off_of_dynamic_nested = outer_string;
      var dynamic_nested_name = 'dynamic_nested_' + sanitize_ref_name(dynamic_nested_source) + '_' + sanitize_ref_name(dynamic_nested_field);
      if (!localRefsHash[dynamic_nested_name]) {
        var dynamic_nested_ref = { name: dynamic_nested_name, type: 'dynamic_nesteds', value: { args: { source: dynamic_nested_source, field: dynamic_nested_field } } };
        localRefsHash[dynamic_nested_name] = dynamic_nested_ref;
        localRefs.push(dynamic_nested_ref);
      }
      args_object[arg_name] = dynamic_nested_name + nested_off_of_dynamic_nested;
    }
function add_dynamic_nested_refs ( localRefsHash , localRefs , ref_type , args_object , arg_name ) { var arg_expression = args_object [ arg_name ] ; var bracket_count = 0 ; var outer_string = '' ; var object_lookup_string = '' ; for ( var j = arg_expression . length - 1 ; j >= 0 ; j -- ) { var arg_expression_char = arg_expression [ j ] ; if ( bracket_count === 0 ) { if ( arg_expression_char === ']' ) { bracket_count ++ ; } else { outer_string = arg_expression_char + outer_string ; } } else { if ( arg_expression_char === ']' ) { bracket_count ++ ; } else if ( arg_expression_char === '[' ) { bracket_count -- ; if ( bracket_count === 0 ) { var parsed_index = esprima . parse ( object_lookup_string ) ; if ( parsed_index . body [ 0 ] . expression . type === "Literal" ) { var constant_ref_name = '$$dynamic_nested_constant_' + constant_count ++ ; var parsed_literal = parsed_index . body [ 0 ] . expression . value ; var constant_ref = { type : 'constants' , value : parsed_literal , name : constant_ref_name } ; localRefs . push ( constant_ref ) ; localRefsHash [ constant_ref_name ] = constant_ref ; object_lookup_string = constant_ref_name ; break ; } else { break ; } } } object_lookup_string = arg_expression_char + object_lookup_string ; } } if ( ! object_lookup_string ) { return ; } var dynamic_nested_source = arg_expression . slice ( 0 , j ) ; var dynamic_nested_field = object_lookup_string ; var nested_off_of_dynamic_nested = outer_string ; var dynamic_nested_name = 'dynamic_nested_' + sanitize_ref_name ( dynamic_nested_source ) + '_' + sanitize_ref_name ( dynamic_nested_field ) ; if ( ! localRefsHash [ dynamic_nested_name ] ) { var dynamic_nested_ref = { name : dynamic_nested_name , type : 'dynamic_nesteds' , value : { args : { source : dynamic_nested_source , field : dynamic_nested_field } } } ; localRefsHash [ dynamic_nested_name ] = dynamic_nested_ref ; localRefs . push ( dynamic_nested_ref ) ; } args_object [ arg_name ] = dynamic_nested_name + nested_off_of_dynamic_nested ; }
Note that this injects into the localRefs array and the algorithm relies on the for loop that calls this eventually running into the refs added here.
Note that this injects into the localRefs array and the algorithm relies on the for loop that calls this eventually running into the refs added here .