diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index a68625d60..01e2b8098 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -195,10 +195,10 @@ return { ref } `; exports[`SFC compile `, { inlineTemplate: true } ) // no need to unref vue component import - expect(content).toMatch(`createVNode(Foo)`) + expect(content).toMatch(`createVNode(Foo,`) + // #2699 should unref named imports from .vue + expect(content).toMatch(`unref(bar)`) // should unref other imports expect(content).toMatch(`unref(other)`) // no need to unref constant literals diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 7dca8606e..b51ae34f2 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -168,7 +168,7 @@ export function compileScript( string, { isType: boolean - imported: string | null + imported: string source: string } > = Object.create(null) @@ -246,7 +246,7 @@ export function compileScript( } userImports[local] = { isType, - imported: imported || null, + imported: imported || 'default', source } } @@ -807,10 +807,12 @@ export function compileScript( for (const key in typeDeclaredProps) { bindingMetadata[key] = BindingTypes.PROPS } - for (const [key, { isType, source }] of Object.entries(userImports)) { + for (const [key, { isType, imported, source }] of Object.entries( + userImports + )) { if (isType) continue bindingMetadata[key] = - source.endsWith('.vue') || source === 'vue' + (imported === 'default' && source.endsWith('.vue')) || source === 'vue' ? BindingTypes.SETUP_CONST : BindingTypes.SETUP_MAYBE_REF }