Skip to content

Commit

Permalink
fix: the empty string importee should not always be treated as extern…
Browse files Browse the repository at this point in the history
…al module id (#2733)

* Update mergeOptions.ts

* Add test for using empty string as virtual module name
  • Loading branch information
LongTengDao authored and lukastaegert committed Mar 4, 2019
1 parent d27ee15 commit 6010bdd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/mergeOptions.ts
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions 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';
}
}
}
]
}
};
2 changes: 2 additions & 0 deletions test/function/samples/empty-string-as-module-name/main.js
@@ -0,0 +1,2 @@
import { importee } from '';
assert.strictEqual(importee, 'xxx');
@@ -0,0 +1 @@
export var importee = 'xxx';

0 comments on commit 6010bdd

Please sign in to comment.