From 3df3f05286fc28dd65eadcd9b5328e0db82bce9f Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 17 Nov 2021 18:35:00 +0800 Subject: [PATCH] fix(mp): v-else --- packages/uni-mp-compiler/__tests__/test.ts | 2 +- packages/uni-mp-compiler/__tests__/vIf.spec.ts | 10 ++++++++++ packages/uni-mp-compiler/src/transform.ts | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/uni-mp-compiler/__tests__/test.ts b/packages/uni-mp-compiler/__tests__/test.ts index 070f67a3da..0402c5e0a5 100644 --- a/packages/uni-mp-compiler/__tests__/test.ts +++ b/packages/uni-mp-compiler/__tests__/test.ts @@ -36,7 +36,7 @@ function assert( } assert( - ``, + ``, ``, `(_ctx, _cache) => { return { a: _f(_ctx.items, (item, index, i0) => { return { a: _r(\"default\", { key: index }) }; }) } diff --git a/packages/uni-mp-compiler/__tests__/vIf.spec.ts b/packages/uni-mp-compiler/__tests__/vIf.spec.ts index a65cecd083..53547f4bd4 100644 --- a/packages/uni-mp-compiler/__tests__/vIf.spec.ts +++ b/packages/uni-mp-compiler/__tests__/vIf.spec.ts @@ -175,6 +175,16 @@ describe(`compiler: v-if`, () => { test(`v-on with v-if`, () => { // }) + + test(`v-for + v-if + v-else`, () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _f(_ctx.items, (item, k0, i0) => { return _ctx.ok ? { a: '2a9ec0b0-0' + '-' + i0 } : { b: item.title, c: '2a9ec0b0-1' + '-' + i0 }; }), b: _ctx.ok } +}` + ) + }) }) describe('errors', () => { diff --git a/packages/uni-mp-compiler/src/transform.ts b/packages/uni-mp-compiler/src/transform.ts index 94523b76bf..ba896bafaf 100644 --- a/packages/uni-mp-compiler/src/transform.ts +++ b/packages/uni-mp-compiler/src/transform.ts @@ -126,7 +126,10 @@ export function isRootScope(scope: CodegenScope): scope is CodegenRootScope { } export function isVIfScope(scope: CodegenScope): scope is CodegenVIfScope { - return !!(scope as CodegenVIfScope).condition + return ( + !!(scope as CodegenVIfScope).condition || + (scope as CodegenVIfScope).name === 'else' + ) } export function isVForScope(scope: CodegenScope): scope is CodegenVForScope { -- GitLab