-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Proposal: Add new __construct helper for better ES5/ES6 class interop #15397
Comments
Though it would add even more helper overhead, we could consider a best effort approach to address the subclassing drawback via var __construct = (this && this.__construct) || (typeof Reflect !== "undefined" && Reflect.construct
? function (s, t, a) { return t !== null && Reflect.construct(t, a, s.constructor); }
: { __proto__: [] } instanceof Array
? function (s, t, a) { var p = s.__proto__, r = t !== null && t.apply(s, a) || s; return r.__proto__ = p, r; }
: function (s, t, a) { return t !== null && t.apply(s, a) || s; });; |
Trying to use native WebComponents with Typescript is not very ergonomic right now, since first we need to target I know that adding tons of specific settings might want to be avoided, but would it not be a minimal change to have a flag (e.g. It would be simple to include a polyfill for There are three other issues open for the same feature. What is blocking progress on this? Is it something that could be added as a PR? |
The problem with compiling to use |
I propose we add a new helper to assist with class instance construction runtime semantics when extending ES6 built-in classes while compiling with
--target ES5
.Background
Our current emit for classes for
--target ES5
assumes that the superclass follows the same runtime semantics as the classes we emit. Generally this means that the constructor can be called as a function viacall()
orapply()
. However, a number of ES6 built-in classes are specified to throw when not used as a constructor (i.e.Promise
,Map
, etc.), and other ES6 built-in classes return a value when called, ignoring thethis
value provided tocall()
orapply()
(i.e.Error
,Array
, etc.).Previously we provided guidance for possible workarounds for this to support the latter scenario, but we do not currently have a solution for the former scenario.
Proposal
The following code listing describes a new
__construct
helper that we would need to emit for any file that contains an explicit (or implicit, for property declarations)super()
call:Benefits
Reflect.construct
.extends null
andextends x
whenx
isnull
in the same way as existing behavior.super
in the same way as existing behavior.Drawbacks
Array
orError
will not have the correct prototype chain. The only solution is to explicitly set the prototype chain using the non-standard__proto__
property as per established guidance.The text was updated successfully, but these errors were encountered: