override arrow function error
Closed this issue · 4 comments
I am using override decorator with webpack babel (transform-decorators-legacy) just like the way below:
class A {
constructor() {
}
a=()=>{
}
}
class B extends A {
constructor() {
super()
}
@override
a=()=>{
}
}
but there are some bugs I can't figure out.
Uncaught SyntaxError: No descriptor matching B#a was found on the prototype chain.
at SyntaxErrorReporter.error (webpack:///./~/core-decorators/es/override.js?:123:13)
at handleDescriptor (webpack:///./~/core-decorators/es/override.js?:268:14)
at decorate (webpack:///./~/core-decorators/es/private/utils.js?:88:29)
at override (webpack:///./~/core-decorators/es/override.js?:281:97)
at eval (webpack:///./src/modules/caton/view/deviceperformance/catonmonitor/diffversion/index.js?:72:10)
at Array.reduce (native)
at _applyDecoratedDescriptor (webpack:///./src/modules/caton/view/deviceperformance/catonmonitor/diffversion/index.js?:71:38)
at eval (webpack:///./src/modules/caton/view/deviceperformance/catonmonitor/diffversion/index.js?:422:22)
at Object.<anonymous> (http://localhost/caton/bundle.bedc15f3a60f4010484a.js:586:1)
at __webpack_require__ (http://localhost/caton/bundle.bedc15f3a60f4010484a.js:20:30)
babel-loader
{
"plugins": [
"transform-decorators-legacy",
"transform-class-properties",
"transform-object-rest-spread",
],
"presets": ['env', "es2015", "react", "es2017"]
}
The @override
decorator only works on things that are prototype based, so only methods/getters/setters. Property initializers are not attached to the prototype so there is no way (at least currently) to look them up from the parent to see if they might match.
Works with methods and getters/setters. Will ensure name, parameter count, as well as descriptor type (accessor/data). Provides a suggestion if it finds a method with a similar signature, including slight misspellings.
Thinking about this further, even if we could look them up I'm not sure how we could check they override correctly since property initializers are thunked expressions that are only evaluated at class instance creation time so for example, we wouldn't know that the contents of the initializer was an arrow function with zero parameters. They're just fundamentally incompatible concepts.
@jayphelps thanks for your answer