meteor / meteor/ecmascript-runtime
getters not working with inheritance
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
This is most likely an issue w/ Babel, and may be [related to this issue](https://github.com/babel/babel/issues/343), but I wanted to post this to see if someone might be able to help me.
Say I have the following classes defined:
``` javascript
A = class A {
constructor(value, options) {
this.value = value;
this.options = options;
console.log('constructor this: ', this);
}
get value() {
return this._value;
}
set value(value) {
this._value = value;
}
get options() {
return this._options;
}
set options(options) {
this._options = options;
}
get validationErrors() {
// Do standard validations for all classes of type A here
console.log('A.validationErrors this: ', this);
var validationErrs = [];
if (options && options.required && !value) {
validationErrs.push('Value is required');
}
return validationErrs;
}
}
B = class B extends A {
get validationErrors() {
console.log('B.validationErrors this: ', this);
var valErrs = super.validationErrors;
// Do custom validations for class B here
return valErrs;
}
}
var b = new B('val', {required: true});
var valErrs = b.validationErrors;
```
Strangely, what I see in the logs is:
```
constructor this: B{_value: "val", _options: {required: true}}
B.validationErrors this: B{_value: "val", _options: {requried: true}}
A.validationErrors this: A{}
```
Furthermore, if I call `this.value` or `this.options` in the parent's `validationErrors`, I end up with undefined returned. It seems like the constructor and getters are being copied down, at least in behavior, but they shouldn't be, right? I would think that the child's constructor would simply call the parent's in this case, but that doesn't seem to be happening.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the A/B class example with the Babel version involved and compare the generated output for the constructor, getters, and super.validationErrors call. The issue names no repository files or tests; done means determining whether transpilation preserves the instance and inherited accessor behavior, with a focused regression test if the repository provides a suitable test location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- babel, javascript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100