diff --git a/src/ast/nodes/LogicalExpression.ts b/src/ast/nodes/LogicalExpression.ts index d5d9583f044..2744968d143 100644 --- a/src/ast/nodes/LogicalExpression.ts +++ b/src/ast/nodes/LogicalExpression.ts @@ -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 { diff --git a/test/function/samples/reassigned-return-expression/_config.js b/test/function/samples/reassigned-return-expression/_config.js new file mode 100644 index 00000000000..5223fccf634 --- /dev/null +++ b/test/function/samples/reassigned-return-expression/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not bind return expressions before assignments are bound (#3382)' +}; diff --git a/test/function/samples/reassigned-return-expression/main.js b/test/function/samples/reassigned-return-expression/main.js new file mode 100644 index 00000000000..f2370cc243b --- /dev/null +++ b/test/function/samples/reassigned-return-expression/main.js @@ -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');