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

async-to-generator transform does not rename local var called arguments #7328

Open
overlookmotel opened this issue Nov 17, 2024 · 0 comments
Assignees
Labels
A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Comments

@overlookmotel
Copy link
Contributor

Input:

// Sloppy mode
function outer() {
  let arguments = 123;
  return async () => arguments;
}

function outer2() {
  let {arguments} = {arguments: 123};
  return async () => arguments;
}

Desired output:

function outer() {
  let _arguments = 123;
  return _asyncToGenerator(function* () {
    return _arguments;
  });
}

function outer2() {
  let { arguments: _arguments2 } = {
    arguments: 123
  };
  return _asyncToGenerator(function* () {
    return _arguments2;
  });
}

Babel REPL

Actual output:

function outer() {
  let arguments = 123;
  return _asyncToGenerator(function* () {
    return _arguments; // <-- `_arguments` does not exist
  });
}

function outer2() {
  let { arguments } = { arguments: 123 };
  return _asyncToGenerator(function* () {
    return _arguments2; // <-- `_arguments2` does not exist
  });
}

This is pretty hard to solve as you may not discover that arguments needs to be renamed until quite deep in the function, and then you'd need to re-traverse the whole block where arguments var is bound to rename all references. Obviously we'd want to avoid all that unless it does need to be renamed.

Also, arguments can be defined after it's used:

const fn = async () => arguments;
if (foo) {
  while (deep) {
    {
      var arguments = 123;
    }
  }
}

or even:

const fn = async () => arguments;
function arguments() {}
@overlookmotel overlookmotel added C-bug Category - Bug A-transformer Area - Transformer / Transpiler labels Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transformer Area - Transformer / Transpiler C-bug Category - Bug
Projects
None yet
Development

No branches or pull requests

2 participants