Browse Source

handle calls to default exports other than function expressions – fixes #421

gh-438-b
Rich Harris 9 years ago
parent
commit
d0879d4d4e
  1. 10
      src/Declaration.js
  2. 3
      test/function/default-exports-in-parens/_config.js
  3. 3
      test/function/default-exports-in-parens/foo.js
  4. 3
      test/function/default-exports-in-parens/main.js

10
src/Declaration.js

@ -110,9 +110,15 @@ export class SyntheticDefaultDeclaration {
return this.original.run( strongDependencies );
}
if ( /FunctionExpression/.test( this.node.declaration.type ) ) {
return run( this.node.declaration.body, this.statement.scope, this.statement, strongDependencies, false );
let declaration = this.node.declaration;
while ( declaration.type === 'ParenthesizedExpression' ) declaration = declaration.expression;
if ( /FunctionExpression/.test( declaration.type ) ) {
return run( declaration.body, this.statement.scope, this.statement, strongDependencies, false );
}
// otherwise assume the worst
return true;
}
use () {

3
test/function/default-exports-in-parens/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'handles default function exports wrapped in parens'
};

3
test/function/default-exports-in-parens/foo.js

@ -0,0 +1,3 @@
export default (function () {
global.answer = 42;
});

3
test/function/default-exports-in-parens/main.js

@ -0,0 +1,3 @@
import foo from './foo.js';
foo();
assert.equal( global.answer, 42 );
Loading…
Cancel
Save