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

feat(v3): Dynamic Slot Names

上级 70b4f9da
...@@ -147,5 +147,11 @@ describe('codegen', () => { ...@@ -147,5 +147,11 @@ describe('codegen', () => {
`with(this){return (_$s(0,'i',a))?_c('text'):(_$s(1,'e',b))?_c('text'):(_$s(2,'e',c))?_c('text'):_c('text')}` `with(this){return (_$s(0,'i',a))?_c('text'):(_$s(1,'e',b))?_c('text'):(_$s(2,'e',c))?_c('text'):_c('text')}`
) )
}) })
it('generate dynamic slot', () => {
assertCodegen(
'<base-layout><template v-slot:[dynamicSlotName]></template></base-layout>',
`with(this){return _c('base-layout',{attrs:{"_i":0},scopedSlots:_u([{key:_$s(1,'st',dynamicSlotName),fn:function(_empty_, _svm, _si){return undefined}}],null,true)})}`
)
})
}) })
/* eslint-enable quotes */ /* eslint-enable quotes */
...@@ -88,5 +88,11 @@ describe('codegen', () => { ...@@ -88,5 +88,11 @@ describe('codegen', () => {
`with(this){return (_$g(0,'i'))?_c('v-uni-text',{attrs:{"_i":0}},[_v("1")]):(_$g(1,'e'))?_c('v-uni-text',{attrs:{"_i":1}},[_v("2")]):(_$g(2,'e'))?_c('v-uni-text',{attrs:{"_i":2}},[_v("3")]):_c('v-uni-text',{attrs:{"_i":3}},[_v("d")])}` `with(this){return (_$g(0,'i'))?_c('v-uni-text',{attrs:{"_i":0}},[_v("1")]):(_$g(1,'e'))?_c('v-uni-text',{attrs:{"_i":1}},[_v("2")]):(_$g(2,'e'))?_c('v-uni-text',{attrs:{"_i":2}},[_v("3")]):_c('v-uni-text',{attrs:{"_i":3}},[_v("d")])}`
) )
}) })
it('generate dynamic slot', () => {
assertCodegen(
'<base-layout><template v-slot:[dynamicSlotName]></template></base-layout>',
`with(this){return _c('base-layout',{attrs:{"_i":0},scopedSlots:_u([{key:_$g(1,'st'),fn:function(_empty_, _svm, _si){return undefined}}],null,true)})}`
)
})
}) })
/* eslint-enable quotes */ /* eslint-enable quotes */
...@@ -19,7 +19,7 @@ const scopedPath = path.resolve(__dirname, '../../') ...@@ -19,7 +19,7 @@ const scopedPath = path.resolve(__dirname, '../../')
const compiler = require('../lib') const compiler = require('../lib')
const res = compiler.compile( const res = compiler.compile(
` `
<view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view> <base-layout><template v-slot:[dynamicSlotName]></template></base-layout>
`, { `, {
miniprogram: true, miniprogram: true,
resourcePath: '/User/fxy/Documents/test.wxml', resourcePath: '/User/fxy/Documents/test.wxml',
......
...@@ -163,6 +163,7 @@ function postTransformNode (el, options) { ...@@ -163,6 +163,7 @@ function postTransformNode (el, options) {
options.root = el options.root = el
} }
traverseNode(el, false, { traverseNode(el, false, {
createGenVar,
forIteratorId: 0, forIteratorId: 0,
transformNode, transformNode,
filterModules: options.filterModules filterModules: options.filterModules
......
...@@ -207,6 +207,9 @@ function traverseNode (el, parent, state, isScopedSlot) { ...@@ -207,6 +207,9 @@ function traverseNode (el, parent, state, isScopedSlot) {
el.scopedSlots && Object.values(el.scopedSlots).forEach((slot, index) => { el.scopedSlots && Object.values(el.scopedSlots).forEach((slot, index) => {
state.childIndex = index state.childIndex = index
slot.slotScope = `${slot.slotScope}, _svm, _si` slot.slotScope = `${slot.slotScope}, _svm, _si`
if (slot.slotTargetDynamic && slot.slotTarget) {
slot.slotTarget = state.createGenVar(slot.attrsMap[ID])('st', slot.slotTarget)
}
traverseNode(slot, el, state, true) traverseNode(slot, el, state, true)
}) })
} }
......
...@@ -162,6 +162,7 @@ function postTransformNode (el, options) { ...@@ -162,6 +162,7 @@ function postTransformNode (el, options) {
options.root = el options.root = el
} }
traverseNode(el, false, { traverseNode(el, false, {
createGenVar,
forIteratorId: 0, forIteratorId: 0,
transformNode, transformNode,
filterModules: options.filterModules filterModules: options.filterModules
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册