Description
We have a typescript application and a use a file per class. There are lots of benefits to this the major one being source control conflict reduction.
We compile our app using the --out compiler flag but I think there is room for some serious optimization of the compilers output for modules.
Currently if you have two classes defined in separate files the compile generates the following JavaScript.
var Example;
(function (Example) {
(function (Nested) {
(function (Issue) {
var bar = (function () {
function bar() {
}
return bar;
})();
Issue.bar = bar;
})(Nested.Issue || (Nested.Issue = {}));
var Issue = Nested.Issue;
})(Example.Nested || (Example.Nested = {}));
var Nested = Example.Nested;
})(Example || (Example = {}));
var Example;
(function (Example) {
(function (Nested) {
(function (Issue) {
var foo = (function () {
function foo() {
}
return foo;
})();
Issue.foo = foo;
})(Nested.Issue || (Nested.Issue = {}));
var Issue = Nested.Issue;
})(Example.Nested || (Example.Nested = {}));
var Nested = Example.Nested;
})(Example || (Example = {}));
I suggest a compiler flag that composes all classes/ functions etc under a single module declaration? So the output code would be like the example below. This would dramatically reduce the size of the JavaScript the compiler outputs. I estimate that our app which currently compiles to around 15,000 lines of probably be only be 2000 lines if this were available.
var Example;
(function (Example) {
(function (Nested) {
(function (Issue) {
var bar = (function () {
function bar() {
}
return bar;
})();
Issue.bar = bar;
var foo = (function () {
function foo() {
}
return foo;
})();
Issue.foo = foo;
})(Nested.Issue || (Nested.Issue = {}));
var Issue = Nested.Issue;
})(Example.Nested || (Example.Nested = {}));
var Nested = Example.Nested;
})(Example || (Example = {}));