microsoft / microsoft/TypeScript
No compile error thrown when `this` referenced before call to `super` completes
未关闭
还没有人认领这个 Issue。
Effort: Difficult
Help Wanted
Suggestion
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version:
1.8.9
Code
JSFiddle: https://jsfiddle.net/kitsonk/fs9t96ep/
TS Playground: http://goo.gl/X7cgvV
class A {
constructor(fn: () => void) {
fn.call(this);
}
foo: string = 'foo';
}
class B extends A {
constructor() {
super(() => {
console.log(this);
});
}
bar: string = 'bar';
}
const b = new B();
Expected behavior:
Typescript should guard against the use of this as the call to super has not completed. Thus it should not compile.
Actual behavior:
Typescript compiles this successfully. It works fine when the target is set to es5 but breaks the browser when target is set to es6.
Error is: VM89:55 Uncaught ReferenceError: this is not defined
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的 TypeScript 1.8.9 复现开始,使用链接的 TS Playground 或 JSFiddle,并比较以 ES5 和 ES6 为目标时的编译结果。跟踪编译器如何处理传递给 super 的 callback 内部的 this;当无效的 ES6 情况被拒绝,同时有效的构造函数用法仍受支持时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100