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

Invalid read-only when using destructuring shadowed by import #10627

Closed
dasa opened this issue Nov 2, 2019 · 1 comment · Fixed by #10628
Closed

Invalid read-only when using destructuring shadowed by import #10627

dasa opened this issue Nov 2, 2019 · 1 comment · Fixed by #10628
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@dasa
Copy link

dasa commented Nov 2, 2019

Bug Report

Current Behavior
The commonjs and amd plugins create invalid throw new Error('"' + "foo" + '" is read-only.'); statements in the output when there is an import with the same name as used in the destructuring even though it's shadowed by a function parameter.

Input Code

import { foo } from "./x";

function test(foo) {
  console.log(foo);
  [foo] = [1];
  ({foo} = { foo: 1 });
  console.log(foo);
}

test(0);

Output:

"use strict";

var _x = require("./x");

function test(foo) {
  console.log(foo);
  [foo] = ([1], function () {
    throw new Error('"' + "foo" + '" is read-only.');
  }());
  ({
    foo
  } = ({
    foo: 1
  }, function () {
    throw new Error('"' + "foo" + '" is read-only.');
  }()));
  console.log(foo);
}

test(0);

Expected behavior/code
No Error's in output, like this when the import name is changed:

"use strict";

var _x = require("./x");

function test(foo) {
  console.log(foo);
  [foo] = [1];
  ({
    foo
  } = {
    foo: 1
  });
  console.log(foo);
}

test(0);

Babel Configuration (.babelrc, package.json, cli command)

  "babel": {
    "plugins": [
      "@babel/plugin-transform-modules-commonjs"
    ]
  }

Environment

  • Babel version(s): v7.6.4
  • Node/npm version: Node 12
  • OS: OSX
  • Monorepo: no
  • How you are using Babel: cli or REPL

Possible Solution

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

@babel-bot
Copy link
Collaborator

Hey @dasa! 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."

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 3, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants