microsoft / microsoft/TypeScript
namespace / module: Duplicate declaration & needlessly remove line-breaks
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the namespace and module example with TSC and comparing the emitted JavaScript. Inspect the compiler path responsible for namespace/module emission, then define expected output for duplicate declarations and preserved line breaks. Add regression coverage for both formatting concerns and verify the generated output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100