From 6010bdd416503e6c47549369682574a0f9fe1ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E9=81=93?= Date: Mon, 4 Mar 2019 15:41:22 +0800 Subject: [PATCH] fix: the empty string importee should not always be treated as external module id (#2733) * Update mergeOptions.ts * Add test for using empty string as virtual module name --- src/utils/mergeOptions.ts | 2 +- .../empty-string-as-module-name/_config.js | 15 +++++++++++++++ .../samples/empty-string-as-module-name/main.js | 2 ++ .../empty-string-as-module-name/main.js#.js | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/function/samples/empty-string-as-module-name/_config.js create mode 100644 test/function/samples/empty-string-as-module-name/main.js create mode 100644 test/function/samples/empty-string-as-module-name/main.js#.js diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts index f2f86f76e61..8f8c2629a98 100644 --- a/src/utils/mergeOptions.ts +++ b/src/utils/mergeOptions.ts @@ -168,7 +168,7 @@ function addUnknownOptionErrors( function getCommandOptions(rawCommandOptions: GenericConfigObject): GenericConfigObject { const command = { ...rawCommandOptions }; - command.external = (rawCommandOptions.external || '').split(','); + command.external = rawCommandOptions.external ? rawCommandOptions.external.split(',') : []; if (rawCommandOptions.globals) { command.globals = Object.create(null); diff --git a/test/function/samples/empty-string-as-module-name/_config.js b/test/function/samples/empty-string-as-module-name/_config.js new file mode 100644 index 00000000000..dfbc2595b37 --- /dev/null +++ b/test/function/samples/empty-string-as-module-name/_config.js @@ -0,0 +1,15 @@ +module.exports = { + description: 'allows using empty string as a valid module name', + options: { + external: () => false, + plugins: [ + { + resolveId(importee, importer) { + if (importee === '') { + return importer + '#.js'; + } + } + } + ] + } +}; diff --git a/test/function/samples/empty-string-as-module-name/main.js b/test/function/samples/empty-string-as-module-name/main.js new file mode 100644 index 00000000000..29634821528 --- /dev/null +++ b/test/function/samples/empty-string-as-module-name/main.js @@ -0,0 +1,2 @@ +import { importee } from ''; +assert.strictEqual(importee, 'xxx'); diff --git a/test/function/samples/empty-string-as-module-name/main.js#.js b/test/function/samples/empty-string-as-module-name/main.js#.js new file mode 100644 index 00000000000..221b08850db --- /dev/null +++ b/test/function/samples/empty-string-as-module-name/main.js#.js @@ -0,0 +1 @@ +export var importee = 'xxx';