Skip to content

编译递归async函数错误 #22183

Description

@kaivean

Describe the bug

Source code:

const typeNext = async () => {
    await new Promise(resolve => setTimeout(resolve, 1000));
    console.log('typeNext');
    typeNext();
};


typeNext();

the compiled code (Target=es2015)

(function() {
	var _ref = _asyncToGenerator(function* () {
		yield new Promise((resolve) => setTimeout(resolve, 1e3));
		console.log("typeNext");
		typeNext();
	});
	return function typeNext() {
		return _ref.apply(this, arguments);
	};
})()();

Error: typeNext is not defined

Reproduction

https://stackblitz.com/edit/vitejs-vite-677ytex9?file=package.json

Steps to reproduce

Source code:

const typeNext = async () => {
    await new Promise(resolve => setTimeout(resolve, 1000));
    console.log('typeNext');
    typeNext();
};


typeNext();

the compiled code (Target=es2015)

(function() {
	var _ref = _asyncToGenerator(function* () {
		yield new Promise((resolve) => setTimeout(resolve, 1e3));
		console.log("typeNext");
		typeNext();
	});
	return function typeNext() {
		return _ref.apply(this, arguments);
	};
})()();

Error: typeNext is not defined

System Info

vite: 8.0.5
macos

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: upstreamBug in a dependency of Vitep2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions