microsoft / microsoft/TypeScript
Function expressions in a property assignment of a prototype object should be methods, not nested classes
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
/** @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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với trường hợp tái hiện trong issue và kiểm tra bindThisPropertyAssignment, đặc biệt là cách các biểu thức hàm bên trong các phép gán thuộc tính của đối tượng prototype được xử lý. Xác minh hành vi với ví dụ đã cho dưới noImplicitThis, bao gồm việc cả c.a và c.b có hoạt động hay không và chẩn đoán được báo cáo có biến mất hay không.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, typescript
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100