Skip to content

Commit a695c5a

Browse files
authored
fix(sfc): align <script setup> component resolution edge case with v3 (#12687)
fix #12685
1 parent fabc1cf commit a695c5a

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/compiler/codegen/index.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ASTText,
1414
CompilerOptions
1515
} from 'types/compiler'
16-
import { BindingMetadata } from 'sfc/types'
16+
import { BindingMetadata, BindingTypes } from 'sfc/types'
1717

1818
type TransformFunction = (el: ASTElement, code: string) => string
1919
type DataGenFunction = (el: ASTElement) => string
@@ -104,10 +104,7 @@ export function genElement(el: ASTElement, state: CodegenState): string {
104104
// check if this is a component in <script setup>
105105
const bindings = state.options.bindings
106106
if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
107-
tag =
108-
checkBindingType(bindings, el.tag) ||
109-
checkBindingType(bindings, camelize(el.tag)) ||
110-
checkBindingType(bindings, capitalize(camelize(el.tag)))
107+
tag = checkBindingType(bindings, el.tag)
111108
}
112109
if (!tag) tag = `'${el.tag}'`
113110

@@ -127,9 +124,32 @@ export function genElement(el: ASTElement, state: CodegenState): string {
127124
}
128125

129126
function checkBindingType(bindings: BindingMetadata, key: string) {
130-
const type = bindings[key]
131-
if (type && type.startsWith('setup')) {
132-
return key
127+
const camelName = camelize(key)
128+
const PascalName = capitalize(camelName)
129+
const checkType = (type) => {
130+
if (bindings[key] === type) {
131+
return key
132+
}
133+
if (bindings[camelName] === type) {
134+
return camelName
135+
}
136+
if (bindings[PascalName] === type) {
137+
return PascalName
138+
}
139+
}
140+
const fromConst =
141+
checkType(BindingTypes.SETUP_CONST) ||
142+
checkType(BindingTypes.SETUP_REACTIVE_CONST)
143+
if (fromConst) {
144+
return fromConst
145+
}
146+
147+
const fromMaybeRef =
148+
checkType(BindingTypes.SETUP_LET) ||
149+
checkType(BindingTypes.SETUP_REF) ||
150+
checkType(BindingTypes.SETUP_MAYBE_REF)
151+
if (fromMaybeRef) {
152+
return fromMaybeRef
133153
}
134154
}
135155

0 commit comments

Comments
 (0)