Skip to content

Commit 1a35cf4

Browse files
committed
support template slot
1 parent e9ae818 commit 1a35cf4

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

Diff for: src/compiler/codegen/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { genDirectives } from './directives/index'
33

44
export function generate (ast) {
55
const code = ast ? genElement(ast) : '__h__("div")'
6-
console.log(code)
76
return `with (this) { return ${code}}`
87
}
98

@@ -12,7 +11,7 @@ function genElement (el) {
1211
return genFor(el)
1312
} else if (el.if) {
1413
return genIf(el)
15-
} else if (el.tag === 'template') {
14+
} else if (el.tag === 'template' && !el.attrsMap.slot) {
1615
return genChildren(el)
1716
} else if (el.tag === 'render') {
1817
return genRender(el)

Diff for: src/compiler/parser/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function parse (template, preserveWhitespace) {
8282
'Component template should contain exactly one root element:\n\n' + template
8383
)
8484
}
85-
if (currentParent) {
85+
if (currentParent && tag !== 'script') {
8686
currentParent.children.push(element)
8787
}
8888
if (!unary) {
@@ -91,7 +91,7 @@ export function parse (template, preserveWhitespace) {
9191
}
9292
},
9393

94-
end () {
94+
end (tag) {
9595
// remove trailing whitespace
9696
const element = stack[stack.length - 1]
9797
const lastNode = element.children[element.children.length - 1]

Diff for: src/runtime/instance/render.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ export function initRender (vm) {
1919

2020
function resolveSlots (vm, children) {
2121
if (children) {
22+
children = children.slice()
2223
const slots = { default: children }
2324
let i = children.length
2425
let name, child
2526
while (i--) {
2627
child = children[i]
2728
if ((name = child.data && child.data.slot)) {
28-
(slots[name] || (slots[name] = [])).push(child)
29+
let slot = (slots[name] || (slots[name] = []))
30+
if (child.tag === 'template') {
31+
slot.push.apply(slot, child.children)
32+
} else {
33+
slot.push(child)
34+
}
2935
children.splice(i, 1)
3036
}
3137
}
@@ -123,7 +129,6 @@ export function renderMixin (Vue) {
123129
mergeParentDirectives(this, data, _renderData)
124130
updateParentCallbacks(this, data, _renderData)
125131
}
126-
console.log(vnode)
127132
return vnode
128133
}
129134

Diff for: src/runtime/vdom/component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function Component (Ctor, data, parent, children) {
77
// return a placeholder vnode
88
const key = data && data.key
99
return {
10-
sel: 'component',
10+
tag: 'component',
1111
key,
1212
data: {
1313
hook: { init, prepatch, destroy },

Diff for: src/runtime/vdom/patch.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function isDef (s) {
1515
}
1616

1717
function sameVnode (vnode1, vnode2) {
18-
return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel
18+
return vnode1.key === vnode2.key && vnode1.tag === vnode2.tag
1919
}
2020

2121
function getElm (vnode) {
@@ -68,7 +68,7 @@ export default function createPatchFunction (modules, api) {
6868
}
6969
}
7070
const children = vnode.children
71-
const tag = vnode.sel
71+
const tag = vnode.tag
7272
if (isDef(tag)) {
7373
elm = vnode.elm = isDef(data) && data.svg
7474
? api.createElementNS(svgNS, tag)
@@ -118,7 +118,7 @@ export default function createPatchFunction (modules, api) {
118118
let i, listeners, rm
119119
const ch = vnodes[startIdx]
120120
if (isDef(ch)) {
121-
if (isDef(ch.sel)) {
121+
if (isDef(ch.tag)) {
122122
invokeDestroyHook(ch)
123123
listeners = cbs.remove.length + 1
124124
rm = createRmCb(getElm(ch), listeners)
@@ -245,7 +245,7 @@ export default function createPatchFunction (modules, api) {
245245
if (!oldVnode) {
246246
createElm(vnode, insertedVnodeQueue)
247247
} else {
248-
if (isUndef(oldVnode.sel)) {
248+
if (isUndef(oldVnode.tag)) {
249249
oldVnode = emptyNodeAt(oldVnode)
250250
}
251251

Diff for: src/runtime/vdom/vnode.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export default function VNode (sel, data, children, text, elm) {
2-
return { sel, data, children, text, elm, key: data && data.key }
1+
export default function VNode (tag, data, children, text, elm) {
2+
return { tag, data, children, text, elm, key: data && data.key }
33
}

0 commit comments

Comments
 (0)