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)
|
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>
|
</script>
|
||||||
`)
|
`)
|
||||||
expect(bindings).toStrictEqual({
|
expect(bindings).toStrictEqual({
|
||||||
bar: BindingTypes.SETUP_MAYBE_REF,
|
bar: BindingTypes.SETUP_REF,
|
||||||
computed: BindingTypes.SETUP_CONST
|
computed: BindingTypes.SETUP_CONST
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1095,8 +1095,16 @@ function walkDeclaration(
|
||||||
: BindingTypes.SETUP_CONST
|
: BindingTypes.SETUP_CONST
|
||||||
} else if (isConst) {
|
} else if (isConst) {
|
||||||
if (
|
if (
|
||||||
isCallOf(init, userImportAliases['ref']) ||
|
isCallOf(
|
||||||
isCallOf(init, DEFINE_MODEL)
|
init,
|
||||||
|
m =>
|
||||||
|
m === userImportAliases['ref'] ||
|
||||||
|
m === userImportAliases['computed'] ||
|
||||||
|
m === userImportAliases['shallowRef'] ||
|
||||||
|
m === userImportAliases['customRef'] ||
|
||||||
|
m === userImportAliases['toRef'] ||
|
||||||
|
m === DEFINE_MODEL
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
bindingType = BindingTypes.SETUP_REF
|
bindingType = BindingTypes.SETUP_REF
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue