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

Why post function declaration would not be treeshake? #2962

Open
LongTengDao opened this issue Jun 25, 2019 · 2 comments
Open

Why post function declaration would not be treeshake? #2962

LongTengDao opened this issue Jun 25, 2019 · 2 comments

Comments

@LongTengDao
Copy link
Contributor

  • Rollup Version: 1.14.4
  • Operating System (or Browser):
  • Node Version:

How Do We Reproduce?

var successShaked = function () {
    function inner () {
        /* ... */
    }
    return function outer (){
        return /*#__PURE__*/ inner();
    };
}();
successShaked();
var failedShaked = function () {
    return function outer (){
        return /*#__PURE__*/ inner();
    };
    function inner () {
        /* ... */
    }
}();
failedShaked();

Expected Behavior

Both be shaked.

Actual Behavior

Leave this:

var failedShaked = function () {
    return function outer (){
        return /*#__PURE__*/ inner();
    };
    function inner () {
        /* ... */
    }
}();
failedShaked();
@lukastaegert
Copy link
Member

The problem is probably that the algorithm to determine side-effects of function return values tries to "cache" the return value at an early stage where the function definition has not been properly processed. Marking this as an "enhancement" as the generated code is not broken but could be optimized better.

@antfu
Copy link
Contributor

antfu commented Jun 7, 2023

I guess static side-effects analysis will always reach limitations for dynamic parts. #5024 introduced the annotation to manually mark functions as side-effects-free, which I think should be able to solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants