Skip to content

Commit 3f99e23

Browse files
committed
feat(compiler-sfc): support kebab-case components in <script setup> sfc template
1 parent 8cf0a40 commit 3f99e23

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

packages/compiler-core/src/transform.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
isArray,
2323
NOOP,
2424
PatchFlags,
25-
PatchFlagNames
25+
PatchFlagNames,
26+
EMPTY_OBJ
2627
} from '@vue/shared'
2728
import { defaultOnError } from './errors'
2829
import {
@@ -122,7 +123,7 @@ export function createTransformContext(
122123
scopeId = null,
123124
ssr = false,
124125
ssrCssVars = ``,
125-
bindingMetadata = {},
126+
bindingMetadata = EMPTY_OBJ,
126127
onError = defaultOnError
127128
}: TransformOptions
128129
): TransformContext {

packages/compiler-core/src/transforms/transformElement.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import {
2626
isSymbol,
2727
isOn,
2828
isObject,
29-
isReservedProp
29+
isReservedProp,
30+
capitalize,
31+
camelize,
32+
EMPTY_OBJ
3033
} from '@vue/shared'
3134
import { createCompilerError, ErrorCodes } from '../errors'
3235
import {
@@ -246,8 +249,15 @@ export function resolveComponentType(
246249
}
247250

248251
// 3. user component (from setup bindings)
249-
if (context.bindingMetadata[tag] === 'setup') {
250-
return `$setup[${JSON.stringify(tag)}]`
252+
let tagFromSetup = tag
253+
const bindings = context.bindingMetadata
254+
if (
255+
bindings !== EMPTY_OBJ &&
256+
(bindings[tagFromSetup] === 'setup' ||
257+
bindings[(tagFromSetup = camelize(tag))] === 'setup' ||
258+
bindings[(tagFromSetup = capitalize(camelize(tag)))] === 'setup')
259+
) {
260+
return `$setup[${JSON.stringify(tagFromSetup)}]`
251261
}
252262

253263
// 4. user component (resolve)

packages/compiler-sfc/src/compileScript.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const hasWarned: Record<string, boolean> = {}
4141
function warnOnce(msg: string) {
4242
if (!hasWarned[msg]) {
4343
hasWarned[msg] = true
44-
console.log(`\n\x1b[33m[@vue/compiler-sfc] %s\x1b[0m\n`, msg)
44+
console.log(`\x1b[33m[@vue/compiler-sfc] %s\x1b[0m\n`, msg)
4545
}
4646
}
4747

@@ -59,7 +59,7 @@ export function compileScript(
5959
if (__DEV__ && !__TEST__ && scriptSetup) {
6060
warnOnce(
6161
`<script setup> is still an experimental proposal.\n` +
62-
`Follow https://github.com/vuejs/rfcs/pull/227 for its status.`
62+
`Follow its status at https://github.com/vuejs/rfcs/pull/227.`
6363
)
6464
}
6565

@@ -461,9 +461,9 @@ export function compileScript(
461461
) {
462462
if (enableRefSugar) {
463463
warnOnce(
464-
`ref: sugar is still an experimental proposal and is not\n` +
464+
`ref: sugar is still an experimental proposal and is not ` +
465465
`guaranteed to be a part of <script setup>.\n` +
466-
`Follow its status at https://github.com/vuejs/rfcs/pull/228`
466+
`Follow its status at https://github.com/vuejs/rfcs/pull/228.`
467467
)
468468
s.overwrite(
469469
node.label.start! + startOffset,

0 commit comments

Comments
 (0)