CARVIEW |
Select Language
HTTP/2 200
date: Mon, 21 Jul 2025 07:08:33 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-repository-download: git clone https://github.com/microsoft/TypeScript.git
etag: W/"19f478d45ae9e947ed13116100b5f0e5"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=%2BU96aGma62qUJ7bmyWzHU4ZNa%2B%2BGB8jNprtMpmdtFRlwcaQImYN8pBGICoOkcFmIB3ByrMs2Mgc9NeQMUyoT7kdm7ASmSMyt3PfR3arkrFN4wnEgpWaTlfBXxKRhInWpnjV6LUSzenQXgPi3ljS5ZDjHzZi%2FpbqytHEnPBTopN4eUyK0x68hJ2QILNn%2BwJ1L1B05VekiqddaWkau81i%2FWM74iE7UuJlOI0dH8Bx7%2FxNlFSLFUzFnyDbcdyJGqc8TBLRinO%2FimzVRmbxzFhtqNA%3D%3D--dlwRnSIlESCcd199--azyH7Wr6XW6CJrj%2BjZhRMA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.35916659.1753081711; Path=/; Domain=github.com; Expires=Tue, 21 Jul 2026 07:08:31 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Tue, 21 Jul 2026 07:08:31 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: C7DC:110E0E:160746E:1C3D3F1:687DE76F
Allowed non-this, non-super code before super call in derived classes… · microsoft/TypeScript@b7fee7f · GitHub


authored Dismiss banner
Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json
Copy file name to clipboardExpand all lines: src/compiler/factory/nodeFactory.ts
Copy file name to clipboardExpand all lines: src/compiler/transformers/classFields.ts
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit b7fee7f

Allowed non-this, non-super code before super call in derived classes with property initializers (#29374)
* Allowed non-this, non-super code before super call in derived classes
Fixes #8277.
It feels wrong to put a new `forEachChild` loop in the checker, though in the vast majority of user files this will be a very quick one. Is there a better way to check for a reference to `super` or `this`?
* Used new isNewThisScope utility and dummy prop in baselines
* Accounted for parameters and get/set accessor bodies
* Accounted for class extensions
* (node|statement)RefersToSuperOrThis wasn't checking root level scope boundaries
```ts
function () {
return this;
}
```
It was immediately going to `ts.forEachChild` so the statement itself wasn't being counted as a new `this` scope.
* Better 'references' name and comments; accounted for more method edge case
* Limited super calls to root-level statements in constructor bodies
As per discussion in the issue, it would be ideal to consider any block that always ends up calling to super() the equivalent of a root-level super() statement. This would be valid:
```ts
foo = 1;
constructor() {
condition() ? super(1) : super(0);
this.foo;
}
```
...as it would compile to the equivalent of:
```ts
function () {
condition() ? super(1) : super(0);
this.foo = 1;
this.foo;
}
That change would a bit more intense and I'm very timid, so leaving it out of this PR. In the meantime the requirement is that the super() statement must itself be root-level.
* Fixed error number following 'master' merge
* Added decorator test cases
* Again allowed arrow functions
* Accepted new baselines
* Added allowance for (super())
* Reworked emitter transforms for ES this binding semantics
In trying to adjust to rbuckton's PR feedback, this orders derived class constructor bodies into five sections:
1. Pre-`super()` code
2. The `super()` call itself
3. Class properties with initializers
4. Parameter properties
5. The rest of the constructor
I've looked through the updated baselines and it looks like they're generally better than before. Within the existing test cases that result in semantic errors for `this` access before `super`, several previously resulted in a global `_this` being created; now, they correctly defer referring to `_this` until it's assigned to `_super.call(this) || this`.
* Used skipOuterExpressions when diving for super()s; fix prop ordering
* Allow direct var _this = super() when no pre-super() statements; lint fixes
* Always with the TSLint
* One last touchup: skipOuterExpressions in es2015 transformer
* Fixed new lint complaint in utilities.ts
* Again added a falls-through; it'd be swell if I could run linting locally
* This time I think I got it
* Well at least the error is a different one
* Undid irrelevant whitespace changes
* Mostly addressed private/field issues
* Accepted derivedClassSuperProperties baseline
* Lint fix, lovely
* Remove now-unnecesary comment
* First round of feedback
* Moved prologue statements to start of statements
* Added consideration for super statements in loops and the like
* Ordering and a _this_1 test
* Missed the one change I needed...
* First round of feedback corrections
* Feedback round two: statements
* Feedback: used more direct statements
* Fixed classFields emit to not duplicate temp variables
* Refactored es2015 helper to be less overloaded
* Accounted for parentheses
* Simpler feedback: -1, and emptyArray
* Next feedback: superStatementIndex
* Feedback: simplified to no longer create slice arrays
* Adjusted for default and rest parameters
* Added test case for commas
* Corrected comment ranges
* Handled comments after super, with tests
* Fixed Bad/Late super baselines
* Remove unused param and unnecessary baseline comments
Co-authored-by: Orta Therox <orta.therox@gmail.com>
Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>1 parent 70097c4 commit b7fee7fCopy full SHA for b7fee7f
File tree
Expand file treeCollapse file tree
74 files changed
+5561
-317
lines changedFilter options
- src/compiler
- factory
- transformers
- tests
- baselines/reference
- cases
- compiler
- conformance/classes
- constructorDeclarations/superCalls
- members/privateNames
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Expand file treeCollapse file tree
74 files changed
+5561
-317
lines changed+42-17Lines changed: 42 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
34731 | 34731 |
| |
34732 | 34732 |
| |
34733 | 34733 |
| |
34734 |
| - | |
34735 |
| - | |
| 34734 | + | |
34736 | 34735 |
| |
34737 | 34736 |
| |
34738 | 34737 |
| |
34739 |
| - | |
| 34738 | + | |
| 34739 | + | |
34740 | 34740 |
| |
34741 | 34741 |
| |
34742 | 34742 |
| |
34743 | 34743 |
| |
34744 |
| - | |
34745 |
| - | |
34746 |
| - | |
34747 |
| - | |
34748 |
| - | |
| 34744 | + | |
| 34745 | + | |
| 34746 | + | |
| 34747 | + | |
| 34748 | + | |
| 34749 | + | |
| 34750 | + | |
| 34751 | + | |
| 34752 | + | |
34749 | 34753 |
| |
34750 |
| - | |
34751 |
| - | |
34752 |
| - | |
34753 |
| - | |
| 34754 | + | |
| 34755 | + | |
| 34756 | + | |
| 34757 | + | |
| 34758 | + | |
| 34759 | + | |
| 34760 | + | |
| 34761 | + | |
34754 | 34762 |
| |
34755 |
| - | |
34756 |
| - | |
| 34763 | + | |
| 34764 | + | |
| 34765 | + | |
| 34766 | + | |
| 34767 | + | |
34757 | 34768 |
| |
34758 | 34769 |
| |
34759 |
| - | |
34760 |
| - | |
34761 |
| - | |
34762 | 34770 |
| |
34763 | 34771 |
| |
34764 | 34772 |
| |
| |||
34767 | 34775 |
| |
34768 | 34776 |
| |
34769 | 34777 |
| |
| 34778 | + | |
| 34779 | + | |
| 34780 | + | |
| 34781 | + | |
| 34782 | + | |
| 34783 | + | |
| 34784 | + | |
| 34785 | + | |
| 34786 | + | |
| 34787 | + | |
| 34788 | + | |
| 34789 | + | |
| 34790 | + | |
| 34791 | + | |
| 34792 | + | |
| 34793 | + | |
| 34794 | + | |
34770 | 34795 |
| |
34771 | 34796 |
| |
34772 | 34797 |
| |
|
src/compiler/diagnosticMessages.json
Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json+5-1Lines changed: 5 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1747 | 1747 |
| |
1748 | 1748 |
| |
1749 | 1749 |
| |
1750 |
| - | |
| 1750 | + | |
1751 | 1751 |
| |
1752 | 1752 |
| |
1753 | 1753 |
| |
| |||
1839 | 1839 |
| |
1840 | 1840 |
| |
1841 | 1841 |
| |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
1842 | 1846 |
| |
1843 | 1847 |
| |
1844 | 1848 |
| |
|
src/compiler/factory/nodeFactory.ts
Copy file name to clipboardExpand all lines: src/compiler/factory/nodeFactory.ts+4-3Lines changed: 4 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5885 | 5885 |
| |
5886 | 5886 |
| |
5887 | 5887 |
| |
5888 |
| - | |
| 5888 | + | |
5889 | 5889 |
| |
5890 | 5890 |
| |
5891 | 5891 |
| |
| |||
5901 | 5901 |
| |
5902 | 5902 |
| |
5903 | 5903 |
| |
| 5904 | + | |
5904 | 5905 |
| |
| 5906 | + | |
5905 | 5907 |
| |
5906 |
| - | |
| 5908 | + | |
5907 | 5909 |
| |
5908 | 5910 |
| |
5909 |
| - | |
5910 | 5911 |
| |
5911 | 5912 |
| |
5912 | 5913 |
| |
|
src/compiler/transformers/classFields.ts
Copy file name to clipboardExpand all lines: src/compiler/transformers/classFields.ts+65-14Lines changed: 65 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1249 | 1249 |
| |
1250 | 1250 |
| |
1251 | 1251 |
| |
1252 |
| - | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
1253 | 1256 |
| |
1254 | 1257 |
| |
1255 |
| - | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
1256 | 1274 |
| |
1257 | 1275 |
| |
1258 | 1276 |
| |
| |||
1268 | 1286 |
| |
1269 | 1287 |
| |
1270 | 1288 |
| |
1271 |
| - | |
1272 |
| - | |
1273 |
| - | |
1274 | 1289 |
| |
1275 | 1290 |
| |
1276 | 1291 |
| |
| |||
1281 | 1296 |
| |
1282 | 1297 |
| |
1283 | 1298 |
| |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
1284 | 1302 |
| |
1285 |
| - | |
1286 |
| - | |
1287 |
| - | |
| 1303 | + | |
| 1304 | + | |
1288 | 1305 |
| |
1289 |
| - | |
1290 |
| - | |
1291 |
| - | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
1292 | 1333 |
| |
1293 |
| - | |
1294 | 1334 |
| |
1295 | 1335 |
| |
| 1336 | + | |
1296 | 1337 |
| |
1297 | 1338 |
| |
1298 | 1339 |
| |
1299 | 1340 |
| |
1300 | 1341 |
| |
1301 |
| - | |
| 1342 | + | |
1302 | 1343 |
| |
1303 |
| - | |
| 1344 | + | |
1304 | 1345 |
| |
1305 | 1346 |
| |
1306 | 1347 |
| |
| |||
1315 | 1356 |
| |
1316 | 1357 |
| |
1317 | 1358 |
| |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
1318 | 1367 |
| |
1319 | 1368 |
| |
1320 | 1369 |
| |
| |||
1335 | 1384 |
| |
1336 | 1385 |
| |
1337 | 1386 |
| |
| 1387 | + | |
1338 | 1388 |
| |
1339 | 1389 |
| |
1340 | 1390 |
| |
1341 | 1391 |
| |
1342 | 1392 |
| |
| 1393 | + | |
1343 | 1394 |
| |
1344 | 1395 |
| |
1345 | 1396 |
| |
|
You can’t perform that action at this time.
0 commit comments