Issue 1:
TypeScript Version: 1.8.10

Code

This is the file in the libary

// File ../../lib/test.ts
/**
* Created by ThomasP on 29.04.2016.
*/

export function test(): number {
return Model.getNum();
}

export class Model {

static getNum(): number {
return 1;
}
}

And this is the test spec for the libary file

// File: test.Spec.ts
import {test} from "../../lib/test";
/**
* Created by ThomasP on 29.04.2016.
*/

describe( 'test', function () {

it( 'should be able to get Model', function () {
expect( test() ).toBe( 1 );
});

});

The actual compile target is es6 and the module system is system, see below

{
"compilerOptions": {
"target": "es6",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}

Expected behavior:

The test should work and the method test should be able to call the static method on the class Model

Actual behavior:

The class Model is not reachable for the method test. The compiled target looks like this. Model will be defined but is undefined. Creating the class Model in the local execute function will not set Model to the variable defined in the context.

/**
* Created by ThomasP on 29.04.2016.
*/
System.register([], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var Model;
function test() {
return Model.getNum();
}
exports_1("test", test);
return {
setters:[],
execute: function() {
class Model {
static getNum() {
return 1;
}
}
exports_1("Model", Model);
}
}
});
//# sourceMappingURL=test.js.map

Solution:

I think all defined classes must be set to the variables, which are defined in the upper context. Than the module will work as expected. I changed he output like above and now it will work fine. Another possible solution is to define a class not in the execute function, should be also work as expected.

/**
* Created by ThomasP on 29.04.2016.
*/
System.register([], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var Model;
function test() {
return Model.getNum();
}
exports_1("test", test);
return {
setters:[],
execute: function() {
Model = class Model {
static getNum() {
return 1;
}
}
exports_1("Model", Model);
}
}
});
//# sourceMappingURL=test.js.map

Issue 2:
We have a large TypeScript project using different git repositories to separate work domains inside the project. We tend to create separate repositories for self-contained modules and use those modules in other repositories using git submodules. This helps tremendously to reduce clutter and distribute work.

In our case some modules are used in many other repositories and those repositories are in turn used in other repositories. This sometimes leads to duplicate sources in projects using submodules which themselves depend on a common submodule. Assume the following example to clarify this:

Project git
|-- A (git submodule)
| |-- a.ts
| |-- C (git submodule)
| |-- c.ts
|-- B (git submodule)
| |-- b.ts
| |-- C (git submodule)
| |-- c.ts
|-- app.ts

Submodule A git
|-- a.ts
|-- C (git submodule)
|-- c.ts

Submodule B git
|-- b.ts
|-- C (git submodule)
|-- c.ts

Submodule C git
|-- c.ts

In this case submodule C is a self-contained repository used as submodule in repositories A and B which in turn are used as submodules in our main project git. This results in duplicate sources for c.ts in the main project which can sometimes lead to compiler errors along the lines of Types have separate declarations bla bla. See #5039 for an example (this feature request is a spin-off from the discussion in #5039 which proposes path mappings).

This is because the TypeScript compiler treats the duplicate implementations of submodule C as separate implementations. Would it not be nice if the compiler detects those duplicate sources (by generating some sort of hash for each compiled source) and automatically maps subsequent sources to the first source already compiled? It would greatly improve the use of git submodules in TypeScript projects and prevents the formation of separate type declarations.