From c406f976fa54a5341a0a1198e5bdf5832f23251b Mon Sep 17 00:00:00 2001 From: Lukas Taegert Date: Fri, 3 Nov 2017 10:26:17 +0100 Subject: [PATCH] Resolve #1645 --- src/ast/variables/ExternalVariable.js | 2 +- .../_config.js | 13 +++++++++++++ .../main.js | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/function/samples/keep-used-imports-from-pure-external-modules/_config.js create mode 100644 test/function/samples/keep-used-imports-from-pure-external-modules/main.js diff --git a/src/ast/variables/ExternalVariable.js b/src/ast/variables/ExternalVariable.js index b8a5672b6d6..097a79b3516 100644 --- a/src/ast/variables/ExternalVariable.js +++ b/src/ast/variables/ExternalVariable.js @@ -29,7 +29,7 @@ export default class ExternalVariable extends Variable { return es ? this.safeName : `${this.module.name}.${this.name}`; } - includeDeclaration () { + includeVariable () { if ( this.included ) { return false; } diff --git a/test/function/samples/keep-used-imports-from-pure-external-modules/_config.js b/test/function/samples/keep-used-imports-from-pure-external-modules/_config.js new file mode 100644 index 00000000000..97676f56303 --- /dev/null +++ b/test/function/samples/keep-used-imports-from-pure-external-modules/_config.js @@ -0,0 +1,13 @@ +module.exports = { + description: 'imports from pure external modules that are used should not be omitted', + options: { + external: [ 'warning' ], + pureExternalModules: [ 'warning' ] + }, + context: { + require: id => { + if ( id === 'warning' ) return arg => console.log( arg ); + throw new Error( 'Unexpected import', id ); + } + } +}; diff --git a/test/function/samples/keep-used-imports-from-pure-external-modules/main.js b/test/function/samples/keep-used-imports-from-pure-external-modules/main.js new file mode 100644 index 00000000000..992a4573f52 --- /dev/null +++ b/test/function/samples/keep-used-imports-from-pure-external-modules/main.js @@ -0,0 +1,3 @@ +import warning from 'warning'; + +warning('hi');