mirror of https://github.com/vuejs/core.git
perf(compiler-sfc): infer ref binding type for more built-in methods
This commit is contained in:
parent
433a58ccb6
commit
a370e8006a
|
@ -1520,4 +1520,19 @@ describe('SFC genDefaultAs', () => {
|
|||
)
|
||||
assertCode(content)
|
||||
})
|
||||
|
||||
test('binding type for edge cases', () => {
|
||||
const { bindings } = compile(
|
||||
`<script setup lang="ts">
|
||||
import { toRef } from 'vue'
|
||||
const props = defineProps<{foo: string}>()
|
||||
const foo = toRef(() => props.foo)
|
||||
</script>`
|
||||
)
|
||||
expect(bindings).toStrictEqual({
|
||||
toRef: BindingTypes.SETUP_CONST,
|
||||
props: BindingTypes.SETUP_REACTIVE_CONST,
|
||||
foo: BindingTypes.SETUP_REF
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -581,7 +581,7 @@ const props = defineProps({ foo: String })
|
|||
</script>
|
||||
`)
|
||||
expect(bindings).toStrictEqual({
|
||||
bar: BindingTypes.SETUP_MAYBE_REF,
|
||||
bar: BindingTypes.SETUP_REF,
|
||||
computed: BindingTypes.SETUP_CONST
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1095,8 +1095,16 @@ function walkDeclaration(
|
|||
: BindingTypes.SETUP_CONST
|
||||
} else if (isConst) {
|
||||
if (
|
||||
isCallOf(init, userImportAliases['ref']) ||
|
||||
isCallOf(init, DEFINE_MODEL)
|
||||
isCallOf(
|
||||
init,
|
||||
m =>
|
||||
m === userImportAliases['ref'] ||
|
||||
m === userImportAliases['computed'] ||
|
||||
m === userImportAliases['shallowRef'] ||
|
||||
m === userImportAliases['customRef'] ||
|
||||
m === userImportAliases['toRef'] ||
|
||||
m === DEFINE_MODEL
|
||||
)
|
||||
) {
|
||||
bindingType = BindingTypes.SETUP_REF
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue