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

Object properties are incorrectly erased when using hoist_props #7710

Closed
ThomasJClark opened this issue Jul 26, 2023 · 1 comment · Fixed by #7702
Closed

Object properties are incorrectly erased when using hoist_props #7710

ThomasJClark opened this issue Jul 26, 2023 · 1 comment · Fixed by #7702
Assignees
Labels
Milestone

Comments

@ThomasJClark
Copy link

ThomasJClark commented Jul 26, 2023

Describe the bug

When some, but not all, properties of an object are accessed, other properties are erased, even if the object itself is exported.

Input code

const obj = {
    foo: 1,
    bar: 2,
};

console.log(obj.bar);

export default obj;

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript"
    },
    "loose": false,
    "minify": {
      "compress": {
        "hoist_props": true
      }
    }
  }
}

Playground link

https://play.swc.rs/?version=1.3.71&code=H4sIAAAAAAAAA0vOzysuUchPylKwVajmUgCCtPx8KwVDHTA7KbHISsFIh6vWmosrGagyPydVLyc%2FXQOoXg8opwkUTq0oyC8qUUhJTUsszQGbZA0ASUDqO1QAAAA%3D&config=H4sIAAAAAAAAA02MSwqAMAxE956iZO0JvE0JKVT6I6lgKb270Yq4CMy8mUxfjIFdEDbTVaoploX480qkpWpPJUAYrSD7UuEJxzp%2FQs5CWnA2CL0s%2BuRd%2B%2B9gjoVJRFnlg%2BbCct%2B4AIS%2FUhWHAAAA

Expected behavior

The export is equal to { foo: 1, bar: 2 }

console.log(2);
export default {
    foo: 1,
    bar: 2
};

Actual behavior

The export is equal to { bar: 2 }, and foo is erased from the compiled code.

console.log(2);
export default {
    bar: 2
};

Version

1.3.70, 1.3.71

Additional context

This only occurs when at least one property of obj is accessed. Without the console.log, all properties of obj are correctly included.

@ThomasJClark ThomasJClark changed the title Object properties are incorrectly erased when using hoist_props Object properties are incorrectly erased when using hoist_props Jul 26, 2023
@kdy1 kdy1 self-assigned this Jul 27, 2023
@kdy1 kdy1 added this to the Planned milestone Jul 27, 2023
kdy1 added a commit to kdy1/swc that referenced this issue Jul 28, 2023
kdy1 added a commit that referenced this issue Jul 28, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.72 Jul 28, 2023
kdy1 added a commit to kdy1/swc that referenced this issue Aug 15, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Aug 28, 2023

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 Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.