Skip to content

Commit 85a90cc

Browse files
committed
fix: use modelValueModifiers intead of modelModifiers
1 parent 021f8f3 commit 85a90cc

File tree

7 files changed

+26
-28
lines changed

7 files changed

+26
-28
lines changed

packages/compiler-core/__tests__/transforms/vModel.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ describe('compiler: transform v-model', () => {
449449
expect(codegen.dynamicProps).toBe(`["modelValue", "onUpdate:modelValue"]`)
450450
})
451451

452-
test('should generate modelModifiers for component v-model', () => {
452+
test('should generate modelValueModifiers for component v-model', () => {
453453
const root = parseWithVModel('<Comp v-model.trim.bar-baz="foo" />', {
454454
prefixIdentifiers: true,
455455
})
@@ -461,15 +461,15 @@ describe('compiler: transform v-model', () => {
461461
{ key: { content: `modelValue` } },
462462
{ key: { content: `onUpdate:modelValue` } },
463463
{
464-
key: { content: 'modelModifiers' },
464+
key: { content: 'modelValueModifiers' },
465465
value: {
466466
content: `{ trim: true, "bar-baz": true }`,
467467
isStatic: false,
468468
},
469469
},
470470
],
471471
})
472-
// should NOT include modelModifiers in dynamicPropNames because it's never
472+
// should NOT include modelValueModifiers in dynamicPropNames because it's never
473473
// gonna change
474474
expect(vnodeCall.dynamicProps).toBe(`["modelValue", "onUpdate:modelValue"]`)
475475
})

packages/compiler-core/src/transforms/vModel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
138138
? isStaticExp(arg)
139139
? `${arg.content}Modifiers`
140140
: createCompoundExpression([arg, ' + "Modifiers"'])
141-
: `modelModifiers`
141+
: `modelValueModifiers`
142142
props.push(
143143
createObjectProperty(
144144
modifiersKey,

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`defineModel() > basic usage 1`] = `
66
export default {
77
props: {
88
"modelValue": { required: true },
9-
"modelModifiers": {},
9+
"modelValueModifiers": {},
1010
"count": {},
1111
"countModifiers": {},
1212
"toString": { type: Function },
@@ -34,7 +34,7 @@ export default /*@__PURE__*/_defineComponent({
3434
"modelValue": {
3535
required: true
3636
},
37-
"modelModifiers": {},
37+
"modelValueModifiers": {},
3838
},
3939
emits: ["update:modelValue"],
4040
setup(__props, { expose: __expose }) {
@@ -60,7 +60,7 @@ export default /*@__PURE__*/_defineComponent({
6060
default: 0,
6161
required: true,
6262
},
63-
"modelModifiers": {},
63+
"modelValueModifiers": {},
6464
},
6565
emits: ["update:modelValue"],
6666
setup(__props, { expose: __expose }) {
@@ -86,7 +86,7 @@ export default /*@__PURE__*/_defineComponent({
8686
}, {
8787
"modelValue": {
8888
},
89-
"modelModifiers": {},
89+
"modelValueModifiers": {},
9090
}),
9191
emits: ["update:modelValue"],
9292
setup(__props: any, { expose: __expose }) {
@@ -109,7 +109,7 @@ exports[`defineModel() > w/ Boolean And Function types, production mode 1`] = `
109109
export default /*@__PURE__*/_defineComponent({
110110
props: {
111111
"modelValue": { type: [Boolean, String] },
112-
"modelModifiers": {},
112+
"modelValueModifiers": {},
113113
},
114114
emits: ["update:modelValue"],
115115
setup(__props, { expose: __expose }) {
@@ -150,7 +150,7 @@ exports[`defineModel() > w/ defineProps and defineEmits 1`] = `
150150
export default {
151151
props: /*@__PURE__*/_mergeModels({ foo: String }, {
152152
"modelValue": { default: 0 },
153-
"modelModifiers": {},
153+
"modelValueModifiers": {},
154154
}),
155155
emits: /*@__PURE__*/_mergeModels(['change'], ["update:modelValue"]),
156156
setup(__props, { expose: __expose }) {
@@ -172,7 +172,7 @@ exports[`defineModel() > w/ types, basic usage 1`] = `
172172
export default /*@__PURE__*/_defineComponent({
173173
props: {
174174
"modelValue": { type: [Boolean, String] },
175-
"modelModifiers": {},
175+
"modelValueModifiers": {},
176176
"count": { type: Number },
177177
"countModifiers": {},
178178
"disabled": { type: Number, ...{ required: false } },
@@ -201,7 +201,7 @@ exports[`defineModel() > w/ types, production mode 1`] = `
201201
export default /*@__PURE__*/_defineComponent({
202202
props: {
203203
"modelValue": { type: Boolean },
204-
"modelModifiers": {},
204+
"modelValueModifiers": {},
205205
"fn": {},
206206
"fnModifiers": {},
207207
"fnWithDefault": { type: Function, ...{ default: () => null } },
@@ -233,7 +233,7 @@ exports[`defineModel() > w/ types, production mode, boolean + multiple types 1`]
233233
export default /*@__PURE__*/_defineComponent({
234234
props: {
235235
"modelValue": { type: [Boolean, String, Object] },
236-
"modelModifiers": {},
236+
"modelValueModifiers": {},
237237
},
238238
emits: ["update:modelValue"],
239239
setup(__props, { expose: __expose }) {
@@ -253,7 +253,7 @@ exports[`defineModel() > w/ types, production mode, function + runtime opts + mu
253253
export default /*@__PURE__*/_defineComponent({
254254
props: {
255255
"modelValue": { type: [Number, Function], ...{ default: () => 1 } },
256-
"modelModifiers": {},
256+
"modelValueModifiers": {},
257257
},
258258
emits: ["update:modelValue"],
259259
setup(__props, { expose: __expose }) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('defineModel()', () => {
9494
)
9595
assertCode(content)
9696
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
97-
expect(content).toMatch('"modelModifiers": {}')
97+
expect(content).toMatch('"modelValueModifiers": {}')
9898
expect(content).toMatch('"count": { type: Number }')
9999
expect(content).toMatch(
100100
'"disabled": { type: Number, ...{ required: false } }',

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ export function genModelProps(ctx: ScriptCompileContext) {
167167
modelPropsDecl += `\n ${JSON.stringify(name)}: ${decl},`
168168

169169
// also generate modifiers prop
170-
const modifierPropName = JSON.stringify(
171-
name === 'modelValue' ? `modelModifiers` : `${name}Modifiers`,
172-
)
170+
const modifierPropName = JSON.stringify(`${name}Modifiers`)
173171
modelPropsDecl += `\n ${modifierPropName}: {},`
174172
}
175173
return `{${modelPropsDecl}\n }`

packages/runtime-core/__tests__/componentEmits.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ describe('component: emit', () => {
325325
const Comp = () =>
326326
h(Foo, {
327327
modelValue: null,
328-
modelModifiers: { number: true },
328+
modelValueModifiers: { number: true },
329329
'onUpdate:modelValue': fn1,
330330

331331
foo: null,
@@ -356,7 +356,7 @@ describe('component: emit', () => {
356356
const Comp = () =>
357357
h(Foo, {
358358
modelValue: null,
359-
modelModifiers: { trim: true },
359+
modelValueModifiers: { trim: true },
360360
'onUpdate:modelValue': fn1,
361361

362362
foo: null,
@@ -410,7 +410,7 @@ describe('component: emit', () => {
410410
const Comp = () =>
411411
h(Foo, {
412412
modelValue: null,
413-
modelModifiers: { trim: true },
413+
modelValueModifiers: { trim: true },
414414
'onUpdate:modelValue': fn1,
415415

416416
firstName: null,
@@ -464,7 +464,7 @@ describe('component: emit', () => {
464464
const Comp = () =>
465465
h(Foo, {
466466
modelValue: null,
467-
modelModifiers: { trim: true, number: true },
467+
modelValueModifiers: { trim: true, number: true },
468468
'onUpdate:modelValue': fn1,
469469

470470
foo: null,
@@ -492,7 +492,7 @@ describe('component: emit', () => {
492492
const Comp = () =>
493493
h(Foo, {
494494
modelValue: null,
495-
modelModifiers: { trim: true },
495+
modelValueModifiers: { trim: true },
496496
'onUpdate:modelValue': fn,
497497
})
498498

packages/runtime-core/src/helpers/useModel.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ export const getModelModifiers = (
121121
props: Record<string, any>,
122122
modelName: string,
123123
): Record<string, boolean> | undefined => {
124-
return modelName === 'modelValue' || modelName === 'model-value'
125-
? props.modelModifiers
126-
: props[`${modelName}Modifiers`] ||
127-
props[`${camelize(modelName)}Modifiers`] ||
128-
props[`${hyphenate(modelName)}Modifiers`]
124+
return (
125+
props[`${modelName}Modifiers`] ||
126+
props[`${camelize(modelName)}Modifiers`] ||
127+
props[`${hyphenate(modelName)}Modifiers`]
128+
)
129129
}

0 commit comments

Comments
 (0)