Skip to content

Commit

Permalink
chore: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 authored and haoqunjiang committed Feb 10, 2023
1 parent 5272bc1 commit 7ed4bfe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/compiler-ssr/__tests__/ssrVModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ describe('ssr: v-model', () => {
`<select v-model="model"><option value="1"></option></select>`
).code
).toMatchInlineSnapshot(`
"const { ssrLooseContain: _ssrLooseContain, ssrIncludeBooleanAttr: _ssrIncludeBooleanAttr, ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
"const { ssrLooseContain: _ssrLooseContain, ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
return function ssrRender(_ctx, _push, _parent, _attrs) {
_push(\`<div\${
_ssrRenderAttrs(_attrs)
}><select><option value="1"\${
((Array.isArray(_ctx.model))
? _ssrLooseContain(_ctx.model, "1")
: _ssrIncludeBooleanAttr(_ssrLooseEqual(_ctx.model, "1"))) ? " selected" : ""
: _ssrLooseEqual(_ctx.model, "1")) ? " selected" : ""
}></option></select></div>\`)
}"
`)
Expand All @@ -57,15 +57,15 @@ describe('ssr: v-model', () => {
`<select multiple v-model="model"><option value="1" selected></option><option value="2"></option></select>`
).code
).toMatchInlineSnapshot(`
"const { ssrLooseContain: _ssrLooseContain, ssrIncludeBooleanAttr: _ssrIncludeBooleanAttr, ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
"const { ssrLooseContain: _ssrLooseContain, ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
return function ssrRender(_ctx, _push, _parent, _attrs) {
_push(\`<div\${
_ssrRenderAttrs(_attrs)
}><select multiple><option value="1" selected></option><option value="2"\${
((Array.isArray(_ctx.model))
? _ssrLooseContain(_ctx.model, "2")
: _ssrIncludeBooleanAttr(_ssrLooseEqual(_ctx.model, "2"))) ? " selected" : ""
: _ssrLooseEqual(_ctx.model, "2")) ? " selected" : ""
}></option></select></div>\`)
}"
`)
Expand Down
16 changes: 5 additions & 11 deletions packages/compiler-ssr/src/transforms/ssrVModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
import {
SSR_LOOSE_EQUAL,
SSR_LOOSE_CONTAIN,
SSR_RENDER_DYNAMIC_MODEL,
SSR_INCLUDE_BOOLEAN_ATTR
SSR_RENDER_DYNAMIC_MODEL
} from '../runtimeHelpers'
import { DirectiveTransformResult } from 'packages/compiler-core/src/transform'

Expand Down Expand Up @@ -143,15 +142,10 @@ export const ssrTransformModel: DirectiveTransform = (dir, node, context) => {
model,
value
]),
createCallExpression(
context.helper(SSR_INCLUDE_BOOLEAN_ATTR),
[
createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
model,
value
])
]
)
createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
model,
value
])
),
createSimpleExpression(' selected', true),
createSimpleExpression('', true),
Expand Down

0 comments on commit 7ed4bfe

Please sign in to comment.