diff --git a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts
index bc2c9686a6c..1258398d465 100644
--- a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts
+++ b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts
@@ -2,7 +2,8 @@ import {
CompilerOptions,
baseParse as parse,
transform,
- ErrorCodes
+ ErrorCodes,
+ BindingTypes
} from '../../src'
import {
RESOLVE_COMPONENT,
@@ -78,6 +79,28 @@ describe('compiler: element transform', () => {
expect(root.components).toContain(`Example__self`)
})
+ test('resolve component from setup bindings', () => {
+ const { root, node } = parseWithElementTransform(``, {
+ bindingMetadata: {
+ Example: BindingTypes.SETUP_MAYBE_REF
+ }
+ })
+ expect(root.helpers).not.toContain(RESOLVE_COMPONENT)
+ expect(node.tag).toBe(`$setup["Example"]`)
+ })
+
+ test('do not resolve component from non-script-setup bindings', () => {
+ const bindingMetadata = {
+ Example: BindingTypes.SETUP_MAYBE_REF
+ }
+ Object.defineProperty(bindingMetadata, '__isScriptSetup', { value: false })
+ const { root } = parseWithElementTransform(``, {
+ bindingMetadata
+ })
+ expect(root.helpers).toContain(RESOLVE_COMPONENT)
+ expect(root.components).toContain(`Example`)
+ })
+
test('static props', () => {
const { node } = parseWithElementTransform(`
`)
expect(node).toMatchObject({
diff --git a/packages/compiler-core/src/options.ts b/packages/compiler-core/src/options.ts
index d8d2573a6e8..1b5450de29d 100644
--- a/packages/compiler-core/src/options.ts
+++ b/packages/compiler-core/src/options.ts
@@ -94,8 +94,10 @@ export const enum BindingTypes {
OPTIONS = 'options'
}
-export interface BindingMetadata {
+export type BindingMetadata = {
[key: string]: BindingTypes | undefined
+} & {
+ __isScriptSetup?: boolean
}
interface SharedTransformCodegenOptions {
diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts
index 398758f4234..9f4f3389564 100644
--- a/packages/compiler-core/src/transforms/transformElement.ts
+++ b/packages/compiler-core/src/transforms/transformElement.ts
@@ -286,7 +286,7 @@ export function resolveComponentType(
function resolveSetupReference(name: string, context: TransformContext) {
const bindings = context.bindingMetadata
- if (!bindings) {
+ if (!bindings || bindings.__isScriptSetup === false) {
return
}
diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts
index 30cef0fbcd4..f083a0b6731 100644
--- a/packages/compiler-sfc/__tests__/compileScript.spec.ts
+++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts
@@ -962,6 +962,7 @@ describe('SFC analyze