René's URL Explorer Experiment


Title: Invalid emit for declaring a class that references itself inside of a loop · Issue #31330 · microsoft/TypeScript · GitHub

Open Graph Title: Invalid emit for declaring a class that references itself inside of a loop · Issue #31330 · microsoft/TypeScript

X Title: Invalid emit for declaring a class that references itself inside of a loop · Issue #31330 · microsoft/TypeScript

Description: TypeScript Version: Version 3.5.0-dev.20190509 Search Terms: Class inside loop Uncaught SyntaxError: Illegal return statement Code const classesByRow: Record = {}; for (const row of ['1', '2', '3', '4', '5']) { class RowC...

Open Graph Description: TypeScript Version: Version 3.5.0-dev.20190509 Search Terms: Class inside loop Uncaught SyntaxError: Illegal return statement Code const classesByRow: Record = {}; for (const row of...

X Description: TypeScript Version: Version 3.5.0-dev.20190509 Search Terms: Class inside loop Uncaught SyntaxError: Illegal return statement Code const classesByRow: Record<string, object> = {}; for (const ...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/31330

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invalid emit for declaring a class that references itself inside of a loop ","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:**  Version 3.5.0-dev.20190509\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\nClass inside loop\r\nUncaught SyntaxError: Illegal return statement\r\n\r\n**Code**\r\n```ts\r\nconst classesByRow: Record\u003cstring, object> = {};\r\nfor (const row of ['1', '2', '3', '4', '5']) {\r\n  class RowClass {\r\n    row = row;\r\n    static factory = () => new RowClass();\r\n  }\r\n\r\n  classesByRow[row] = RowClass;\r\n}\r\n\r\nconsole.log(classesByRow)\r\n```\r\n\r\n**Expected behavior:**\r\nWhen downleveled to ES5 the compiled code runs and logs something like:\r\n```\r\n{1: ƒ, 2: ƒ, 3: ƒ, 4: ƒ, 5: ƒ}\r\n  1: class RowClass\r\n  2: class RowClass\r\n  3: class RowClass\r\n  4: class RowClass\r\n  5: class RowClass\r\n```\r\n\r\n**Actual behavior:**\r\nWhen downleveled to ES5 the compiled code does not run and throws a syntax error:\r\n```\r\nUncaught SyntaxError: Illegal return statement\r\n```\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\nhttps://www.typescriptlang.org/play/index.html#src=const%20classesByRow%3A%20Record%3Cstring%2C%20object%3E%20%3D%20%7B%7D%3B%0Afor%20(const%20row%20of%20%5B'1'%2C%20'2'%2C%20'3'%2C%20'4'%2C%20'5'%5D)%20%7B%0A%20%20class%20RowClass%20%7B%0A%20%20%20%20row%20%3D%20row%3B%0A%20%20%20%20static%20factory%20%3D%20()%20%3D%3E%20new%20RowClass()%3B%0A%20%20%7D%0A%0A%20%20classesByRow%5Brow%5D%20%3D%20RowClass%3B%0A%7D%0A%0Aconsole.log(classesByRow)\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\nI could not find any.\r\n\r\n---\r\nWhen downleveling the ES5 in this weird situation the TS compiler produces JS with either a syntax error or incorrect runtime semantics by placing a `return` statement where it does not belong. This error _seems_ to happen when a class declared inside of a loop has a property that references itself. The error does not happen when the self-referencing property is removed. To test this, remove line 5 from the above example. This issue is reproducable for every kind of loop, not just `for ... of` loops, it also comes up when using `while` loops and `for` loops.\r\n\r\nThe bug does not happen when targeting ES2015 or above.\r\n\r\nI was able to reproduce this on TS 3.3 as well.","author":{"url":"https://github.com/rrdelaney","@type":"Person","name":"rrdelaney"},"datePublished":"2019-05-09T20:44:53Z","url":"https://github.com/microsoft/TypeScript/issues/31330"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b6248134-d65b-139e-1583-d6dab3f0b566
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id819C:E3C4F:2701DDA:31B836D:6B019D86
html-safe-nonceb4803caccbd053bce36a3a55b4d3d8023233b397d1900dca89bed6043889138d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTlDOkUzQzRGOjI3MDFEREE6MzFCODM2RDo2QjAxOUQ4NiIsInZpc2l0b3JfaWQiOiI2OTQ2OTI2MzU4Mjk1NTg0MTM1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac9f6d69a6d57d928cecf03e44b0a0e2c180531375669cc690f1b8598b48957507
hovercard-subject-tagissue:442425250
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/31330/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f813e5def77c398e167197cb0712493c00552213197eabf79262ae32a7f8bce8/microsoft/TypeScript/issues/31330
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f813e5def77c398e167197cb0712493c00552213197eabf79262ae32a7f8bce8/microsoft/TypeScript/issues/31330
og:image:altTypeScript Version: Version 3.5.0-dev.20190509 Search Terms: Class inside loop Uncaught SyntaxError: Illegal return statement Code const classesByRow: Record = {}; for (const row of...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerrdelaney
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/31330#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F31330
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F31330
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/31330
Reloadhttps://github.com/microsoft/TypeScript/issues/31330
Reloadhttps://github.com/microsoft/TypeScript/issues/31330
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/31330
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/31330
#36795https://github.com/microsoft/TypeScript/pull/36795
Invalid emit for declaring a class that references itself inside of a loop https://github.com/microsoft/TypeScript/issues/31330#top
#36795https://github.com/microsoft/TypeScript/pull/36795
https://github.com/rbuckton
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Domain: JS EmitThe issue relates to the emission of JavaScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20JS%20Emit%22
TypeScript 3.9.0https://github.com/microsoft/TypeScript/milestone/109
https://github.com/rrdelaney
Ryan Delaney (rrdelaney)https://github.com/rrdelaney
on May 9, 2019https://github.com/microsoft/TypeScript/issues/31330#issue-442425250
https://www.typescriptlang.org/play/index.html#src=const%20classesByRow%3A%20Record%3Cstring%2C%20object%3E%20%3D%20%7B%7D%3B%0Afor%20(const%20row%20of%20%5B'1'%2C%20'2'%2C%20'3'%2C%20'4'%2C%20'5'%5D)%20%7B%0A%20%20class%20RowClass%20%7B%0A%20%20%20%20row%20%3D%20row%3B%0A%20%20%20%20static%20factory%20%3D%20()%20%3D%3E%20new%20RowClass()%3B%0A%20%20%7D%0A%0A%20%20classesByRow%5Brow%5D%20%3D%20RowClass%3B%0A%7D%0A%0Aconsole.log(classesByRow)https://www.typescriptlang.org/play/index.html#src=const%20classesByRow%3A%20Record%3Cstring%2C%20object%3E%20%3D%20%7B%7D%3B%0Afor%20(const%20row%20of%20%5B'1'%2C%20'2'%2C%20'3'%2C%20'4'%2C%20'5'%5D)%20%7B%0A%20%20class%20RowClass%20%7B%0A%20%20%20%20row%20%3D%20row%3B%0A%20%20%20%20static%20factory%20%3D%20()%20%3D%3E%20new%20RowClass()%3B%0A%20%20%7D%0A%0A%20%20classesByRow%5Brow%5D%20%3D%20RowClass%3B%0A%7D%0A%0Aconsole.log(classesByRow)
https://github.com/rrdelaney
Ryan Delaney (rrdelaney)https://github.com/rrdelaney
on Jun 21, 2019https://github.com/microsoft/TypeScript/issues/31330#issuecomment-504538418
Wesley Wigham (weswigham)https://github.com/weswigham
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Domain: JS EmitThe issue relates to the emission of JavaScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20JS%20Emit%22
on Jun 21, 2019https://github.com/microsoft/TypeScript/issues/31330#event-2431405078
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 3.7.0https://github.com/microsoft/TypeScript/milestone/98
on Jul 16, 2019https://github.com/microsoft/TypeScript/issues/31330#event-2486554556
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Ron Buckton (rbuckton)https://github.com/rbuckton
on Jul 16, 2019https://github.com/microsoft/TypeScript/issues/31330#event-2486554864
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 3.7.0https://github.com/microsoft/TypeScript/milestone/98
TypeScript 3.7.1https://github.com/microsoft/TypeScript/milestone/105
on Oct 14, 2019https://github.com/microsoft/TypeScript/issues/31330#event-2711294076
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 3.7.1https://github.com/microsoft/TypeScript/milestone/105
TypeScript 3.8.0https://github.com/microsoft/TypeScript/milestone/102
on Oct 29, 2019https://github.com/microsoft/TypeScript/issues/31330#event-2753808447
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 3.8.0https://github.com/microsoft/TypeScript/milestone/102
TypeScript 3.8.1https://github.com/microsoft/TypeScript/milestone/107
on Jan 8, 2020https://github.com/microsoft/TypeScript/issues/31330#event-2932089309
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
TypeScript 3.8.1https://github.com/microsoft/TypeScript/milestone/107
TypeScript 3.9.0https://github.com/microsoft/TypeScript/milestone/109
on Feb 14, 2020https://github.com/microsoft/TypeScript/issues/31330#event-3040222382
Ron Buckton (rbuckton)https://github.com/rbuckton
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#36795https://github.com/microsoft/TypeScript/pull/36795
on Feb 24, 2020https://github.com/microsoft/TypeScript/issues/31330#event-3066568772
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/31330#event-20416675777
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/31330
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/31330
Ron Buckton (rbuckton)https://github.com/rbuckton
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Domain: JS EmitThe issue relates to the emission of JavaScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20JS%20Emit%22
TypeScript 3.9.0https://github.com/microsoft/TypeScript/milestone/109
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.