提交 9f22b637 编写于 作者: Q qiang

fix(App): slot name dynamic data (question/95109)

上级 dd5a4988
...@@ -178,6 +178,10 @@ describe('codegen', () => { ...@@ -178,6 +178,10 @@ describe('codegen', () => {
'<div><slot name="one"></slot></div>', '<div><slot name="one"></slot></div>',
`with(this){return _c('div',[_t("one",null,{"_i":1})],2)}` `with(this){return _c('div',[_t("one",null,{"_i":1})],2)}`
) )
assertCodegen(
'<div><slot :name="one"></slot></div>',
`with(this){return _c('div',[_t(_$s(1,'name',one),null,{"_i":1})],2)}`
)
}) })
it('generate slot fallback content', () => { it('generate slot fallback content', () => {
......
...@@ -178,6 +178,10 @@ describe('codegen', () => { ...@@ -178,6 +178,10 @@ describe('codegen', () => {
'<div><slot name="one"></slot></div>', '<div><slot name="one"></slot></div>',
`with(this){return _c('div',{attrs:{"_i":0}},[_t("one",null,{"_i":1})],2)}` `with(this){return _c('div',{attrs:{"_i":0}},[_t("one",null,{"_i":1})],2)}`
) )
assertCodegen(
'<div><slot :name="one"></slot></div>',
`with(this){return _c('div',{attrs:{"_i":0}},[_t(_$g(1,'name'),null,{"_i":1})],2)}`
)
}) })
it('generate slot fallback content', () => { it('generate slot fallback content', () => {
......
...@@ -2,6 +2,7 @@ const { ...@@ -2,6 +2,7 @@ const {
ID, ID,
C_IS, C_IS,
C_REF, C_REF,
C_NAME,
V_IF, V_IF,
V_FOR, V_FOR,
V_ELSE_IF, V_ELSE_IF,
...@@ -16,6 +17,12 @@ function parseRef (el, genVar) { ...@@ -16,6 +17,12 @@ function parseRef (el, genVar) {
} }
} }
function parseSlotName (el, genVar) {
if (el.slotName && isVar(el.slotName)) {
el.slotName = genVar(C_NAME, el.slotName)
}
}
function parseIs (el, genVar) { function parseIs (el, genVar) {
if (!el.component) { if (!el.component) {
return return
...@@ -106,6 +113,7 @@ function parseText (el, parent, state) { ...@@ -106,6 +113,7 @@ function parseText (el, parent, state) {
module.exports = { module.exports = {
parseIs, parseIs,
parseRef, parseRef,
parseSlotName,
parseIf, parseIf,
parseFor, parseFor,
parseText, parseText,
......
...@@ -18,6 +18,7 @@ const { ...@@ -18,6 +18,7 @@ const {
const { const {
parseIs, parseIs,
parseRef, parseRef,
parseSlotName,
parseIf, parseIf,
parseFor, parseFor,
parseText, parseText,
...@@ -137,6 +138,7 @@ function transformNode (el, parent, state, isScopedSlot) { ...@@ -137,6 +138,7 @@ function transformNode (el, parent, state, isScopedSlot) {
parseIs(el, genVar) parseIs(el, genVar)
parseRef(el, genVar) parseRef(el, genVar)
parseSlotName(el, genVar)
parseFor(el, createGenVar, isScopedSlot, checkAutoFill(el)) parseFor(el, createGenVar, isScopedSlot, checkAutoFill(el))
parseKey(el, isScopedSlot) parseKey(el, isScopedSlot)
......
...@@ -15,6 +15,7 @@ const GET_CHANGE_DATA = '_$gc' // wxs ...@@ -15,6 +15,7 @@ const GET_CHANGE_DATA = '_$gc' // wxs
const C_IS = 'is' const C_IS = 'is'
const C_SLOT_TARGET = 'st' const C_SLOT_TARGET = 'st'
const C_REF = 'ref' const C_REF = 'ref'
const C_NAME = 'name'
const V_FOR = 'f' const V_FOR = 'f'
const V_IF = 'i' const V_IF = 'i'
...@@ -268,6 +269,7 @@ function addHandler (el, name, value, important) { ...@@ -268,6 +269,7 @@ function addHandler (el, name, value, important) {
module.exports = { module.exports = {
C_IS, C_IS,
C_REF, C_REF,
C_NAME,
V_FOR, V_FOR,
V_IF, V_IF,
V_ELSE_IF, V_ELSE_IF,
......
...@@ -13,6 +13,7 @@ const { ...@@ -13,6 +13,7 @@ const {
const { const {
parseIs, parseIs,
parseRef, parseRef,
parseSlotName,
parseIf, parseIf,
parseFor, parseFor,
parseText, parseText,
...@@ -130,6 +131,7 @@ function transformNode (el, parent, state, isScopedSlot) { ...@@ -130,6 +131,7 @@ function transformNode (el, parent, state, isScopedSlot) {
parseIs(el, genVar) parseIs(el, genVar)
parseRef(el, genVar) parseRef(el, genVar)
parseSlotName(el, genVar)
if (parseFor(el, createGenVar, isScopedSlot)) { if (parseFor(el, createGenVar, isScopedSlot)) {
if (el.alias[0] === '{') { // <div><li v-for=" { a, b } in items"></li></div> if (el.alias[0] === '{') { // <div><li v-for=" { a, b } in items"></li></div>
el.alias = '$item' el.alias = '$item'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册