microsoft / microsoft/TypeScript
Function expressions in a property assignment of a prototype object should be methods, not nested classes
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
/** @class */
module.exports.C = function() {
this.x = 1
}
module.exports.C.prototype = {
m1() {
this.a = 1
},
m2: function() {
this.b = 2
}
}
var c = new module.exports.C()
c.a
c.b
Expected behavior:
c.a and c.b both work.
Actual behavior:
Only c.a works; c.b says that 'd' does not exist on type 'C'. There's also an error on this.b = 2 when noImplicitThis: true.
bindThisPropertyAssignment needs to understand that function expressions might be part of a property assignment in an object literal. The code to handle this will probably look like this:
// For `{ x: function() }` should modify the object literal's members, not behave like a fresh class (as long as it doesn't have @class on it)
if (isPropertyAssignment(thisContainer.parent)) {
// wow I hope those parent pointers are set!
const containingClass = thisContainer.parent.parent;
const symbolTable = containingClass.symbol.members!;
if (hasDynamicName(node)) {
bindDynamicallyNamedThisPropertyAssignment(node, containingClass.symbol);
}
else {
declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.None, /*isReplaceableByMethod*/ true);
}
break;
}
I expect this to break a lot of tests, but it didn't. However, I haven't tried it on the user tests yet.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue の再現から始めて、bindThisPropertyAssignment を調査してください。特に、prototype オブジェクトのプロパティ代入内にある関数式がどのように扱われるかを確認してください。noImplicitThis 下で、示された例の動作を確認し、c.a と c.b の両方が機能するか、また報告された診断がなくなっているかどうかも確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100