TypeScript: an exported variable of sibling namespaces can not be correctly transformed when assigned
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Example input code:
```ts
namespace A {
export var x = 0;
}
namespace A {
console.log(x);
x = 0;
}
```
TypeScript 6.0.2 ([playground][pg1]):
[pg1]: https://www.typescriptlang.org/play/?target=7&module=1&ts=6.0.2#code/HYQwtgpgzgDiDGEAEBBJBvAUEnSIA8YB7AJwBckA3EEpfJAXiQAYBuTAX001ElgWRosuJPCLAoRADYQAdFKIBzABT4AlOxH0mbTkA
```js
"use strict";
var A;
(function (A) {
A.x = 0;
})(A || (A = {}));
(function (A) {
console.log(A.x);
A.x = 0;
})(A || (A = {}));
```
esbuild 0.28.0 ([playground][pg2]):
[pg2]: https://esbuild.github.io/try/#dAAwLjI4LjAALS1sb2FkZXI9dHMAbmFtZXNwYWNlIEEgewogICAgZXhwb3J0IHZhciB4ID0gMDsKfQoKbmFtZXNwYWNlIEEgewogICAgY29uc29sZS5sb2coeCk7CiAgICB4ID0gMDsKfQ
```js
var A;
((A2) => {
A2.x = 0;
})(A || (A = {}));
((A2) => {
console.log(A2.x);
x = 0;
})(A || (A = {}));
```
Related issue: #1410
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by compiling the reported TypeScript namespace example with esbuild 0.28.0 and comparing its output with the TypeScript output shown. Trace how the sibling namespace assignment is transformed; done means the assignment targets the exported namespace variable rather than an unresolved bare identifier.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100