fix(compiler-sfc): defineProps return binding or rest binding should be considered reactive
This commit is contained in:
@@ -68,7 +68,7 @@ const bar = 1
|
||||
expect(bindings).toStrictEqual({
|
||||
foo: BindingTypes.PROPS,
|
||||
bar: BindingTypes.SETUP_CONST,
|
||||
props: BindingTypes.SETUP_CONST
|
||||
props: BindingTypes.SETUP_REACTIVE_CONST
|
||||
})
|
||||
|
||||
// should remove defineOptions import and call
|
||||
|
||||
@@ -141,7 +141,7 @@ describe('sfc props transform', () => {
|
||||
foo: BindingTypes.PROPS,
|
||||
bar: BindingTypes.PROPS,
|
||||
baz: BindingTypes.PROPS,
|
||||
rest: BindingTypes.SETUP_CONST
|
||||
rest: BindingTypes.SETUP_REACTIVE_CONST
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1207,7 +1207,8 @@ export function compileScript(
|
||||
// props aliases
|
||||
if (propsDestructureDecl) {
|
||||
if (propsDestructureRestId) {
|
||||
bindingMetadata[propsDestructureRestId] = BindingTypes.SETUP_CONST
|
||||
bindingMetadata[propsDestructureRestId] =
|
||||
BindingTypes.SETUP_REACTIVE_CONST
|
||||
}
|
||||
for (const key in propsDestructuredBindings) {
|
||||
const { local } = propsDestructuredBindings[key]
|
||||
@@ -1525,14 +1526,18 @@ function walkDeclaration(
|
||||
const userReactiveBinding = userImportAlias['reactive'] || 'reactive'
|
||||
if (isCallOf(init, userReactiveBinding)) {
|
||||
// treat reactive() calls as let since it's meant to be mutable
|
||||
bindingType = BindingTypes.SETUP_LET
|
||||
bindingType = isConst
|
||||
? BindingTypes.SETUP_REACTIVE_CONST
|
||||
: BindingTypes.SETUP_LET
|
||||
} else if (
|
||||
// if a declaration is a const literal, we can mark it so that
|
||||
// the generated render fn code doesn't need to unref() it
|
||||
isDefineCall ||
|
||||
(isConst && canNeverBeRef(init!, userReactiveBinding))
|
||||
) {
|
||||
bindingType = BindingTypes.SETUP_CONST
|
||||
bindingType = isCallOf(init, DEFINE_PROPS)
|
||||
? BindingTypes.SETUP_REACTIVE_CONST
|
||||
: BindingTypes.SETUP_CONST
|
||||
} else if (isConst) {
|
||||
if (isCallOf(init, userImportAlias['ref'] || 'ref')) {
|
||||
bindingType = BindingTypes.SETUP_REF
|
||||
|
||||
Reference in New Issue
Block a user