microsoft / microsoft/TypeScript

"const" was transformed to "var" when target is "esnext"

オープン
#59,877 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: JS Emit Help Wanted
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

transform, const, var, target, ECMA, esnext

🕗 Version & Regression Information
  • This is the behavior in every version I tried from Version 5.4 to Version 5.7.0-dev.20240904
⏯ Playground Link

No response

💻 Code
export const cilBlurLinear : string [ ] = [  ,  ] 
const [ ,  ] = cilBlurLinear;
🙁 Actual behavior

The JS code generated by tsc is as follows:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cilBlurLinear = void 0;
exports.cilBlurLinear = [,];
var ;
🙂 Expected behavior

“const” should be translated as "const" instead of "var", as the target in my configuration file is "esnext".

Additional information about the issue

tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "esnext",
    "moduleResolution": "Node",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2023","dom"],
    "noEmitOnError":true,
    "force":true,
    "strict":true
  },
  "include": [
    "TScorpus/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提示されたコードを tsc と示されている tsconfig.json で再現し、次に、ターゲットが ESNext の場合にコンパイラーが const の分割代入をどのように処理するかを確認します。生成された JavaScript が const を保持し、無効な var の出力を生成しなければ完了です。リポジトリの既存のコンパイラーテストで適切な配置場所が見つかる場合は、このケースの回帰テストを追加してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。