diff --git a/src/utils/identifierHelpers.ts b/src/utils/identifierHelpers.ts index 3b603eb1a31..38463f07be5 100644 --- a/src/utils/identifierHelpers.ts +++ b/src/utils/identifierHelpers.ts @@ -24,5 +24,5 @@ export function makeLegal(str: string): string { if (startsWithDigit(str) || blacklisted[str]) str = `_${str}`; - return str; + return str || '_'; } diff --git a/test/function/samples/avoid-variable-be-empty/_config.js b/test/function/samples/avoid-variable-be-empty/_config.js new file mode 100644 index 00000000000..9571570ca02 --- /dev/null +++ b/test/function/samples/avoid-variable-be-empty/_config.js @@ -0,0 +1,19 @@ +module.exports = { + description: 'avoid variable from empty module name be empty', + options: { + input: '', + plugins: [ + { + resolveId (importee) { + return ''; + }, + load (path) { + return 'export default 0;'; + }, + } + ], + output: { + format: 'cjs' + } + } +};