-
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
if first line in constructor is 'somestring', "this" is called before calling super() in constructor #6901
Comments
CC: @yuit |
Proposing the following behavior (@ahejlsberg, @bterlson any thoughts?)
|
@RyanCavanaugh I think what you propose works. |
As talked with @RyanCavanaugh off-line, the two bullet points should be address separately as they will involve discussing whether we should allow |
@yuit Right, the issue here is that the checker skips prologue directives (expression statements consisting of a string literal) but the emitter doesn't. We need similar logic in the emitter where we locate the first |
@bterlson Brian, are there any proposals in TC39 to support property declarations with initializers in classes? @RyanCavanaugh Seems like there are so many ways this could go wrong. What about situations where there are multiple super calls, e.g. in both branches of an |
@ahejlsberg indeed, see https://github.com/jeffmo/es-class-fields-and-static-properties. Notably, "execution of the initializers happens at the end of the internal "initialization" process that occurs while executing super() in the derived constructor", which seems to align with @RyanCavanaugh's behavior. Also note the next sentence: "This means that if a derived constructor never calls super() , instance fields specified on the derived class will not be initialized". |
I don't think we can realistically pick and choose which ES6 classes
That's fine - we emit the initializers twice. There's nothing wrong with that. If you call
If the |
Honestly guys: your speed is amazing! Thx for the quick help to all of you :) |
@davidreher you're welcome :). Just an fyi, the porting to master will be done today so if you would like to give it a try on today's nightly ! |
Hi,
we have experienced a problem where
this
is called beforesuper()
in a constructor function. This happen if the first line in a constructor is a string (for e.gngInject
;)Typescript
and here the transpiled output
The transpiled output with
'someStringForEgngInject'
removed works correct.We are using Typescript 1.7.5 and compile to ES6 which is handed of to Babel which will print a error message like this
The code for transpiling constructors probably "assumes" that the first line is always the "super" call and insert all default values in the second line?!
Issue found by @loxy, CC'ing @davidreher
Cheers,
Fabian
The text was updated successfully, but these errors were encountered: