Skip to content
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

for await is transpiled to invalid code #1721

Closed
mischnic opened this issue May 20, 2021 · 2 comments · Fixed by #1724
Closed

for await is transpiled to invalid code #1721

mischnic opened this issue May 20, 2021 · 2 comments · Fixed by #1724
Assignees
Labels
Milestone

Comments

@mischnic
Copy link
Contributor

mischnic commented May 20, 2021

Describe the bug

Transpiling for await produces code that fails with:

                    for(_iterator = lol()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                                                          ^

TypeError: lol(...)[Symbol.iterator] is not a function

Input code

async function* lol() {
	yield 1;
	yield 2;
}

async function main() {
	for await (const x of lol()) {
		console.log(x);
	}
}
main();

Config

{
	"env": {
		"mode": "entry",
		"coreJs": 3
	}
}
{
	"browserslist": [
		"Safari 9"
	],
	"devDependencies": {
		"@swc/cli": "^0.1.40",
		"@swc/core": "^1.2.57",
		"browserslist": "^4.16.6",
		"regenerator-runtime": "^0.13.7"
	}
}

Expected behavior
Prints 1, 2.

Version
The version of @swc/core: 1.2.57

@mischnic mischnic added the C-bug label May 20, 2021
@kdy1 kdy1 added this to the v1.2.58 milestone May 21, 2021
@kdy1 kdy1 self-assigned this May 21, 2021
kdy1 added a commit to kdy1/swc that referenced this issue May 21, 2021
kdy1 added a commit to kdy1/swc that referenced this issue May 21, 2021
kdy1 added a commit to kdy1/swc that referenced this issue May 21, 2021
kdy1 added a commit to kdy1/swc that referenced this issue May 21, 2021
kdy1 added a commit to kdy1/swc that referenced this issue May 21, 2021
kdy1 added a commit that referenced this issue May 21, 2021
swc_ecma_transforms_compat:
 - `async_to_generator`: Fix async iife. (#1722)
 - `async_to_generator`: Don't apply iife optimization to named function expressions.
 - `async_to_generator`: Remove duplicated works.
 - `async_to_generator`: Support `await for`. (#1721)
 - `async_to_generator`: Support async generators.
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 24, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

1 similar comment
@swc-bot
Copy link
Collaborator

swc-bot commented Nov 23, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants