From 42d8090f5ee88586a943bb4e0363c094169dbb54 Mon Sep 17 00:00:00 2001 From: daiwei Date: Tue, 3 Jan 2023 09:02:55 +0800 Subject: [PATCH] chore: improve code --- .../compiler-ssr/__tests__/ssrVModel.spec.ts | 12 ++++----- .../compiler-ssr/src/transforms/ssrVModel.ts | 27 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/packages/compiler-ssr/__tests__/ssrVModel.spec.ts b/packages/compiler-ssr/__tests__/ssrVModel.spec.ts index 421dc981ff9..a77ffacb82e 100644 --- a/packages/compiler-ssr/__tests__/ssrVModel.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrVModel.spec.ts @@ -39,15 +39,15 @@ describe('ssr: v-model', () => { `` ).code ).toMatchInlineSnapshot(` - "const { ssrLooseContain: _ssrLooseContain, ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer") + "const { ssrIncludeBooleanAttr: _ssrIncludeBooleanAttr, ssrLooseContain: _ssrLooseContain, ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) }" `) @@ -57,15 +57,15 @@ describe('ssr: v-model', () => { `` ).code ).toMatchInlineSnapshot(` - "const { ssrLooseContain: _ssrLooseContain, ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer") + "const { ssrIncludeBooleanAttr: _ssrIncludeBooleanAttr, ssrLooseContain: _ssrLooseContain, ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) }" `) diff --git a/packages/compiler-ssr/src/transforms/ssrVModel.ts b/packages/compiler-ssr/src/transforms/ssrVModel.ts index 483837ef2ee..bd587edcb9c 100644 --- a/packages/compiler-ssr/src/transforms/ssrVModel.ts +++ b/packages/compiler-ssr/src/transforms/ssrVModel.ts @@ -18,7 +18,8 @@ import { import { SSR_LOOSE_EQUAL, SSR_LOOSE_CONTAIN, - SSR_RENDER_DYNAMIC_MODEL + SSR_RENDER_DYNAMIC_MODEL, + SSR_INCLUDE_BOOLEAN_ATTR } from '../runtimeHelpers' import { DirectiveTransformResult } from 'packages/compiler-core/src/transform' @@ -136,17 +137,19 @@ export const ssrTransformModel: DirectiveTransform = (dir, node, context) => { const value = findValueBinding(plainNode) plainNode.ssrCodegenNode!.elements.push( createConditionalExpression( - createConditionalExpression( - createCallExpression(`Array.isArray`, [model]), - createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [ - model, - value - ]), - createCallExpression(context.helper(SSR_LOOSE_EQUAL), [ - model, - value - ]) - ), + createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [ + createConditionalExpression( + createCallExpression(`Array.isArray`, [model]), + createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [ + model, + value + ]), + createCallExpression(context.helper(SSR_LOOSE_EQUAL), [ + model, + value + ]) + ) + ]), createSimpleExpression(' selected', true), createSimpleExpression('', true), false /* no newline */