Skip to content

[Bug]: Assignment to constant variables is not prevented using tdz option #15171

@p51lee

Description

@p51lee

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

const x = 0; x = 0;

Configuration file name

No response

Configuration

{
  "plugins": [
    [
      "@babel/plugin-transform-block-scoping",
      {
        "tdz": true
      }
    ]
  ]
}

Current and expected behavior

Validation function of const variables (_readOnlyError) is never called when tdz option is enabled:

// output.js
"use strict";

function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
var x = 0;
x;
x = 0;

Environment

npm version 8.19.2

@babel/[email protected]
@babel/[email protected]
@babel/[email protected]

node version 18.11.0
macos version 13.0

Possible solution

No response

Additional context

No response

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