From e20a332c57b903d6bf63ab08d79bff7b6dc39aaa Mon Sep 17 00:00:00 2001 From: kzc Date: Tue, 18 Oct 2016 08:51:16 -0400 Subject: [PATCH 1/2] fix TypeError in arrow function without braces returning a function (#1032) --- src/ast/nodes/shared/callHasEffects.js | 2 +- .../braceless-arrow-function-returning-function/_config.js | 3 +++ .../braceless-arrow-function-returning-function/main.js | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/function/braceless-arrow-function-returning-function/_config.js create mode 100644 test/function/braceless-arrow-function-returning-function/main.js diff --git a/src/ast/nodes/shared/callHasEffects.js b/src/ast/nodes/shared/callHasEffects.js index cf8d964..8fa026d 100644 --- a/src/ast/nodes/shared/callHasEffects.js +++ b/src/ast/nodes/shared/callHasEffects.js @@ -11,7 +11,7 @@ function fnHasEffects ( fn ) { // handle body-less arrow functions const scope = fn.body.scope || fn.scope; - const body = fn.body.body || [ fn.body ]; + const body = Array.isArray(fn.body.body) && fn.body.body || [ fn.body ]; for ( const node of body ) { if ( node.hasEffects( scope ) ) { diff --git a/test/function/braceless-arrow-function-returning-function/_config.js b/test/function/braceless-arrow-function-returning-function/_config.js new file mode 100644 index 0000000..03ddb4d --- /dev/null +++ b/test/function/braceless-arrow-function-returning-function/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'arrow function without braces returning a function (#1032)' +}; diff --git a/test/function/braceless-arrow-function-returning-function/main.js b/test/function/braceless-arrow-function-returning-function/main.js new file mode 100644 index 0000000..637a0ee --- /dev/null +++ b/test/function/braceless-arrow-function-returning-function/main.js @@ -0,0 +1,7 @@ +const f = (a) => (b) => { return a * b } +function ff (a) { return f(a) } +assert.equal( ff(2)(3), 6 ); + +const g = (a) => { return (b) => { return a - b } } +function gg (a) { return g(a) } +assert.equal( gg(2)(3), -1 ); From 0006ea1e1c7e9b0e41d178ab3959cd0a27259c54 Mon Sep 17 00:00:00 2001 From: kzc Date: Tue, 18 Oct 2016 09:02:44 -0400 Subject: [PATCH 2/2] use buble for test to resolve node 0.12 failure --- .../braceless-arrow-function-returning-function/_config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/function/braceless-arrow-function-returning-function/_config.js b/test/function/braceless-arrow-function-returning-function/_config.js index 03ddb4d..3204f3c 100644 --- a/test/function/braceless-arrow-function-returning-function/_config.js +++ b/test/function/braceless-arrow-function-returning-function/_config.js @@ -1,3 +1,4 @@ module.exports = { - description: 'arrow function without braces returning a function (#1032)' + description: 'arrow function without braces returning a function (#1032)', + buble: true };