@@ -65,6 +65,7 @@ const DEFINE_EXPOSE = 'defineExpose'
6565const WITH_DEFAULTS = 'withDefaults'
6666
6767const $REF = `$ref`
68+ const $SHALLOW_REF = '$shallowRef'
6869const $COMPUTED = `$computed`
6970const $FROM_REFS = `$fromRefs`
7071const $RAW = `$raw`
@@ -531,7 +532,12 @@ export function compileScript(
531532 }
532533
533534 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+ )
535541 }
536542
537543 function processRefSugar (
@@ -558,24 +564,28 @@ export function compileScript(
558564
559565 const callee = ( decl . init . callee as Identifier ) . name
560566 const start = decl . init . start ! + startOffset
561- if ( callee === $REF ) {
567+ if ( callee === $REF || callee === $SHALLOW_REF ) {
562568 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 )
564570 }
565571 if ( decl . id . type !== 'Identifier' ) {
566572 error (
567- `${ $REF } () bindings cannot be used with destructuring. ` +
573+ `${ callee } () bindings cannot be used with destructuring. ` +
568574 `If you are trying to destructure from an object of refs, ` +
569575 `use \`let { x } = $fromRefs(obj)\`.` ,
570576 decl . id
571577 )
572578 }
573579 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+ )
575585 } else if ( callee === $COMPUTED ) {
576586 if ( decl . id . type !== 'Identifier' ) {
577587 error (
578- `${ $COMPUTED } () bindings cannot be used with destructuring.` ,
588+ `${ callee } () bindings cannot be used with destructuring.` ,
579589 decl . id
580590 )
581591 }
@@ -584,7 +594,7 @@ export function compileScript(
584594 } else if ( callee === $FROM_REFS ) {
585595 if ( ! decl . id . type . endsWith ( 'Pattern' ) ) {
586596 error (
587- `${ $FROM_REFS } () declaration must be used with destructure patterns.` ,
597+ `${ callee } () declaration must be used with destructure patterns.` ,
588598 decl
589599 )
590600 }
@@ -1124,10 +1134,7 @@ export function compileScript(
11241134 return false // skip walk
11251135 } else if (
11261136 parent &&
1127- isCallOf (
1128- node ,
1129- id => id === $REF || id === $FROM_REFS || id === $COMPUTED
1130- ) &&
1137+ isCallOf ( node , isRefSugarCall ) &&
11311138 ( parent . type !== 'VariableDeclarator' || node !== parent . init )
11321139 ) {
11331140 error (
0 commit comments