'super.prop' should only be allowed for accessors
#42,214 opened on 2021年1月5日
説明
Bug Report
🔎 Search Terms
super property access
🕗 Version & Regression Information
- This changed in version v1.8.2
⏯ Playground Link
Playground link with relevant code
💻 Code
class Base {
method() {}
prop = 1;
get accessor() { return 1 }
}
class Derived extends Base {
fn() {
super.method; // allowed, as expected
super.accessor; // allowed for target >=ES2016, expected it to always be allowed
super.prop; // allowed for target >=ES2016, expected it to always be disallowed, gives 'undefined' at runtime
}
}
🙁 Actual behavior
For target <= ES5 both super.accessor and super.prop are an error, for target > ES5 both are allowed, although the runtime behavior is exactly the same. This change was introduced in #5860 because back then there was no (reliable) information whether a property was an accessor or a regular property. Now we have that information even in DTS files. The PR comments even mention that this change was not really correct.
Related: #24678 which was marked "Working as intended", although in the comments it was clearly stated that there should've been a compile error.
🙂 Expected behavior
Property access on super allows everything that resides on the prototype (methods and accessors) and disallows instance properties.
Same logic should apply to all target ES versions as the behavior is always the same.