From 7f61f5c75402785d956c9de6d838bc7bd580161c Mon Sep 17 00:00:00 2001 From: Permutator Date: Mon, 19 Sep 2016 12:57:20 -0700 Subject: [PATCH 1/4] Added failing test for inclusion of internally used default export --- .../includes-internally-used-default-export/_config.js | 3 +++ .../includes-internally-used-default-export/main.js | 3 +++ .../includes-internally-used-default-export/module.js | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 test/function/includes-internally-used-default-export/_config.js create mode 100644 test/function/includes-internally-used-default-export/main.js create mode 100644 test/function/includes-internally-used-default-export/module.js diff --git a/test/function/includes-internally-used-default-export/_config.js b/test/function/includes-internally-used-default-export/_config.js new file mode 100644 index 0000000..3eab340 --- /dev/null +++ b/test/function/includes-internally-used-default-export/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'includes default exports that are only used internally' +}; diff --git a/test/function/includes-internally-used-default-export/main.js b/test/function/includes-internally-used-default-export/main.js new file mode 100644 index 0000000..c196b10 --- /dev/null +++ b/test/function/includes-internally-used-default-export/main.js @@ -0,0 +1,3 @@ +import { b } from './module.js'; + +assert.equal(b(), 15); diff --git a/test/function/includes-internally-used-default-export/module.js b/test/function/includes-internally-used-default-export/module.js new file mode 100644 index 0000000..8f3524b --- /dev/null +++ b/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; +} From 33934791dde9389a85547520b199223e8d60ec4d Mon Sep 17 00:00:00 2001 From: Permutator Date: Mon, 19 Sep 2016 12:58:23 -0700 Subject: [PATCH 2/4] Default exports that are only used internally now included --- src/ast/nodes/ExportDefaultDeclaration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ast/nodes/ExportDefaultDeclaration.js b/src/ast/nodes/ExportDefaultDeclaration.js index 716ffcf..30e402c 100644 --- a/src/ast/nodes/ExportDefaultDeclaration.js +++ b/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 ) { From 1d51b06592cc334029b1eb9fade62130e5040848 Mon Sep 17 00:00:00 2001 From: Permutator Date: Mon, 19 Sep 2016 13:09:26 -0700 Subject: [PATCH 3/4] Whoops, tabs, not spaces --- .../includes-internally-used-default-export/module.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/function/includes-internally-used-default-export/module.js b/test/function/includes-internally-used-default-export/module.js index 8f3524b..ba2c4ee 100644 --- a/test/function/includes-internally-used-default-export/module.js +++ b/test/function/includes-internally-used-default-export/module.js @@ -1,7 +1,7 @@ export default function a() { - return 5; + return 5; } export function b() { - return a() + 10; + return a() + 10; } From d9193654dcb2bde76e15c8699240a9659ee237c6 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 22 Sep 2016 09:59:26 -0700 Subject: [PATCH 4/4] Remove redundant check. --- src/ast/nodes/ExportDefaultDeclaration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ast/nodes/ExportDefaultDeclaration.js b/src/ast/nodes/ExportDefaultDeclaration.js index 30e402c..ab4a776 100644 --- a/src/ast/nodes/ExportDefaultDeclaration.js +++ b/src/ast/nodes/ExportDefaultDeclaration.js @@ -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 );