evanw / evanw/esbuild

TypeScript: `import x = A.x` syntax should always be converted to a var declaration

Open
#4,449 1 comment 0 reactions 0 assignees View on GitHub
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;
}
import x = A.x;
console.log(x);
```

TypeScript 6.0.2 with `"target": "ES2020"` ([playground](https://www.typescriptlang.org/play/?target=7&module=1&ts=6.0.2#code/HYQwtgpgzgDiDGEAEBBJBvAUEnSIA8YB7AJwBckA3EEpfJAXiQAYBuTAX0wEsxjy6jVADp87eEWBQiAGwjCZRAOYAKfAEp2QA)):

```js
"use strict";
var A;
(function (A) {
A.x = 0;
})(A || (A = {}));
var x = A.x;
console.log(x);
```

esbuild 0.28.0 with `--target=es2020` ([playground](https://esbuild.github.io/try/#dAAwLjI4LjAALS1sb2FkZXI9dHMgLS10YXJnZXQ9ZXMyMDIwAG5hbWVzcGFjZSBBIHsKICAgIGV4cG9ydCB2YXIgeCA9IDA7Cn0KaW1wb3J0IHggPSBBLng7CmNvbnNvbGUubG9nKHgpOw)):

```js
var A;
((A2) => {
A2.x = 0;
})(A || (A = {}));
const x = A.x;
console.log(x);
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the TypeScript reproduction from the issue and compare esbuild's output with TypeScript's output for the namespace and import-assignment case. Trace the TypeScript lowering path for `import x = A.x`, then add a regression test showing that this syntax is emitted as a `var` declaration and that the test output matches the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.