Skip to content

Commit df81da8

Browse files
authored
fix(compiler-sfc): model name conflict (#8798)
1 parent 26ca89e commit df81da8

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineModel.spec.ts.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ export default {
77
props: {
88
\\"modelValue\\": { required: true },
99
\\"count\\": {},
10+
\\"toString\\": { type: Function },
1011
},
11-
emits: [\\"update:modelValue\\", \\"update:count\\"],
12+
emits: [\\"update:modelValue\\", \\"update:count\\", \\"update:toString\\"],
1213
setup(__props, { expose: __expose }) {
1314
__expose();
1415
1516
const modelValue = _useModel(__props, \\"modelValue\\")
1617
const c = _useModel(__props, \\"count\\")
18+
const toString = _useModel(__props, \\"toString\\")
1719
18-
return { modelValue, c }
20+
return { modelValue, c, toString }
1921
}
2022
2123
}"

packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('defineModel()', () => {
88
<script setup>
99
const modelValue = defineModel({ required: true })
1010
const c = defineModel('count')
11+
const toString = defineModel('toString', { type: Function })
1112
</script>
1213
`,
1314
{ defineModel: true }
@@ -16,18 +17,22 @@ describe('defineModel()', () => {
1617
expect(content).toMatch('props: {')
1718
expect(content).toMatch('"modelValue": { required: true },')
1819
expect(content).toMatch('"count": {},')
19-
expect(content).toMatch('emits: ["update:modelValue", "update:count"],')
20+
expect(content).toMatch('"toString": { type: Function },')
21+
expect(content).toMatch(
22+
'emits: ["update:modelValue", "update:count", "update:toString"],'
23+
)
2024
expect(content).toMatch(
2125
`const modelValue = _useModel(__props, "modelValue")`
2226
)
2327
expect(content).toMatch(`const c = _useModel(__props, "count")`)
24-
expect(content).toMatch(`return { modelValue, c }`)
28+
expect(content).toMatch(`return { modelValue, c, toString }`)
2529
expect(content).not.toMatch('defineModel')
2630

2731
expect(bindings).toStrictEqual({
2832
modelValue: BindingTypes.SETUP_REF,
2933
count: BindingTypes.PROPS,
30-
c: BindingTypes.SETUP_REF
34+
c: BindingTypes.SETUP_REF,
35+
toString: BindingTypes.SETUP_REF
3136
})
3237
})
3338

packages/compiler-sfc/src/script/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class ScriptCompileContext {
5353
emitDecl: Node | undefined
5454

5555
// defineModel
56-
modelDecls: Record<string, ModelDecl> = {}
56+
modelDecls: Record<string, ModelDecl> = Object.create(null)
5757

5858
// defineOptions
5959
optionsRuntimeDecl: Node | undefined

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy