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

Nested object destructure #311

Closed
duncanbeevers opened this issue Mar 4, 2019 · 1 comment
Closed

Nested object destructure #311

duncanbeevers opened this issue Mar 4, 2019 · 1 comment
Assignees
Milestone

Comments

@duncanbeevers
Copy link

swc version

$ grep swc package.json
    "@swc/cli": "0.1.12",
    "@swc/core": "1.0.33",
    "swc-loader": "0.1.4",

Input

const Foo = 'foo';

const bar = {
  [Foo]: {
    qux: 'baz'
  }
};

const {
  [Foo]: {
    qux
  }
} = bar;

Output

function _defineProperty(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _throw(e) {
    throw e;
}
var Foo = 'foo';
var bar = _defineProperty({
}, Foo, {
    qux: 'baz'
});
var ref = bar ? bar : _throw(new TypeError("Cannot destructure 'undefined' or 'null'")), _ref$Foo = ref.Foo, ref1 = _ref$Foo ? _ref$Foo : _throw(new TypeError("Cannot destructure 'undefined' or 'null'")), qux = ref1.qux;

Problem

Fails to assign variable qux.

$ swc test.js | node
[stdin]:15
    throw e;
    ^

TypeError: Cannot destructure 'undefined' or 'null'
    at [stdin]:22:146
@kdy1 kdy1 added this to the v1.0.33 milestone Mar 5, 2019
@kdy1 kdy1 self-assigned this Mar 5, 2019
@kdy1 kdy1 modified the milestones: v1.0.33, v1.0.34 Mar 5, 2019
@kdy1 kdy1 closed this as completed in #312 Mar 5, 2019
kdy1 added a commit that referenced this issue Mar 5, 2019
swc_ecma_transforms:
 - es2015::destructuring pass now uses computed member if necessary. (#311)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 30, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants
@duncanbeevers @kdy1 @swc-bot and others