fix(compiler-sfc): model name conflict (#8798)
This commit is contained in:
parent
26ca89e5cf
commit
df81da8be9
|
@ -7,15 +7,17 @@ export default {
|
||||||
props: {
|
props: {
|
||||||
\\"modelValue\\": { required: true },
|
\\"modelValue\\": { required: true },
|
||||||
\\"count\\": {},
|
\\"count\\": {},
|
||||||
|
\\"toString\\": { type: Function },
|
||||||
},
|
},
|
||||||
emits: [\\"update:modelValue\\", \\"update:count\\"],
|
emits: [\\"update:modelValue\\", \\"update:count\\", \\"update:toString\\"],
|
||||||
setup(__props, { expose: __expose }) {
|
setup(__props, { expose: __expose }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
const modelValue = _useModel(__props, \\"modelValue\\")
|
const modelValue = _useModel(__props, \\"modelValue\\")
|
||||||
const c = _useModel(__props, \\"count\\")
|
const c = _useModel(__props, \\"count\\")
|
||||||
|
const toString = _useModel(__props, \\"toString\\")
|
||||||
|
|
||||||
return { modelValue, c }
|
return { modelValue, c, toString }
|
||||||
}
|
}
|
||||||
|
|
||||||
}"
|
}"
|
||||||
|
|
|
@ -8,6 +8,7 @@ describe('defineModel()', () => {
|
||||||
<script setup>
|
<script setup>
|
||||||
const modelValue = defineModel({ required: true })
|
const modelValue = defineModel({ required: true })
|
||||||
const c = defineModel('count')
|
const c = defineModel('count')
|
||||||
|
const toString = defineModel('toString', { type: Function })
|
||||||
</script>
|
</script>
|
||||||
`,
|
`,
|
||||||
{ defineModel: true }
|
{ defineModel: true }
|
||||||
|
@ -16,18 +17,22 @@ describe('defineModel()', () => {
|
||||||
expect(content).toMatch('props: {')
|
expect(content).toMatch('props: {')
|
||||||
expect(content).toMatch('"modelValue": { required: true },')
|
expect(content).toMatch('"modelValue": { required: true },')
|
||||||
expect(content).toMatch('"count": {},')
|
expect(content).toMatch('"count": {},')
|
||||||
expect(content).toMatch('emits: ["update:modelValue", "update:count"],')
|
expect(content).toMatch('"toString": { type: Function },')
|
||||||
|
expect(content).toMatch(
|
||||||
|
'emits: ["update:modelValue", "update:count", "update:toString"],'
|
||||||
|
)
|
||||||
expect(content).toMatch(
|
expect(content).toMatch(
|
||||||
`const modelValue = _useModel(__props, "modelValue")`
|
`const modelValue = _useModel(__props, "modelValue")`
|
||||||
)
|
)
|
||||||
expect(content).toMatch(`const c = _useModel(__props, "count")`)
|
expect(content).toMatch(`const c = _useModel(__props, "count")`)
|
||||||
expect(content).toMatch(`return { modelValue, c }`)
|
expect(content).toMatch(`return { modelValue, c, toString }`)
|
||||||
expect(content).not.toMatch('defineModel')
|
expect(content).not.toMatch('defineModel')
|
||||||
|
|
||||||
expect(bindings).toStrictEqual({
|
expect(bindings).toStrictEqual({
|
||||||
modelValue: BindingTypes.SETUP_REF,
|
modelValue: BindingTypes.SETUP_REF,
|
||||||
count: BindingTypes.PROPS,
|
count: BindingTypes.PROPS,
|
||||||
c: BindingTypes.SETUP_REF
|
c: BindingTypes.SETUP_REF,
|
||||||
|
toString: BindingTypes.SETUP_REF
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ export class ScriptCompileContext {
|
||||||
emitDecl: Node | undefined
|
emitDecl: Node | undefined
|
||||||
|
|
||||||
// defineModel
|
// defineModel
|
||||||
modelDecls: Record<string, ModelDecl> = {}
|
modelDecls: Record<string, ModelDecl> = Object.create(null)
|
||||||
|
|
||||||
// defineOptions
|
// defineOptions
|
||||||
optionsRuntimeDecl: Node | undefined
|
optionsRuntimeDecl: Node | undefined
|
||||||
|
|
Loading…
Reference in New Issue