-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SUGGESTION] support for custom components on es5 #17825
Comments
However, a working |
@Kovensky Reflect can be polyfilled just like web components and this is what we expect to do when transpiling to es5... try { super(); } catch(e) { this = Reflect.construct(_super, [], this.constructor); } An adapter is present but only works with es6 browsers... and is slower than a Reflect.construct. Keep in mind that everything here is suggestion. |
I would suggest the following implementation : var MyComponent = (function (_super) {
__extends(MyComponent, _super);
function MyComponent() {
var args = []; // Whatever is used as super constructor arguments
var _this = _super !== null ? (Reflect && Reflect.construct && Reflect.construct(_super, args, MyComponent) || _super.apply(this, args)) : this;
return _this;
}
return MyComponent;
}(HTMLElement)); The real issue is that we cannot choose to use feature detection and load a polyfill only when custom elements are not implemented. We HAVE to use a polyfill if we want to target ES5 as the compilation output. |
Given the rarity of people targeting DOM environments with only ES5, this doesn't seem like a good area of investment. |
SUGGESTION
Transpiles to :
The
_super.call(this)
suggests that the super constructor is callable. This isn't true forHTMLElement
(s) which are part of the Custom Elements. These requires es6 classes or usingReflect.construct(HTMLElement, [], MyComponent);
A proper es5 should output :
For performances issues, the transpiler should probably only use
var _this = Reflect.construct(_super, [], MyComponent);
in replacement to_super.call(this)
if the mother class is an instance of HTMLElement (done at transpile time, this includes HTMLElement, HTMLImageElement,... and every futures uncallable class constructors).As an example, this behavior is already present in babel.
A fast fix (not optimized because executing at runtime) could be done though :
The text was updated successfully, but these errors were encountered: