@@ -19,7 +19,10 @@ import {
19
19
TemplateTextChildNode ,
20
20
DirectiveArguments ,
21
21
createVNodeCall ,
22
- ConstantTypes
22
+ ConstantTypes ,
23
+ JSChildNode ,
24
+ createFunctionExpression ,
25
+ createBlockStatement
23
26
} from '../ast'
24
27
import {
25
28
PatchFlags ,
@@ -58,7 +61,7 @@ import {
58
61
} from '../utils'
59
62
import { buildSlots } from './vSlot'
60
63
import { getConstantType } from './hoistStatic'
61
- import { BindingTypes } from '../options'
64
+ import { BindingMetadata , BindingTypes } from '../options'
62
65
import {
63
66
checkCompatEnabled ,
64
67
CompilerDeprecationTypes ,
@@ -459,19 +462,21 @@ export function buildProps(
459
462
const prop = props [ i ]
460
463
if ( prop . type === NodeTypes . ATTRIBUTE ) {
461
464
const { loc, name, value } = prop
462
- let isStatic = true
465
+ let valueNode = createSimpleExpression (
466
+ value ? value . content : '' ,
467
+ true ,
468
+ value ? value . loc : loc
469
+ ) as JSChildNode
463
470
if ( name === 'ref' ) {
464
471
hasRef = true
465
472
// in inline mode there is no setupState object, so we can't use string
466
473
// keys to set the ref. Instead, we need to transform it to pass the
467
474
// acrtual ref instead.
468
- if (
469
- ! __BROWSER__ &&
470
- value &&
471
- context . inline &&
472
- context . bindingMetadata [ value . content ]
473
- ) {
474
- isStatic = false
475
+ if ( ! __BROWSER__ && context . inline && value ?. content ) {
476
+ valueNode = createFunctionExpression ( [ '_value' , '_refs' ] )
477
+ valueNode . body = createBlockStatement (
478
+ processInlineRef ( context . bindingMetadata , value . content )
479
+ )
475
480
}
476
481
}
477
482
// skip is on <component>, or is="vue:xxx"
@@ -494,11 +499,7 @@ export function buildProps(
494
499
true ,
495
500
getInnerRange ( loc , 0 , name . length )
496
501
) ,
497
- createSimpleExpression (
498
- value ? value . content : '' ,
499
- isStatic ,
500
- value ? value . loc : loc
501
- )
502
+ valueNode
502
503
)
503
504
)
504
505
} else {
@@ -891,3 +892,17 @@ function stringifyDynamicPropNames(props: string[]): string {
891
892
function isComponentTag ( tag : string ) {
892
893
return tag [ 0 ] . toLowerCase ( ) + tag . slice ( 1 ) === 'component'
893
894
}
895
+
896
+ function processInlineRef (
897
+ bindings : BindingMetadata ,
898
+ raw : string
899
+ ) : JSChildNode [ ] {
900
+ const body = [ createSimpleExpression ( `_refs['${ raw } '] = _value` ) ]
901
+ const type = bindings [ raw ]
902
+ if ( type === BindingTypes . SETUP_REF ) {
903
+ body . push ( createSimpleExpression ( `${ raw } .value = _value` ) )
904
+ } else if ( type === BindingTypes . SETUP_LET ) {
905
+ body . push ( createSimpleExpression ( `${ raw } = _value` ) )
906
+ }
907
+ return body
908
+ }
0 commit comments