function process_inline_scopes(scope_type, scope_hash) {
    var scope_names = Object.keys(scope_hash);
    scope_names.forEach(function (scope_name) {
      var scope = scope_hash[scope_name];
      process_inline_scopes_in_scope(scope_type, scope_name, scope);
    });

    function process_inline_scopes_in_scope (scope_type, scope_name, scope) {
      // Support top level object being the result of an element/model template function.
      if (scope.$$coral_macro_type === 'generated_inline_scope') {
        scope = scope.args.scope;
        scope_hash[scope_name] = scope;
      }
      var allowed_top_level_keys = ['models', 'dynamicElementLists', 'elements'];
      find_and_process_inline_scopes(scope, []);

      function find_and_process_inline_scopes (object, key_path) {
        for (var key in object) {
          if (!key_path.length && allowed_top_level_keys.indexOf(key) === -1) {
            continue;
          }

          var key_value = object[key];

          if (key === 'args') {
            continue;
          }

          if (key_value && typeof key_value === 'object') {
            var is_macro_result = key_value.$$coral_macro_type === 'generated_inline_scope';
            var inline_scope_type = 'inline';
            if (is_macro_result) {
              inline_scope_type = key_value.args.source;
              key_value = key_value.args.scope;
            }
            var is_inline_scope = false;
            var has_view = typeof key_value.view === 'string';
            var is_in_models_section = key_path[0] === 'models';
            var is_likely_inline_model = is_in_models_section && (is_macro_result || !(('args' in key_value) || ('type' in key_value)));
            var is_likely_inline_element = !is_in_models_section && (is_macro_result || has_view);
            var updated_key_path = key_path.concat(key);
            if (is_likely_inline_element) {
              is_inline_scope = true;
              if (!is_macro_result) {
                inline_scope_type += ' element';
              }
              object[key] = inline_scope('element', updated_key_path, key_value, inline_scope_type);
            } else if (is_likely_inline_model) {
              is_inline_scope = true;
              if (!is_macro_result) {
                inline_scope_type += ' model';
              }
              object[key] = inline_scope('model', updated_key_path, key_value, inline_scope_type);
            }

            if (!is_inline_scope) {
              find_and_process_inline_scopes(key_value, updated_key_path);
            }
          }
        }
      }

      function inline_scope (scope_type, key_path, scope_object, inline_scope_type) {
        var originating_is_inline_scope = /\n/.test(scope_name);
        var inline_scope_name = scope_name + (originating_is_inline_scope ? '' : '.js') + '\n    - ' + inline_scope_type +  ' at ' + key_path.join('.');

        source[scope_type + 's'][inline_scope_name] = scope_object;

        process_inline_scopes_in_scope(scope_type, inline_scope_name, scope_object);

        return inline_scope_name;
      }
    }
  }
// We have to process inline scopes before we apply constants since constants must be applied to the scope they reside in, respecting any inline element usages.
We have to process inline scopes before we apply constants since constants must be applied to the scope they reside in, respecting any inline element usages.
We have to process inline scopes before we apply constants since constants must be applied to the scope they reside in respecting any inline element usages .
function process_inline_scopes(scope_type, scope_hash) {
    var scope_names = Object.keys(scope_hash);
    scope_names.forEach(function (scope_name) {
      var scope = scope_hash[scope_name];
      process_inline_scopes_in_scope(scope_type, scope_name, scope);
    });
    function process_inline_scopes_in_scope (scope_type, scope_name, scope) {
      if (scope.$$coral_macro_type === 'generated_inline_scope') {
        scope = scope.args.scope;
        scope_hash[scope_name] = scope;
      }
      var allowed_top_level_keys = ['models', 'dynamicElementLists', 'elements'];
      find_and_process_inline_scopes(scope, []);
      function find_and_process_inline_scopes (object, key_path) {
        for (var key in object) {
          if (!key_path.length && allowed_top_level_keys.indexOf(key) === -1) {
            continue;
          }
          var key_value = object[key];
          if (key === 'args') {
            continue;
          }
          if (key_value && typeof key_value === 'object') {
            var is_macro_result = key_value.$$coral_macro_type === 'generated_inline_scope';
            var inline_scope_type = 'inline';
            if (is_macro_result) {
              inline_scope_type = key_value.args.source;
              key_value = key_value.args.scope;
            }
            var is_inline_scope = false;
            var has_view = typeof key_value.view === 'string';
            var is_in_models_section = key_path[0] === 'models';
            var is_likely_inline_model = is_in_models_section && (is_macro_result || !(('args' in key_value) || ('type' in key_value)));
            var is_likely_inline_element = !is_in_models_section && (is_macro_result || has_view);
            var updated_key_path = key_path.concat(key);
            if (is_likely_inline_element) {
              is_inline_scope = true;
              if (!is_macro_result) {
                inline_scope_type += ' element';
              }
              object[key] = inline_scope('element', updated_key_path, key_value, inline_scope_type);
            } else if (is_likely_inline_model) {
              is_inline_scope = true;
              if (!is_macro_result) {
                inline_scope_type += ' model';
              }
              object[key] = inline_scope('model', updated_key_path, key_value, inline_scope_type);
            }
            if (!is_inline_scope) {
              find_and_process_inline_scopes(key_value, updated_key_path);
            }
          }
        }
      }
      function inline_scope (scope_type, key_path, scope_object, inline_scope_type) {
        var originating_is_inline_scope = /\n/.test(scope_name);
        var inline_scope_name = scope_name + (originating_is_inline_scope ? '' : '.js') + '\n    - ' + inline_scope_type +  ' at ' + key_path.join('.');
        source[scope_type + 's'][inline_scope_name] = scope_object;
        process_inline_scopes_in_scope(scope_type, inline_scope_name, scope_object);
        return inline_scope_name;
      }
    }
  }
