We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
This PR fixes #7574.
In ES2015, constructors which return a value (which is an object) implicitly substitute the value of this for any callers of super(). As a result, it is necessary to capture any potential return value of super() and replace it with this.
this
super()
Some remaining work might be to do some refactoring on the emit code.
I'd suggest reading one commit at a time.
Sorry, something went wrong.
Emit '_this' declaration for derived classes; initialize it when call…
9dbab97
…ing 'super(...)'.
Accepted baselines.
99f1df4
Transform other instances of 'this' to '_this' when in the constructo…
d778e78
…r of a derived class.
Accepted baselines for all tests apart from one with source map changes.
c21cc24
Accepted baselines for sourcemap test.
9c6e148
Always tack on a return statement for '_this' in derived classes.
cd5e76b
30ec599
Ensure prologue directives occur first.
bab6d6f
ce953ce
Consolidate '_this' declaration and assignments for first statements …
d6e548b
…in constructors.
Fixed issue where last function context & parent node wasn't being pr…
11bc6c4
…eserved. This came up when a `super()` call was nested in another constructor body. Current logic in the transform says that if the last containing non-arrow function body is non-static, and the current parent isn't a call expression, the call target of a `super` call will become `_super.prototype` instead of `super`. If the state is not saved, the containing arrow function and parent are not saved, and the information for this check won't be accurate.
d8846dd
Always perform this captures after default & rest parameters.
86088d0
dd27139
Added a test for branched returns at the end of a constructor.
f3dcaae
1be4cee
Don't emit a return statement at the end in most useful cases.
c87a773
d144665
Added test for '_this'.
b476815
230737f
Mark constructors as this-capturing if they are defined in a derived …
b11db57
…class.
Merge branch 'master' into useReturnedThisFromSuperCalls
25f9555
3a5fb0c
Added missing semicolons.
f11c646
Awesome work! I have verified, that with this branch of TypeScript, I can now in fact create CustomElements entirely in TypeScript. Thank You FYI: @treshugart
Merge remote-tracking branch 'origin/master' into useReturnedThisFrom…
a63a0d8
…SuperCalls
138e18c
Remove usage of 'useCapturedThis'.
4a5830d
Collapse 'super()' capture/returns into a single return statement for…
c668644
… generated 'super()' calls.
1fbdb86
Restore arrow function.
e0c35f2
Reuse the 'captureThisForNode' function.
f8fbc22
Removed pointlessish overloads.
fb4b503
Moved code around, fixed indent, reworded comment.
b5a1031
36a5c42
I don't think our test harness gives an error for this right now.
@sandersn how have we been operating like this? In any case, it looks like GitHub just has a limitation and might not be showing that file. I seem to have it locally.
It's only been since we made the tests run faster by not writing output for passing tests.
I have the PR open in codeflow too or I would not have noticed the missing file at all. But maybe it's missing at the API level, not just the UI level.
Consolidated 'super()' transformation logic into one function.
c29ec6f
@sandersn are you sure you don't see a tests/cases/compiler/derivedClassConstructorWithExplicitReturns01.ts?
tests/cases/compiler/derivedClassConstructorWithExplicitReturns01.ts
When I check out the branch myself I see it, but I don't find it in the github list of files either. I guess it's a limitation of github proper, not just its UI.
@DanielRosenwasser after the removal of useCapturedThis did you see any changes in the test results?
useCapturedThis
02b9917
@rbuckton nope, no changes.
bcdf1dc
Thanks @sandersn!
sandersn sandersn left review comments
rbuckton rbuckton approved these changes
Successfully merging this pull request may close these issues.