@@ -2,6 +2,7 @@ import { genExpression } from './expression'
2
2
import type { CodegenContext } from '../generate'
3
3
import type { DeclareOldRefIRNode , SetTemplateRefIRNode } from '../ir'
4
4
import { type CodeFragment , NEWLINE , genCall } from './utils'
5
+ import { BindingTypes , type SimpleExpressionNode } from '@vue/compiler-dom'
5
6
6
7
export const setTemplateRefIdent = `_setTemplateRef`
7
8
@@ -15,7 +16,7 @@ export function genSetTemplateRef(
15
16
...genCall (
16
17
setTemplateRefIdent , // will be generated in root scope
17
18
`n${ oper . element } ` ,
18
- genExpression ( oper . value , context ) ,
19
+ genRefValue ( oper . value , context ) ,
19
20
oper . effect ? `r${ oper . element } ` : oper . refFor ? 'void 0' : undefined ,
20
21
oper . refFor && 'true' ,
21
22
) ,
@@ -25,3 +26,20 @@ export function genSetTemplateRef(
25
26
export function genDeclareOldRef ( oper : DeclareOldRefIRNode ) : CodeFragment [ ] {
26
27
return [ NEWLINE , `let r${ oper . id } ` ]
27
28
}
29
+
30
+ function genRefValue ( value : SimpleExpressionNode , context : CodegenContext ) {
31
+ // in inline mode there is no setupState object, so we can't use string
32
+ // keys to set the ref. Instead, we need to transform it to pass the
33
+ // actual ref instead.
34
+ if ( ! __BROWSER__ && value && context . options . inline ) {
35
+ const binding = context . options . bindingMetadata [ value . content ]
36
+ if (
37
+ binding === BindingTypes . SETUP_LET ||
38
+ binding === BindingTypes . SETUP_REF ||
39
+ binding === BindingTypes . SETUP_MAYBE_REF
40
+ ) {
41
+ return [ value . content ]
42
+ }
43
+ }
44
+ return genExpression ( value , context )
45
+ }
0 commit comments