[Bug] PrivateIdentifier nodes are omitted from 2020 semantic classifications

オープン 初心者向け
#64,322 コメント 2 件 リアクション 1 件 担当者 2 名 GitHub で見る

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript, vscode

調査の方向性

src/services/classifier2020.ts の collectTokens から始め、識別子ノードに対する既存の declaration-kind マッピングを確認します。private フィールドとメソッドの宣言および参照を対象とする関連する fourslash 回帰テストを追加し、その後、ノードが property または method の分類と declaration modifiers を受け取ることを確認します。

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

説明

Bug Report

🔎 Search Terms

semantic highlighting, semantic token, PrivateIdentifier, private field, private method, encodedSemanticClassifications

🕗 Version & Regression Information
  • TypeScript 6.0.3 (bundled with VS Code)
  • Also present in the v5.9 classifier implementation
  • This is not a theme-specific issue
💻 Code
class Foo {
    field = 1;
    #privateField = 1;

    method() {}
    #privateMethod() {}

    test() {
        this.field;
        this.#privateField;

        this.method();
        this.#privateMethod();
    }
}
🙁 Actual behavior

In VS Code's Developer: Inspect Editor Tokens and Scopes:

  • field and method receive semantic token types.
  • #privateField and #privateMethod receive no semantic token and fall back to TextMate scopes.
  • As a result, editor.semanticTokenColorCustomizations rules for property and method do not apply to ECMAScript private members.
Image Image
🙂 Expected behavior
  • #privateField should be classified as property.
  • #privateMethod should be classified as method.
  • Declarations should also receive the declaration modifier.
Root cause

VS Code requests encodedSemanticClassifications-full with format "2020".

In src/services/classifier2020.ts, collectTokens only enters the semantic-classification path for isIdentifier(node):

if (isIdentifier(node) && ...) {
    let symbol = typeChecker.getSymbolAtLocation(node);
    // ...
}

ECMAScript private names are separate SyntaxKind.PrivateIdentifier nodes, so they are skipped before getSymbolAtLocation is called.

Relevant source:
https://github.com/microsoft/TypeScript/blob/050880ce59e30b356b686bd3144efe24f875ebc8/src/services/classifier2020.ts#L121-L203

Proposed fix
+    isPrivateIdentifier,
     isPropertyAccessExpression,
-        if (isIdentifier(node) && ...) {
+        if ((isIdentifier(node) || isPrivateIdentifier(node)) && ...) {

The existing declaration-kind mapping already classifies private fields and methods correctly once these nodes reach the symbol-classification path.

I tested the equivalent change against TypeScript 6.0.3:

  • #privateField declaration/reference → property
  • #privateMethod declaration/reference → member internally, mapped by VS Code to method
  • declaration occurrences receive the declaration modifier
  • added fourslash regression test passes
Related issue

https://github.com/microsoft/TypeScript/issues/44483 requests new private/protected semantic modifiers. This report is different: ECMAScript PrivateIdentifier nodes currently receive no semantic classification at all.

主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 15時間
マージ済み PR(30日)
106

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

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

はじめの一歩

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

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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