microsoft / microsoft/TypeScript
__esDecorate transpiled code uses "Symbol" even of this is shadowed by a local variable
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
helper symbol tslib
🕗 Version & Regression Information
- This changed between versions 5.1.6 and 5.2.2
Tested via playground and reading its debug output.
⏯ Playground Link
💻 Code
function fooDecorator(originalMethod: any, context: any) {}
export class Symbol { constructor() { } }
@fooDecorator
export class myClass {
constructor() {
const _newSym = new Symbol();
}
}
🙁 Actual behavior
The generated js code for myClass contains
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
Which will access my local variable Symbol instead of window.Symbol/globalThis.Symbol.
🙂 Expected behavior
The generated code should access globalThis.Symbol in any case or perhaps only if the file contains a local variable (from class, const or import) with a colliding name.
Additional information about the issue
I found this with an import { Symbol } from "./service"; call (roughly modelled via this Bug Workbench) but this should not change the main problem.
We started to use the class name Symbol in our code (and public API) since 2014.
Right now we circumvent this issue by using different names inside the local file via alias names in import/export
But this is hard to understand and maintain.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンク先の TypeScript playground から始め、生成された __esDecorate コードでローカルの Symbol 宣言または import を調べます。decorator metadata helper が Symbol 参照をどのように選択するかを追跡し、その後、出力されたコードがローカルバインディングを解決しなくなり、示されている decorator の例も引き続き処理できることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100