Skip to content

Mangler generates duplicated idents if there's eval #11294

@CPunisher

Description

@CPunisher

Describe the bug

Mangler generates duplicated idents if there's eval.

The problem disappears if we comment memberValue = eval("");

Input code

var Config = function () {
    if (chart.series) {
        var specialUnit = {
            ids: [],
        };
        var normalUnit = {
            ids: [],
        };
        chart.series.forEach(function (item) {
            var mId = item.split("-")[2];
            specialUnit.ids.push(mId);
            normalUnit.ids.push(mId);
        });
    }
    memberValue = eval("");
}();
console.log(Config);

Config

{
  "jsc": {
    "target": "es2024",
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "transform": {
      "legacyDecorator": false,
      "decoratorVersion": "2022-03"
    },
    "minify": {
      "compress": true,
      "mangle": true,
    },
    "loose": false
    },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
}

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.15.2&code=H4sIAAAAAAAAA52RvQ7CIBSFd5%2BCMNFEGRxtnIyDD6BL0wHpxZLw0wDtYvru3taftiYu3uGGnHs%2B7iF0IpCDd0rfyJ6o1smkvSMsI%2FcVwdKKMFmLkHiEoCG%2B9aE6RGMDUgtzdjohP81Gtoo7UpTrj9jnC9b5YP9A53G48uEoZM2m5DqBzb6uG7bZU4VrhimPjdGJ0Q3Nim2ZL5yz93AMwZs21gzRbGmbov9y9a9zP3YL9grhIkwLGAI6YRil6OgZNuld9Aa48Tf2%2FAoUH1%2F9jO%2BYAQAA&config=H4sIAAAAAAAAA2WQvQ6DMAyEd54CZW4lRKsOnbt27R4Fg1KRH9lGaoR49yZAKKhbcj5%2FPnssylK8SYl7OcZn%2FLDEDjj%2BBVBd1VdxWnQvkQA3X1QoWJaf5OTggRRqz6s7cSiVWtkTzNK0chilpdah2aN66KQKD1AOJTvMjRusyZUXIGln09AYrj5XF3GgG211G%2FZo5YxHIIoa4%2FBDGmm7Hg5qhvTOEfyHF8Y1w9ySTxXXXg51SylWU06wbSA0PXPnMqyYvsBkYKd4AQAA

SWC Info output

No response

Expected behavior

It should not generate duplicated idents, which makes the program broken

Actual behavior

e and r are duplicated

var Config = function() {
    if (chart.series) {
        var e = [], r = [];
        chart.series.forEach(function(e) {
            var r = e.split("-")[2];
            e.push(r), r.push(r);
        });
    }
    memberValue = eval("");
}();
console.log(Config);

Version

1.15.2

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions