Skip to content

Commit

Permalink
fix(compiler-sfc): fix template usage check edge case for v-slot dest…
Browse files Browse the repository at this point in the history
…ructured default value (vuejs#12841)
  • Loading branch information
a161803398 committed Oct 19, 2022
1 parent 6d9aac8 commit 855f47d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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, '')
Expand Down
16 changes: 16 additions & 0 deletions packages/compiler-sfc/test/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1574,5 +1574,21 @@ describe('SFC analyze <script> bindings', () => {
</tempalte>
`)
})

// #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>
`)
})
})
})
2 changes: 1 addition & 1 deletion src/compiler/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 855f47d

Please sign in to comment.