Browse Source

handle call expressions of uncallable things more gracefully (#1257)

master
Rich-Harris 8 years ago
parent
commit
5c88259abc
  1. 10
      src/ast/nodes/shared/callHasEffects.js
  2. 3
      test/function/handle-calling-uncallable/_config.js
  3. 3
      test/function/handle-calling-uncallable/foo.js
  4. 5
      test/function/handle-calling-uncallable/main.js

10
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;

3
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
test/function/handle-calling-uncallable/foo.js

@ -0,0 +1,3 @@
function foo() {}
export default { foo };

5
test/function/handle-calling-uncallable/main.js

@ -0,0 +1,5 @@
import foo from './foo.js';
assert.throws( function () {
foo();
}, /is not a function/ );
Loading…
Cancel
Save