index.js
function createGlobal(expr, nodes, opt_namedPartial) {
    var exprs = [];
    while (t.isMemberExpression(expr)) {
      exprs.push(expr);
      expr = expr.object;
    }

    var currGlobalName = '';
    for (var i = exprs.length - 2; opt_namedPartial ? i >= 0 : i > 0; i--) {
      currGlobalName += '.' + exprs[i].property.value;
      if (!createdGlobals[currGlobalName]) {
        createdGlobals[currGlobalName] = true;
        nodes.push(t.expressionStatement(
          t.assignmentExpression('=', exprs[i], t.logicalExpression(
            '||',
            exprs[i],
            t.objectExpression([])
          ))
        ));
      }
    }
  }
function createGlobal(expr, nodes, opt_namedPartial) {
    var exprs = [];
    while (t.isMemberExpression(expr)) {
      exprs.push(expr);
      expr = expr.object;
    }

    var currGlobalName = '';
    for (var i = exprs.length - 2; opt_namedPartial ? i >= 0 : i > 0; i--) {
      currGlobalName += '.' + exprs[i].property.value;
      if (!createdGlobals[currGlobalName]) {
        createdGlobals[currGlobalName] = true;
        nodes.push(t.expressionStatement(
          t.assignmentExpression('=', exprs[i], t.logicalExpression(
            '||',
            exprs[i],
            t.objectExpression([])
          ))
        ));
      }
    }
  }
function createGlobal ( expr , nodes , opt_namedPartial ) { var exprs = [ ] ; while ( t . isMemberExpression ( expr ) ) { exprs . push ( expr ) ; expr = expr . object ; } var currGlobalName = '' ; for ( var i = exprs . length - 2 ; opt_namedPartial ? i >= 0 : i > 0 ; i -- ) { currGlobalName += '.' + exprs [ i ] . property . value ; if ( ! createdGlobals [ currGlobalName ] ) { createdGlobals [ currGlobalName ] = true ; nodes . push ( t . expressionStatement ( t . assignmentExpression ( '=' , exprs [ i ] , t . logicalExpression ( '||' , exprs [ i ] , t . objectExpression ( [ ] ) ) ) ) ) ; } } }
Creates the global for the given name, if it hasn't been created yet.
@param {!MemberExpression} expr
@param {!Array} nodes Array to add the global creation assignments to.
Creates the global for the given name if it hasn t been created yet .