Rollup: Bug: Treeshaking destroys valid function contents > 0.49.0

Created on 30 Aug 2017  路  3Comments  路  Source: rollup/rollup

This can be reproduced by using inferno mono repo:
original issue: https://github.com/infernojs/inferno/issues/1199
repo: https://github.com/infernojs/inferno

steps to reproduce
clone repo
npm i (install latest rollup also)
npm run build
verify that file packages/inferno-mobx/dist/index.js has empty makeReactive function. Downgrading to 0.48.2 fixed the issue.

All 3 comments

This alias via a logical or is tripping up rollup version 0.49.2.

Reduced repro:

$ cat t1599.js 
function foo(obj) {
    var alias = obj.prototype || obj;
    alias.prop = "PASS";
    return obj;
}
console.log(foo({}).prop || "FAIL");

```
$ cat t1599.js | node
PASS


$ bin/rollup t1599.js -f es --silent | node
FAIL


$ bin/rollup t1599.js -f es --silent
function foo(obj) {
return obj;
}
console.log(foo({}).prop || "FAIL");

Fix:
```patch
--- a/src/ast/nodes/LogicalExpression.js
+++ b/src/ast/nodes/LogicalExpression.js
@@ -16,4 +16,8 @@ export default class LogicalExpression extends Node {

                return operators[ this.operator ]( leftValue, rightValue );
        }
+
+       hasEffectsWhenMutated () {
+               return true;
+       }
 }

No test regressions.

Thanks @Havunen for the report with easy to reproduce steps and especially @kzc for the speedy and correct analysis. This is a big oversight I am right now working on correcting. This problem does not only affect LogicalExpressions but can potentially affects other expressions as well. I will make hasEffectsWhenMutated() = true the default and will change this for nodes where this has properly been tested after the next PR.

Should be fixed in the next released 馃槆

Was this page helpful?
0 / 5 - 0 ratings