Skip to content

Commit 4294e72

Browse files
committedJun 19, 2019
fix(compiler): add condition to see whether the element may be an component
fixes vuejs#10152
1 parent bad3c32 commit 4294e72

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
@@ -881,4 +881,20 @@ describe('parser', () => {
881881
expect(ast.children[2].type).toBe(3)
882882
expect(ast.children[2].text).toBe('\ndef')
883883
})
884+
885+
// #10152
886+
it('not warn when scoped slot used inside of dynamic component on regular element', () => {
887+
parse(`
888+
<div>
889+
<div is="customComp" v-slot="slotProps"></div>
890+
<div :is="'customComp'" v-slot="slotProps"></div>
891+
<div v-bind:is="'customComp'" v-slot="slotProps"></div>
892+
</div>
893+
`, baseOptions)
894+
expect('v-slot can only be used on components or <template>').not.toHaveBeenWarned()
895+
896+
parse(`<div is="customComp"><template v-slot="slotProps"></template></div>`, baseOptions)
897+
expect(`<template v-slot> can only appear at the root level inside the receiving the component`)
898+
.not.toHaveBeenWarned()
899+
})
884900
})

1 commit comments

Comments
 (1)

2472289148 commented on Nov 7, 2019

@2472289148

Thanks for your code, it's very userful, but why cant merge with dev branch?

Please sign in to comment.