Skip to content

Commit 3b40fc5

Browse files
committed
fix(compiler-ssr): fix input w/ v-bind="obj" codegen
1 parent 9eef37f commit 3b40fc5

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

packages/compiler-core/src/ast.ts

+18
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const enum NodeTypes {
5252
JS_TEMPLATE_LITERAL,
5353
JS_IF_STATEMENT,
5454
JS_ASSIGNMENT_EXPRESSION,
55+
JS_SEQUENCE_EXPRESSION,
5556
JS_RETURN_STATEMENT
5657
}
5758

@@ -282,6 +283,7 @@ export type JSChildNode =
282283
| ConditionalExpression
283284
| CacheExpression
284285
| AssignmentExpression
286+
| SequenceExpression
285287

286288
export interface CallExpression extends Node {
287289
type: NodeTypes.JS_CALL_EXPRESSION
@@ -344,6 +346,7 @@ export type SSRCodegenNode =
344346
| IfStatement
345347
| AssignmentExpression
346348
| ReturnStatement
349+
| SequenceExpression
347350

348351
export interface BlockStatement extends Node {
349352
type: NodeTypes.JS_BLOCK_STATEMENT
@@ -368,6 +371,11 @@ export interface AssignmentExpression extends Node {
368371
right: JSChildNode
369372
}
370373

374+
export interface SequenceExpression extends Node {
375+
type: NodeTypes.JS_SEQUENCE_EXPRESSION
376+
expressions: JSChildNode[]
377+
}
378+
371379
export interface ReturnStatement extends Node {
372380
type: NodeTypes.JS_RETURN_STATEMENT
373381
returns: TemplateChildNode | TemplateChildNode[] | JSChildNode
@@ -727,6 +735,16 @@ export function createAssignmentExpression(
727735
}
728736
}
729737

738+
export function createSequenceExpression(
739+
expressions: SequenceExpression['expressions']
740+
): SequenceExpression {
741+
return {
742+
type: NodeTypes.JS_SEQUENCE_EXPRESSION,
743+
expressions,
744+
loc: locStub
745+
}
746+
}
747+
730748
export function createReturnStatement(
731749
returns: ReturnStatement['returns']
732750
): ReturnStatement {

packages/compiler-core/src/codegen.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
IfStatement,
2424
AssignmentExpression,
2525
ReturnStatement,
26-
VNodeCall
26+
VNodeCall,
27+
SequenceExpression
2728
} from './ast'
2829
import { SourceMapGenerator, RawSourceMap } from 'source-map'
2930
import {
@@ -593,6 +594,9 @@ function genNode(node: CodegenNode | symbol | string, context: CodegenContext) {
593594
case NodeTypes.JS_ASSIGNMENT_EXPRESSION:
594595
!__BROWSER__ && genAssignmentExpression(node, context)
595596
break
597+
case NodeTypes.JS_SEQUENCE_EXPRESSION:
598+
!__BROWSER__ && genSequenceExpression(node, context)
599+
break
596600
case NodeTypes.JS_RETURN_STATEMENT:
597601
!__BROWSER__ && genReturnStatement(node, context)
598602
break
@@ -914,6 +918,15 @@ function genAssignmentExpression(
914918
genNode(node.right, context)
915919
}
916920

921+
function genSequenceExpression(
922+
node: SequenceExpression,
923+
context: CodegenContext
924+
) {
925+
context.push(`(`)
926+
genNodeList(node.expressions, context)
927+
context.push(`)`)
928+
}
929+
917930
function genReturnStatement(
918931
{ returns }: ReturnStatement,
919932
context: CodegenContext

packages/compiler-ssr/__tests__/ssrVModel.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('ssr: v-model', () => {
118118
return function ssrRender(_ctx, _push, _parent) {
119119
let _temp0
120120
121-
_push(\`<input\${_ssrRenderAttrs(_temp0 = _ctx.obj, _mergeProps(_temp0, _ssrGetDynamicModelProps(_temp0, _ctx.foo)))}>\`)
121+
_push(\`<input\${_ssrRenderAttrs((_temp0 = _ctx.obj, _mergeProps(_temp0, _ssrGetDynamicModelProps(_temp0, _ctx.foo))))}>\`)
122122
}"
123123
`)
124124

@@ -130,7 +130,7 @@ describe('ssr: v-model', () => {
130130
return function ssrRender(_ctx, _push, _parent) {
131131
let _temp0
132132
133-
_push(\`<input\${_ssrRenderAttrs(_temp0 = _mergeProps({ id: \\"x\\" }, _ctx.obj, { class: \\"y\\" }), _mergeProps(_temp0, _ssrGetDynamicModelProps(_temp0, _ctx.foo)))}>\`)
133+
_push(\`<input\${_ssrRenderAttrs((_temp0 = _mergeProps({ id: \\"x\\" }, _ctx.obj, { class: \\"y\\" }), _mergeProps(_temp0, _ssrGetDynamicModelProps(_temp0, _ctx.foo))))}>\`)
134134
}"
135135
`)
136136
})

packages/compiler-ssr/src/transforms/ssrTransformElement.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
TextNode,
2323
hasDynamicKeyVBind,
2424
MERGE_PROPS,
25-
isBindKey
25+
isBindKey,
26+
createSequenceExpression
2627
} from '@vue/compiler-dom'
2728
import {
2829
escapeHtml,
@@ -107,16 +108,18 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
107108
const tempId = `_temp${context.temps++}`
108109
const tempExp = createSimpleExpression(tempId, false)
109110
propsExp.arguments = [
110-
createAssignmentExpression(tempExp, props),
111-
createCallExpression(context.helper(MERGE_PROPS), [
112-
tempExp,
113-
createCallExpression(
114-
context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
115-
[
116-
tempExp, // existing props
117-
vModel.exp! // model
118-
]
119-
)
111+
createSequenceExpression([
112+
createAssignmentExpression(tempExp, props),
113+
createCallExpression(context.helper(MERGE_PROPS), [
114+
tempExp,
115+
createCallExpression(
116+
context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
117+
[
118+
tempExp, // existing props
119+
vModel.exp! // model
120+
]
121+
)
122+
])
120123
])
121124
]
122125
}

0 commit comments

Comments
 (0)