Skip to content

Commit

Permalink
Merge pull request #4 from rollup/master
Browse files Browse the repository at this point in the history
Sync Fork from Upstream Repo
  • Loading branch information
sthagen committed Mar 12, 2020
2 parents a44e1a3 + 99a9c41 commit 7675295
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# rollup changelog

## 2.0.5
*2020-03-12*

### Bug Fixes
* Fix an issue where conditional statements would assume they have the wrong test value (#3438)

### Pull Requests
* [#3438](https://github.com/rollup/rollup/pull/3438): Make sure logical expressions always check the left argument for side-effects (@lukastaegert)

## 2.0.4
*2020-03-12*

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "2.0.4",
"version": "2.0.5",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/es/rollup.js",
Expand Down
9 changes: 6 additions & 3 deletions src/ast/nodes/LogicalExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ export default class LogicalExpression extends NodeBase implements Deoptimizable
}

hasEffects(context: HasEffectsContext): boolean {
if (this.usedBranch === null) {
return this.left.hasEffects(context) || this.right.hasEffects(context);
if (this.left.hasEffects(context)) {
return true;
}
if (this.usedBranch !== this.left) {
return this.right.hasEffects(context);
}
return this.usedBranch.hasEffects(context);
return false;
}

hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean {
Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/reassigned-return-expression/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'does not bind return expressions before assignments are bound (#3382)'
};
17 changes: 17 additions & 0 deletions test/function/samples/reassigned-return-expression/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function getIcon() {
var icon = undefined;
icon = { code: true };
return icon;
}

function main() {
var a = getIcon() || {
code: undefined
};
if (!a.code) {
return 'broken';
}
return 'works';
}

assert.strictEqual(main(), 'works');

0 comments on commit 7675295

Please sign in to comment.