diff --git a/src/Module.js b/src/Module.js index 018d2b6..17d35e0 100644 --- a/src/Module.js +++ b/src/Module.js @@ -201,7 +201,7 @@ export default class Module { let strongDependencies = blank(); this.statements.forEach( statement => { - if ( statement.isImportDeclaration && !statement.node.specifiers.length ) { + if ( statement.isImportDeclaration && !statement.node.specifiers.length && !statement.module.isExternal ) { // include module for its side-effects strongDependencies[ statement.module.id ] = statement.module; // TODO is this right? `statement.module` should be `this`, surely? } @@ -475,6 +475,9 @@ export default class Module { return this.bundle.fetchModule( statement.node.source.value, this.id ) .then( module => { statement.module = module; + if ( module.isExternal ) { + return; + } return module.markAllStatements(); }); } diff --git a/test/function/import-empty-from-external/_config.js b/test/function/import-empty-from-external/_config.js new file mode 100644 index 0000000..c2207ae --- /dev/null +++ b/test/function/import-empty-from-external/_config.js @@ -0,0 +1,15 @@ +module.exports = { + description: 'imports external module for side effects', + context: { + // override require here, making "foo" appear as a global module + require: function ( name ) { + if ( name === 'foo' ) { + return require( './foo' ); + } + return require( name ); + } + }, + options: { + external: [ 'foo' ] + } +}; diff --git a/test/function/import-empty-from-external/foo.js b/test/function/import-empty-from-external/foo.js new file mode 100644 index 0000000..fcd98c3 --- /dev/null +++ b/test/function/import-empty-from-external/foo.js @@ -0,0 +1 @@ +global.answer = 42; diff --git a/test/function/import-empty-from-external/main.js b/test/function/import-empty-from-external/main.js new file mode 100644 index 0000000..91e0072 --- /dev/null +++ b/test/function/import-empty-from-external/main.js @@ -0,0 +1,3 @@ +import 'foo'; + +assert.equal( global.answer, 42 );