-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allowed non-this, non-super code before super call in derived classes with property initializers #29374
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
Merged
rbuckton
merged 61 commits into
microsoft:main
from
JoshuaKGoldberg:non-this-super-before-super
Jan 14, 2022
Merged
Allowed non-this, non-super code before super call in derived classes with property initializers #29374
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
6845db9
Allowed non-this, non-super code before super call in derived classes
dbd3a2a
Used new isNewThisScope utility and dummy prop in baselines
5aa79cd
Accounted for parameters and get/set accessor bodies
02516cc
Accounted for class extensions
00b4a2b
(node|statement)RefersToSuperOrThis wasn't checking root level scope …
6d06b21
Better 'references' name and comments; accounted for more method edge…
ccd52fc
Limited super calls to root-level statements in constructor bodies
da71ed9
Merge branch 'master'
b4a9ac2
Fixed error number following 'master' merge
0d91548
Added decorator test cases
e4dca14
Again allowed arrow functions
c8fc681
Merge branch 'master'
cf52812
Accepted new baselines
a39761d
Added allowance for (super())
afc58e1
Reworked emitter transforms for ES this binding semantics
a48d1ea
Used skipOuterExpressions when diving for super()s; fix prop ordering
efbe416
Allow direct var _this = super() when no pre-super() statements; lint…
429347d
Always with the TSLint
03da7f7
One last touchup: skipOuterExpressions in es2015 transformer
142704e
Merge branch 'master'
e71bee1
Fixed new lint complaint in utilities.ts
4cef299
Again added a falls-through; it'd be swell if I could run linting loc…
660feb2
This time I think I got it
e425e9b
Well at least the error is a different one
041c58a
Merge branch 'master'
JoshuaKGoldberg 74e6972
Undid irrelevant whitespace changes
JoshuaKGoldberg 093b1b7
Mostly addressed private/field issues
JoshuaKGoldberg 7d99293
Merge branch 'master' of https://github.com/microsoft/TypeScript into…
orta c09a156
Accepted derivedClassSuperProperties baseline
JoshuaKGoldberg 25c5c10
Merge branch 'master'
JoshuaKGoldberg 39207d2
Lint fix, lovely
JoshuaKGoldberg 25aff6c
Remove now-unnecesary comment
JoshuaKGoldberg f33707f
Merge branch 'master'
34ad5b3
First round of feedback
9022a17
Moved prologue statements to start of statements
cd82cc5
Added consideration for super statements in loops and the like
2629491
Ordering and a _this_1 test
8039315
Missed the one change I needed...
eb7388a
Merge branch 'master'
JoshuaKGoldberg 39ffad6
First round of feedback corrections
JoshuaKGoldberg 26fc18c
Feedback round two: statements
JoshuaKGoldberg 0448f54
Feedback: used more direct statements
JoshuaKGoldberg 70e741b
Fixed classFields emit to not duplicate temp variables
JoshuaKGoldberg d5ad9c3
Refactored es2015 helper to be less overloaded
JoshuaKGoldberg fe2ac08
Accounted for parentheses
JoshuaKGoldberg 360ad2e
Simpler feedback: -1, and emptyArray
JoshuaKGoldberg 23780a1
Next feedback: superStatementIndex
JoshuaKGoldberg 4b0bd82
Feedback: simplified to no longer create slice arrays
JoshuaKGoldberg 6319af5
Adjusted for default and rest parameters
e434962
Added test case for commas
bacc434
Corrected comment ranges
b250f5f
Merge branch 'master' into non-this-super-before-super
rbuckton 44d7a9a
Handled comments after super, with tests
f16ccd4
Merge branch 'master'
44a164e
Merge branch 'master'
JoshuaKGoldberg af16920
Merge branch 'master'
47fc125
Merge branch 'main'
ffdc7f8
Merge branch 'main'
dea7150
Merge branch 'main'
JoshuaKGoldberg 39d9901
Fixed Bad/Late super baselines
JoshuaKGoldberg 1b3dd6d
Remove unused param and unnecessary baseline comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
tests/baselines/reference/derivedClassSuperProperties.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(9,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(16,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(16,32): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(23,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(24,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(30,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(30,32): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(31,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(44,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(58,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
|
||
|
||
==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts (10 errors) ==== | ||
class Base { | ||
constructor(a?) { } | ||
|
||
receivesAnything(param?) { } | ||
} | ||
|
||
class Derived1 extends Base { | ||
constructor() { | ||
super.receivesAnything(); | ||
~~~~~ | ||
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. | ||
super(); | ||
} | ||
} | ||
|
||
class Derived2 extends Base { | ||
constructor() { | ||
super.receivesAnything(this); | ||
~~~~~ | ||
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. | ||
~~~~ | ||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
super(); | ||
} | ||
} | ||
|
||
class Derived3 extends Base { | ||
constructor() { | ||
super.receivesAnything(); | ||
~~~~~ | ||
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. | ||
super(this); | ||
~~~~ | ||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
} | ||
} | ||
|
||
class Derived4 extends Base { | ||
constructor() { | ||
super.receivesAnything(this); | ||
~~~~~ | ||
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. | ||
~~~~ | ||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
super(this); | ||
~~~~ | ||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
} | ||
} | ||
|
||
class Derived5 extends Base { | ||
constructor() { | ||
super(); | ||
super.receivesAnything(); | ||
} | ||
} | ||
|
||
class Derived6 extends Base { | ||
constructor() { | ||
super(this); | ||
~~~~ | ||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
super.receivesAnything(); | ||
} | ||
} | ||
|
||
class Derived7 extends Base { | ||
constructor() { | ||
super(); | ||
super.receivesAnything(this); | ||
} | ||
} | ||
|
||
class Derived8 extends Base { | ||
constructor() { | ||
super(this); | ||
~~~~ | ||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. | ||
super.receivesAnything(this); | ||
} | ||
} | ||
|
||
class DerivedWithFunction extends Base { | ||
constructor() { | ||
(function () { | ||
return this; | ||
})(); | ||
super(); | ||
} | ||
} | ||
|
||
class DerivedWithClassExpression extends Base { | ||
constructor() { | ||
console.log(class { }); | ||
super(); | ||
} | ||
} | ||
|
||
class DerivedWithDerivedClassExpression extends Base { | ||
constructor() { | ||
console.log(class extends Base { | ||
constructor() { | ||
super(); | ||
} | ||
}); | ||
super(); | ||
} | ||
} | ||
class DerivedWithNewDerivedClassExpression extends Base { | ||
constructor() { | ||
console.log(new class extends Base { | ||
constructor() { | ||
super(); | ||
} | ||
}()); | ||
super(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.