|
1 | 1 | import {
|
| 2 | + IRNodeTypes, |
2 | 3 | transformChildren,
|
3 | 4 | transformElement,
|
4 | 5 | transformSlotOutlet,
|
@@ -29,17 +30,63 @@ const compileWithSlots = makeCompile({
|
29 | 30 |
|
30 | 31 | describe('compiler: transform slot', () => {
|
31 | 32 | test('implicit default slot', () => {
|
32 |
| - const { code } = compileWithSlots(`<Comp><div/></Comp>`) |
| 33 | + const { ir, code } = compileWithSlots(`<Comp><div/></Comp>`) |
33 | 34 | expect(code).toMatchSnapshot()
|
| 35 | + |
| 36 | + expect(ir.template).toEqual(['<div></div>']) |
| 37 | + expect(ir.block.operation).toMatchObject([ |
| 38 | + { |
| 39 | + type: IRNodeTypes.CREATE_COMPONENT_NODE, |
| 40 | + id: 1, |
| 41 | + tag: 'Comp', |
| 42 | + props: [[]], |
| 43 | + slots: { |
| 44 | + default: { |
| 45 | + type: IRNodeTypes.BLOCK, |
| 46 | + dynamic: { |
| 47 | + children: [{ template: 0 }], |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + ]) |
| 53 | + expect(ir.block.returns).toEqual([1]) |
| 54 | + expect(ir.block.dynamic).toMatchObject({ |
| 55 | + children: [{ id: 1 }], |
| 56 | + }) |
34 | 57 | })
|
35 | 58 |
|
36 | 59 | test('named slots w/ implicit default slot', () => {
|
37 |
| - const { code } = compileWithSlots( |
| 60 | + const { ir, code } = compileWithSlots( |
38 | 61 | `<Comp>
|
39 | 62 | <template #one>foo</template>bar<span/>
|
40 | 63 | </Comp>`,
|
41 | 64 | )
|
42 | 65 | expect(code).toMatchSnapshot()
|
| 66 | + |
| 67 | + expect(ir.template).toEqual(['foo', 'bar', '<span></span>']) |
| 68 | + expect(ir.block.operation).toMatchObject([ |
| 69 | + { |
| 70 | + type: IRNodeTypes.CREATE_COMPONENT_NODE, |
| 71 | + id: 4, |
| 72 | + tag: 'Comp', |
| 73 | + props: [[]], |
| 74 | + slots: { |
| 75 | + one: { |
| 76 | + type: IRNodeTypes.BLOCK, |
| 77 | + dynamic: { |
| 78 | + children: [{ template: 0 }], |
| 79 | + }, |
| 80 | + }, |
| 81 | + default: { |
| 82 | + type: IRNodeTypes.BLOCK, |
| 83 | + dynamic: { |
| 84 | + children: [{}, { template: 1 }, { template: 2 }], |
| 85 | + }, |
| 86 | + }, |
| 87 | + }, |
| 88 | + }, |
| 89 | + ]) |
43 | 90 | })
|
44 | 91 |
|
45 | 92 | test('nested slots', () => {
|
|
0 commit comments