Skip to content

Commit

Permalink
fix(compiler-sfc): model name conflict (#8798)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Oct 20, 2023
1 parent 26ca89e commit df81da8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ export default {
props: {
\\"modelValue\\": { required: true },
\\"count\\": {},
\\"toString\\": { type: Function },
},
emits: [\\"update:modelValue\\", \\"update:count\\"],
emits: [\\"update:modelValue\\", \\"update:count\\", \\"update:toString\\"],
setup(__props, { expose: __expose }) {
__expose();
const modelValue = _useModel(__props, \\"modelValue\\")
const c = _useModel(__props, \\"count\\")
const toString = _useModel(__props, \\"toString\\")
return { modelValue, c }
return { modelValue, c, toString }
}
}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('defineModel()', () => {
<script setup>
const modelValue = defineModel({ required: true })
const c = defineModel('count')
const toString = defineModel('toString', { type: Function })
</script>
`,
{ defineModel: true }
Expand All @@ -16,18 +17,22 @@ describe('defineModel()', () => {
expect(content).toMatch('props: {')
expect(content).toMatch('"modelValue": { required: true },')
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(
`const modelValue = _useModel(__props, "modelValue")`
)
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(bindings).toStrictEqual({
modelValue: BindingTypes.SETUP_REF,
count: BindingTypes.PROPS,
c: BindingTypes.SETUP_REF
c: BindingTypes.SETUP_REF,
toString: BindingTypes.SETUP_REF
})
})

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/script/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ScriptCompileContext {
emitDecl: Node | undefined

// defineModel
modelDecls: Record<string, ModelDecl> = {}
modelDecls: Record<string, ModelDecl> = Object.create(null)

// defineOptions
optionsRuntimeDecl: Node | undefined
Expand Down

0 comments on commit df81da8

Please sign in to comment.