fix(compiler-sfc): fix treeshaking of namespace import when used in template

fix #5209
This commit is contained in:
Evan You
2022-05-12 18:56:54 +08:00
parent 8c51c6514f
commit 8a123ac34f
3 changed files with 14 additions and 3 deletions

View File

@@ -1011,10 +1011,13 @@ export function compileScript(
for (let i = 0; i < node.specifiers.length; i++) {
const specifier = node.specifiers[i]
const local = specifier.local.name
const imported =
let imported =
specifier.type === 'ImportSpecifier' &&
specifier.imported.type === 'Identifier' &&
specifier.imported.name
if (specifier.type === 'ImportNamespaceSpecifier') {
imported = '*'
}
const source = node.source.value
const existing = userImports[local]
if (
@@ -1257,7 +1260,9 @@ export function compileScript(
)) {
if (isType) continue
bindingMetadata[key] =
(imported === 'default' && source.endsWith('.vue')) || source === 'vue'
imported === '*' ||
(imported === 'default' && source.endsWith('.vue')) ||
source === 'vue'
? BindingTypes.SETUP_CONST
: BindingTypes.SETUP_MAYBE_REF
}