Skip to content

Commit

Permalink
Resolve #1702
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Nov 8, 2017
1 parent d91cba0 commit 2d9d29a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ast/nodes/ReturnStatement.js
@@ -1,4 +1,5 @@
import Statement from './shared/Statement.js';
import {UNKNOWN_ASSIGNMENT} from '../values';

export default class ReturnStatement extends Statement {
hasEffects ( options ) {
Expand All @@ -7,6 +8,6 @@ export default class ReturnStatement extends Statement {
}

initialiseNode () {
this.scope.addReturnExpression( this.argument );
this.scope.addReturnExpression( this.argument || UNKNOWN_ASSIGNMENT );
}
}
@@ -0,0 +1,8 @@
var assert = require( 'assert' );

module.exports = {
description: 'Handles empty return statements (#1702)',
exports: function ( exports ) {
assert.equal( exports.bar, 'present' );
}
};
15 changes: 15 additions & 0 deletions test/function/samples/associate-function-return-values-4/main.js
@@ -0,0 +1,15 @@
const foo = {mightBeExported: {}};
const exported = {};

function getFooOrUndefined() {
if (Math.random() < 0.5) {
return;
}
return foo;
}

const returnedFoo = getFooOrUndefined() || foo;
returnedFoo.mightBeExported = exported;
foo.mightBeExported.bar = 'present';

export default exported;

0 comments on commit 2d9d29a

Please sign in to comment.