* Runtime helper for resolving raw children VNodes into a slot object.
( children, context )
| 1935 | * Runtime helper for resolving raw children VNodes into a slot object. |
| 1936 | */ |
| 1937 | function resolveSlots ( |
| 1938 | children, |
| 1939 | context |
| 1940 | ) { |
| 1941 | var slots = {}; |
| 1942 | if (!children) { |
| 1943 | return slots |
| 1944 | } |
| 1945 | var defaultSlot = []; |
| 1946 | var name, child; |
| 1947 | for (var i = 0, l = children.length; i < l; i++) { |
| 1948 | child = children[i]; |
| 1949 | // named slots should only be respected if the vnode was rendered in the |
| 1950 | // same context. |
| 1951 | if ((child.context === context || child.functionalContext === context) && |
| 1952 | child.data && (name = child.data.slot)) { |
| 1953 | var slot = (slots[name] || (slots[name] = [])); |
| 1954 | if (child.tag === 'template') { |
| 1955 | slot.push.apply(slot, child.children); |
| 1956 | } else { |
| 1957 | slot.push(child); |
| 1958 | } |
| 1959 | } else { |
| 1960 | defaultSlot.push(child); |
| 1961 | } |
| 1962 | } |
| 1963 | // ignore whitespace |
| 1964 | if (!defaultSlot.every(isWhitespace)) { |
| 1965 | slots.default = defaultSlot; |
| 1966 | } |
| 1967 | return slots |
| 1968 | } |
| 1969 | |
| 1970 | function isWhitespace (node) { |
| 1971 | return node.isComment || node.text === ' ' |
no outgoing calls
no test coverage detected