We're upgrading our project to Vite8 and noticed this transpilation issue.
When transpiling an object with async methods to ES2015, if the object's field is the same name as an outer scope variable, that variable will be lost. Here's a minimal repro example:
interface Element {
previous(): Promise<Element | null>;
next(): Promise<Element | null>;
};
function customIteratorMethod(): Element {
let previous: Element | null = null;
let next: Element | null = null;
return {
previous: async () =>
previous || (previous = "previous value"),
next: async () => next || (next = "next value"),
};
}
export default customIteratorMethod;
Those async methods get transpiled to:
{
next: function() {
var _ref2 = _asyncToGenerator(function* () {
return next || (next = "next value");
});
return function next() {
return _ref2.apply(this, arguments);
};
}()
}
If the names don't match, return function next() { becomes return function() {
But when they do match, the actual reference to the outer let next; get mixed up.
An object fields like { next: async () => { /* ... */ } } should not be in the lexical scope.
Repro on oxc playground.
We're upgrading our project to Vite8 and noticed this transpilation issue.
When transpiling an object with async methods to ES2015, if the object's field is the same name as an outer scope variable, that variable will be lost. Here's a minimal repro example:
Those async methods get transpiled to:
If the names don't match,
return function next() {becomesreturn function() {But when they do match, the actual reference to the outer
let next;get mixed up.An object fields like
{ next: async () => { /* ... */ } }should not be in the lexical scope.Repro on oxc playground.