microsoft / microsoft/TypeScript
__esDecorate transpiled code uses "Symbol" even of this is shadowed by a local variable
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 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 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript playground 开始,检查生成的 __esDecorate 代码中是否存在本地 Symbol 声明或导入。跟踪 decorator metadata helper 如何选择 Symbol 引用,然后验证生成的代码不再解析本地绑定,并且仍能处理所示的 decorator 示例。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100