Skip to content

Commit

Permalink
handle call expressions of uncallable things more gracefully (#1257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jan 14, 2017
1 parent 9c58833 commit 5c88259
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ast/nodes/shared/callHasEffects.js
Expand Up @@ -96,12 +96,14 @@ export default function callHasEffects ( scope, callee, isNew ) {
}
}

else {
if ( !node.gatherPossibleValues ) {
throw new Error( 'TODO' );
}
else if ( node.gatherPossibleValues ) {
node.gatherPossibleValues( values );
}

else {
// probably an error in the user's code — err on side of caution
return true;
}
}

return false;
Expand Down
3 changes: 3 additions & 0 deletions test/function/handle-calling-uncallable/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'does not give cryptic error when calling uncallable things (#1257)'
};
3 changes: 3 additions & 0 deletions test/function/handle-calling-uncallable/foo.js
@@ -0,0 +1,3 @@
function foo() {}

export default { foo };
5 changes: 5 additions & 0 deletions test/function/handle-calling-uncallable/main.js
@@ -0,0 +1,5 @@
import foo from './foo.js';

assert.throws( function () {
foo();
}, /is not a function/ );

0 comments on commit 5c88259

Please sign in to comment.