Skip to content

Commit fc74eb9

Browse files
committed
fix(compiler-sfc): update to inline error message
1 parent 2b8ab9f commit fc74eb9

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

packages/compiler-core/src/errors.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export enum ErrorCodes {
9090
X_V_MODEL_ON_PROPS,
9191
X_INVALID_EXPRESSION,
9292
X_KEEP_ALIVE_INVALID_CHILDREN,
93-
X_DEFINE_MODEL_NO_ASSIGNMENT,
9493
// generic errors
9594
X_PREFIX_ID_NOT_SUPPORTED,
9695
X_MODULE_MODE_NOT_SUPPORTED,
@@ -179,7 +178,6 @@ export const errorMessages: Record<ErrorCodes, string> = {
179178
[ErrorCodes.X_INVALID_EXPRESSION]: `Error parsing JavaScript expression: `,
180179
[ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN]: `<KeepAlive> expects exactly one child component.`,
181180
[ErrorCodes.X_VNODE_HOOKS]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`,
182-
[ErrorCodes.X_DEFINE_MODEL_NO_ASSIGNMENT]: `defineModel() must be assigned to a variable. For example: const model = defineModel()`,
183181

184182
// generic errors
185183
[ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED]: `"prefixIdentifiers" option is not supported in this build of compiler.`,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BindingTypes, ErrorCodes, errorMessages } from '@vue/compiler-core'
1+
import { BindingTypes } from '@vue/compiler-core'
22
import { assertCode, compileSFCScript as compile } from '../utils'
33

44
describe('defineModel()', () => {
@@ -277,6 +277,8 @@ describe('defineModel()', () => {
277277
defineModel()
278278
</script>
279279
`),
280-
).toThrow(errorMessages[ErrorCodes.X_DEFINE_MODEL_NO_ASSIGNMENT])
280+
).toThrow(
281+
'defineModel() must be assigned to a variable. For example: const model = defineModel()',
282+
)
281283
})
282284
})

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import type { LVal, Node, TSType } from '@babel/types'
22
import type { ScriptCompileContext } from './context'
33
import { inferRuntimeType } from './resolveType'
44
import { UNKNOWN_TYPE, isCallOf, toRuntimeTypeString } from './utils'
5-
import {
6-
BindingTypes,
7-
ErrorCodes,
8-
errorMessages,
9-
unwrapTSNode,
10-
} from '@vue/compiler-dom'
5+
import { BindingTypes, unwrapTSNode } from '@vue/compiler-dom'
116

127
export const DEFINE_MODEL = 'defineModel'
138

@@ -28,7 +23,10 @@ export function processDefineModel(
2823
}
2924

3025
if (!declId) {
31-
ctx.error(errorMessages[ErrorCodes.X_DEFINE_MODEL_NO_ASSIGNMENT], node)
26+
ctx.error(
27+
'defineModel() must be assigned to a variable. For example: const model = defineModel()',
28+
node,
29+
)
3230
}
3331

3432
ctx.hasDefineModelCall = true

0 commit comments

Comments
 (0)