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

Mangler inserts wrong function name on anonymous function declaration #6344

Closed
hyp3rflow opened this issue Nov 3, 2022 · 3 comments · Fixed by #6345
Closed

Mangler inserts wrong function name on anonymous function declaration #6344

hyp3rflow opened this issue Nov 3, 2022 · 3 comments · Fixed by #6345
Assignees
Labels
Milestone

Comments

@hyp3rflow
Copy link
Contributor

Describe the bug

After the mangling, the second return value (return value of var he)'s logic becomes wrong.

Input code

function a() {}
var te = function() {
    function n(e) {}
    var t = null;
    return {
        init: function(e) {
            return t = new n(e);
        }
    }
}();
var he = function() {
    function n() {
        a();
    };
    var t = null;
    return {
        init: function(e) {
            return t
        }
    }
}();

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": {
        "toplevel": false,
        "keep_classnames": false,
        "keep_fnames": false,
        "keep_private_props": false,
        "ie8": false,
        "safari10": false
      }
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.12&code=H4sIAAAAAAAAA62OMQ6AIAxFd07REa4g8TDElEhCakJAB8PdhYrKYOJix9ff128TTdEtBEYq2LNYTYCIMIJti4oFlLkAkESOVsjxkqbkvWYSMKZA7aaOIxeHR4eq23UHbMGN7foOnF%2ByyLLA%2Bmz%2B6tbrjWyqrP9u%2B9rwALbE1g9NAQAA&config=H4sIAAAAAAAAA22OSwrDMAxE76J1Fu2iUHKHnqEIVw5O%2FRGSExqC714b8qHQlYZ5g3grjGqgX4FRlKQlXWLGD%2FRAJqAacZyhq7NaWfRKpYOMMlBuE71V5lNS2mgHwUVnl%2FbJpMBCqifCOHhqKCf2NJM%2F0JuIn8ajasRA%2BtvbPx2LmzFTvYlP5Oh%2BZEWL4q6X3btU85Be02awcL3NMaQ4KpTTfP%2Blj22dZaLyBbcl34krAQAA

Expected behavior

The init function in the he variable's logic should be same as before.
return t should reference variable inside he, not the function itself.

Actual behavior

return t reference the function itself.

Version

1.3.12

Additional context

I think this result occurs in very tricky situation.
If you rename the function init to another or remove some lines, it works well :(

@hyp3rflow hyp3rflow added the C-bug label Nov 3, 2022
@kdy1 kdy1 added this to the Planned milestone Nov 3, 2022
@kdy1 kdy1 self-assigned this Nov 3, 2022
@kdy1
Copy link
Member

kdy1 commented Nov 3, 2022

@kdy1
Copy link
Member

kdy1 commented Nov 3, 2022

I tried one more thing.

I passed

"use strict";
function a() { }
var te = function () {
    var n = function n(e) { };
    var t = null;
    return {
        init: function init(e) {
            return t = new n(e);
        }
    };
}();
var he = function () {
    var n = function n() {
        a();
    };
    ;
    var t = null;
    return {
        init: function init(e) {
            return t;
        }
    };
}();

to the name mangler, and it emitted

"use strict";
function n() {}
var r = function() {
    var n = function n(n) {};
    var r = null;
    return {
        init: function t(t) {
            return r = new n(t);
        }
    };
}();
var t = function() {
    var r = function r() {
        n();
    };
    var t = null;
    return {
        init: function n(n) {
            return t;
        }
    };
}();

which is correct. So... I think the block scoping pass broken the rule of span hygiene

@swc-bot
Copy link
Collaborator

swc-bot commented Dec 15, 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 Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants