Skip to content

Commit

Permalink
feat(compiler-sfc): support kebab-case components in <script setup>
Browse files Browse the repository at this point in the history
… sfc template
  • Loading branch information
yyx990803 committed Nov 9, 2020
1 parent 8cf0a40 commit 3f99e23
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 3 additions & 2 deletions packages/compiler-core/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
isArray,
NOOP,
PatchFlags,
PatchFlagNames
PatchFlagNames,
EMPTY_OBJ
} from '@vue/shared'
import { defaultOnError } from './errors'
import {
Expand Down Expand Up @@ -122,7 +123,7 @@ export function createTransformContext(
scopeId = null,
ssr = false,
ssrCssVars = ``,
bindingMetadata = {},
bindingMetadata = EMPTY_OBJ,
onError = defaultOnError
}: TransformOptions
): TransformContext {
Expand Down
16 changes: 13 additions & 3 deletions packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
isSymbol,
isOn,
isObject,
isReservedProp
isReservedProp,
capitalize,
camelize,
EMPTY_OBJ
} from '@vue/shared'
import { createCompilerError, ErrorCodes } from '../errors'
import {
Expand Down Expand Up @@ -246,8 +249,15 @@ export function resolveComponentType(
}

// 3. user component (from setup bindings)
if (context.bindingMetadata[tag] === 'setup') {
return `$setup[${JSON.stringify(tag)}]`
let tagFromSetup = tag
const bindings = context.bindingMetadata
if (
bindings !== EMPTY_OBJ &&
(bindings[tagFromSetup] === 'setup' ||
bindings[(tagFromSetup = camelize(tag))] === 'setup' ||
bindings[(tagFromSetup = capitalize(camelize(tag)))] === 'setup')
) {
return `$setup[${JSON.stringify(tagFromSetup)}]`
}

// 4. user component (resolve)
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const hasWarned: Record<string, boolean> = {}
function warnOnce(msg: string) {
if (!hasWarned[msg]) {
hasWarned[msg] = true
console.log(`\n\x1b[33m[@vue/compiler-sfc] %s\x1b[0m\n`, msg)
console.log(`\x1b[33m[@vue/compiler-sfc] %s\x1b[0m\n`, msg)
}
}

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

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

0 comments on commit 3f99e23

Please sign in to comment.