|
|
@@ -509,4 +509,60 @@ describe('compiler: transform slot', () => {
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ describe(`with whitespace: 'preserve'`, () => {
|
|
|
+ test('named default slot + implicit whitespace content', () => {
|
|
|
+ const source = `
|
|
|
+ <Comp>
|
|
|
+ <template #header> Header </template>
|
|
|
+ <template #default> Default </template>
|
|
|
+ </Comp>
|
|
|
+ `
|
|
|
+ const { code } = compileWithSlots(source, {
|
|
|
+ whitespace: 'preserve',
|
|
|
+ })
|
|
|
+
|
|
|
+ expect(
|
|
|
+ `Extraneous children found when component already has explicitly named default slot.`,
|
|
|
+ ).not.toHaveBeenWarned()
|
|
|
+ expect(code).toMatchSnapshot()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('implicit default slot', () => {
|
|
|
+ const source = `
|
|
|
+ <Comp>
|
|
|
+ <template #header> Header </template>
|
|
|
+ <p/>
|
|
|
+ </Comp>
|
|
|
+ `
|
|
|
+ const { code } = compileWithSlots(source, {
|
|
|
+ whitespace: 'preserve',
|
|
|
+ })
|
|
|
+
|
|
|
+ expect(
|
|
|
+ `Extraneous children found when component already has explicitly named default slot.`,
|
|
|
+ ).not.toHaveBeenWarned()
|
|
|
+ expect(code).toMatchSnapshot()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('should not generate whitespace only default slot', () => {
|
|
|
+ const source = `
|
|
|
+ <Comp>
|
|
|
+ <template #header> Header </template>
|
|
|
+ <template #footer> Footer </template>
|
|
|
+ </Comp>
|
|
|
+ `
|
|
|
+ const { code, ir } = compileWithSlots(source, {
|
|
|
+ whitespace: 'preserve',
|
|
|
+ })
|
|
|
+
|
|
|
+ const slots = (ir.block.dynamic.children[0].operation as any).slots[0]
|
|
|
+ .slots
|
|
|
+ // should be: header, footer (no default)
|
|
|
+ expect(Object.keys(slots).length).toBe(2)
|
|
|
+ expect(!!slots['default']).toBe(false)
|
|
|
+
|
|
|
+ expect(code).toMatchSnapshot()
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|