@@ -118,38 +118,32 @@ export function processExpression(
118
118
// setup inline mode
119
119
if ( type === BindingTypes . SETUP_CONST ) {
120
120
return raw
121
- } else if ( type === BindingTypes . SETUP_REF ) {
121
+ } else if (
122
+ type === BindingTypes . SETUP_REF ||
123
+ type === BindingTypes . SETUP_MAYBE_REF
124
+ ) {
125
+ // const binding that may or may not be ref
126
+ // if it's not a ref, then assignments don't make sense -
127
+ // so we ignore the non-ref assignment case and generate code
128
+ // that assumes the value to be a ref for more efficiency
122
129
return isAssignmentLVal || isUpdateArg
123
130
? `${ raw } .value`
124
131
: `${ context . helperString ( UNREF ) } (${ raw } )`
125
- } else if (
126
- type === BindingTypes . SETUP_MAYBE_REF ||
127
- type === BindingTypes . SETUP_LET
128
- ) {
132
+ } else if ( type === BindingTypes . SETUP_LET ) {
129
133
if ( isAssignmentLVal ) {
130
- if ( type === BindingTypes . SETUP_MAYBE_REF ) {
131
- // const binding that may or may not be ref
132
- // if it's not a ref, then the assignment doesn't make sense so
133
- // just no-op it
134
- // x = y ---> !isRef(x) ? null : x.value = y
135
- return `!${ context . helperString (
136
- IS_REF
137
- ) } (${ raw } ) ? null : ${ raw } .value`
138
- } else {
139
- // let binding.
140
- // this is a bit more tricky as we need to cover the case where
141
- // let is a local non-ref value, and we need to replicate the
142
- // right hand side value.
143
- // x = y --> isRef(x) ? x.value = y : x = y
144
- const rVal = ( parent as AssignmentExpression ) . right
145
- const rExp = rawExp . slice ( rVal . start ! - 1 , rVal . end ! - 1 )
146
- const rExpString = stringifyExpression (
147
- processExpression ( createSimpleExpression ( rExp , false ) , context )
148
- )
149
- return `${ context . helperString ( IS_REF ) } (${ raw } )${
150
- context . isTS ? ` //@ts-ignore\n` : ``
151
- } ? ${ raw } .value = ${ rExpString } : ${ raw } `
152
- }
134
+ // let binding.
135
+ // this is a bit more tricky as we need to cover the case where
136
+ // let is a local non-ref value, and we need to replicate the
137
+ // right hand side value.
138
+ // x = y --> isRef(x) ? x.value = y : x = y
139
+ const rVal = ( parent as AssignmentExpression ) . right
140
+ const rExp = rawExp . slice ( rVal . start ! - 1 , rVal . end ! - 1 )
141
+ const rExpString = stringifyExpression (
142
+ processExpression ( createSimpleExpression ( rExp , false ) , context )
143
+ )
144
+ return `${ context . helperString ( IS_REF ) } (${ raw } )${
145
+ context . isTS ? ` //@ts-ignore\n` : ``
146
+ } ? ${ raw } .value = ${ rExpString } : ${ raw } `
153
147
} else if ( isUpdateArg ) {
154
148
// make id replace parent in the code range so the raw update operator
155
149
// is removed
@@ -158,21 +152,11 @@ export function processExpression(
158
152
const { prefix : isPrefix , operator } = parent as UpdateExpression
159
153
const prefix = isPrefix ? operator : ``
160
154
const postfix = isPrefix ? `` : operator
161
- if ( type === BindingTypes . SETUP_MAYBE_REF ) {
162
- // const binding that may or may not be ref
163
- // if it's not a ref, then the assignment doesn't make sense so
164
- // just no-op it
165
- // x++ ---> !isRef(x) ? null : x.value++
166
- return `!${ context . helperString (
167
- IS_REF
168
- ) } (${ raw } ) ? null : ${ prefix } ${ raw } .value${ postfix } `
169
- } else {
170
- // let binding.
171
- // x++ --> isRef(a) ? a.value++ : a++
172
- return `${ context . helperString ( IS_REF ) } (${ raw } )${
173
- context . isTS ? ` //@ts-ignore\n` : ``
174
- } ? ${ prefix } ${ raw } .value${ postfix } : ${ prefix } ${ raw } ${ postfix } `
175
- }
155
+ // let binding.
156
+ // x++ --> isRef(a) ? a.value++ : a++
157
+ return `${ context . helperString ( IS_REF ) } (${ raw } )${
158
+ context . isTS ? ` //@ts-ignore\n` : ``
159
+ } ? ${ prefix } ${ raw } .value${ postfix } : ${ prefix } ${ raw } ${ postfix } `
176
160
} else {
177
161
return `${ context . helperString ( UNREF ) } (${ raw } )`
178
162
}
0 commit comments