}"
`;
+exports[`compiler: transform component slots > template named v-if/else and whitespace preserve 1`] = `
+"const { toDisplayString: _toDisplayString, createTextVNode: _createTextVNode, resolveComponent: _resolveComponent, withCtx: _withCtx, createSlots: _createSlots, openBlock: _openBlock, createBlock: _createBlock } = Vue
+
+return function render(_ctx, _cache) {
+ const _component_Comp = _resolveComponent(\\"Comp\\")
+
+ return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 2 /* DYNAMIC */ }, [
+ true
+ ? {
+ name: \\"one\\",
+ fn: _withCtx(() => [
+ _createTextVNode(_toDisplayString(_ctx.foo) + _toDisplayString(_ctx.bar), 1 /* TEXT */)
+ ]),
+ key: \\"0\\"
+ }
+ : true
+ ? {
+ name: \\"one\\",
+ fn: _withCtx(() => [
+ _createTextVNode(_toDisplayString(_ctx.foo) + _toDisplayString(_ctx.bar), 1 /* TEXT */)
+ ]),
+ key: \\"1\\"
+ }
+ : undefined
+ ]), 1024 /* DYNAMIC_SLOTS */))
+}"
+`;
+
exports[`compiler: transform component slots > with whitespace: 'preserve' > implicit default slot 1`] = `
"const { createElementVNode: _createElementVNode, resolveComponent: _resolveComponent, withCtx: _withCtx, openBlock: _openBlock, createBlock: _createBlock } = Vue
import { PatchFlags } from '@vue/shared'
import { transformFor } from '../../src/transforms/vFor'
import { transformIf } from '../../src/transforms/vIf'
+import { transformText } from '../../src/transforms/transformText'
-function parseWithSlots(template: string, options: CompilerOptions = {}) {
+function parseWithSlots(
+ template: string,
+ options: CompilerOptions & {
+ appendNodeTransforms?: CompilerOptions['nodeTransforms']
+ } = {}
+) {
const ast = parse(template, {
whitespace: options.whitespace
})
: []),
transformSlotOutlet,
transformElement,
- trackSlotScopes
+ trackSlotScopes,
+ ...(options.appendNodeTransforms ?? [])
],
directiveTransforms: {
on: transformOn,
expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot()
})
+ // #6063 should not throw error
+ test('template named v-if/else and whitespace preserve', () => {
+ const { root } = parseWithSlots(
+ `<Comp>
+ <template v-if="true" #one>
+ {{ foo }}{{ bar }}
+ </template>
+ <template v-else="true" #one>
+ {{ foo }}{{ bar }}
+ </template>
+ </Comp>`,
+ {
+ whitespace: 'preserve',
+ prefixIdentifiers: true,
+ appendNodeTransforms: [transformText]
+ }
+ )
+
+ expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot()
+ })
+
test('on component dynamically named slot', () => {
const { root, slots } = parseWithSlots(
`<Comp v-slot:[named]="{ foo }">{{ foo }}{{ bar }}</Comp>`,