From 5c88259abc94157953b97b4b7d3e5fa06abafb0b Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 14 Jan 2017 13:28:31 -0500 Subject: [PATCH] handle call expressions of uncallable things more gracefully (#1257) --- src/ast/nodes/shared/callHasEffects.js | 10 ++++++---- test/function/handle-calling-uncallable/_config.js | 3 +++ test/function/handle-calling-uncallable/foo.js | 3 +++ test/function/handle-calling-uncallable/main.js | 5 +++++ 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/function/handle-calling-uncallable/_config.js create mode 100644 test/function/handle-calling-uncallable/foo.js create mode 100644 test/function/handle-calling-uncallable/main.js diff --git a/src/ast/nodes/shared/callHasEffects.js b/src/ast/nodes/shared/callHasEffects.js index 2c37442..09d58cc 100644 --- a/src/ast/nodes/shared/callHasEffects.js +++ b/src/ast/nodes/shared/callHasEffects.js @@ -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; diff --git a/test/function/handle-calling-uncallable/_config.js b/test/function/handle-calling-uncallable/_config.js new file mode 100644 index 0000000..74b7d98 --- /dev/null +++ b/test/function/handle-calling-uncallable/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not give cryptic error when calling uncallable things (#1257)' +}; diff --git a/test/function/handle-calling-uncallable/foo.js b/test/function/handle-calling-uncallable/foo.js new file mode 100644 index 0000000..505dc43 --- /dev/null +++ b/test/function/handle-calling-uncallable/foo.js @@ -0,0 +1,3 @@ +function foo() {} + +export default { foo }; diff --git a/test/function/handle-calling-uncallable/main.js b/test/function/handle-calling-uncallable/main.js new file mode 100644 index 0000000..57e3120 --- /dev/null +++ b/test/function/handle-calling-uncallable/main.js @@ -0,0 +1,5 @@ +import foo from './foo.js'; + +assert.throws( function () { + foo(); +}, /is not a function/ );