Skip to content

No assignment to constant variable error #11475

@butlimous

Description

@butlimous

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions