Microsoft/TypeScript

namespace / module: Duplicate declaration & needlessly remove line-breaks

Open

#5,553 opened on 2015年11月6日

GitHub で見る
 (5 comments) (0 reactions) (0 assignees)TypeScript (48,455 stars) (6,726 forks)batch import
Help WantedSuggestion

説明

I wonder why TSC re-declare a global var after each namespace or module block.

namespace OurName {
    export var isAndroid = true;
    export var isWinPhone = false;
    // do something
    var checkCookies = function() {
        return true;
    }
}

namespace OurName {
    export var HTML = '<b>hello</b>';
    export var state = [1, 2, 3];
    export var addToCart = function() {
        return true;
    }
}

namespace OurName {
    var xyz = false;
    // do something
    export module Office {
        var isClosed = false;
    }
}

Above code is translated to:

var OurName;
(function (OurName) {
    OurName.isAndroid = true;
    OurName.isWinPhone = false;
    // do something
    var checkCookies = function () {
        return true;
    };
})(OurName || (OurName = {}));
var OurName;
(function (OurName) {
    OurName.HTML = '<b>hello</b>';
    OurName.state = [1, 2, 3];
    OurName.addToCart = function () {
        return true;
    };
})(OurName || (OurName = {}));
var OurName;
(function (OurName) {
    var xyz = false;
    // do something
    var Office;
    (function (Office) {
        var isClosed = false;
    })(Office = OurName.Office || (OurName.Office = {}));
})(OurName || (OurName = {}));

It also removes the line-breaks that help me keeping the code easier to look. I am porting our production ES5 code to TypeScript, so I have to carefully re-check the output of TSC. This behaviour makes my work even harder.

コントリビューターガイド