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

No assignment to constant variable error #11475

Closed
butlimous opened this issue Apr 24, 2020 · 3 comments · Fixed by #15019
Closed

No assignment to constant variable error #11475

butlimous opened this issue Apr 24, 2020 · 3 comments · Fixed by #15019
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@butlimous
Copy link

Bug Report

Current Behavior
Code is not logging the expected error in the browser.

Input Code

const array = [1, 2, 3];
for (const element of array) {
  const from = 50;
  from--;
}

Expected behavior/code
The output code from Babel should log the following error Uncaught Error: "from" is read-only as I'm assigning a new value to a constant. The code without Babel would output the following Uncaught TypeError: Assignment to constant variable. which is basically the same.

The error seems to not output when the constant is defined inside a loop like the code above.
For example, if I have the following code:

const from = 50;
from--;

The error would log as expected so it's just the case inside the loop.

Environment

- Babel version(s): v7.7.7
- Node/npm version: Node 12.13.1/npm 6.13.6
- OS: macOS 10.15.3
- How you are using Babel: As webpack loader
@babel-bot
Copy link
Collaborator

Hey @butlimous! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@janiewang26
Copy link
Contributor

Could I work on this?

@butlimous
Copy link
Author

Is this fixed?

@liuxingbaoyu liuxingbaoyu added this to the Babel 8.0 milestone Sep 4, 2022
@liuxingbaoyu liuxingbaoyu removed this from the Babel 8.0 milestone Oct 5, 2022
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 8, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
4 participants