function process_inline_scopes ( scope_type , scope_hash ) { var scope_names = Object . keys ( scope_hash ) ; scope_names . forEach ( function ( scope_name ) { var scope = scope_hash [ scope_name ] ; process_inline_scopes_in_scope ( scope_type , scope_name , scope ) ; } ) ; function process_inline_scopes_in_scope ( scope_type , scope_name , scope ) { if ( scope . $$coral_macro_type === 'generated_inline_scope' ) { scope = scope . args . scope ; scope_hash [ scope_name ] = scope ; } var allowed_top_level_keys = [ 'models' , 'dynamicElementLists' , 'elements' ] ; find_and_process_inline_scopes ( scope , [ ] ) ; function find_and_process_inline_scopes ( object , key_path ) { for ( var key in object ) { if ( ! key_path . length && allowed_top_level_keys . indexOf ( key ) === - 1 ) { continue ; } var key_value = object [ key ] ; if ( key === 'args' ) { continue ; } if ( key_value && typeof key_value === 'object' ) { var is_macro_result = key_value . $$coral_macro_type === 'generated_inline_scope' ; var inline_scope_type = 'inline' ; if ( is_macro_result ) { inline_scope_type = key_value . args . source ; key_value = key_value . args . scope ; } var is_inline_scope = false ; var has_view = typeof key_value . view === 'string' ; var is_in_models_section = key_path [ 0 ] === 'models' ; var is_likely_inline_model = is_in_models_section && ( is_macro_result || ! ( ( 'args' in key_value ) || ( 'type' in key_value ) ) ) ; var is_likely_inline_element = ! is_in_models_section && ( is_macro_result || has_view ) ; var updated_key_path = key_path . concat ( key ) ; if ( is_likely_inline_element ) { is_inline_scope = true ; if ( ! is_macro_result ) { inline_scope_type += ' element' ; } object [ key ] = inline_scope ( 'element' , updated_key_path , key_value , inline_scope_type ) ; } else if ( is_likely_inline_model ) { is_inline_scope = true ; if ( ! is_macro_result ) { inline_scope_type += ' model' ; } object [ key ] = inline_scope ( 'model' , updated_key_path , key_value , inline_scope_type ) ; } if ( ! is_inline_scope ) { find_and_process_inline_scopes ( key_value , updated_key_path ) ; } } } } function inline_scope ( scope_type , key_path , scope_object , inline_scope_type ) { var originating_is_inline_scope = / \n / . test ( scope_name ) ; var inline_scope_name = scope_name + ( originating_is_inline_scope ? '' : '.js' ) + '\n    - ' + inline_scope_type + ' at ' + key_path . join ( '.' ) ; source [ scope_type + 's' ] [ inline_scope_name ] = scope_object ; process_inline_scopes_in_scope ( scope_type , inline_scope_name , scope_object ) ; return inline_scope_name ; } } }
We have to process inline scopes before we apply constants since constants must be applied to the scope they reside in, respecting any inline element usages.
We have to process inline scopes before we apply constants since constants must be applied to the scope they reside in respecting any inline element usages .
// Support top level object being the result of an element/model template function.