fix(compiler-sfc): fix template usage check edge case for v-slot destructured default value (#12842)

fix #12841
This commit is contained in:
a161803398 2022-11-09 17:52:35 +08:00 committed by GitHub
parent 5aed733ab6
commit 5e3d4e90cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -39,7 +39,7 @@ import { walk } from 'estree-walker'
import { RawSourceMap } from 'source-map'
import { warnOnce } from './warn'
import { isReservedTag } from 'web/util'
import { bindRE, dirRE, onRE } from 'compiler/parser'
import { bindRE, dirRE, onRE, slotRE } from 'compiler/parser'
import { parseText } from 'compiler/parser/text-parser'
import { DEFAULT_FILENAME } from './parseComponent'
import {
@ -1804,6 +1804,8 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor, isTS: boolean) {
if (dirRE.test(name)) {
const baseName = onRE.test(name)
? 'on'
: slotRE.test(name)
? 'slot'
: bindRE.test(name)
? 'bind'
: name.replace(dirRE, '')

View File

@ -1574,5 +1574,21 @@ describe('SFC analyze <script> bindings', () => {
</template>
`)
})
// #12841
test('should not error when performing ts expression check for v-slot destructured default value', () => {
compile(`
<script setup lang="ts">
import FooComp from './Foo.vue'
</script>
<template>
<FooComp>
<template #bar="{ bar = { baz: '' } }">
{{ bar.baz }}
</template>
</FooComp>
</template>
`)
})
})
})

View File

@ -42,7 +42,7 @@ export const bindRE = /^:|^\.|^v-bind:/
const propBindRE = /^\./
const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g
const slotRE = /^v-slot(:|$)|^#/
export const slotRE = /^v-slot(:|$)|^#/
const lineBreakRE = /[\r\n]/
const whitespaceRE = /[ \f\t\r\n]+/g