2019-10-09 23:13:13 +08:00
|
|
|
import {
|
|
|
|
SourceLocation,
|
|
|
|
CompilerError,
|
|
|
|
createCompilerError,
|
|
|
|
ErrorCodes
|
|
|
|
} from '@vue/compiler-core'
|
|
|
|
|
|
|
|
export interface DOMCompilerError extends CompilerError {
|
|
|
|
code: DOMErrorCodes
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createDOMCompilerError(
|
|
|
|
code: DOMErrorCodes,
|
|
|
|
loc?: SourceLocation
|
|
|
|
): DOMCompilerError {
|
|
|
|
return createCompilerError(
|
|
|
|
code,
|
|
|
|
loc,
|
|
|
|
__DEV__ || !__BROWSER__ ? DOMErrorMessages : undefined
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const enum DOMErrorCodes {
|
|
|
|
X_V_HTML_NO_EXPRESSION = ErrorCodes.__EXTEND_POINT__,
|
|
|
|
X_V_HTML_WITH_CHILDREN,
|
|
|
|
X_V_TEXT_NO_EXPRESSION,
|
2019-10-11 06:02:51 +08:00
|
|
|
X_V_TEXT_WITH_CHILDREN,
|
|
|
|
X_V_MODEL_ON_INVALID_ELEMENT,
|
2019-10-16 00:23:38 +08:00
|
|
|
X_V_MODEL_ARG_ON_ELEMENT,
|
2019-11-25 11:04:26 +08:00
|
|
|
X_V_MODEL_ON_FILE_INPUT_ELEMENT,
|
2020-02-06 03:23:03 +08:00
|
|
|
X_V_MODEL_UNNECESSARY_VALUE,
|
2020-02-05 01:20:51 +08:00
|
|
|
X_V_SHOW_NO_EXPRESSION,
|
|
|
|
__EXTEND_POINT__
|
2019-10-09 23:13:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const DOMErrorMessages: { [code: number]: string } = {
|
|
|
|
[DOMErrorCodes.X_V_HTML_NO_EXPRESSION]: `v-html is missing expression.`,
|
|
|
|
[DOMErrorCodes.X_V_HTML_WITH_CHILDREN]: `v-html will override element children.`,
|
|
|
|
[DOMErrorCodes.X_V_TEXT_NO_EXPRESSION]: `v-text is missing expression.`,
|
2019-10-11 06:02:51 +08:00
|
|
|
[DOMErrorCodes.X_V_TEXT_WITH_CHILDREN]: `v-text will override element children.`,
|
|
|
|
[DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
2019-10-16 00:23:38 +08:00
|
|
|
[DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT]: `v-model argument is not supported on plain elements.`,
|
2019-11-25 11:04:26 +08:00
|
|
|
[DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT]: `v-model cannot used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
2020-02-06 03:23:03 +08:00
|
|
|
[DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
2019-11-25 11:04:26 +08:00
|
|
|
[DOMErrorCodes.X_V_SHOW_NO_EXPRESSION]: `v-show is missing expression.`
|
2019-10-09 23:13:13 +08:00
|
|
|
}
|