Browse Source

Merge pull request #423 from rollup/gh-421

handle calls to default exports other than function expressions
gh-438-b
Rich Harris 9 years ago
parent
commit
000403250a
  1. 10
      src/Declaration.js
  2. 3
      test/function/call-non-function-default-exports/_config.js
  3. 9
      test/function/call-non-function-default-exports/foo.js
  4. 4
      test/function/call-non-function-default-exports/main.js
  5. 3
      test/function/default-exports-in-parens/_config.js
  6. 3
      test/function/default-exports-in-parens/foo.js
  7. 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/call-non-function-default-exports/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'calls non-function default exports'
};

9
test/function/call-non-function-default-exports/foo.js

@ -0,0 +1,9 @@
function x () {
global.answer = 'x';
}
function y () {
global.answer = 'y';
}
export default Math.random() < 0.5 ? x : y;

4
test/function/call-non-function-default-exports/main.js

@ -0,0 +1,4 @@
import foo from './foo.js';
foo();
assert.ok( /[xy]/.test( global.answer ) );

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