Browse Source

Merge pull request #738 from rollup/gh-733

Preserve side-effects to default exports that coincide with used named exports
semi-dynamic-namespace-imports
Rich Harris 8 years ago
committed by GitHub
parent
commit
16272e8808
  1. 2
      src/utils/run.js
  2. 4
      test/function/export-two-ways-default-b/_config.js
  3. 6
      test/function/export-two-ways-default-b/bar.js
  4. 8
      test/function/export-two-ways-default-b/foo.js
  5. 6
      test/function/export-two-ways-default-b/main.js
  6. 6
      test/function/export-two-ways-default-b/x.js
  7. 3
      test/function/export-two-ways-default/_config.js
  8. 6
      test/function/export-two-ways-default/bar.js
  9. 8
      test/function/export-two-ways-default/foo.js
  10. 6
      test/function/export-two-ways-default/main.js
  11. 6
      test/function/export-two-ways-default/x.js

2
src/utils/run.js

@ -104,7 +104,7 @@ export default function run ( node, scope, statement, strongDependencies, force
} else {
declaration = statement.module.trace( subject.name );
if ( !declaration || declaration.isExternal || declaration.isUsed ) {
if ( !declaration || declaration.isExternal || declaration.isUsed || ( declaration.original && declaration.original.isUsed ) ) {
hasSideEffect = true;
}
}

4
test/function/export-two-ways-default-b/_config.js

@ -0,0 +1,4 @@
module.exports = {
skip: true,
description: 'side-effects are preserved if subject is exported in multiple ways, even if default export has no direct link to original (#733)'
};

6
test/function/export-two-ways-default-b/bar.js

@ -0,0 +1,6 @@
import { X } from './x.js';
X.prototype.bar = function () {
this.didBar = true;
return this;
};

8
test/function/export-two-ways-default-b/foo.js

@ -0,0 +1,8 @@
export function X () {}
X.prototype.foo = function () {
this.didFoo = true;
return this;
};
export default ( false || X );

6
test/function/export-two-ways-default-b/main.js

@ -0,0 +1,6 @@
import { x } from './x.js';
import './bar.js';
var result = x().foo().bar();
assert.ok( result.didFoo );
assert.ok( result.didBar );

6
test/function/export-two-ways-default-b/x.js

@ -0,0 +1,6 @@
export { default as X } from './foo.js';
import { X } from './foo.js';
export function x () {
return new X();
}

3
test/function/export-two-ways-default/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'side-effects are preserved if subject is exported in multiple ways (#733)'
};

6
test/function/export-two-ways-default/bar.js

@ -0,0 +1,6 @@
import { X } from './x.js';
X.prototype.bar = function () {
this.didBar = true;
return this;
};

8
test/function/export-two-ways-default/foo.js

@ -0,0 +1,8 @@
export function X () {}
X.prototype.foo = function () {
this.didFoo = true;
return this;
};
export default X;

6
test/function/export-two-ways-default/main.js

@ -0,0 +1,6 @@
import { x } from './x.js';
import './bar.js';
var result = x().foo().bar();
assert.ok( result.didFoo );
assert.ok( result.didBar );

6
test/function/export-two-ways-default/x.js

@ -0,0 +1,6 @@
export { default as X } from './foo.js';
import { X } from './foo.js';
export function x () {
return new X();
}
Loading…
Cancel
Save