提交 6652d78c 编写于 作者: fxy060608's avatar fxy060608

fix(mp): v-slot can only be used on components or <template> tags (#3094)

上级 47f1b762
......@@ -1249,7 +1249,7 @@ function getWxsVm(el) {
}
}
const isClickEvent = (val) => val.type === "click";
const isMouseEvent = (val) => val.type.indexOf("mouse") === 0;
const isMouseEvent = (val) => val.type.indexOf("mouse") === 0 || ["contextmenu"].includes(val.type);
function $nne(evt, eventValue, instance2) {
const { currentTarget } = evt;
if (!(evt instanceof Event) || !(currentTarget instanceof HTMLElement)) {
......
......@@ -21,6 +21,13 @@ describe('compiler: transform v-slot', () => {
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view slot="d">test</view></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<custom><view>test</view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view slot="d">test</view></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
})
......
......@@ -127,11 +127,11 @@ export const transformSlot: NodeTransform = (node, context) => {
// <custom>test</custom> => <custom><template #default>test</template></custom>
const vSlotDir = createDirectiveNode('slot', 'default')
const child = implicitDefaultChildren[0] as ElementNode
const isSingleElementNode =
const isSingleComponent =
implicitDefaultChildren.length === 1 &&
child.type === NodeTypes.ELEMENT &&
isUserComponent(child, context) &&
!findDir(child, 'for')
if (isSingleElementNode) {
if (isSingleComponent) {
child.props.unshift(vSlotDir)
} else {
const templateNode = createTemplateNode(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册