diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/vSkip.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/vSkip.spec.ts.snap index 113926c9b4b..bb7cdf978f4 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/vSkip.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/vSkip.spec.ts.snap @@ -192,6 +192,20 @@ return function render(_ctx, _cache) { }" `; +exports[`compiler: v-skip > transform > v-skip with key 1`] = ` +"const _Vue = Vue + +return function render(_ctx, _cache) { + with (_ctx) { + const { createCommentVNode: _createCommentVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue + + return (_ctx.nested) + ? _createCommentVNode("v-skip", true) + : (_openBlock(), _createElementBlock("div", { key: "foo" })) + } +}" +`; + exports[`compiler: v-skip > transform > with component children 1`] = ` "const _Vue = Vue diff --git a/packages/compiler-core/__tests__/transforms/vSkip.spec.ts b/packages/compiler-core/__tests__/transforms/vSkip.spec.ts index 15572cb9e1f..d1251ffeeeb 100644 --- a/packages/compiler-core/__tests__/transforms/vSkip.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vSkip.spec.ts @@ -2,6 +2,7 @@ import { type CompilerOptions, type ElementNode, ElementTypes, + ErrorCodes, type IfBranchNode, type IfNode, NodeTypes, @@ -190,6 +191,28 @@ describe('compiler: v-skip', () => { expect(generate(root).code).toMatchSnapshot() }) + test('v-skip with key', () => { + const { root, node } = parseWithSkipTransform( + `
`, + ) + expect(node.type).toBe(NodeTypes.SKIP) + expect((node.test as SimpleExpressionNode).content).toBe(`_ctx.nested`) + expect(node.consequent.type === NodeTypes.JS_CALL_EXPRESSION).toBe(true) + expect(node.alternate.children.length).toBe(1) + expect(node.alternate.children[0].type).toBe(NodeTypes.ELEMENT) + expect((node.alternate.children[0] as ElementNode).tag).toBe(`div`) + expect( + (node.alternate.children[0] as ElementNode).props[0], + ).toMatchObject({ + name: 'key', + type: NodeTypes.ATTRIBUTE, + value: { + content: 'foo', + }, + }) + expect(generate(root).code).toMatchSnapshot() + }) + test('v-else + v-skip', () => { const { root, node } = parseWithSkipTransform( ``, @@ -338,5 +361,63 @@ describe('compiler: v-skip', () => { }) }) - describe.todo('errors', () => {}) + describe('errors', () => { + test('no expression', () => { + const onError = vi.fn() + const { node } = parseWithSkipTransform(``, { onError }) + expect(onError.mock.calls[0]).toMatchObject([ + { + code: ErrorCodes.X_V_SKIP_NO_EXPRESSION, + loc: node.loc, + }, + ]) + }) + + test('on