提交 aa4d0951 编写于 作者: Q qiang

fix(mp): scopedSlotsCompiler-auto ignore event (question/127859,127297)

上级 9a603b05
......@@ -97,6 +97,14 @@ describe('mp:compiler-mp-weixin', () => {
scopedSlotsCompiler: 'auto'
}
)
assertCodegen(
'<my-component><template v-slot="{item}"><view @click="getValue(item)">{{item}}</view><template></my-component>',
'<my-component generic:scoped-slots-default="test-my-component-default" data-vue-generic="scoped" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"></my-component>',
'with(this){}',
{
scopedSlotsCompiler: 'auto'
}
)
assertCodegen(
'<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>',
'<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>',
......
......@@ -2,17 +2,27 @@ const t = require('@babel/types')
const {
METHOD_BUILT_IN,
METHOD_CREATE_EMPTY_VNODE
METHOD_CREATE_EMPTY_VNODE,
METHOD_CREATE_ELEMENT
} = require('../../constants')
function needSlotMode (path, ids) {
let need
path.traverse({
noScope: false,
Property (path) {
// 跳过事件
if (path.node.key.name === 'on') {
const parentPath = path.parentPath.parentPath
if (t.isCallExpression(parentPath) && parentPath.node.callee.name === METHOD_CREATE_ELEMENT) {
path.skip()
}
}
},
Identifier (path) {
const name = path.node.name
if (path.key !== 'key' && (path.key !== 'property' || path.parent.computed)) {
// 使用方法或作用域外数据
// 使用作用域内方法或作用域外数据
if (name in ids) {
need = path.key === 'callee' ? true : need
} else if (!path.scope.hasBinding(name) && !METHOD_BUILT_IN.includes(name)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册