Browse Source

Merge pull request #967 from Permutatrix/internally-used-default

Include default exports used within the module but not by importers.
legacy-quote-reserved-properties
Rich Harris 8 years ago
committed by GitHub
parent
commit
e83e5937f4
  1. 4
      src/ast/nodes/ExportDefaultDeclaration.js
  2. 3
      test/function/includes-internally-used-default-export/_config.js
  3. 3
      test/function/includes-internally-used-default-export/main.js
  4. 7
      test/function/includes-internally-used-default-export/module.js

4
src/ast/nodes/ExportDefaultDeclaration.js

@ -49,7 +49,7 @@ export default class ExportDefaultDeclaration extends Node {
const treeshake = this.module.bundle.treeshake;
const name = this.getName( es );
if ( this.shouldInclude ) {
if ( this.shouldInclude || this.declaration.activated ) {
if ( this.activated ) {
if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
if ( this.declaration.id ) {
@ -76,7 +76,7 @@ export default class ExportDefaultDeclaration extends Node {
super.render( code, es );
} else {
if ( treeshake ) {
if ( functionOrClassDeclaration.test( this.declaration.type ) && !this.declaration.activated ) {
if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
code.remove( this.leadingCommentStart || this.start, this.next || this.end );
} else {
const hasEffects = this.declaration.hasEffects( this.module.scope );

3
test/function/includes-internally-used-default-export/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'includes default exports that are only used internally'
};

3
test/function/includes-internally-used-default-export/main.js

@ -0,0 +1,3 @@
import { b } from './module.js';
assert.equal(b(), 15);

7
test/function/includes-internally-used-default-export/module.js

@ -0,0 +1,7 @@
export default function a() {
return 5;
}
export function b() {
return a() + 10;
}
Loading…
Cancel
Save