Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(warns): modify maybeComponent function in parser #10167

Merged
merged 1 commit into from Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/compiler/parser/index.js
Expand Up @@ -86,8 +86,12 @@ export function parse (
platformMustUseProp = options.mustUseProp || no
platformGetTagNamespace = options.getTagNamespace || no
const isReservedTag = options.isReservedTag || no
maybeComponent = (el: ASTElement) => !!el.component || !isReservedTag(el.tag)

maybeComponent = (el: ASTElement) => !!(
el.component ||
el.attrsMap[':is'] ||
el.attrsMap['v-bind:is'] ||
!(el.attrsMap.is ? isReservedTag(el.attrsMap.is) : isReservedTag(el.tag))
)
transforms = pluckModuleFunction(options.modules, 'transformNode')
preTransforms = pluckModuleFunction(options.modules, 'preTransformNode')
postTransforms = pluckModuleFunction(options.modules, 'postTransformNode')
Expand Down
16 changes: 16 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Expand Up @@ -881,4 +881,20 @@ describe('parser', () => {
expect(ast.children[2].type).toBe(3)
expect(ast.children[2].text).toBe('\ndef')
})

// #10152
it('not warn when scoped slot used inside of dynamic component on regular element', () => {
parse(`
<div>
<div is="customComp" v-slot="slotProps"></div>
<div :is="'customComp'" v-slot="slotProps"></div>
<div v-bind:is="'customComp'" v-slot="slotProps"></div>
</div>
`, baseOptions)
expect('v-slot can only be used on components or <template>').not.toHaveBeenWarned()

parse(`<div is="customComp"><template v-slot="slotProps"></template></div>`, baseOptions)
expect(`<template v-slot> can only appear at the root level inside the receiving the component`)
.not.toHaveBeenWarned()
})
})