From 456f4d2c3603976f69f1e753377f9b1649a99b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E9=81=93?= Date: Tue, 6 Aug 2019 00:21:38 +0800 Subject: [PATCH] Avoid variable from empty module name be empty (#3026) * Create main.js * Create _config.js * Update _config.js * Update _config.js * Delete main.js * Update identifierHelpers.ts --- src/utils/identifierHelpers.ts | 2 +- .../avoid-variable-be-empty/_config.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/function/samples/avoid-variable-be-empty/_config.js 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' + } + } +};