Skip to content

Commit 0603ff6

Browse files
authored
fix(warns): modify maybeComponent function in parser (#10167)
fixes #10152
1 parent 5c459f0 commit 0603ff6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/compiler/parser/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ export function parse (
8686
platformMustUseProp = options.mustUseProp || no
8787
platformGetTagNamespace = options.getTagNamespace || no
8888
const isReservedTag = options.isReservedTag || no
89-
maybeComponent = (el: ASTElement) => !!el.component || !isReservedTag(el.tag)
90-
89+
maybeComponent = (el: ASTElement) => !!(
90+
el.component ||
91+
el.attrsMap[':is'] ||
92+
el.attrsMap['v-bind:is'] ||
93+
!(el.attrsMap.is ? isReservedTag(el.attrsMap.is) : isReservedTag(el.tag))
94+
)
9195
transforms = pluckModuleFunction(options.modules, 'transformNode')
9296
preTransforms = pluckModuleFunction(options.modules, 'preTransformNode')
9397
postTransforms = pluckModuleFunction(options.modules, 'postTransformNode')

test/unit/modules/compiler/parser.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -909,4 +909,20 @@ describe('parser', () => {
909909
expect(ast.children[2].type).toBe(3)
910910
expect(ast.children[2].text).toBe('\ndef')
911911
})
912+
913+
// #10152
914+
it('not warn when scoped slot used inside of dynamic component on regular element', () => {
915+
parse(`
916+
<div>
917+
<div is="customComp" v-slot="slotProps"></div>
918+
<div :is="'customComp'" v-slot="slotProps"></div>
919+
<div v-bind:is="'customComp'" v-slot="slotProps"></div>
920+
</div>
921+
`, baseOptions)
922+
expect('v-slot can only be used on components or <template>').not.toHaveBeenWarned()
923+
924+
parse(`<div is="customComp"><template v-slot="slotProps"></template></div>`, baseOptions)
925+
expect(`<template v-slot> can only appear at the root level inside the receiving the component`)
926+
.not.toHaveBeenWarned()
927+
})
912928
})

0 commit comments

Comments
 (0)