From 89c5909a6f063dddcdf61650a6ed08f8be138521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=9C=C9=B4=D0=B2=CA=8F=D1=82=E1=B4=87?= Date: Thu, 8 Oct 2020 08:57:17 +0800 Subject: [PATCH] fix(compiler-core): allow spaces between if-else branches (#2305) fix #2299 --- .../__tests__/transforms/vIf.spec.ts | 21 +++++++++++++++++++ packages/compiler-core/src/transforms/vIf.ts | 10 +++++++++ 2 files changed, 31 insertions(+) diff --git a/packages/compiler-core/__tests__/transforms/vIf.spec.ts b/packages/compiler-core/__tests__/transforms/vIf.spec.ts index 315497a590c..a21ab1f019b 100644 --- a/packages/compiler-core/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vIf.spec.ts @@ -606,6 +606,27 @@ describe('compiler: v-if', () => { expect(branch1.props).toMatchObject(createObjectMatcher({ key: `[0]` })) }) + test('with spaces between branches', () => { + const { + node: { codegenNode } + } = parseWithIfTransform( + `
` + ) + expect(codegenNode.consequent).toMatchObject({ + tag: `"div"`, + props: createObjectMatcher({ key: `[0]` }) + }) + const branch = codegenNode.alternate as ConditionalExpression + expect(branch.consequent).toMatchObject({ + tag: `"div"`, + props: createObjectMatcher({ key: `[1]` }) + }) + expect(branch.alternate).toMatchObject({ + tag: `"div"`, + props: createObjectMatcher({ key: `[2]` }) + }) + }) + test('with comments', () => { const { node } = parseWithIfTransform(`