@@ -65,6 +65,7 @@ const DEFINE_EXPOSE = 'defineExpose'
65
65
const WITH_DEFAULTS = 'withDefaults'
66
66
67
67
const $REF = `$ref`
68
+ const $SHALLOW_REF = '$shallowRef'
68
69
const $COMPUTED = `$computed`
69
70
const $FROM_REFS = `$fromRefs`
70
71
const $RAW = `$raw`
@@ -531,7 +532,12 @@ export function compileScript(
531
532
}
532
533
533
534
function isRefSugarCall ( callee : string ) {
534
- return callee === $REF || callee === $COMPUTED || callee === $FROM_REFS
535
+ return (
536
+ callee === $REF ||
537
+ callee === $COMPUTED ||
538
+ callee === $FROM_REFS ||
539
+ callee === $SHALLOW_REF
540
+ )
535
541
}
536
542
537
543
function processRefSugar (
@@ -558,24 +564,28 @@ export function compileScript(
558
564
559
565
const callee = ( decl . init . callee as Identifier ) . name
560
566
const start = decl . init . start ! + startOffset
561
- if ( callee === $REF ) {
567
+ if ( callee === $REF || callee === $SHALLOW_REF ) {
562
568
if ( statement . kind !== 'let' ) {
563
- error ( `${ $REF } () bindings can only be declared with let.` , decl )
569
+ error ( `${ callee } () bindings can only be declared with let.` , decl )
564
570
}
565
571
if ( decl . id . type !== 'Identifier' ) {
566
572
error (
567
- `${ $REF } () bindings cannot be used with destructuring. ` +
573
+ `${ callee } () bindings cannot be used with destructuring. ` +
568
574
`If you are trying to destructure from an object of refs, ` +
569
575
`use \`let { x } = $fromRefs(obj)\`.` ,
570
576
decl . id
571
577
)
572
578
}
573
579
registerRefBinding ( decl . id )
574
- s . overwrite ( start , start + $REF . length , helper ( 'ref' ) )
580
+ s . overwrite (
581
+ start ,
582
+ start + callee . length ,
583
+ helper ( callee === $REF ? 'ref' : 'shallowRef' )
584
+ )
575
585
} else if ( callee === $COMPUTED ) {
576
586
if ( decl . id . type !== 'Identifier' ) {
577
587
error (
578
- `${ $COMPUTED } () bindings cannot be used with destructuring.` ,
588
+ `${ callee } () bindings cannot be used with destructuring.` ,
579
589
decl . id
580
590
)
581
591
}
@@ -584,7 +594,7 @@ export function compileScript(
584
594
} else if ( callee === $FROM_REFS ) {
585
595
if ( ! decl . id . type . endsWith ( 'Pattern' ) ) {
586
596
error (
587
- `${ $FROM_REFS } () declaration must be used with destructure patterns.` ,
597
+ `${ callee } () declaration must be used with destructure patterns.` ,
588
598
decl
589
599
)
590
600
}
@@ -1124,10 +1134,7 @@ export function compileScript(
1124
1134
return false // skip walk
1125
1135
} else if (
1126
1136
parent &&
1127
- isCallOf (
1128
- node ,
1129
- id => id === $REF || id === $FROM_REFS || id === $COMPUTED
1130
- ) &&
1137
+ isCallOf ( node , isRefSugarCall ) &&
1131
1138
( parent . type !== 'VariableDeclarator' || node !== parent . init )
1132
1139
) {
1133
1140
error (
0 commit comments