Skip to content

Left-hand side with object attributes substituted by value in array destructuring #11084

@0xc22b

Description

@0xc22b

Describe the bug

Using array destructuring with object attributes on the left-hand side:

const bin = {
  hasMore: false, hasDisorder: false,
};
[bin.hasMore, bin.hasDisorder] = [true, true];

It gets compiled into:

  [!1, !1] = [
    !0,
    !0
  ];

which is incorrect: SyntaxError: Invalid destructuring assignment target

Input code

export function test() {
  const bin = {
    hasMore: false, hasDisorder: false,
  };
  [bin.hasMore, bin.hasDisorder] = [true, true];
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es2017",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": false,
        "arrows": true,
        "booleans": true,
        "booleans_as_integers": false,
        "collapse_vars": true,
        "comparisons": true,
        "computed_props": true,
        "conditionals": true,
        "dead_code": true,
        "directives": true,
        "drop_console": false,
        "drop_debugger": true,
        "evaluate": true,
        "expression": false,
        "hoist_funs": false,
        "hoist_props": true,
        "hoist_vars": false,
        "if_return": true,
        "join_vars": true,
        "keep_classnames": false,
        "keep_fargs": true,
        "keep_fnames": false,
        "keep_infinity": false,
        "loops": true,
        "negate_iife": true,
        "properties": true,
        "reduce_funcs": false,
        "reduce_vars": false,
        "side_effects": true,
        "switches": true,
        "typeofs": true,
        "unsafe": false,
        "unsafe_arrows": false,
        "unsafe_comps": false,
        "unsafe_Function": false,
        "unsafe_math": false,
        "unsafe_symbols": false,
        "unsafe_methods": false,
        "unsafe_proto": false,
        "unsafe_regexp": false,
        "unsafe_undefined": false,
        "unused": true,
        "const_to_let": true,
        "pristine_globals": true
      },
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.13.5&code=H4sIAAAAAAAAA0utKMgvKlFIK81LLsnMz1MoSS0u0dBUqOZSUEjOzysuUUjKzFOwBfMVFDISi33zi1KtFNISc4pTdUB8l8zi%2FKKU1CKYGFBdrTWQiAbq04Oq11GAcmCKY4EmRpcUlQJlQGSsNVctALa6YPWIAAAA&config=H4sIAAAAAAAAA32US27jMAyG9z1F4PUspl3MAD1Adz2DoFiUo44sGiKVxihy96Fs59GG9s7mx5%2BUSIpfT7td80Ft87r7kk%2F5GWwmyNd%2FsdCY2J7E0vA4ALU5DNz8ulCmiryNBJPpPJOGbe6Aqwro5ffz30XRRESCi2Kx9SEFP97nbLEfMhDd2cQqIUsPiem7fmEZPyvgXO7te8QINm0QY8mExNBB1gK3GKMdCMzRZiVKPanNgVBLUWFhcGbIOKg8ucABk%2BR8pA6sMy06UFDI0HI4giaTXCJLJNdT7jNhB%2FvSdVOff6jhaGOxrOSE09QSOa0S9YCB2PiStBLOcKUGM1yK%2B1MZvMnAJadH3QeGtNKTfwBSgWiJku1Bizt5eJmnNbXfVIbkZWR5VLjMt3bLBJ0U1YTglcrWykDmoHUzgyst1Mq22nEWvFI%2BCg4MeC%2BzooSmz8DtQUtaHzp6BUh%2Frdemagbm%2BgpXeH0QG%2FhNbsn6gC0eveXDOqWx32PcSNADH9BtOEgrGNdxli1xGtZ5SQ5kNMCpLoUm8LgE5AEwmjjty4fZkOchEU0XcX9bE4vD%2BbqHe5u623ufV%2FHT4tD06MoElyVf%2Bzuv5j%2FNzemyha8HbwK9X5RT0vN%2FuBQ5ujAGAAA%3D

SWC Info output

No response

Expected behavior

No substitution of the left-hand side in array destructuring.

Actual behavior

Left side of array destructuring replaced by values.

Version

1.13.5

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions