Skip to content

Commit 0bb0c2c

Browse files
committed
fix(codegen): improve resolve component name in <script setup>
1 parent 15e6f1d commit 0bb0c2c

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/compiler/codegen/index.ts

Lines changed: 29 additions & 5 deletions
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
@@ -103,10 +103,34 @@ export function genElement(el: ASTElement, state: CodegenState): string {
103103
// check if this is a component in <script setup>
104104
const bindings = state.options.bindings
105105
if (bindings && bindings.__isScriptSetup !== false) {
106-
tag =
107-
checkBindingType(bindings, el.tag) ||
108-
checkBindingType(bindings, camelize(el.tag)) ||
109-
checkBindingType(bindings, capitalize(camelize(el.tag)))
106+
const camelName = camelize(el.tag)
107+
const PascalName = capitalize(camelName)
108+
const checkType = (type) => {
109+
if (bindings[el.tag] === type) {
110+
return el.tag
111+
}
112+
if (bindings[camelName] === type) {
113+
return camelName
114+
}
115+
if (bindings[PascalName] === type) {
116+
return PascalName
117+
}
118+
}
119+
120+
const fromConst =
121+
checkType(BindingTypes.SETUP_CONST) ||
122+
checkType(BindingTypes.SETUP_REACTIVE_CONST)
123+
if (fromConst) {
124+
tag = fromConst
125+
} else {
126+
const fromMaybeRef =
127+
checkType(BindingTypes.SETUP_LET) ||
128+
checkType(BindingTypes.SETUP_REF) ||
129+
checkType(BindingTypes.SETUP_MAYBE_REF)
130+
if (fromMaybeRef) {
131+
tag = fromMaybeRef
132+
}
133+
}
110134
}
111135
if (!tag) tag = `'${el.tag}'`
112136

0 commit comments

Comments
 (0)