Browse Source

Merge pull request #406 from rollup/gh-403

handle a => a at top level
gh-438-b
Rich Harris 9 years ago
parent
commit
ff446b9a3b
  1. 5
      src/ast/isReference.js
  2. 4
      test/function/top-level-arrow-function/_config.js
  3. 2
      test/function/top-level-arrow-function/main.js

5
src/ast/isReference.js

@ -4,6 +4,11 @@ export default function isReference ( node, parent ) {
}
if ( node.type === 'Identifier' ) {
// the only time we could have an identifier node without a parent is
// if it's the entire body of a function without a block statement –
// i.e. an arrow function expression like `a => a`
if ( !parent ) return true;
// TODO is this right?
if ( parent.type === 'MemberExpression' ) return parent.computed || node === parent.object;

4
test/function/top-level-arrow-function/_config.js

@ -0,0 +1,4 @@
module.exports = {
description: 'handles naked return value from top-level arrow function expression (#403)',
babel: true
};

2
test/function/top-level-arrow-function/main.js

@ -0,0 +1,2 @@
const f = a => a;
assert.equal( f( 42 ), 42 );
Loading…
Cancel
Save