title: Referencing nested TypeScript modules
body: <p>I have the following situation:</p>
  
  <pre><code>/*file A/Z.ts*/
  ///&lt;reference path="B/Y.ts"/&gt;
  module A{
      import Y = B.Y;
      export class Z{
          //use class Y
      }
  }
  
  
  /*file A/B/Y.ts*/
  ///&lt;reference path="../Z.ts"/&gt;
  module A.B{
      import Z = A.Z;
      export class Y{
          //use class Z
      }
  }
  </code></pre>
  
  <p>Which seems to compile fine however I get javascript issues.
  When calling <code>var y = new Y()</code> in the chrome dev console I get: <code>Uncaught TypeError: undefined is not a function</code> and looking in the generated JavaScript the IntelliJ code inspection notes that <code>B</code> is private and not accessible.</p>
  
  <p>It's worth noting that all my .ts are compiled into a single file.</p>
  
  <p>EDIT: On further inspection it is an ordering issue. Moving the declarations around in the generated javascript fixed the JavaScript errors.
  The issue only came about when I started wrapping my classes in modules. i.e. the ordering was fine pre-modules making me assume all my ref's are fine.</p>
  
  <p>TSC Version is 1.5.0-beta</p>